ToPath converts the polyline to a path. If the last coordinate equals the first one, we close the path.
()
| 56 | |
| 57 | // ToPath converts the polyline to a path. If the last coordinate equals the first one, we close the path. |
| 58 | func (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. |
| 77 | func (p *Polyline) FillCount(x, y float64) int { |