/**
   * Determines the {@link Location} of a point in an areal {@link Geometry}.
   *
   * @param p the point to test
   * @return the location of the point in the geometry
   */
  public int locate(Coordinate p) {
    RayCrossingCounter rcc = new RayCrossingCounter(p);
    MCSegmentCounter mcSegCounter = new MCSegmentCounter(rcc);
    Envelope rayEnv = new Envelope(p.x, maxXExtent, p.y, p.y);
    List mcs = index.query(rayEnv);
    countSegs(rcc, rayEnv, mcs, mcSegCounter);

    return rcc.getLocation();
  }
 private void countSegs(
     RayCrossingCounter rcc, Envelope rayEnv, List monoChains, MCSegmentCounter mcSegCounter) {
   for (Iterator i = monoChains.iterator(); i.hasNext(); ) {
     MonotoneChain mc = (MonotoneChain) i.next();
     mc.select(rayEnv, mcSegCounter);
     // short-circuit if possible
     if (rcc.isOnSegment()) return;
   }
 }
 public void select(LineSegment ls) {
   rcc.countSegment(ls.getCoordinate(0), ls.getCoordinate(1));
 }