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

import [mix linreg clamp fallback] from "@iosevka/util"
import as Gr from "@iosevka/glyph/relation"

glyph-module

glyph-block Symbol-Mosaic-Smooth : begin
	glyph-block-import CommonShapes
	glyph-block-import Common-Derivatives

	for-width-kinds WideWidth4

		define top     fontMetrics.os2.sTypoAscender
		define bottom  fontMetrics.os2.sTypoDescender
		define left    0
		define right   MosaicWidth

		# Corner numbers
		# 1 2 3
		# 4   5
		# 6   7
		# 8 9 0
		define [PatternCorner23 bit] : match bit
			1 : corner [mix left right (0 / 2)] [mix top bottom (0 / 3)]
			2 : corner [mix left right (1 / 2)] [mix top bottom (0 / 3)]
			3 : corner [mix left right (2 / 2)] [mix top bottom (0 / 3)]
			4 : corner [mix left right (0 / 2)] [mix top bottom (1 / 3)]
			5 : corner [mix left right (2 / 2)] [mix top bottom (1 / 3)]
			6 : corner [mix left right (0 / 2)] [mix top bottom (2 / 3)]
			7 : corner [mix left right (2 / 2)] [mix top bottom (2 / 3)]
			8 : corner [mix left right (0 / 2)] [mix top bottom (3 / 3)]
			9 : corner [mix left right (1 / 2)] [mix top bottom (3 / 3)]
			0 : corner [mix left right (2 / 2)] [mix top bottom (3 / 3)]

		# Corner numbers
		# 1 2 3
		# 4 5 6
		# 7 8 9
		define [PatternCorner22 bit] : match bit
			1 : corner [mix left right (0 / 2)] [mix top bottom (0 / 2)]
			2 : corner [mix left right (1 / 2)] [mix top bottom (0 / 2)]
			3 : corner [mix left right (2 / 2)] [mix top bottom (0 / 2)]
			4 : corner [mix left right (0 / 2)] [mix top bottom (1 / 2)]
			5 : corner [mix left right (1 / 2)] [mix top bottom (1 / 2)]
			6 : corner [mix left right (2 / 2)] [mix top bottom (1 / 2)]
			7 : corner [mix left right (0 / 2)] [mix top bottom (2 / 2)]
			8 : corner [mix left right (1 / 2)] [mix top bottom (2 / 2)]
			9 : corner [mix left right (2 / 2)] [mix top bottom (2 / 2)]

		define [PatternPolygon22 bits] : spiro-outline : bits.map : x => [PatternCorner22 (x - 0)]

		define [SmoothMosaic23 unicode pattern] : begin
			create-glyph [MangleName ('blockMosaicSmooth23/' + pattern)] [MangleUnicode unicode] : glyph-proc
				set-width MosaicWidth
				include : ForceUpright
				define corners : [pattern.split ''].map : x => [PatternCorner23 (x - 0)]
				include : spiro-outline corners

		SmoothMosaic23 0x1FB3C '689'
		SmoothMosaic23 0x1FB3D '680'
		SmoothMosaic23 0x1FB3E '489'
		SmoothMosaic23 0x1FB3F '480'
		SmoothMosaic23 0x1FB40 '189'
		SmoothMosaic23 0x1FB41 '42308'
		SmoothMosaic23 0x1FB42 '4308'
		SmoothMosaic23 0x1FB43 '62308'
		SmoothMosaic23 0x1FB44 '6308'
		SmoothMosaic23 0x1FB45 '2308'
		SmoothMosaic23 0x1FB46 '6508'
		SmoothMosaic23 0x1FB47 '970'
		SmoothMosaic23 0x1FB48 '870'
		SmoothMosaic23 0x1FB49 '950'
		SmoothMosaic23 0x1FB4A '850'
		SmoothMosaic23 0x1FB4B '930'
		SmoothMosaic23 0x1FB4C '25081'
		SmoothMosaic23 0x1FB4D '5081'
		SmoothMosaic23 0x1FB4E '27081'
		SmoothMosaic23 0x1FB4F '7081'
		SmoothMosaic23 0x1FB50 '2081'
		SmoothMosaic23 0x1FB51 '7084'
		SmoothMosaic23 0x1FB52 '69031'
		SmoothMosaic23 0x1FB53 '6031'
		SmoothMosaic23 0x1FB54 '49031'
		SmoothMosaic23 0x1FB55 '4031'
		SmoothMosaic23 0x1FB56 '9031'
		SmoothMosaic23 0x1FB57 '142'
		SmoothMosaic23 0x1FB58 '143'
		SmoothMosaic23 0x1FB59 '162'
		SmoothMosaic23 0x1FB5A '163'
		SmoothMosaic23 0x1FB5B '182'
		SmoothMosaic23 0x1FB5C '1653'
		SmoothMosaic23 0x1FB5D '18973'
		SmoothMosaic23 0x1FB5E '1873'
		SmoothMosaic23 0x1FB5F '18953'
		SmoothMosaic23 0x1FB60 '1853'
		SmoothMosaic23 0x1FB61 '1893'
		SmoothMosaic23 0x1FB62 '235'
		SmoothMosaic23 0x1FB63 '135'
		SmoothMosaic23 0x1FB64 '237'
		SmoothMosaic23 0x1FB65 '137'
		SmoothMosaic23 0x1FB66 '230'
		SmoothMosaic23 0x1FB67 '1473'

		define [SmoothMosaic22 unicode pattern] : begin
			create-glyph [MangleName ('blockMosaicSmooth22/' + pattern)] [if unicode [MangleUnicode unicode] null] : glyph-proc
				set-width MosaicWidth
				include : ForceUpright
				define corners : [pattern.split ''].map : x => [PatternCorner22 (x - 0)]
				include : spiro-outline corners

		SmoothMosaic22 0x1FB68 '15793'
		SmoothMosaic22 0x1FB69 '17935'
		SmoothMosaic22 0x1FB6A '17953'
		SmoothMosaic22 0x1FB6B '17593'
		SmoothMosaic22 0x1FB6C '175'
		SmoothMosaic22 0x1FB6D '315'
		SmoothMosaic22 0x1FB6E '359'
		SmoothMosaic22 0x1FB6F '579'
		SmoothMosaic22 0x1FB9A '1379'
		SmoothMosaic22 0x1FB9B '1739'

		SmoothMosaic22 null '138'
		SmoothMosaic22 null '167'
		SmoothMosaic22 null '279'
		SmoothMosaic22 null '349'
		# SmoothMosaic22 null '2486'
		Gr.linkSingleGlyphPairGr glyphStore [MangleName 'blackTriangleUp']    [MangleName 'blockMosaicSmooth22/279'] Gr.MosaicForm
		Gr.linkSingleGlyphPairGr glyphStore [MangleName 'blackTriangleDown']  [MangleName 'blockMosaicSmooth22/138'] Gr.MosaicForm
		Gr.linkSingleGlyphPairGr glyphStore [MangleName 'blackTriangleLeft']  [MangleName 'blockMosaicSmooth22/349'] Gr.MosaicForm
		Gr.linkSingleGlyphPairGr glyphStore [MangleName 'blackTriangleRight'] [MangleName 'blockMosaicSmooth22/167'] Gr.MosaicForm
		# Gr.linkSingleGlyphPairGr glyphStore [MangleName 'blackDiamond'] [MangleName 'blockMosaicSmooth22/2486'] Gr.MosaicForm
