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

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

glyph-module

glyph-block Symbol-Cross : 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 Size : GeometricSizes Geom

	define normalSw     : UnicodeWeightGrade 400  Geom.Scalar GeometryStroke
	define mediumSw     : UnicodeWeightGrade 500  Geom.Scalar GeometryStroke
	define heavySw      : UnicodeWeightGrade 900  Geom.Scalar GeometryStroke

	define pBottom 2
	define pShortBar 0.6
	define pRing 0.6

	define crossHeight : Geom.Size * Size.Large.size * 2
	define shortSize : crossHeight / (pBottom + 1)
	define yTop : Geom.MidY + 0.5 * crossHeight
	define yBot : Geom.MidY - 0.5 * crossHeight
	define yCenter : yTop - shortSize

	define [LatinCross sw fSecondBar] : glyph-proc
		include : dispiro
			corner Geom.MidX yTop [widths.center sw]
			corner Geom.MidX yBot
		include : dispiro
			corner (Geom.MidX - shortSize) yCenter [widths.center sw]
			corner (Geom.MidX + shortSize) yCenter
		if fSecondBar : include : dispiro
			corner (Geom.MidX - pShortBar * shortSize) [mix yCenter yTop 0.5] [widths.center sw]
			corner (Geom.MidX + pShortBar * shortSize) [mix yCenter yTop 0.5]

	create-glyph [MangleName 'latinCross'] [MangleUnicode 0x271D] : glyph-proc
		set-width Geom.Width
		include : LatinCross mediumSw false
	create-glyph [MangleName 'heavyLatinCross'] [MangleUnicode 0x1F547] : glyph-proc
		set-width Geom.Width
		include : LatinCross heavySw false

	create-glyph [MangleName 'lorraineCross'] [MangleUnicode 0x2628] : glyph-proc
		set-width Geom.Width
		include : LatinCross mediumSw true
	create-glyph [MangleName 'orthodoxCross'] [MangleUnicode 0x2626] : glyph-proc
		set-width Geom.Width
		include : LatinCross mediumSw true
		include : dispiro
			corner (Geom.MidX - pShortBar * shortSize) [mix yBot yCenter 0.45] [widths.center mediumSw]
			corner (Geom.MidX + pShortBar * shortSize) [mix yBot yCenter 0.3]
	create-glyph [MangleName 'celticCross'] [MangleUnicode 0x1F548] : glyph-proc
		set-width Geom.Width
		include : LatinCross mediumSw false
		include : RingStrokeAt Geom.MidX yCenter (pRing * shortSize + 0.5 * mediumSw) mediumSw

	do "non-latin cross"
		create-glyph [MangleName 'malteseCross'] [MangleUnicode 0x2720] : glyph-proc
			set-width Geom.Width

			define span : normalSw / 2 + Geom.Size * 4.5 / 7
			define sw normalSw

			include : lift-@ : spiro-outline
				corner (@x1 = Geom.Left) (@y1 = Geom.MidY + span)
				corner (@x2 = @x1 + [HSwToV : 0.5 * sw]) @y1
				arcvh
				flat (@x3 = @x1 + span) (@y2 = Geom.MidY + sw / 2)
				curl (@x4 = @x6 - span) @y2
				archv
				corner (@x5 = @x6 - [HSwToV : 0.5 * sw]) @y1
				corner (@x6 = Geom.Right) @y1
				corner @x6 (@y3 = Geom.MidY - span)
				corner @x5 @y3
				arcvh
				flat @x4 (@y4 = Geom.MidY - sw / 2)
				curl @x3 @y4
				archv
				corner @x2 @y3
				corner @x1 @y3
			include : lift-@ : spiro-outline
				corner (@x1 = Geom.MidX + span) (@y1 = Geom.Top)
				corner @x1 (@y2 = @y1 - sw / 2)
				archv
				flat (@x2 = Geom.MidX + [HSwToV : 0.5 * sw]) (@y3 = @y1 - span)
				curl @x2 (@y4 = @y6 + span)
				arcvh
				corner @x1 (@y5 = @y6 + sw / 2)
				corner @x1 (@y6 = Geom.Bot)
				corner (@x4 = Geom.MidX - span) @y6
				corner @x4 @y5
				archv
				flat (@x3 = Geom.MidX - [HSwToV : 0.5 * sw]) @y4
				curl @x3 @y3
				arcvh
				corner @x4 @y2
				corner @x4 @y1
