Checks if one of the lines in the polyline intersects
with a given rectangle.
@see java.awt.Shape#intersects(java.awt.geom.Rectangle2D)
518162
public boolean intersects(Rectangle2D r) {
		if(np==0)return false;
		Line2D line = new Line2D.Double(x[0],y[0],x[0],y[0]);
		for (int i = 1; i < np; i++) {
			line.setLine(x[i-1], y[i-1], x[i], y[i]);
			if(line.intersects(r))return true;
		}
		return false;
	}
1185974
public boolean intersects(Geometry geometry) {
		if (isEmpty()) {
			return false;
		}
		if (exteriorRing.intersects(geometry)) {
			return true;
		}
		if (interiorRings != null) {
			for (LinearRing interiorRing : interiorRings) {
				if (interiorRing.intersects(geometry)) {
					return true;
				}
			}
		}
		return false;
	}
395592
public boolean intersects(GeoBounds other)
    {
        boolean rv = false;
        for (Rectangle2D r1 : rects)
        {
            for (Rectangle2D r2 : other.rects)
            {
                rv = r1.intersects(r2);
                if (rv)
                {
                    break;
                }
            }
            if (rv)
            {
                break;
            }

        }
        return rv;
    }
418221
private boolean intersects(Rectangle other) {
		Rectangle box = other;
		Circle circle = this;
		
		if (box.contains(x+radius,y+radius)) {
			return true;
		}
		
		float x1 = box.getX();
		float y1 = box.getY();
		float x2 = box.getX() + box.getWidth();
		float y2 = box.getY() + box.getHeight();
		
		Line[] lines = new Line[4];
		lines[0] = new Line(x1,y1,x2,y1);
		lines[1] = new Line(x2,y1,x2,y2);
		lines[2] = new Line(x2,y2,x1,y2);
		lines[3] = new Line(x1,y2,x1,y1);
		
		float r2 = circle.getRadius() * circle.getRadius();
		
		Vector2f pos = new Vector2f(circle.getCenterX(), circle.getCenterY());
		
		for (int i=0;i<4;i++) {
			float dis = lines[i].distanceSquared(pos);
			if (dis < r2) {
				return true;
			}
		}
		
		return false;
	}
541348
private boolean intersects(Line other) { 
        // put it nicely into vectors 
        Vector2f lineSegmentStart = new Vector2f(other.getX1(), other.getY1()); 
        Vector2f lineSegmentEnd = new Vector2f(other.getX2(), other.getY2()); 
        Vector2f circleCenter = new Vector2f(getCenterX(), getCenterY()); 

        // calculate point on line closest to the circle center and then 
        // compare radius to distance to the point for intersection result 
        Vector2f closest; 
        Vector2f segv = lineSegmentEnd.copy().sub(lineSegmentStart); 
        Vector2f ptv = circleCenter.copy().sub(lineSegmentStart); 
        float segvLength = segv.length(); 
        float projvl = ptv.dot(segv) / segvLength; 
        if (projvl < 0) 
        { 
            closest = lineSegmentStart; 
        } 
        else if (projvl > segvLength) 
        { 
            closest = lineSegmentEnd; 
        } 
        else 
        { 
            Vector2f projv = segv.copy().scale(projvl / segvLength); 
            closest = lineSegmentStart.copy().add(projv); 
        } 
        boolean intersects = circleCenter.copy().sub(closest).lengthSquared() <= getRadius()*getRadius(); 
        
        return intersects; 
    }
87084
public boolean intersects(Geometry geometry) {
		if (geometry == null || isEmpty() || geometry.isEmpty()) {
			return false;
		}

		if (geometry.getNumGeometries() > 1) {
			for (int n = 0; n < geometry.getNumGeometries(); n++) {
				if (intersects(geometry.getGeometryN(n))) {
					return true;
				}
			}
		} else {
			Coordinate[] coordinates = geometry.getCoordinates();
			if (coordinates.length == 1) {
				return coordinate.equals(coordinates[0]);
			} else {
				for (int i = 0; i < coordinates.length - 1; i++) {
					if (Mathlib.distance(coordinates[i], coordinates[i + 1], coordinate) < Mathlib.ZERO) {
						return true;
					}
				}
			}
		}

		return false;
	}
372811
public boolean contains(Shape other) {
    	if (other.intersects(this)) {
    		return false;
    	}
    	
    	for (int i=0;i<other.getPointCount();i++) {
    		float[] pt = other.getPoint(i);
    		if (!contains(pt[0], pt[1])) {
    			return false;
    		}
    	}
    	
    	return true;
    }
463311
protected boolean intersectsVertically(CmsPositionBean p1, CmsPositionBean p2) {

        return intersectIntervals(p1.getTop(), p1.getTop() + HEIGHT, p2.getTop(), p2.getTop() + HEIGHT);
    }
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;
	}
1175763
public boolean intersects(Geometry geometry) {
		if (geometry == null || isEmpty() || geometry.isEmpty()) {
			return false;
		}

		if (geometry.getNumGeometries() > 1) {
			for (int n = 0; n < geometry.getNumGeometries(); n++) {
				if (intersects(geometry.getGeometryN(n))) {
					return true;
				}
			}
		} else {
			final Coordinate[] coords = geometry.getCoordinates();
			if (coords.length > 1 && coordinates.length > 1) {
				for (int i = 0; i < coordinates.length - 1; i++) {
					for (int j = 0; j < coords.length - 1; j++) {
						if (Mathlib.lineIntersects(coordinates[i], coordinates[i + 1], coords[j], coords[j + 1])) {
							return true;
						}
					}
					if (Mathlib.touches(geometry, coordinates[i])) {
						return true;
					}
				}
			} else {
				// TODO implement me
			}
		}

		return false;
	}
1332079
@Override
	@Pure
	public boolean intersects(Shape2D<?, ?, ?, ?, ?, ? extends Rectangle2afp<?, ?, ?, ?, ?, ?>> rectangle) {
		if (boundsIntersects(rectangle)) {
			final Path2d p = toPath2D();
			return p.intersects(rectangle);
		}
		return false;
	}
1123602
private boolean drawLine(FeatureTileGraphics graphics, Path2D line,
			FeatureStyle featureStyle) {

		Graphics2D lineGraphics = graphics.getLineGraphics();

		Paint paint = getLinePaint(featureStyle);
		lineGraphics.setColor(paint.getColor());
		lineGraphics.setStroke(paint.getStroke());

		boolean drawn = lineGraphics.hit(new java.awt.Rectangle(tileWidth,
				tileHeight), line, true);
		if (drawn) {
			lineGraphics.draw(line);
		}

		return drawn;
	}
972739
public Rectangle2D getBounds2D() {
		int[] r = rect();
		return r==null?null:new Rectangle2D.Double(r[0], r[1], r[2], r[3]);
	}
1193600
public boolean intersect(double tolerance, boolean b_intersecting) {
		if (m_input_segments.size() != 2)
			throw GeometryException.GeometryInternalError();

		m_tolerance = tolerance;
		double small_tolerance_sqr = MathUtils.sqr(tolerance * 0.01);
		boolean bigmove = false;
		
		IntersectionPart part1 = m_input_segments.get(0);
		IntersectionPart part2 = m_input_segments.get(1);
		if (b_intersecting
				|| (part1.seg._isIntersecting(part2.seg, tolerance, true) & 5) != 0) {
			if (part1.seg.getType().value() == Geometry.GeometryType.Line) {
				Line line_1 = (Line) part1.seg;
				if (part2.seg.getType().value() == Geometry.GeometryType.Line) {
					Line line_2 = (Line) part2.seg;
					int count = Line._intersectLineLine(line_1, line_2, null,
							m_param_1, m_param_2, tolerance);
					if (count == 0) {
						assert (count > 0);
						throw GeometryException.GeometryInternalError();
					}
					Point2D[] points = new Point2D[9];
					for (int i = 0; i < count; i++) {
						// For each point of intersection, we calculate a
						// weighted point
						// based on the ranks and weights of the endpoints and
						// the interior.
						double t1 = m_param_1[i];
						double t2 = m_param_2[i];
						int rank1 = part1.rank_interior;
						double weight1 = 1.0;

						if (t1 == 0) {
							rank1 = part1.rank_start;
							weight1 = part1.weight_start;
						} else if (t1 == 1.0) {
							rank1 = part1.rank_end;
							weight1 = part1.weight_end;
						}

						int rank2 = part2.rank_interior;
						double weight2 = 1.0;
						if (t2 == 0) {
							rank2 = part2.rank_start;
							weight2 = part2.weight_start;
						} else if (t2 == 1.0) {
							rank2 = part2.rank_end;
							weight2 = part2.weight_end;
						}

						double ptWeight;

						Point2D pt = new Point2D();
						if (rank1 == rank2) {// for equal ranks use weighted sum
							Point2D pt_1 = new Point2D();
							line_1.getCoord2D(t1, pt_1);
							Point2D pt_2 = new Point2D();
							line_2.getCoord2D(t2, pt_2);
							ptWeight = weight1 + weight2;
							double t = weight2 / ptWeight;
							MathUtils.lerp(pt_1, pt_2, t, pt);
							if (Point2D.sqrDistance(pt, pt_1)
									+ Point2D.sqrDistance(pt, pt_2) > small_tolerance_sqr)
								bigmove = true;
							
						} else {// for non-equal ranks, the higher rank wins
							if (rank1 > rank2) {
								line_1.getCoord2D(t1, pt);
								ptWeight = weight1;
								Point2D pt_2 = new Point2D();
								line_2.getCoord2D(t2, pt_2);
								if (Point2D.sqrDistance(pt, pt_2) > small_tolerance_sqr)
									bigmove = true;
							} else {
								line_2.getCoord2D(t2, pt);
								ptWeight = weight2;
								Point2D pt_1 = new Point2D();
								line_1.getCoord2D(t1, pt_1);
								if (Point2D.sqrDistance(pt, pt_1) > small_tolerance_sqr)
									bigmove = true;
							}
						}
						points[i] = pt;
					}

					// Split the line_1, making sure the endpoints are adusted
					// to the weighted
					double t0 = 0;
					int i0 = -1;
					for (int i = 0; i <= count; i++) {
						double t = i < count ? m_param_1[i] : 1.0;
						if (t != t0) {
							SegmentBuffer seg_buffer = newSegmentBuffer_();
							line_1.cut(t0, t, seg_buffer);
							if (i0 != -1)
								seg_buffer.get().setStartXY(points[i0]);
							if (i != count)
								seg_buffer.get().setEndXY(points[i]);

							t0 = t;
							m_result_segments_1
									.add(newIntersectionPart_(seg_buffer.get()));
						}
						i0 = i;
					}

					int[] indices = new int[9];
					for (int i = 0; i < count; i++)
						indices[i] = i;

					if (count > 1) {
						if (m_param_2[0] > m_param_2[1]) {
							double t = m_param_2[0];
							m_param_2[0] = m_param_2[1];
							m_param_2[1] = t;
							int i = indices[0];
							indices[0] = indices[1];
							indices[1] = i;
						}
					}

					// Split the line_2
					t0 = 0;
					i0 = -1;
					for (int i = 0; i <= count; i++) {
						double t = i < count ? m_param_2[i] : 1.0;
						if (t != t0) {
							SegmentBuffer seg_buffer = newSegmentBuffer_();
							line_2.cut(t0, t, seg_buffer);
							if (i0 != -1) {
								int ind = indices[i0];
								seg_buffer.get().setStartXY(points[ind]);
							}
							if (i != count) {
								int ind = indices[i];
								seg_buffer.get().setEndXY(points[ind]);
							}

							t0 = t;
							m_result_segments_2
									.add(newIntersectionPart_(seg_buffer.get()));
						}
						i0 = i;
					}

					return bigmove;
				}

				throw GeometryException.GeometryInternalError();
			}

			throw GeometryException.GeometryInternalError();
		}
		
		return false;
	}
928220
public void intersect (Area area) {
        if (area == null) {
            return;
        } else if (isEmpty() || area.isEmpty()) {
            reset();
            return;
        }

        if (isPolygonal() && area.isPolygonal()) {
            intersectPolygon(area);
        } else {
            intersectCurvePolygon(area);
        }

        if (areaBoundsSquare() < GeometryUtil.EPSILON) {
            reset();
        }
    }
761637
@Pure
	protected final boolean boundsIntersects(Shape2D<?, ?, ?, ?, ?, ? extends Rectangle2afp<?, ?, ?, ?, ?, ?>> rectangle) {
		final Rectangle2d bounds = getBoundingBox();
		assert bounds != null;
		return bounds.intersects(rectangle);
	}
995807
public boolean intersects(LineSegment lineSegment) {
		double x1 = this.x1();
		double y1 = this.y1();
		double x2 = this.x2();
		double y2 = this.y2();
		double x3 = lineSegment.x1();
		double y3 = lineSegment.y1();
		double x4 = lineSegment.x2();
		double y4 = lineSegment.y2();

		double denom = (y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1);
		if (denom == 0) {
			return false;
		}
		double u1 = ((x4 - x3) * (y1 - y3) - (y4 - y3) * (x1 - x3)) / denom;
		double u2 = ((x2 - x1) * (y1 - y3) - (y2 - y1) * (x1 - x3)) / denom;
		return (u1 > 0 && u1 < 1 && u2 > 0 && u2 < 1);
	}