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

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

glyph-module

glyph-block Letter-Greek-Lower-Omega : begin
	glyph-block-import CommonShapes
	glyph-block-import Common-Derivatives

	define [LowerOmegaShape df top p1 p2] : glyph-proc
		local fine : AdviceStroke 3 df.adws
		local mfine : fine * CThin
		local x0 : mix df.leftSB df.rightSB 0.1
		local y0 : top - O
		local y1 : mix 0 top 0.8
		local x1 : df.leftSB + OX
		local y3 : top * p1
		local y4 : top * p2

		include : dispiro
			widths.lhs fine
			g4 x0 y0
			g4 x1 (top / 2)
			arch.lhs 0 (sw -- fine) (swAfter -- mfine)
			flat (df.middle + [HSwToV : mfine - fine / 2]) y3 [widths.heading mfine 0 Upward]
			curl (df.middle + [HSwToV : mfine - fine / 2]) y4 [heading Upward]
		include : dispiro
			widths.rhs fine
			g4 (df.width - x0) y0
			g4 (df.width - x1) (top / 2)
			arch.rhs 0 (sw -- fine) (swAfter -- mfine)
			flat (df.middle - [HSwToV : mfine - fine / 2]) y3 [widths.heading 0 mfine Upward]
			curl (df.middle - [HSwToV : mfine - fine / 2]) y4 [heading Upward]

	create-glyph 'grek/omega' 0x3C9 : glyph-proc
		local df : include : DivFrame para.advanceScaleM 3
		include : df.markSet.e
		include : LowerOmegaShape df XH 0.5 0.65

	create-glyph 'grek/pomega' 0x3D6 : glyph-proc
		local df : include : DivFrame para.advanceScaleM 3
		include : df.markSet.e

		include : union
			HBar.m df.leftSB df.rightSB (XH - HalfStroke)
			difference
				LowerOmegaShape df XH 0.5 0.65
				MaskAbove XH

	create-glyph 'closeomega' 0x277 : glyph-proc
		local df : include : DivFrame para.advanceScaleM 3
		include : df.markSet.e
		local fine : AdviceStroke 3
		local mfine : fine * CThin
		local y0 : XH - O
		local y1 : mix 0 XH 0.45
		local x1 : df.leftSB + OX
		local y3 : XH / 2
		local y4 : XH * 0.65
		include : dispiro
			widths.rhs mfine
			flat (df.middle + [HSwToV : mfine - fine / 2]) y4 [heading Downward]
			curl (df.middle + [HSwToV : mfine - fine / 2]) y3 [heading Downward]
			arch.rhs 0 (sw -- fine) (swBefore -- mfine)
			g4 x1 y1
			arch.rhs y0 (sw -- fine)
			g4 (df.width - x1) y1
			arch.rhs 0 (sw -- fine) (swAfter -- mfine)
			flat (df.middle - [HSwToV : mfine - fine / 2]) y3 [widths.heading 0 mfine Upward]
			curl (df.middle - [HSwToV : mfine - fine / 2]) y4 [heading Upward]

	create-glyph 'latn/Omega' 0xA7B6 : glyph-proc
		local df : include : DivFrame para.advanceScaleMM 3
		include : df.markSet.capital
		include : LowerOmegaShape df CAP 0.5 0.65

	alias 'latn/omega' 0xA7B7 'grek/omega'
