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

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

glyph-module

glyph-block Letter-Greek-Lower-Gamma : begin
	glyph-block-import CommonShapes
	glyph-block-import Common-Derivatives
	glyph-block-import Letter-Blackboard : BBS BBD BBBarLeft

	alias 'grek/gamma.straight' null 'cyrl/ue.straightSerifless'
	alias 'grek/gamma.curly'    null 'cyrl/ue.curlySerifless'

	create-glyph 'grek/gamma.casual' : glyph-proc
		include : MarkSet.p

		local xMid : [mix SB RightSB 0.46] + [HSwToV HalfStroke]
		local xStart : SB + [HSwToV : 0.4 * Stroke]
		include : dispiro
			g4 xStart (XH - O) [widths.rhs]
			bezControls 0.33 0.17 1 0.62 6 important
			flat xMid 0
			curl xMid Descender [heading Downward]

		include : dispiro
			widths.rhs
			flat RightSB XH [heading Downward]
			curl RightSB (XH * 0.9) [heading Downward]
			quadControls 0 0.3 6
			g4   xMid 0 [widths.rhs : Stroke * 0.9]

	select-variant 'grek/gamma' 0x3B3

	create-glyph 'mathbb/grek/gamma' 0x213D : glyph-proc
		include : MarkSet.p

		local cor : DiagCorDs (XH - Descender) (RightSB - SB) BBD
		local swEqv : 2 * BBS + BBD
		local xMid : [mix SB RightSB 0.46] + [HSwToV : 0.46 * swEqv]
		local xStart : SB + [HSwToV : 0.4 * swEqv]

		include : HBar.t (xStart - BBD) (xStart + (cor - 1) * BBD) XH        BBS
		include : HBar.b (xMid   - BBD) (xMid)                     Descender BBS

		foreach {ob ot} [items-of {{ 0 (cor - 1) } { (-1) (-1) }}] : include : dispiro
			g4 (xStart + ot * BBD) XH [widths.rhs.heading BBS Downward]
			bezControls 0.33 0.17 1 0.62 6 important
			flat (xMid + ob * BBD) 0
			curl (xMid + ob * BBD) Descender [heading Downward]

		include : dispiro
			widths.rhs BBS
			flat RightSB XH [heading Downward]
			curl RightSB (XH * 0.9) [heading Downward]
			quadControls 0 0.3 6
			g4   xMid 0 [widths.rhs : BBS * 0.9]
