sdf.go

Functions

Functions

func SDFCircleCoverage

SDFCircleCoverage computes anti-aliased coverage for a stroked circle

using a signed distance field approach.

 

Parameters:

- px, py: pixel center coordinates

- cx, cy: circle center

- radius: circle radius (to center of stroke)

- halfStrokeWidth: half the stroke width

 

Returns a coverage value in [0, 1] where 1 means fully inside the stroke.

func SDFCircleCoverage(px, py, cx, cy, radius, halfStrokeWidth float64) float64 {
	dist := math.Hypot(px-cx, py-cy)
	sdf := math.Abs(dist-radius) - halfStrokeWidth
	return smoothstepCoverage(sdf)
}

func SDFFilledCircleCoverage

SDFFilledCircleCoverage computes anti-aliased coverage for a filled circle

using a signed distance field approach.

 

Parameters:

- px, py: pixel center coordinates

- cx, cy: circle center

- radius: circle radius

 

Returns a coverage value in [0, 1] where 1 means fully inside.

func SDFFilledCircleCoverage(px, py, cx, cy, radius float64) float64 {
	dist := math.Hypot(px-cx, py-cy)
	sdf := dist - radius
	return smoothstepCoverage(sdf)
}

func SDFFilledRRectCoverage

SDFFilledRRectCoverage computes anti-aliased coverage for a filled rounded

rectangle using a signed distance field approach.

 

Parameters:

- px, py: pixel center coordinates

- cx, cy: rectangle center

- halfW, halfH: half-width and half-height of the rectangle

- cornerRadius: radius of the rounded corners

 

Returns a coverage value in [0, 1] where 1 means fully inside.

func SDFFilledRRectCoverage(px, py, cx, cy, halfW, halfH, cornerRadius float64) float64 {
	dist := sdfRRect(px, py, cx, cy, halfW, halfH, cornerRadius)
	return smoothstepCoverage(dist)
}

func SDFRRectCoverage

SDFRRectCoverage computes anti-aliased coverage for a stroked rounded

rectangle using a signed distance field approach.

 

Parameters:

- px, py: pixel center coordinates

- cx, cy: rectangle center

- halfW, halfH: half-width and half-height of the rectangle

- cornerRadius: radius of the rounded corners

- halfStrokeWidth: half the stroke width

 

Returns a coverage value in [0, 1] where 1 means fully inside the stroke.

func SDFRRectCoverage(px, py, cx, cy, halfW, halfH, cornerRadius, halfStrokeWidth float64) float64 {
	dist := sdfRRect(px, py, cx, cy, halfW, halfH, cornerRadius)
	sdf := math.Abs(dist) - halfStrokeWidth
	return smoothstepCoverage(sdf)
}