geom

package
v0.11.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 21, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FitSpline

func FitSpline(path []P, tanv1, tanv2 P, barriers []Segment) []ctrlp

FitSpline computes the control points of a cubic bezier curve that fits a polygonal path. The input path points must be ordered from start to end.

func MakeSpline added in v0.9.0

func MakeSpline(a, b P) ctrlp

MakeSpline computes control points of a cubic bezier from a to b so that it gently curves in the direction of the slope.

Types

type P

type P struct {
	X, Y float64
}

P represents a point on the plane

func Shortest

func Shortest(p1, p2 P, rects []Rect) []P

Shortest finds the shortest path between p1 and p2 through the inner polygon identified by the given list of rectangles.

func (P) SVG added in v0.9.0

func (p P) SVG() string

type Polygon

type Polygon struct {
	Points []P // counterclockwise list of points
	// contains filtered or unexported fields
}

Polygon represents a polygon on the plane

func MergeRects

func MergeRects(rects []Rect) Polygon

func (Polygon) Sides

func (p Polygon) Sides() []Segment

type Rect

type Rect struct {
	TL P // top-left vertex of the rectangle
	BR P // bottom-right vertex of the rectangle
}

Rect represents a rectangle

func (Rect) Height

func (r Rect) Height() float64

func (Rect) SVG added in v0.9.0

func (r Rect) SVG() string

func (Rect) String

func (r Rect) String() string

func (Rect) Width

func (r Rect) Width() float64

type Segment

type Segment struct {
	A, B P
}

func (Segment) Other

func (seg Segment) Other(v P) P

func (Segment) SVG added in v0.9.0

func (seg Segment) SVG() string

type Tri

type Tri struct {
	ID      int
	A, B, C P
}

Tri represents a triangle

func Triangulate

func Triangulate(rects []Rect) []Tri

Triangulate returns a list of triangles resulting from the triangulation of the polygon obtained by merging the rectangles (the rectangles aren't actually merged). Since the polygon's internal angles are all fractions of π, the triangulation is special-cased to run in O(n). Note that the polygon is y-monotone but isn't also strictly y-monotone, therefore the left and right vertex chains can't be considered sorted. For each output triangle, the segment (A,B) is a diagonal of the polygon.

func (Tri) Barycenter

func (t Tri) Barycenter() P

func (Tri) Contains

func (t Tri) Contains(p P) bool

func (Tri) OrderedSide

func (t Tri) OrderedSide(i int) Segment

func (Tri) SVG added in v0.9.0

func (t Tri) SVG() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL