Skip to content

Commit

Permalink
Implements Region for Polyline
Browse files Browse the repository at this point in the history
  • Loading branch information
j16sdiz committed Jun 9, 2015
1 parent d21eee5 commit 784db26
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions s2/polyline.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,49 @@ func (pl *Polyline) initPoints(vertices []Point) {

func (pl Polyline) NumVertices() int { return len(pl.vertices) }
func (pl Polyline) Vertex(k int) Point { return pl.vertices[k] }

func (pl *Polyline) GetRectBound() *Rect {
rb := NewRectBounder()
for _, pt := range pl.vertices {
rb.AddPoint(&pt)
}
bound := rb.Bound()
return &bound
}

func (pl *Polyline) MayIntersect(cell Cell) bool {
if pl.NumVertices() == 0 {
return false
}

for _, pt := range pl.vertices {
if cell.ContainsPoint(pt) {
return true
}
}

cellVertices := []Point{
cell.Vertex(0),
cell.Vertex(1),
cell.Vertex(2),
cell.Vertex(3),
}

for j := 0; j < 4; j++ {
crosser := NewEdgeCrosser(&cellVertices[j], &cellVertices[(j+1)&3], &pl.vertices[0])
for _, vetex := range pl.vertices[1:] {
if crosser.RobustCrossing(&vetex) >= 0 {
return true
}
}
}

return false
}

func (pl *Polyline) ContainsCell(cell Cell) bool { return false }
func (pl *Polyline) ContainsPoint(p Point) bool { return false }

func (pl *Polyline) CapBound() Cap {
return pl.GetRectBound().CapBound()
}

0 comments on commit 784db26

Please sign in to comment.