### Punctuation symbols
$$include '../../meta/macros.ptl'

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

glyph-module


glyph-block Symbol-Punctuation-At : begin
	glyph-block-import CommonShapes
	glyph-block-import Common-Derivatives

	define [ThreeFoldShape height fSolidInner] : glyph-proc
		local top : SymbolMid + height / 2
		local bot : SymbolMid - height / 2
		local otop : mix bot top 0.75
		local obot : mix top bot 0.8

		local sw : AdviceStroke 3.5
		local m1 : if fSolidInner [mix SB RightSB 0.5] : [mix (SB + sw) (RightSB - sw) 0.47] - sw / 2
		local m2 : [mix m1 RightSB 0.52] + TanSlope * sw

		local ada : ArchDepthA * ((RightSB - m1) / (RightSB - SB) * 1.1)
		local adb : ArchDepthB * ((RightSB - m1) / (RightSB - SB) * 1.1)

		include : union
			[if fSolidInner spiro-outline dispiro]
				widths.lhs sw
				flat RightSB (otop - O) [heading Leftward]
				curl m2 (otop - O)
				archv
				flat m1 (otop - ada)
				curl m1 (obot + adb)
				arch.lhs obot (sw -- sw)
				flat RightSB (obot + ada)
				curl RightSB (otop - O)
			dispiro
				widths.lhs sw
				flat RightSB (obot + ada)
				curl RightSB (top - ArchDepthB)
				arch.lhs top
				flat SB (top - ArchDepthA) [widths.lhs sw]
				curl SB (bot + ArchDepthB)
				arcvh
				arch.lhs.centerAt.ltr.b Middle bot (knot-ty -- flat)
				curl (RightSB - HalfStroke + TanSlope * sw) (bot + O)

	define [FourFoldShape height fSolidInner] : glyph-proc
		local df : include : DivFrame para.advanceScaleM [if fSolidInner 3.25 4]

		local top : SymbolMid + height / 2
		local bot : SymbolMid - height / 2
		local otop : mix bot top 0.75
		local obot : mix top bot 0.8

		local sw  : AdviceStroke [if fSolidInner 3.25 4]    df.adws
		local swh : AdviceStroke [if fSolidInner 3.25 3.75] df.adws

		local kM12   : if fSolidInner 0.40 (1 / 3)
		local kM12Sw : if fSolidInner 0.25 0.5
		local m1 : [mix (df.leftSB + [HSwToV (sw / 2)]) (df.rightSB - [HSwToV (sw / 2)]) kM12      ] - [HSwToV (sw * kM12Sw)]
		local m2 : [mix (df.leftSB + [HSwToV (sw / 2)]) (df.rightSB - [HSwToV (sw / 2)]) (1 - kM12)] + [HSwToV (sw * kM12Sw)]

		local ad : ArchDepth * [Math.sqrt df.adws]
		local ada : ArchDepthAOf ad df.width
		local adb : ArchDepthBOf ad df.width

		local adInner : Math.max (ad * (m2 - m1) / (df.rightSB - df.leftSB)) (sw * 1.25)
		local adaInner : ArchDepthAOf adInner (m2 - m1 + df.leftSB * 2)
		local adbInner : ArchDepthBOf adInner (m2 - m1 + df.leftSB * 2)

		include : union
			dispiro
				widths.lhs sw
				if fSolidInner
				: then { }
				: else : list
					flat m2 (obot - O) [heading Upward]
					curl m2 (otop - adbInner)
					arch.lhs otop (sw -- sw)
					flat m1 (otop - adaInner)
					curl m1 (obot + adbInner)
					arcvh
				flat df.middle obot
				curl (df.rightSB - [Math.max ((m2 - m1) / 2) [HSwToV : 1.5 * sw]]) obot
				archv
				flat df.rightSB (obot + [Math.max adaInner (sw * 1.5)])
				curl df.rightSB (top - adb)
				arch.lhs top (sw -- swh)
				flat df.leftSB (top - ada) [widths.lhs sw]
				curl df.leftSB (bot + adb)
				arcvh
				arch.lhs.centerAt.ltr.b df.middle bot (knot-ty -- flat)
				curl (df.rightSB - HalfStroke + TanSlope * sw) (bot + O)

			if fSolidInner
				spiro-outline
					corner m2 obot
					curl   m2 (otop - adbInner)
					arch.lhs otop (sw -- sw)
					flat   m1 (otop - adaInner)
					curl   m1 (obot + adbInner)
					arcvh
					flat   df.middle obot
				glyph-proc

	define [CompactShape] : glyph-proc
		local top  CAP
		local obot 0
		local otop [mix obot top 0.675]

		local sw : AdviceStroke 3.5
		local m1 : [mix (SB + sw) (RightSB - sw) 0.53] + sw / 2
		local m2 : [mix SB m1 0.5] + TanSlope * sw

		local ada : ArchDepthA * ((m1 - SB) / (RightSB - SB) * 1.1)
		local adb : ArchDepthB * ((m1 - SB) / (RightSB - SB) * 1.1)
		local atTurnBot (obot - ada / 4)

		local shrink 0.6

		include : dispiro
			straight.up.start (m1 - [HSwToV : sw * (1 - shrink)]) (otop - adb) [widths.heading (sw * shrink) 0 Upward]
			arch.lhs otop (sw -- sw) (swBefore -- (sw * shrink))
			flat SB (otop - ada)
			curl SB (obot + adb)
			arch.lhs obot (sw -- sw) (swAfter -- (sw * shrink))
			straight.up.end (m1 - [HSwToV : sw * (1 - shrink)]) (obot + ada) [widths.heading (sw * shrink) 0 Upward]

		include : dispiro
			widths.lhs sw
			corner m1 (atTurnBot + ada) [heading Upward]
			corner m1 (otop - adb) [heading Upward]
			corner m1 otop [widths.heading (sw * shrink) 0 Upward]

		include : dispiro
			widths.lhs (sw * shrink)
			straight.down.start (m1 - sw * [HSwToV shrink]) (atTurnBot + ada) [heading Downward]
			arch.lhs atTurnBot (sw -- sw) (swBefore -- (sw * shrink))
			flat RightSB (atTurnBot + ada)
			curl RightSB (top - ArchDepthB)
			hookend top (sw -- sw)
			g4 SB (top - Hook)

	define NormalHeight : mix (OperTop - OperBot) (ParenTop - ParenBot) 0.600
	define TallHeight   : mix (OperTop - OperBot) (ParenTop - ParenBot) 0.875

	define AtConfig : object
		threefold               { ThreeFoldShape NormalHeight false }
		threefoldTall           { ThreeFoldShape TallHeight   false }
		threefoldSolidInner     { ThreeFoldShape NormalHeight true  }
		threefoldSolidInnerTall { ThreeFoldShape TallHeight   true  }

		fourfold                { FourFoldShape  NormalHeight false }
		fourfoldTall            { FourFoldShape  TallHeight   false }
		fourfoldSolidInner      { FourFoldShape  NormalHeight true  }
		fourfoldSolidInnerTall  { FourFoldShape  TallHeight   true  }

		compact                 { CompactShape   CAP          false }

	foreach { suffix { body height fSolidInner } } [Object.entries AtConfig] : do
		create-glyph "at.\(suffix)" : body height fSolidInner

	select-variant 'at' '@'
