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

import [mix linreg clamp fallback] from "@iosevka/util"

glyph-module

glyph-block Letter-Greek-Lower-Delta : begin
	glyph-block-import CommonShapes
	glyph-block-import Common-Derivatives
	glyph-block-import Letter-Shared : CreateTurnedLetter

	create-glyph 'grek/delta.rounded' : glyph-proc
		include : MarkSet.b

		local yRingTop : QuarterStroke + Ascender * 0.619
		local xNeck   : mix SB RightSB 0.06
		local xOTLeft : mix SB RightSB 0.5

		include : dispiro
			g4   [mix Middle RightSB 0.85] [mix XH Ascender 0.8] [widths.lhs]
			alsoThru 0.5 0.7
			g4   Middle (Ascender - O)
			archv 2
			g4   (xNeck + Stroke) [mix (Ascender - O - Stroke) yRingTop 0.5] [widths.rhs]
			arcvh 2
			g4   xOTLeft yRingTop [heading Rightward]
			alsoThruThem : list {0.25 0.05} {0.5 0.13}
			flat (RightSB - OX) (yRingTop - SmallArchDepthB)
			curl (RightSB - OX) SmallArchDepthA
			arch.rhs 0
			flat (SB + OX) SmallArchDepthB
			curl (SB + OX) (yRingTop - SmallArchDepthA)
			arcvh
			g4   xOTLeft (yRingTop - QuarterStroke) [widths.rhs HalfStroke]

	create-glyph 'grek/delta.flatTop' : glyph-proc
		include : MarkSet.b

		local fine ShoulderFine
		local coFine : mix fine Stroke 0.5
		local yTop : Ascender - Stroke
		local yMid : QuarterStroke + [mix 0 XH (7 / 8)]
		local yMid2 : mix yMid [YSmoothMidR yMid 0 SmallArchDepthA SmallArchDepthB] 0.95
		local yMid3 : mix yMid [YSmoothMidR yMid 0 SmallArchDepthA SmallArchDepthB] 0.5
		local yMockBarStart : yMid3 + 2.25 * Stroke
		local pStraightBarStart : 0.75 - (Stroke / Ascender)

		include : HBar.t SB RightSB Ascender
		include : intersection [MaskBelow yTop] : dispiro
			widths.lhs fine
			flat (RightSB - OX - [HSwToV : Stroke - fine]) SmallArchDepthA
			curl (RightSB - OX - [HSwToV : Stroke - fine]) (yMid - SmallArchDepthB)
			arch.lhs yMid (swBefore -- fine)
			flat (SB + OX) (yMid - SmallArchDepthA)
			curl (SB + OX) SmallArchDepthB
			arch.lhs 0
			flat (RightSB - OX) SmallArchDepthA
			curl (RightSB - OX) yMid2
			flat [mix Width SB pStraightBarStart] [mix yMockBarStart yTop pStraightBarStart]
			curl [mix Width SB 1]                 [mix yMockBarStart yTop 1] [widths.rhs]

	select-variant 'grek/delta' 0x3B4

	alias 'cyrl/be.SRB' null 'grek/delta.rounded'
	alias 'latindelta' 0x1E9F 'grek/delta'

	CreateTurnedLetter 'turndelta' 0x18D 'grek/delta' HalfAdvance (XH / 2)
