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

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

glyph-module

glyph-block Letter-Cyrillic-Omega : begin
	glyph-block-import CommonShapes
	glyph-block-import Common-Derivatives
	glyph-block-import Letter-Latin-W
	glyph-block-import Letter-Cyrillic-Te-Comb

	define [CyrlOmegaShape df top p1 p2] : glyph-proc
		local fine : AdviceStroke 3 df.adws
		local mfine : fine * CThin

		local minHookDepth : Math.min (0.625 * (df.middle - df.leftSB - [HSwToV fine])) ((1 / 3) * (df.rightSB - df.leftSB))
		local xMidBarLeft    : df.middle - [HSwToV : fine / 2]
		local xMidBarRight   : df.middle + [HSwToV : fine / 2]
		local xMidBarCoLeft  : df.middle - [HSwToV : mfine - fine / 2]
		local xMidBarCoRight : df.middle + [HSwToV : mfine - fine / 2]
		local y3 : top * p1
		local y4 : top * p2

		local xOpenL : Math.max [mix df.leftSB xMidBarRight 0.5] (df.leftSB + [HSwToV fine] + minHookDepth)
		local xOpenR : Math.min [mix df.rightSB xMidBarLeft 0.5] (df.rightSB - [HSwToV fine] - minHookDepth)

		include : dispiro
			widths.lhs fine
			g4.left.start [arch.adjust-x.top xOpenL (sw -- fine)] top
			archv 8
			flat df.leftSB (top - ArchDepthA)
			curl df.leftSB ArchDepthB
			arcvh 8
			g4 [mix df.leftSB xMidBarRight 0.5] O [heading Rightward]
			archv 8
			flat xMidBarCoRight y3 [widths.heading mfine 0 Upward]
			curl xMidBarCoRight y4 [heading Upward]
		include : dispiro
			widths.rhs fine
			g4.right.start [arch.adjust-x.top xOpenR (sw -- fine)] top
			archv 8
			flat df.rightSB (top - ArchDepthB)
			curl df.rightSB ArchDepthA
			arcvh 8
			g4 [mix df.rightSB xMidBarLeft 0.5] O [heading Leftward]
			archv 8
			flat xMidBarCoLeft y3 [widths.heading 0 mfine Upward]
			curl xMidBarCoLeft y4 [heading Upward]

	create-glyph 'cyrl/BroadOmega' 0xA64C : glyph-proc
		define df : include : DivFrame para.advanceScaleMM 3
		include : [DivFrame df.adws].markSet.capital
		include : CyrlOmegaShape df CAP 0.30 0.31

	create-glyph 'cyrl/broadOmega' 0xA64D : glyph-proc
		define df : include : DivFrame para.advanceScaleM 3
		include : [DivFrame df.adws].markSet.e
		include : CyrlOmegaShape df XH 0.30 0.31
