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

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

glyph-module

glyph-block Letter-Armenian-Lower-Dza-Cheh : begin
	glyph-block-import CommonShapes
	glyph-block-import Common-Derivatives
	glyph-block-import Letter-Shared-Shapes : OBarRight SerifFrame

	# Common Params
	define barPos : XH / 2
	define highBarPos XH
	define jut Jut

	do "Dz'a"
		create-glyph 'armn/dza' 0x571 : glyph-proc
			local df : include : DivFrame 1
			include : df.markSet.b
			local x1 : mix df.leftSB df.rightSB 0.25
			local x2 : mix df.leftSB df.rightSB 0.75
			local y2 : mix XH Ascender 0.5
			include : dispiro
				widths.center df.mvs
				straight.down.start x1 Ascender [heading Downward]
				arcvh
				flat df.middle y2
				curl x2 y2 [heading Rightward]

			local yMid : Math.max (y2 + 0.5 * df.mvs - 1.5 * SmallArchDepthA) (0 + SmallArchDepthB + TINY)
			define [knots] : list
				straight.left.start x2 (y2 + 0.5 * df.mvs) [heading Leftward]
				archv
				flat df.leftSB yMid
				curl df.leftSB (0 + SmallArchDepthB) [heading Downward]
			include : dispiro
				widths.lhs df.mvs
				knots
				OBarRight.arcEnd 0 df.leftSB df.rightSB df.mvs df.shoulderFine SmallArchDepthA SmallArchDepthB
			include : intersection
				spiro-outline
					knots
					corner df.leftSB 0
					corner VERY-FAR 0
					corner VERY-FAR (y2 + 0.5 * df.mvs)
				dispiro
					widths.rhs df.mvs
					flat df.leftSB XH
					curl df.middle XH [heading Rightward]
					archv
					flat df.rightSB (XH - SmallArchDepthB)
					curl df.rightSB 0 [heading Downward]
			if SLAB : begin
				local sf : SerifFrame.fromDf df Ascender 0
				include sf.rb.outer

	do "Cheh"
		create-glyph 'armn/cheh' 0x573 : glyph-proc
			local df : include : DivFrame 1
			include : df.markSet.b
			local x1 : mix df.leftSB df.rightSB 0.75
			include : dispiro
				widths.lhs df.mvs
				flat x1 Ascender
				curl df.middle Ascender [heading Leftward]
				archv
				flat df.leftSB (Ascender - SmallArchDepthA)
				curl df.leftSB (0 + SmallArchDepthB) [heading Downward]
				OBarRight.arcEnd 0 df.leftSB df.rightSB df.mvs df.shoulderFine SmallArchDepthA SmallArchDepthB
			include : dispiro
				widths.rhs df.mvs
				flat (df.leftSB - jut + [HSwToV : 0.5 * df.mvs]) highBarPos
				curl df.middle highBarPos [heading Rightward]
				archv
				flat df.rightSB (highBarPos - SmallArchDepthB)
				curl df.rightSB 0 [heading Downward]
			if SLAB : begin
				local sf : SerifFrame.fromDf df Ascender 0
				include sf.rb.outer
