Crossings returns the set of edge of the shape S that intersect the given edge AB. If the CrossingType is Interior, then only intersections at a point interior to both edges are reported, while if it is CrossingTypeAll then edges that share a vertex are also reported.
(a, b Point, shape Shape, crossType CrossingType)
| 53 | // edges are reported, while if it is CrossingTypeAll then edges that share a vertex |
| 54 | // are also reported. |
| 55 | func (c *CrossingEdgeQuery) Crossings(a, b Point, shape Shape, crossType CrossingType) []int { |
| 56 | edges := c.candidates(a, b, shape) |
| 57 | if len(edges) == 0 { |
| 58 | return nil |
| 59 | } |
| 60 | |
| 61 | crosser := NewEdgeCrosser(a, b) |
| 62 | out := 0 |
| 63 | n := len(edges) |
| 64 | |
| 65 | for in := range n { |
| 66 | b := shape.Edge(edges[in]) |
| 67 | sign := crosser.CrossingSign(b.V0, b.V1) |
| 68 | if crossType == CrossingTypeAll && (sign == MaybeCross || sign == Cross) || crossType != CrossingTypeAll && sign == Cross { |
| 69 | edges[out] = edges[in] |
| 70 | out++ |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | if out < n { |
| 75 | edges = edges[0:out] |
| 76 | } |
| 77 | return edges |
| 78 | } |
| 79 | |
| 80 | // EdgeMap stores a sorted set of edge ids for each shape. |
| 81 | type EdgeMap map[Shape][]int |