$$include '../../meta/macros.ptl'

import [mix linreg clamp fallback] from "@iosevka/util"
import [DesignParameters] from "../../meta/aesthetics.mjs"

glyph-module

glyph-block Symbol-Geometric-Ballot-Box : for-width-kinds WideWidth1
	glyph-block-import CommonShapes
	glyph-block-import Common-Derivatives
	glyph-block-import Symbol-Geometric-Shared : GeometricDim GeometricSizes

	define Geom : GeometricDim MosaicUnitWidth MosaicWidth

	alias [MangleName 'ballotBox'] [MangleUnicode 0x2610] [MangleName 'whiteSquare']

	define [CrossMark cx cy size sw] : glyph-proc
		include : dispiro
			widths.center sw
			corner (cx - size) (cy - size)
			corner (cx + size) (cy + size)
		include : dispiro
			widths.center sw
			corner (cx + size) (cy - size)
			corner (cx - size) (cy + size)

	define [UpArrowMark cx cy size sw] : glyph-proc
		local size2 : size / 1.5
		include : intersection [MaskLeft cx] : dispiro
			widths.center sw
			corner (cx - size2 * 2) (cy - size2)
			corner (cx + size2) (cy + size2 * 2)
		include : intersection [MaskRight cx] : dispiro
			widths.center sw
			corner (cx - size2) (cy + size2 * 2)
			corner (cx + size2 * 2) (cy - size2)

	define bbGap : Math.max (Geom.Size / 6) [AdviceStroke 5 Geom.Scalar]
	define swMark : Math.min GeometryStroke : AdviceStroke 5 Geom.Scalar
	define lightSwMark : UnicodeWeightGrade 300 Geom.Scalar GeometryStroke
	define boldSwMark  : UnicodeWeightGrade 700 Geom.Scalar GeometryStroke
	define bbSize : Geom.Size - bbGap - swMark * 0.75
	define circXSize : (Geom.Size - bbGap) * Math.SQRT1_2 - swMark * 0.75

	create-glyph [MangleName 'checkedBallotBox'] [MangleUnicode 0x2611] : glyph-proc
		local k1 0.4
		local k2 0.425
		local k3 1
		include [refer-glyph : MangleName 'whiteSquare'] AS_BASE ALSO_METRICS

		local z1 : corner (Geom.MidX - bbSize) [mix (Geom.MidY - bbSize) (Geom.MidY + bbSize) k1]
		local z2 : corner [mix (Geom.MidX - bbSize) (Geom.MidX + bbSize) k2] (Geom.MidY - bbSize)
		local z3 : corner (Geom.MidX + bbSize) [mix (Geom.MidY - bbSize) (Geom.MidY + bbSize) k3]

		include : intersection
			spiro-outline z1 z2 z3 [corner z1.x z3.y]
			union
				dispiro [widths.lhs swMark] z1 z2
				dispiro [widths.lhs swMark] z2 z3

	create-glyph [MangleName 'crossBallotBox'] [MangleUnicode 0x2612] : glyph-proc
		include [refer-glyph : MangleName 'whiteSquare'] AS_BASE ALSO_METRICS
		include : CrossMark Geom.MidX Geom.MidY bbSize swMark

	create-glyph [MangleName 'lightCrossBallotBox'] [MangleUnicode 0x2BBD] : glyph-proc
		include [refer-glyph : MangleName 'whiteSquare'] AS_BASE ALSO_METRICS
		include : CrossMark Geom.MidX Geom.MidY bbSize lightSwMark

	create-glyph [MangleName 'crossCircle'] [MangleUnicode 0x2BBE] : glyph-proc
		include [refer-glyph : MangleName 'whiteCircle'] AS_BASE ALSO_METRICS
		include : CrossMark Geom.MidX Geom.MidY circXSize swMark

	create-glyph [MangleName 'boldCrossCircle'] [MangleUnicode 0x2BBF] : glyph-proc
		include [refer-glyph : MangleName 'whiteCircle'] AS_BASE ALSO_METRICS
		include : CrossMark Geom.MidX Geom.MidY circXSize boldSwMark

	do "Delete Symbols"
		glyph-block-import Symbol-Geometric-Shared : ConvexPolygonOutline

		define delGap : Math.max (Geom.Size / 6) [AdviceStroke 5 Geom.Scalar]
		define delSize : (Geom.Size - delGap) / 1.5 - swMark * 0.75

		define [RightFingerpostFill cx cy r] : begin
			define skew : r * 1 / 4
			return : spiro-outline
				corner (cx - r)        (cy + r / 1.5)
				corner (cx + r - skew) (cy + r / 1.5)
				corner (cx + r + skew)  cy
				corner (cx + r - skew) (cy - r / 1.5)
				corner (cx - r)        (cy - r / 1.5)

		define [LeftFingerpostFill cx cy r] : begin
			define skew : r * 1 / 4
			return : spiro-outline
				corner (cx + r)        (cy - r / 1.5)
				corner (cx + r)        (cy + r / 1.5)
				corner (cx - r + skew) (cy + r / 1.5)
				corner (cx - r - skew)  cy
				corner (cx - r + skew) (cy - r / 1.5)

		create-glyph [MangleName 'UpArrowInRectangle'] [MangleUnicode 0x2BB9] : glyph-proc
			include [refer-glyph : MangleName 'whiteHoriRectangle'] AS_BASE ALSO_METRICS
			include : UpArrowMark Geom.MidX Geom.MidY delSize swMark

		create-glyph [MangleName 'xInRectangle'] [MangleUnicode 0x2327] : glyph-proc
			include [refer-glyph : MangleName 'whiteHoriRectangle'] AS_BASE ALSO_METRICS
			include : CrossMark Geom.MidX Geom.MidY delSize swMark

		create-glyph [MangleName 'deleteRight'] [MangleUnicode 0x2326] : glyph-proc
			set-width Geom.Width
			include : ConvexPolygonOutline [new-glyph : RightFingerpostFill Geom.MidX Geom.MidY Geom.Size] GeometryStroke
			include : CrossMark Geom.MidX Geom.MidY delSize swMark

		create-glyph [MangleName 'deleteLeft'] [MangleUnicode 0x232B] : glyph-proc
			set-width Geom.Width
			include : ConvexPolygonOutline [new-glyph : LeftFingerpostFill Geom.MidX Geom.MidY Geom.Size] GeometryStroke
			include : CrossMark Geom.MidX Geom.MidY delSize swMark
