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

import [mix linreg clamp fallback] from "@iosevka/util"
import [DesignParameters] from "../../meta/aesthetics.mjs"

glyph-module

glyph-block Letter-Greek-Upper-Omega : begin
	glyph-block-import CommonShapes
	glyph-block-import Common-Derivatives
	glyph-block-import Letter-Shared : SetGrekUpperTonos CreateTurnedLetter

	define [UpperOmegaShape top extend ada adb] : glyph-proc
		local fine : Stroke * CThin
		local x1 [mix SB RightSB 0.4]
		local x2 (Width - x1)
		local yattach : top * extend + Stroke
		include : dispiro
			g4   x1 (yattach - fine) [widths.rhs.heading fine Leftward]
			archv
			flat SB (yattach - Stroke + adb) [widths.rhs Stroke]
			curl SB (top - ada)
			arch.rhs top
			flat RightSB (top - adb)
			curl RightSB (yattach - Stroke + ada)
			arcvh
			g4   x2 (yattach - fine) [widths.heading 0 fine Leftward]
		include : VBar.r x1 0 (yattach) fine
		include : HBar.m SB x1 HalfStroke
		include : VBar.l x2 0 (yattach) fine
		include : HBar.m x2 RightSB HalfStroke

	create-glyph 'grek/Omega' 0x3A9 : glyph-proc
		include : MarkSet.capital
		include : SetGrekUpperTonos 0
		include : UpperOmegaShape CAP 0.08 ArchDepthA ArchDepthB

	create-glyph 'grek/smcpOmega' 0xAB65 : glyph-proc
		include : MarkSet.e
		include : UpperOmegaShape XH 0.08 SmallArchDepthA SmallArchDepthB

	create-glyph 'latn/Upsilon' 0x1B1 : glyph-proc
		include : MarkSet.capital
		include : UpperOmegaShape CAP 0.08 ArchDepthA ArchDepthB
		include : FlipAround Middle (CAP / 2)

	CreateTurnedLetter 'latn/upsilon' 0x28A 'grek/smcpOmega' HalfAdvance (XH / 2)
