Finds the intersection between the <CODE>yLine</CODE> and the column. It will
set the <CODE>lineStatus</CODE> appropriately.

@param wall the column to intersect
@return the x coordinate of the intersection
439892
protected float findLimitsPoint(ArrayList wall) {
        lineStatus = LINE_STATUS_OK;
        if (yLine < minY || yLine > maxY) {
            lineStatus = LINE_STATUS_OFFLIMITS;
            return 0;
        }
        for (int k = 0; k < wall.size(); ++k) {
            float r[] = (float[])wall.get(k);
            if (yLine < r[0] || yLine > r[1])
                continue;
            return r[2] * yLine + r[3];
        }
        lineStatus = LINE_STATUS_NOLINE;
        return 0;
    }
854276
public static Point2D findIntersection(final int x, final int y, final MultiPath path)
    {
        final Point2D pointerPosition = new Point2D(x, y);

        final BoundingBox box = path.getBoundingBox();

        final Point2D center = findCenter(box);

        // length just needs to ensure the c to xy is outside of the path
        final double length = box.getWidth() + box.getHeight();

        final Point2D projectionPoint = getProjection(center, pointerPosition, length);

        final Point2DArray points = new Point2DArray();

        points.push(center);

        points.push(projectionPoint);

        final Set<Point2D>[] intersects = Geometry.getCardinalIntersects(path, points);

        Point2D nearest = null;

        for (final Set<Point2D> set : intersects)
        {
            double nearesstDistance = length;

            if ((set != null) && !set.isEmpty())
            {
                for (final Point2D p : set)
                {
                    final double currentDistance = p.distance(pointerPosition);

                    if (currentDistance < nearesstDistance)
                    {
                        nearesstDistance = currentDistance;

                        nearest = p;
                    }
                }
            }
        }
        return nearest;
    }
260982
public BBox calculateIntersection(BBox bBox) {
        if (!this.intersects(bBox))
            return null;

        double minLon = Math.max(this.minLon, bBox.minLon);
        double maxLon = Math.min(this.maxLon, bBox.maxLon);
        double minLat = Math.max(this.minLat, bBox.minLat);
        double maxLat = Math.min(this.maxLat, bBox.maxLat);

        return new BBox(minLon, maxLon, minLat, maxLat);
    }
1369841
public static int intersectQuad (float x1, float y1, float cx, float cy, float x2,
                                     float y2, float rx1, float ry1, float rx2, float ry2) {
        // LEFT/RIGHT/UP ------------------------------------------------------
        if ((rx2 < x1 && rx2 < cx && rx2 < x2) || (rx1 > x1 && rx1 > cx && rx1 > x2) ||
            (ry1 > y1 && ry1 > cy && ry1 > y2)) {
            return 0;
        }

        // DOWN ---------------------------------------------------------------
        if (ry2 < y1 && ry2 < cy && ry2 < y2 && rx1 != x1 && rx1 != x2) {
            if (x1 < x2) {
                return x1 < rx1 && rx1 < x2 ? 1 : 0;
            }
            return x2 < rx1 && rx1 < x1 ? -1 : 0;
        }

        // INSIDE -------------------------------------------------------------
        QuadCurve c = new QuadCurve(x1, y1, cx, cy, x2, y2);
        float px1 = rx1 - x1;
        float py1 = ry1 - y1;
        float px2 = rx2 - x1;
        float py2 = ry2 - y1;

        float[] res1 = new float[3];
        float[] res2 = new float[3];
        int rc1 = c.solvePoint(res1, px1);
        int rc2 = c.solvePoint(res2, px2);

        // INSIDE-LEFT/RIGHT
        if (rc1 == 0 && rc2 == 0) {
            return 0;
        }

        // Build bound --------------------------------------------------------
        float minX = px1 - DELTA;
        float maxX = px2 + DELTA;
        float[] bound = new float[28];
        int bc = 0;
        // Add roots
        bc = c.addBound(bound, bc, res1, rc1, minX, maxX, false, 0);
        bc = c.addBound(bound, bc, res2, rc2, minX, maxX, false, 1);
        // Add extremal points
        rc2 = c.solveExtreme(res2);
        bc = c.addBound(bound, bc, res2, rc2, minX, maxX, true, 2);
        // Add start and end
        if (rx1 < x1 && x1 < rx2) {
            bound[bc++] = 0f;
            bound[bc++] = 0f;
            bound[bc++] = 0f;
            bound[bc++] = 4;
        }
        if (rx1 < x2 && x2 < rx2) {
            bound[bc++] = 1f;
            bound[bc++] = c.ax;
            bound[bc++] = c.ay;
            bound[bc++] = 5;
        }
        // End build bound ----------------------------------------------------

        int cross = crossBound(bound, bc, py1, py2);
        if (cross != UNKNOWN) {
            return cross;
        }
        return c.cross(res1, rc1, py1, py2);
    }
184758
public Location intersection(Location other) {
		if (isSameStrand(other)) {
			return intersect(mStart, mEnd, other.mStart, other.mEnd);
		} else {
			throw new IllegalArgumentException("Locations are on opposite strands.");
		}
	}
94875
@Pure
	<CT extends RoadConnection> CT getNearestPoint(Class<CT> connectionClass, double x, double y) {
		final int index = getNearestEndIndex(x, y);
		if (index == 0) {
			return getBeginPoint(connectionClass);
		}
		return getEndPoint(connectionClass);
	}
182506
boolean linesIntoCorners( int numLines, GrowQueue_I32 contourCorners ) {

		skippedCorners.reset();

		// this is the index in the contour of the previous corner.  When a new corner is found this is used
		// to see if the newly fit lines point to the same corner.  If that happens a corner is "skipped"
		int contourIndexPrevious = contourCorners.get(anchor0);
		for (int i = 1; i < numLines; i++) {
			LineGeneral2D_F64 line0 = lines.get(i - 1);
			LineGeneral2D_F64 line1 = lines.get(i);

			int cornerIndex = CircularIndex.addOffset(anchor0, i, contourCorners.size);
			boolean skipped = false;

//			System.out.println("  corner index "+cornerIndex);

			if (null == Intersection2D_F64.intersection(line0, line1, intersection)) {
				if( verbose ) System.out.println("  SKIPPING no intersection");
				// the two lines are parallel (or a bug earlier inserted NaN), so skip and remove one of them
				skipped = true;
			} else {

				int contourIndex = closestPoint(intersection);
				if( contourIndex != contourIndexPrevious ) {

					Point2D_I32 a = contour.get(contourIndexPrevious);
					Point2D_I32 b = contour.get(contourIndex);

					if( a.x == b.x && a.y == b.y ) {
						if( verbose ) System.out.println("  SKIPPING duplicate coordinate");
//						System.out.println("  duplicate "+a+" "+b);
						skipped = true;
					} else {
//						System.out.println("contourCorners[ "+cornerIndex+" ] = "+contourIndex);
						contourCorners.set(cornerIndex, contourIndex);
						contourIndexPrevious = contourIndex;
					}
				} else {
					if( verbose ) System.out.println("  SKIPPING duplicate corner index");
					skipped = true;
				}
			}

			if( skipped ) {
				skippedCorners.add( cornerIndex );
			}

		}
		// check the last anchor to see if there's a duplicate
		int cornerIndex = CircularIndex.addOffset(anchor0, numLines, contourCorners.size);
		Point2D_I32 a = contour.get(contourIndexPrevious);
		Point2D_I32 b = contour.get(contourCorners.get(cornerIndex));
		if( a.x == b.x && a.y == b.y ) {
			skippedCorners.add( cornerIndex );
		}

		// now handle all the skipped corners
		Arrays.sort(skippedCorners.data,0,skippedCorners.size);

		for (int i = skippedCorners.size-1; i >= 0; i--) {
			int index = skippedCorners.get(i);
			contourCorners.remove(index);

			if( anchor0 >= index ) {
				anchor0--;
			}
			if( anchor1 >= index ) {
				anchor1--;
			}
		}
//		cornerIndexes.size -= skippedCorners.size();

		numLines -= skippedCorners.size;
		for (int i = 0; i < numLines; i++) {
			int c0 = CircularIndex.addOffset(anchor0, i, contourCorners.size);
			int c1 = CircularIndex.addOffset(anchor0, i+1, contourCorners.size);
			a = contour.get(contourCorners.get(c0));
			b = contour.get(contourCorners.get(c1));

			if( a.x == b.x && a.y == b.y ) {
				throw new RuntimeException("Well I screwed up");
			}

		}

		return contourCorners.size()>=3;
	}
536815
public HitResult intersect(Shape shape, Line line) {
		float distance = Float.MAX_VALUE;
		HitResult hit = null;
		
		for (int i=0;i<shape.getPointCount();i++) {
			int next = rationalPoint(shape, i+1);
			Line local = getLine(shape, i, next);
		
			Vector2f pt = line.intersect(local, true);
			if (pt != null) {
				float newDis = pt.distance(line.getStart());
				if ((newDis < distance) && (newDis > EPSILON)) {
					hit = new HitResult();
					hit.pt = pt;
					hit.line = local;
					hit.p1 = i;
					hit.p2 = next;
					distance = newDis;
				}
			}
		}
		
		return hit;
	}
826942
public LinePlot line(String id, double[] y) {
        double[] lowerBound = {0, Math.min(y)};
        double[] upperBound = {y.length, Math.max(y)};
        extendBound(lowerBound, upperBound);

        double[][] data = new double[y.length][2];
        for (int i = 0; i < data.length; i++) {
            data[i][0] = i;
            data[i][1] = y[i];
        }

        LinePlot plot = new LinePlot(data);
        plot.setID(id);
        add(plot);

        return plot;
    }
514074
public static Point2D lineLineIntersect(final Line2D lineA, final Line2D lineB) {
        return lineLineIntersect(lineA.getX1(), lineA.getY1(), lineA.getX2(), lineA.getY2(), lineB.getX1(),
                lineB.getY1(), lineB.getX2(), lineB.getY2());

    }
916802
public Point getTileCoords (int x, int y)
    {
        return MisoUtil.screenToTile(_metrics, x, y, new Point());
    }
288602
public int yToLine(int y) {
        FontMetrics fm = this.getFontMetrics(this.getFont());
        int height = fm.getHeight();
        Document doc = this.getDocument();
        int length = doc.getLength();
        Element map = doc.getDefaultRootElement();
        int startLine = map.getElementIndex(0);
        int endline = map.getElementIndex(length);

        return Math.max(0, Math.min(endline - 1, y / height + startLine)) - 1;
    }
561712
@Override
	@Pure
	public boolean intersects(Shape2D<?, ?, ?, ?, ?, ? extends Rectangle2afp<?, ?, ?, ?, ?, ?>> rectangle) {
		if (boundsIntersects(rectangle)) {
			final double x = getX();
			final double y = getY();
			final Rectangle2afp<?, ?, ?, ?, ?, ?> box = rectangle.toBoundingBox();
			final double minx = box.getMinX();
			final double miny = box.getMinY();
			final double maxx = box.getMaxX();
			final double maxy = box.getMaxY();

			return MathUtil.min(
					Segment2afp.calculatesDistanceSegmentPoint(minx, miny, maxx, miny, x, y),
					Segment2afp.calculatesDistanceSegmentPoint(minx, miny, minx, maxy, x, y),
					Segment2afp.calculatesDistanceSegmentPoint(maxx, miny, maxx, maxy, x, y),
					Segment2afp.calculatesDistanceSegmentPoint(minx, maxy, maxx, maxy, x, y)) <= this.radius;
		}
		return false;
	}
219393
private Point intersection(int x1, int y1, int x2, int y2, DesktopWindowRect rect) {
    Point
        bottom =
        intersection(x1, y1, x2, y2, rect.getX(), rect.getY(), rect.getX() + rect.getHeight(),
                     rect.getY());
    if (bottom != null) {
      return bottom;
    }

    Point
        right =
        intersection(x1, y1, x2, y2, rect.getX() + rect.getWidth(), rect.getY(),
                     rect.getX() + rect.getWidth(), rect.getY() + rect.getHeight());
    if (right != null) {
      return right;
    }

    Point
        top =
        intersection(x1, y1, x2, y2, rect.getX(), rect.getY() + rect.getHeight(),
                     rect.getX() + rect.getWidth(), rect.getY() + rect.getHeight());
    if (top != null) {
      return top;
    }

    Point
        left =
        intersection(x1, y1, x2, y2, rect.getX(), rect.getY(), rect.getX(),
                     rect.getY() + rect.getHeight());
    if (left != null) {
      return left;
    }

    return null;
  }
600439
private Point intersection(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) {
    double dem = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);

    // Solve the intersect point
    double xi = ((x1 * y2 - y1 * x2) * (x3 - x4) - (x1 - x2) * (x3 * y4 - y3 * x4)) / dem;
    double yi = ((x1 * y2 - y1 * x2) * (y3 - y4) - (y1 - y2) * (x3 * y4 - y3 * x4)) / dem;

    // Check the point isn't off the ends of the lines
    if ((x1 - xi) * (xi - x2) >= 0 && (x3 - xi) * (xi - x4) >= 0 && (y1 - yi) * (yi - y2) >= 0
        && (y3 - yi) * (yi - y4) >= 0) {
      return new Point((int) xi, (int) yi);
    }
    return null;
  }
1008632
public final Shape<?> findShapeAtPoint(final int x, final int y)
    {
        if (isVisible())
        {
            final NFastArrayList<Layer> layers = getChildNodes();

            if (null != layers)
            {
                final int size = layers.size();

                for (int i = size - 1; i >= 0; i--)
                {
                    final Layer layer = layers.get(i);

                    if (null != layer)
                    {
                        final Shape<?> shape = layer.findShapeAtPoint(x, y);

                        if (null != shape)
                        {
                            return shape;
                        }
                    }
                }
            }
        }
        return null;
    }
832767
public static Polygon lines2Polygon( boolean checkValid, LineString... lines ) {
        List<Coordinate> coordinatesList = new ArrayList<Coordinate>();

        List<LineString> linesList = new ArrayList<LineString>();
        for( LineString tmpLine : lines ) {
            linesList.add(tmpLine);
        }

        LineString currentLine = linesList.get(0);
        linesList.remove(0);
        while( linesList.size() > 0 ) {
            Coordinate[] coordinates = currentLine.getCoordinates();
            List<Coordinate> tmpList = Arrays.asList(coordinates);
            coordinatesList.addAll(tmpList);

            Point thePoint = currentLine.getEndPoint();

            double minDistance = Double.MAX_VALUE;
            LineString minDistanceLine = null;
            boolean needFlip = false;
            for( LineString tmpLine : linesList ) {
                Point tmpStartPoint = tmpLine.getStartPoint();
                double distance = thePoint.distance(tmpStartPoint);
                if (distance < minDistance) {
                    minDistance = distance;
                    minDistanceLine = tmpLine;
                    needFlip = false;
                }

                Point tmpEndPoint = tmpLine.getEndPoint();
                distance = thePoint.distance(tmpEndPoint);
                if (distance < minDistance) {
                    minDistance = distance;
                    minDistanceLine = tmpLine;
                    needFlip = true;
                }
            }

            linesList.remove(minDistanceLine);

            if (needFlip) {
                minDistanceLine = (LineString) minDistanceLine.reverse();
            }

            currentLine = minDistanceLine;

        }
        // add last
        Coordinate[] coordinates = currentLine.getCoordinates();
        List<Coordinate> tmpList = Arrays.asList(coordinates);
        coordinatesList.addAll(tmpList);

        coordinatesList.add(coordinatesList.get(0));
        LinearRing linearRing = gf().createLinearRing(coordinatesList.toArray(new Coordinate[0]));
        Polygon polygon = gf().createPolygon(linearRing, null);

        if (checkValid) {
            if (!polygon.isValid()) {
                return null;
            }
        }
        return polygon;
    }