()
| 82 | } |
| 83 | |
| 84 | func (p *Polygon) Valid() bool { |
| 85 | if !p.Convex { |
| 86 | return true |
| 87 | } |
| 88 | var sign bool |
| 89 | for a := 0; a < p.Order; a++ { |
| 90 | i := (a + 0) % p.Order |
| 91 | j := (a + 1) % p.Order |
| 92 | k := (a + 2) % p.Order |
| 93 | c := cross3(p.X[i], p.Y[i], p.X[j], p.Y[j], p.X[k], p.Y[k]) |
| 94 | if a == 0 { |
| 95 | sign = c > 0 |
| 96 | } else if c > 0 != sign { |
| 97 | return false |
| 98 | } |
| 99 | } |
| 100 | return true |
| 101 | } |
| 102 | |
| 103 | func cross3(x1, y1, x2, y2, x3, y3 float64) float64 { |
| 104 | dx1 := x2 - x1 |