Documentation
¶
Overview ¶
Package clip provides geometric clipping for paths and shapes.
Index ¶
- type ClipStack
- func (cs *ClipStack) Bounds() Rect
- func (cs *ClipStack) Coverage(x, y float64) byte
- func (cs *ClipStack) Depth() int
- func (cs *ClipStack) IsVisible(x, y float64) bool
- func (cs *ClipStack) Pop()
- func (cs *ClipStack) PushPath(path []PathElement, antiAlias bool) error
- func (cs *ClipStack) PushRect(r Rect)
- func (cs *ClipStack) Reset(bounds Rect)
- type Close
- type CubicSeg
- type CubicTo
- type EdgeClipper
- type LineSeg
- type LineTo
- type MaskClipper
- type MoveTo
- type PathElement
- type Point
- type QuadSeg
- type QuadTo
- type Rect
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ClipStack ¶
type ClipStack struct {
// contains filtered or unexported fields
}
ClipStack manages hierarchical clip regions with push/pop operations. It maintains a stack of clip entries, where each entry can be either a rectangular clip or a path-based mask clip.
func NewClipStack ¶
NewClipStack creates a new clip stack with the given bounds. The bounds represent the maximum clipping area (typically the canvas size).
func (*ClipStack) Bounds ¶
Bounds returns the current effective clip bounds. This is the intersection of all pushed clip regions.
func (*ClipStack) Coverage ¶
Coverage returns the combined coverage value (0-255) at the given point. This multiplies the coverage from all mask clips in the stack. Returns 0 if the point is outside the current bounds.
func (*ClipStack) Depth ¶
Depth returns the current depth of the clip stack. This is primarily useful for debugging and testing.
func (*ClipStack) IsVisible ¶
IsVisible returns true if the point (x, y) is within the current clip region. For rectangular clips, this is a simple bounds check. For mask clips, this checks if the coverage is non-zero.
func (*ClipStack) Pop ¶
func (cs *ClipStack) Pop()
Pop removes the most recent clip region from the stack. If the stack is empty, this is a no-op.
func (*ClipStack) PushPath ¶
func (cs *ClipStack) PushPath(path []PathElement, antiAlias bool) error
PushPath pushes a path-based clip region onto the stack. The path is rasterized into a mask using the current bounds. If antiAlias is true, the mask will use anti-aliased rendering.
type CubicSeg ¶
type CubicSeg struct {
P0, P1, P2, P3 Point
}
CubicSeg represents a cubic Bezier segment.
type EdgeClipper ¶
type EdgeClipper struct {
// contains filtered or unexported fields
}
EdgeClipper clips path edges against a rectangular clip region. Inspired by tiny-skia edge_clipper.rs and Skia's SkEdgeClipper.
func NewEdgeClipper ¶
func NewEdgeClipper(clip Rect) *EdgeClipper
NewEdgeClipper creates an edge clipper for the given bounds.
func (*EdgeClipper) ClipCubic ¶
func (ec *EdgeClipper) ClipCubic(p0, p1, p2, p3 Point) []CubicSeg
ClipCubic clips a cubic Bezier curve to the clip region.
func (*EdgeClipper) ClipLine ¶
func (ec *EdgeClipper) ClipLine(p0, p1 Point) []LineSeg
ClipLine clips a line segment to the clip rectangle using Cohen-Sutherland algorithm. Returns nil if the line is entirely outside, or a slice with the clipped segment.
func (*EdgeClipper) ClipQuadratic ¶
func (ec *EdgeClipper) ClipQuadratic(p0, p1, p2 Point) []QuadSeg
ClipQuadratic clips a quadratic Bezier curve to the clip region. The curve is first chopped at extrema to ensure monotonicity, then clipped.
type MaskClipper ¶
type MaskClipper struct {
// contains filtered or unexported fields
}
MaskClipper performs alpha mask-based clipping for anti-aliased complex clips. It rasterizes a path into a grayscale mask where each pixel's value represents coverage (0 = outside, 255 = fully inside).
func NewMaskClipper ¶
func NewMaskClipper(elements []PathElement, bounds Rect, antiAlias bool) (*MaskClipper, error)
NewMaskClipper creates a mask clipper by rasterizing the given path elements into an alpha mask.
Parameters:
- elements: Path elements to rasterize
- bounds: Bounding rectangle for the mask
- antiAlias: Enable anti-aliased rendering (currently always on)
The mask is stored as FormatGray8 (1 byte per pixel) for memory efficiency.
func (*MaskClipper) ApplyCoverage ¶
func (mc *MaskClipper) ApplyCoverage(x, y float64, srcAlpha byte) byte
ApplyCoverage modulates the source alpha by the mask coverage at the given point. Returns the modulated alpha value (0-255).
func (*MaskClipper) Bounds ¶
func (mc *MaskClipper) Bounds() Rect
Bounds returns the bounding rectangle of the mask.
func (*MaskClipper) Coverage ¶
func (mc *MaskClipper) Coverage(x, y float64) byte
Coverage returns the coverage value (0-255) at the given point. Points outside the mask bounds return 0 (no coverage).
func (*MaskClipper) Mask ¶
func (mc *MaskClipper) Mask() *image.ImageBuf
Mask returns the underlying grayscale image buffer. This is useful for debugging or advanced use cases.
type PathElement ¶
type PathElement interface {
// contains filtered or unexported methods
}
PathElement represents a single element in a path (copy to avoid import cycle).
type Point ¶
type Point struct {
X, Y float64
}
Point represents a 2D point with float64 coordinates.
type QuadSeg ¶
type QuadSeg struct {
P0, P1, P2 Point
}
QuadSeg represents a quadratic Bezier segment.
type Rect ¶
Rect represents a rectangle with float64 coordinates.
func (Rect) Intersect ¶
Intersect returns the intersection of two rectangles. Returns an empty rectangle if they don't intersect.
func (Rect) Intersects ¶
Intersects returns true if two rectangles overlap.