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

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

glyph-module

glyph-block Letter-Armenian-Shared-Shapes : begin
	glyph-block-import CommonShapes
	glyph-block-import Common-Derivatives
	glyph-block-import Letter-Shared-Shapes : SerifFrame

	define barPos : XH / 2
	define highBarPos XH
	define jut Jut

	define JUT : object
		NORMAL 0
		RIGHT  1
		LEFT   2

	glyph-block-export ArmHBar
	define [ArmHBar hPos df] : namespace
		define left : match hPos
			[Just JUT.RIGHT]  df.rightSB
			[Just JUT.LEFT]  (df.leftSB - (jut * [if SLAB 1.5 1]) + [HSwToV : 0.5 * df.mvs])
			--                df.leftSB
		define right : match hPos
			[Just JUT.RIGHT] (df.rightSB + (jut * [if SLAB 1.5 1]) - [HSwToV : 0.5 * df.mvs])
			[Just JUT.LEFT]   df.leftSB
			--                df.rightSB

		export : define [cap] : glyph-proc
			include : HBar.t left right CAP df.mvs
		export : define [asc] : glyph-proc
			include : HBar.t left right Ascender df.mvs
		export : define [high] : glyph-proc
			include : HBar.t left right highBarPos df.mvs
		export : define [mid] : glyph-proc
			include : HBar.m left right barPos df.mvs
		export : define [base] : glyph-proc
			include : HBar.b left right 0 df.mvs
		export : define [desc] : glyph-proc
			include : HBar.b left right Descender df.mvs
		export : define [at y] : glyph-proc
			include : HBar.m left right y df.mvs

	set [ArmHBar.normal df] : ArmHBar JUT.NORMAL df
	set [ArmHBar.right  df] : ArmHBar JUT.RIGHT  df
	set [ArmHBar.left   df] : ArmHBar JUT.LEFT   df

	glyph-block-export TwoNeck
	define [TwoNeck df top bot _left _right _adb _flatp] : begin
		local adb : fallback _adb SmallArchDepthB
		local flatp : fallback _flatp 0.75
		local left : fallback _left df.leftSB
		local right : fallback _right df.rightSB
		local refY : top - adb * 1.5 - df.mvs / 2 * (1 - TanSlope)
		return : list
			g4.down.mid right (top - adb)
			flat [mix left right flatp] [mix (bot + df.mvs) refY flatp]
			curl left (bot + df.mvs) [widths.lhs df.mvs]
