ContainsPoint returns true if the loop contains the point.
(p Point)
| 599 | |
| 600 | // ContainsPoint returns true if the loop contains the point. |
| 601 | func (l *Loop) ContainsPoint(p Point) bool { |
| 602 | if !l.index.IsFresh() && !l.bound.ContainsPoint(p) { |
| 603 | return false |
| 604 | } |
| 605 | |
| 606 | // For small loops it is faster to just check all the crossings. We also |
| 607 | // use this method during loop initialization because InitOriginAndBound() |
| 608 | // calls Contains() before InitIndex(). Otherwise, we keep track of the |
| 609 | // number of calls to Contains() and only build the index when enough calls |
| 610 | // have been made so that we think it is worth the effort. Note that the |
| 611 | // code below is structured so that if many calls are made in parallel only |
| 612 | // one thread builds the index, while the rest continue using brute force |
| 613 | // until the index is actually available. |
| 614 | |
| 615 | const maxBruteForceVertices = 32 |
| 616 | // TODO(roberts): add unindexed contains calls tracking |
| 617 | |
| 618 | if len(l.index.shapes) == 0 || // Index has not been initialized yet. |
| 619 | len(l.vertices) <= maxBruteForceVertices { |
| 620 | return l.bruteForceContainsPoint(p) |
| 621 | } |
| 622 | |
| 623 | // Otherwise, look up the point in the index. |
| 624 | it := l.index.Iterator() |
| 625 | if !it.LocatePoint(p) { |
| 626 | return false |
| 627 | } |
| 628 | return l.iteratorContainsPoint(it, p) |
| 629 | } |
| 630 | |
| 631 | // ContainsCell reports whether the given Cell is contained by this Loop. |
| 632 | func (l *Loop) ContainsCell(target Cell) bool { |
no test coverage detected