MCPcopy
hub / github.com/tdewolff/canvas / ToPath

Method ToPath

polyline.go:58–74  ·  view source on GitHub ↗

ToPath converts the polyline to a path. If the last coordinate equals the first one, we close the path.

()

Source from the content-addressed store, hash-verified

56
57// ToPath converts the polyline to a path. If the last coordinate equals the first one, we close the path.
58func (p *Polyline) ToPath() *Path {
59 if len(p.coords) < 2 {
60 return &Path{}
61 }
62
63 q := &Path{}
64 q.MoveTo(p.coords[0].X, p.coords[0].Y)
65 for _, coord := range p.coords[1 : len(p.coords)-1] {
66 q.LineTo(coord.X, coord.Y)
67 }
68 if p.coords[0].Equals(p.coords[len(p.coords)-1]) {
69 q.Close()
70 } else {
71 q.LineTo(p.coords[len(p.coords)-1].X, p.coords[len(p.coords)-1].Y)
72 }
73 return q
74}
75
76// FillCount returns the number of times the test point is enclosed by the polyline. Counter clockwise enclosures are counted positively and clockwise enclosures negatively.
77func (p *Polyline) FillCount(x, y float64) int {

Callers 2

DrawPreviewWithAssetsFunction · 0.95
drawFunction · 0.95

Calls 4

MoveToMethod · 0.95
LineToMethod · 0.95
CloseMethod · 0.95
EqualsMethod · 0.45

Tested by

no test coverage detected