text/msdf/edge.go

Functions Structs

Functions

func Bounds

Bounds returns the bounding box of the edge.

func (e *Edge) Bounds() Rect {
	switch e.Type {
	case EdgeLinear:
		return linearBounds(e.Points[0], e.Points[1])
	case EdgeQuadratic:
		return quadraticBounds(e.Points[0], e.Points[1], e.Points[2])
	case EdgeCubic:
		return cubicBounds(e.Points[0], e.Points[1], e.Points[2], e.Points[3])
	default:
		return Rect{}
	}
}

func Clone

Clone creates a deep copy of the edge.

func (e *Edge) Clone() Edge {
	return Edge{
		Type:	e.Type,
		Points:	e.Points,
		Color:	e.Color,
	}
}

func DirectionAt

DirectionAt returns the tangent direction at parameter t.

func (e *Edge) DirectionAt(t float64) Point {
	switch e.Type {
	case EdgeLinear:
		return e.Points[1].Sub(e.Points[0])
	case EdgeQuadratic:
		return quadraticDerivative(e.Points[0], e.Points[1], e.Points[2], t)
	case EdgeCubic:
		return cubicDerivative(e.Points[0], e.Points[1], e.Points[2], e.Points[3], t)
	default:
		return Point{1, 0}
	}
}

func EndPoint

EndPoint returns the ending point of the edge.

func (e *Edge) EndPoint() Point {
	switch e.Type {
	case EdgeLinear:
		return e.Points[1]
	case EdgeQuadratic:
		return e.Points[2]
	case EdgeCubic:
		return e.Points[3]
	default:
		return e.Points[0]
	}
}

func HasBlue

HasBlue returns true if the color includes the blue channel.

func (c EdgeColor) HasBlue() bool	{ return c&ColorBlue != 0 }

func HasGreen

HasGreen returns true if the color includes the green channel.

func (c EdgeColor) HasGreen() bool	{ return c&ColorGreen != 0 }

func HasRed

HasRed returns true if the color includes the red channel.

func (c EdgeColor) HasRed() bool	{ return c&ColorRed != 0 }

func NewCubicEdge

NewCubicEdge creates a new cubic Bezier edge.

func NewCubicEdge(start, control1, control2, end Point) Edge {
	return Edge{
		Type:	EdgeCubic,
		Points:	[4]Point{start, control1, control2, end},
		Color:	ColorWhite,
	}
}

func NewLinearEdge

NewLinearEdge creates a new linear edge from start to end.

func NewLinearEdge(start, end Point) Edge {
	return Edge{
		Type:	EdgeLinear,
		Points:	[4]Point{start, end, {}, {}},
		Color:	ColorWhite,
	}
}

func NewQuadraticEdge

NewQuadraticEdge creates a new quadratic Bezier edge.

func NewQuadraticEdge(start, control, end Point) Edge {
	return Edge{
		Type:	EdgeQuadratic,
		Points:	[4]Point{start, control, end, {}},
		Color:	ColorWhite,
	}
}

func PointAt

PointAt evaluates the edge at parameter t in [0, 1].

func (e *Edge) PointAt(t float64) Point {
	switch e.Type {
	case EdgeLinear:
		return e.Points[0].Lerp(e.Points[1], t)
	case EdgeQuadratic:
		return evaluateQuadratic(e.Points[0], e.Points[1], e.Points[2], t)
	case EdgeCubic:
		return evaluateCubic(e.Points[0], e.Points[1], e.Points[2], e.Points[3], t)
	default:
		return e.Points[0]
	}
}

func SignedDistance

SignedDistance calculates the signed distance from point p to this edge.

Returns the closest signed distance and the parameter t at that point.

func (e *Edge) SignedDistance(p Point) SignedDistance {
	switch e.Type {
	case EdgeLinear:
		return linearSignedDistance(e.Points[0], e.Points[1], p)
	case EdgeQuadratic:
		return quadraticSignedDistance(e.Points[0], e.Points[1], e.Points[2], p)
	case EdgeCubic:
		return cubicSignedDistance(e.Points[0], e.Points[1], e.Points[2], e.Points[3], p)
	default:
		return Infinite()
	}
}

func StartPoint

StartPoint returns the starting point of the edge.

func (e *Edge) StartPoint() Point {
	return e.Points[0]
}

func String

String returns a string representation of the edge type.

func (t EdgeType) String() string {
	switch t {
	case EdgeLinear:
		return "Linear"
	case EdgeQuadratic:
		return "Quadratic"
	case EdgeCubic:
		return "Cubic"
	default:
		return "Unknown"
	}
}

func String

String returns a string representation of the edge color.

func (c EdgeColor) String() string {
	switch c {
	case ColorBlack:
		return "Black"
	case ColorRed:
		return "Red"
	case ColorGreen:
		return "Green"
	case ColorBlue:
		return "Blue"
	case ColorYellow:
		return "Yellow"
	case ColorCyan:
		return "Cyan"
	case ColorMagenta:
		return "Magenta"
	case ColorWhite:
		return "White"
	default:
		return "Unknown"
	}
}

Structs

type Edge struct

Edge represents a single edge segment for distance calculation.

An edge can be linear, quadratic, or cubic Bezier.

type Edge struct {
	// Type is the geometric type of this edge.
	Type	EdgeType

	// Points contains the control and end points for this edge.
	// Linear: P0 (start), P1 (end)
	// Quadratic: P0 (start), P1 (control), P2 (end)
	// Cubic: P0 (start), P1 (control1), P2 (control2), P3 (end)
	Points	[4]Point

	// Color determines which channels this edge affects.
	Color	EdgeColor
}