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

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

glyph-module

glyph-block Symbol-Geometric-Dice : 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

	define diceCombinations : list
		list 0x2680 'whiteSquare' 7   { { 1 1 } }
		list 0x2681 'whiteSquare' 7   { { 0 0 } { 2 2 } }
		list 0x2682 'whiteSquare' 7   { { 0 0 } { 1 1 } { 2 2 } }
		list 0x2683 'whiteSquare' 7   { { 0 0 } { 2 0 } { 0 2 } { 2 2 } }
		list 0x2684 'whiteSquare' 7   { { 0 0 } { 2 0 } { 1 1 } { 0 2 } { 2 2 } }
		list 0x2685 'whiteSquare' 7   { { 0 0 } { 0 1 } { 0 2 } { 2 0 } { 2 1 } { 2 2 } }
		list 0x2686 'whiteCircle' 4.5 { { (5 / 3) 1 } }
		list 0x2687 'whiteCircle' 4.5 { { (1 / 3) 1 } { (5 / 3) 1 } }

	foreach { u frame dotSizeFactor dots } [items-of diceCombinations] : begin
		create-glyph [MangleName : NameUni u] [MangleUnicode u] : glyph-proc
			include [refer-glyph : MangleName frame] AS_BASE ALSO_METRICS
			define dr : DotRadius / Stroke * [Math.min [AdviceStroke dotSizeFactor Geom.Scalar] [AdviceStroke 7 2]]
			define xLeftEx   : Geom.MidX - Geom.Size + GeometryStroke
			define xRightEx  : Geom.MidX + Geom.Size - GeometryStroke
			define yBottomEx : Geom.MidY + Geom.Size - GeometryStroke
			define yTopEx    : Geom.MidY - Geom.Size + GeometryStroke
			define xLeft     : mix xLeftEx xRightEx (1 / 5)
			define xRight    : mix xLeftEx xRightEx (4 / 5)
			define yBottom   : mix yBottomEx yTopEx (1 / 5)
			define yTop      : mix yBottomEx yTopEx (4 / 5)
			foreach { px py } [items-of dots] : begin
				include : Circle.Outline.DotAt
					mix xLeft xRight (px / 2)
					mix yBottom yTop (py / 2)
					begin dr

	create-glyph [MangleName 'dottedWhiteTriangle'] [MangleUnicode 0x25EC] : glyph-proc
		set-width Geom.Width
		include : refer-glyph : MangleName 'whiteTriangleUp'
		include : Circle.Outline.DotAt Geom.MidX (Geom.MidY - Geom.Size / 3) [Math.min (Geom.Width / 8	) PeriodRadius]

glyph-block Symbol-Geometric-Dotted : for-width-kinds WideWidth4
	glyph-block-import CommonShapes
	glyph-block-import Common-Derivatives
	glyph-block-import Symbol-Geometric-Shared : GeometricDim GeometricSizes

	define Geom : GeometricDim MosaicUnitWidth MosaicWidth
	define Size : GeometricSizes Geom

	create-glyph [MangleName 'dottedCircle'] [MangleUnicode 0x25CC] : glyph-proc
		set-width Geom.Width
		include : [DivFrame Geom.Scalar].markSet.plus
		local n : 12 * [Math.ceil Geom.Scalar]
		local fine : AdviceStroke 10
		foreach j [range 0 n] : begin
			local angle : Math.PI * 2 * j / n
			local cx : Geom.MidX + (Geom.Right - Geom.MidX) * [Math.cos angle]
			local cy : Geom.MidY + (Geom.Right - Geom.MidX) * [Math.sin angle]
			include : Circle.Outline.At cx cy fine

	create-glyph [MangleName 'dottedSquare'] [MangleUnicode 0x2B1A] : glyph-proc
		set-width Geom.Width
		include : [DivFrame Geom.Scalar].markSet.plus
		local n : 4 * [Math.ceil Geom.Scalar]
		local fine : AdviceStroke 10
		local box : object
			Left : Geom.Left + fine
			Right : Geom.Right - fine
			Top : Geom.Top - fine
			Bot : Geom.Bot + fine
		foreach j [range 0 n] : begin
			local t : j / n
			include : Circle.Outline.At box.Left [mix box.Bot box.Top t] fine
			include : Circle.Outline.At [mix box.Left box.Right t] box.Top fine
			include : Circle.Outline.At box.Right [mix box.Top box.Bot t] fine
			include : Circle.Outline.At [mix box.Right box.Left t] box.Bot fine
