Returns true if polygon_a touches envelope_b.
424615
private static boolean polygonTouchesEnvelope_(Polygon polygon_a,
			Envelope envelope_b, double tolerance,
			ProgressTracker progress_tracker) {
		// Quick rasterize test to see whether the the geometries are disjoint,
		// or if one is contained in the other.
		int relation = tryRasterizedContainsOrDisjoint_(polygon_a, envelope_b,
				tolerance, false);

		if (relation == Relation.disjoint || relation == Relation.contains
				|| relation == Relation.within)
			return false;

		Envelope2D env_a = new Envelope2D(), env_b = new Envelope2D();
		polygon_a.queryEnvelope2D(env_a);
		envelope_b.queryEnvelope2D(env_b);

		if (envelopeInfContainsEnvelope_(env_b, env_a, tolerance))
			return false;

		if (env_b.getWidth() <= tolerance && env_b.getHeight() <= tolerance) {// treat
																				// as
																				// point
			Point2D pt_b = envelope_b.getCenterXY();
			return polygonTouchesPointImpl_(polygon_a, pt_b, tolerance,
					progress_tracker);
		}

		if (env_b.getWidth() <= tolerance || env_b.getHeight() <= tolerance) {// treat
																				// as
																				// polyline
			Polyline polyline_b = new Polyline();
			Point p = new Point();
			envelope_b.queryCornerByVal(0, p);
			polyline_b.startPath(p);
			envelope_b.queryCornerByVal(2, p);
			polyline_b.lineTo(p);
			return polygonTouchesPolylineImpl_(polygon_a, polyline_b,
					tolerance, progress_tracker);
		}

		// treat as polygon
		Polygon polygon_b = new Polygon();
		polygon_b.addEnvelope(envelope_b, false);
		return polygonTouchesPolygonImpl_(polygon_a, polygon_b, tolerance,
				progress_tracker);
	}
1283758
public static boolean touches(Geometry geometry, Coordinate coordinate) {
		if (geometry instanceof MultiPolygon) {
			for (int i = 0; i < geometry.getNumGeometries(); i++) {
				if (touches(geometry.getGeometryN(i), coordinate)) {
					return true;
				}
			}
			return false;
		} else if (geometry instanceof Polygon) {
			Polygon polygon = (Polygon) geometry;
			if (touchesLineString(polygon.getExteriorRing(), coordinate)) {
				return true;
			}
			for (int n = 0; n < polygon.getNumInteriorRing(); n++) {
				if (touchesLineString(polygon.getInteriorRingN(n), coordinate)) {
					return true;
				}
			}
			return false;
		} else if (geometry instanceof MultiLineString) {
			for (int i = 0; i < geometry.getNumGeometries(); i++) {
				if (touchesLineString((LineString) geometry.getGeometryN(i), coordinate)) {
					return true;
				}
			}
			return false;
		} else if (geometry instanceof LineString) {
			return touchesLineString((LineString) geometry, coordinate);
		} else if (geometry instanceof Point) {
			Coordinate c = geometry.getCoordinates()[0];
			Vector2D v1 = new Vector2D(c.getX(), c.getY());
			Vector2D v2 = new Vector2D(coordinate.getX(), coordinate.getY());
			return (v1.distance(v2) < ZERO);
		}
		return false;
	}
234004
private static boolean envelopeCrossesEnvelope_(Envelope2D env_a,
			Envelope2D env_b, double tolerance, ProgressTracker progress_tracker) {
		if (envelopeInfContainsEnvelope_(env_a, env_b, tolerance)
				|| envelopeInfContainsEnvelope_(env_b, env_a, tolerance))
			return false;

		if (env_a.getHeight() <= tolerance && env_a.getWidth() <= tolerance)
			return false; // points cannot cross

		if (env_b.getHeight() <= tolerance && env_b.getWidth() <= tolerance)
			return false; // points cannot cross

		if (env_b.getHeight() > tolerance && env_b.getWidth() > tolerance) {
			if (env_a.getHeight() > tolerance && env_a.getWidth() > tolerance)
				return false; // areas cannot cross
		}

		Envelope2D _env_a;
		Envelope2D _env_b;

		if (env_a.getHeight() > tolerance && env_a.getWidth() > tolerance) {
			// swap b and a
			_env_a = env_b;
			_env_b = env_a;
		} else {
			_env_a = env_a;
			_env_b = env_b;
		}

		if (_env_b.getHeight() > tolerance && _env_b.getWidth() > tolerance) {// treat
																				// env_b
																				// as
																				// an
																				// area
																				// (env_a
																				// as
																				// a
																				// line);

			Envelope2D env_inter = new Envelope2D(), env_b_deflated = new Envelope2D();
			env_b_deflated.setCoords(_env_b);
			env_b_deflated.inflate(-tolerance, -tolerance);
			env_inter.setCoords(env_b_deflated);
			env_inter.intersect(_env_a);

			if (env_inter.isEmpty())
				return false;

			if (env_inter.getHeight() <= tolerance
					&& env_inter.getWidth() <= tolerance)
				return false; // not a line

			assert (!envelopeInfContainsEnvelope_(env_inter, _env_a, tolerance));
			return true;
		}

		// treat both as lines

		Line line_a = new Line(), line_b = new Line();
		double[] scalars_a = new double[2];
		double[] scalars_b = new double[2];
		Point2D pt = new Point2D();
		_env_a.queryLowerLeft(pt);
		line_a.setStartXY(pt);
		_env_a.queryUpperRight(pt);
		line_a.setEndXY(pt);
		_env_b.queryLowerLeft(pt);
		line_b.setStartXY(pt);
		_env_b.queryUpperRight(pt);
		line_b.setEndXY(pt);

		line_a.intersect(line_b, null, scalars_a, scalars_b, tolerance);
		int count = line_a.intersect(line_b, null, null, null, tolerance);

		if (count != 1)
			return false;

		return scalars_a[0] > 0.0 && scalars_a[1] < 1.0 && scalars_b[0] > 0.0
				&& scalars_b[1] < 1.0;
	}
122132
public static boolean intersects(Bbox one, Bbox two) {
		if (two.getX() > one.getMaxX()) {
			return false;
		}
		if (two.getY() > one.getMaxY()) {
			return false;
		}
		if (two.getMaxX() < one.getX()) {
			return false;
		}
		if (two.getMaxY() < one.getY()) {
			return false;
		}
		return true;
	}
574346
private static boolean touches_(String scl, int dim_a, int dim_b) {
		// Points cant touch
		if (dim_a == 0 && dim_b == 0)
			return false;

		if (!(dim_a == 2 && dim_b == 2)) {
			// Valid for area-Line, Line-Line, area-Point, and Line-Point
			if (scl.charAt(0) == 'F' && scl.charAt(1) == '*'
					&& scl.charAt(2) == '*' && scl.charAt(3) == 'T'
					&& scl.charAt(4) == '*' && scl.charAt(5) == '*'
					&& scl.charAt(6) == '*' && scl.charAt(7) == '*'
					&& scl.charAt(8) == '*')
				return true;

			if (dim_a == 1 && dim_b == 1) {
				// Valid for Line-Line
				if (scl.charAt(0) == 'F' && scl.charAt(1) == 'T'
						&& scl.charAt(2) == '*' && scl.charAt(3) == '*'
						&& scl.charAt(4) == '*' && scl.charAt(5) == '*'
						&& scl.charAt(6) == '*' && scl.charAt(7) == '*'
						&& scl.charAt(8) == '*')
					return true;
			}
		}

		// Valid for area-area, area-Line, Line-Line

		if (dim_b != 0) {
			if (scl.charAt(0) == 'F' && scl.charAt(1) == '*'
					&& scl.charAt(2) == '*' && scl.charAt(3) == '*'
					&& scl.charAt(4) == 'T' && scl.charAt(5) == '*'
					&& scl.charAt(6) == '*' && scl.charAt(7) == '*'
					&& scl.charAt(8) == '*')
				return true;
		}

		return false;
	}
650968
private static boolean polygonContainsEnvelope_(Polygon polygon_a,
			Envelope envelope_b, double tolerance,
			ProgressTracker progress_tracker) {
		// Quick envelope rejection test

		Envelope2D env_a = new Envelope2D(), env_b = new Envelope2D();
		polygon_a.queryEnvelope2D(env_a);
		envelope_b.queryEnvelope2D(env_b);

		if (!envelopeInfContainsEnvelope_(env_a, env_b, tolerance))
			return false;

		// Quick rasterize test to see whether the the geometries are disjoint,
		// or if one is contained in the other.
		int relation = tryRasterizedContainsOrDisjoint_(polygon_a, envelope_b,
				tolerance, false);

		if (relation == Relation.disjoint || relation == Relation.within)
			return false;

		if (relation == Relation.contains)
			return true;

		if (env_b.getWidth() <= tolerance && env_b.getHeight() <= tolerance) {// treat
																				// as
																				// point
			Point2D pt_b = envelope_b.getCenterXY();
			return polygonContainsPointImpl_(polygon_a, pt_b, tolerance,
					progress_tracker);
		}

		if (env_b.getWidth() <= tolerance || env_b.getHeight() <= tolerance) {// treat
																				// as
																				// polyline
			Polyline polyline_b = new Polyline();
			Point p = new Point();
			envelope_b.queryCornerByVal(0, p);
			polyline_b.startPath(p);
			envelope_b.queryCornerByVal(2, p);
			polyline_b.lineTo(p);
			return polygonContainsPolylineImpl_(polygon_a, polyline_b,
					tolerance, null);
		}

		// treat as polygon
		Polygon polygon_b = new Polygon();
		polygon_b.addEnvelope(envelope_b, false);
		return polygonContainsPolygonImpl_(polygon_a, polygon_b, tolerance,
				null);
	}
1126257
function(a, b) {
                        if (Math.abs(2.0*a.offsetLeft + a.offsetWidth - 2.0*b.offsetLeft - b.offsetWidth) < a.offsetWidth + b.offsetWidth) {
                            if (Math.abs(2.0*a.offsetTop + a.offsetHeight - 2.0*b.offsetTop - b.offsetHeight) < a.offsetHeight + b.offsetHeight) {
                                return true;
                            }
                        }
                        return false;
                    }
54631
public static boolean touches(Geometry geometry, Coordinate coordinate) {
		if (Geometry.MULTI_POLYGON.equals(geometry.getGeometryType())) {
			for (int i = 0; i < geometry.getGeometries().length; i++) {
				if (touches(geometry.getGeometries()[i], coordinate)) {
					return true;
				}
			}
			return false;
		} else if (Geometry.POLYGON.equals(geometry.getGeometryType())) {
			for (int i = 0; i < geometry.getGeometries().length; i++) {
				if (touchesLineString(geometry.getGeometries()[i], coordinate)) {
					return true;
				}
			}
			return false;
		} else if (Geometry.MULTI_LINE_STRING.equals(geometry.getGeometryType())) {
			for (int i = 0; i < geometry.getGeometries().length; i++) {
				if (touchesLineString(geometry.getGeometries()[i], coordinate)) {
					return true;
				}
			}
			return false;
		} else if (Geometry.LINEAR_RING.equals(geometry.getGeometryType())) {
			return touchesLineString(geometry, coordinate);
		} else if (Geometry.LINE_STRING.equals(geometry.getGeometryType())) {
			return touchesLineString(geometry, coordinate);
		} else if (Geometry.POINT.equals(geometry.getGeometryType())) {
			return distance(geometry.getCoordinates()[0], coordinate) < PARAM_DEFAULT_DELTA;
		}
		return false;
	}
703734
private static boolean polygonRelatePoint_(Polygon polygon_a,
			Point point_b, double tolerance, int relation,
			ProgressTracker progress_tracker) {
		switch (relation) {
		case Relation.disjoint:
			return polygonDisjointPoint_(polygon_a, point_b, tolerance,
					progress_tracker);

		case Relation.contains:
			return polygonContainsPoint_(polygon_a, point_b, tolerance,
					progress_tracker);

		case Relation.touches:
			return polygonTouchesPoint_(polygon_a, point_b, tolerance,
					progress_tracker);

		default:
			break; // warning fix
		}

		return false;
	}
1310803
private static boolean polygonTouchesPoint_(Polygon polygon_a,
			Point point_b, double tolerance, ProgressTracker progress_tracker) {
		Point2D pt_b = point_b.getXY();
		return polygonTouchesPointImpl_(polygon_a, pt_b, tolerance, null);
	}
1243078
public boolean intersects(Bbox other) {
		if (other.getX() > this.getEndPoint().getX()) {
			return false;
		}
		if (other.getY() > this.getEndPoint().getY()) {
			return false;
		}
		if (other.getEndPoint().getX() < this.getX()) {
			return false;
		}
		if (other.getEndPoint().getY() < this.getY()) {
			return false;
		}
		return true;
	}
606600
private static boolean pointTouchesEnvelope_(Point2D pt_a,
			Envelope2D env_b, double tolerance, ProgressTracker progress_tracker) {
		if (env_b.getHeight() <= tolerance && env_b.getWidth() <= tolerance)
			return false; // when treates as a point, points cannot touch points

		Envelope2D env_b_inflated = new Envelope2D(), env_b_deflated = new Envelope2D();

		env_b_inflated.setCoords(env_b);
		env_b_inflated.inflate(tolerance, tolerance);

		if (!env_b_inflated.contains(pt_a))
			return false;

		if (env_b.getHeight() <= tolerance || env_b.getWidth() <= tolerance) {
			env_b_deflated.setCoords(env_b);

			if (env_b.getHeight() > tolerance)
				env_b_deflated.inflate(0, -tolerance);
			else
				env_b_deflated.inflate(-tolerance, 0);

			if (env_b.getHeight() > tolerance) {
				if (pt_a.y > env_b_deflated.ymin
						&& pt_a.y < env_b_deflated.ymax)
					return false;
			} else {
				if (pt_a.x > env_b_deflated.xmin
						&& pt_a.x < env_b_deflated.xmax)
					return false;
			}

			return true;
		}

		env_b_deflated.setCoords(env_b);
		env_b_deflated.inflate(-tolerance, -tolerance);

		if (env_b_deflated.containsExclusive(pt_a))
			return false;

		return true;
	}
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;
	}
891754
protected final boolean touchesBorder( List<Point2D_I32> contour ) {
		int endX = imageWidth-1;
		int endY = imageHeight-1;

		for (int j = 0; j < contour.size(); j++) {
			Point2D_I32 p = contour.get(j);
			if( p.x == 0 || p.y == 0 || p.x == endX || p.y == endY )
			{
				return true;
			}
		}

		return false;
	}
540648
public boolean contains(Envelope2D other) {// Note: Will return False, if
												// either envelope is empty.
		return other.xmin >= xmin && other.xmax <= xmax && other.ymin >= ymin
				&& other.ymax <= ymax;
	}
417446
def _check_contact(self):
        
        collision = False
        for contact in self.sim.data.contact[: self.sim.data.ncon]:
            if (
                self.sim.model.geom_id2name(contact.geom1) in self.finger_names
                or self.sim.model.geom_id2name(contact.geom2) in self.finger_names
            ):
                collision = True
                break
        return collision
143122
private static boolean polygonRelateMultiPoint_(Polygon polygon_a,
			MultiPoint multipoint_b, double tolerance, int relation,
			ProgressTracker progress_tracker) {
		switch (relation) {
		case Relation.disjoint:
			return polygonDisjointMultiPoint_(polygon_a, multipoint_b,
					tolerance, true, progress_tracker);

		case Relation.contains:
			return polygonContainsMultiPoint_(polygon_a, multipoint_b,
					tolerance, progress_tracker);

		case Relation.touches:
			return polygonTouchesMultiPoint_(polygon_a, multipoint_b,
					tolerance, progress_tracker);

		case Relation.crosses:
			return polygonCrossesMultiPoint_(polygon_a, multipoint_b,
					tolerance, progress_tracker);

		default:
			break; // warning fix
		}

		return false;
	}