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

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

glyph-module

glyph-block Symbol-Pictograph-Heart : begin
	glyph-block-import CommonShapes
	glyph-block-import Common-Derivatives
	glyph-block-import Symbol-Geometric-Shared : GeometricDim

	glyph-block-export HeartShapeImpl
	define [HeartShapeImpl bound sw tip ext] : begin
		define heart : bound.withTop : bound.mixY 0.975
		local y2 : heart.mixY 0.75
		local y3 : heart.mixY 0.75
		return : spiro-outline
			corner heart.xMid (heart.bottom + sw * tip)
			quadControls 1 (2 / 3)
			g4 (heart.right - O - sw) y2
			arcvh
			g4 [heart.mixXMidRight 0.5] (heart.top - sw * tip / 1.75)
			archv
			if sw
			: then : list
				corner (heart.xMid + sw / 3) (y3 - sw * ext)
				corner (heart.xMid - sw / 3) (y3 - sw * ext)
			: else : corner heart.xMid (y3 - sw)
			arcvh
			g4 [heart.mixXMidLeft 0.5] (heart.top - sw * tip / 1.75)
			archv
			g4 (heart.left + O + sw) y2
			quadControls 0 (1 / 3)
			close

	for-width-kinds WideWidth1 : begin
		define Geom : GeometricDim MosaicUnitWidth MosaicWidth
		define bound : new Box Geom.Top Geom.Bot Geom.Left Geom.Right

		create-glyph [MangleName 'blackHeart'] [MangleUnicode 0x1F5A4] : glyph-proc
			set-width Geom.Width
			include : HeartShapeImpl bound 0 0 0
		alias [MangleName 'heavyblackHeart'] [MangleUnicode 0x2764] [MangleName 'blackHeart']

		create-glyph [MangleName 'whiteHeart'] [MangleUnicode 0x1F90D] : glyph-proc
			set-width Geom.Width
			include : difference
				refer-glyph [MangleName 'blackHeart']
				HeartShapeImpl bound GeometryStroke (1.75 / HVContrast) 0.8
