public bool Equals(IRectangleSizeDecorator other) { if (other == null) { return(false); } return(rect.Equals(other.Rectangle)); }
public IIntersectionResult Solve(IRectangle aRectangle, IRectangle aDifferentRectangle) { var intersectionPoints = new List<IPoint>(); if(aRectangle.Equals(aDifferentRectangle)) throw new ArgumentException(vanBrackel_Rectangles_Resources.SameRectanglesErrorMessage); _aRectanglesLines = _rectangleDecomposer.GetLines(aRectangle); _aDifferentRectanglesLines = _rectangleDecomposer.GetLines(aDifferentRectangle); //TODO: Make more efficient foreach (var aRectanglesLine in _aRectanglesLines) { foreach (var aDifferentRectanglesLine in _aDifferentRectanglesLines) { var result = _lineIntersectionService.Solve(aRectanglesLine, aDifferentRectanglesLine); if(result.HasIntersection) foreach (var intersectionPoint in result.IntersectionPoints) { if(!intersectionPoints.Contains(intersectionPoint)) intersectionPoints.Add(intersectionPoint); } } } //If there are at least two intersection points that create a line, and that line is in both rectangles it's adjacent not an intersection if (intersectionPoints.Count >= 2) { var testLines = new ILine[intersectionPoints.Count - 1]; if (testLines.Length >= 1) testLines[0] = _shapeFactory.CreateLine(intersectionPoints[0].XCoordinate, intersectionPoints[0].YCoordinate, intersectionPoints[1].XCoordinate, intersectionPoints[1].YCoordinate); if (testLines.Length >= 2) testLines[1] = _shapeFactory.CreateLine(intersectionPoints[1].XCoordinate, intersectionPoints[1].YCoordinate, intersectionPoints[2].XCoordinate, intersectionPoints[2].YCoordinate); foreach (var testLine in testLines) { if (_aRectanglesLines.Any(line => line.Contains(testLine)) && _aDifferentRectanglesLines.Any(line => line.Contains(testLine))) return new IntersectionResult(false, new IPoint[0]); } } return new IntersectionResult(intersectionPoints.Any(), intersectionPoints.ToArray()); }
public override bool Evaluate(IShape indexedShape, IShape queryShape) { // LUCENENET specific - added guard clauses if (indexedShape is null) { throw new ArgumentNullException(nameof(indexedShape)); } if (queryShape is null) { throw new ArgumentNullException(nameof(queryShape)); } IRectangle bbox = indexedShape.BoundingBox; return(bbox.Relate(queryShape) == SpatialRelation.Within || bbox.Equals(queryShape)); }
/// <summary> /// Called by <see cref="SpatialContextFactory.NewSpatialContext()"/>. /// </summary> /// <param name="factory"></param> public SpatialContext(SpatialContextFactory factory) { this.geo = factory.geo; if (factory.distCalc == null) { this.calculator = IsGeo ? (IDistanceCalculator) new GeodesicSphereDistCalc.Haversine() : new CartesianDistCalc(); } else { this.calculator = factory.distCalc; } //TODO remove worldBounds from Spatial4j: see Issue #55 IRectangle bounds = factory.worldBounds; if (bounds == null) { this.worldBounds = IsGeo ? new Rectangle(-180, 180, -90, 90, this) : new Rectangle(-double.MaxValue, double.MaxValue, -double.MaxValue, double.MaxValue, this); } else { if (IsGeo && !bounds.Equals(new Rectangle(-180, 180, -90, 90, this))) { throw new ArgumentException("for geo (lat/lon), bounds must be " + GEO.WorldBounds); } if (bounds.MinX > bounds.MaxX) { throw new ArgumentException("worldBounds minX should be <= maxX: " + bounds); } if (bounds.MinY > bounds.MaxY) { throw new ArgumentException("worldBounds minY should be <= maxY: " + bounds); } //hopefully worldBounds' rect implementation is compatible this.worldBounds = new Rectangle(bounds, this); } this.normWrapLongitude = factory.normWrapLongitude && this.IsGeo; this.wktShapeParser = factory.MakeWktShapeParser(this); this.binaryCodec = factory.MakeBinaryCodec(this); }
public virtual SpatialRelation Relate(IRectangle r) { //Note: Surprisingly complicated! //--We start by leveraging the fact we have a calculated bbox that is "cheaper" than use of DistanceCalculator. SpatialRelation bboxSect = enclosingBox.Relate(r); if (bboxSect == SpatialRelation.DISJOINT || bboxSect == SpatialRelation.WITHIN) { return(bboxSect); } if (bboxSect == SpatialRelation.CONTAINS && enclosingBox.Equals(r)) //nasty identity edge-case { return(SpatialRelation.WITHIN); } //bboxSect is INTERSECTS or CONTAINS //The result can be DISJOINT, CONTAINS, or INTERSECTS (not WITHIN) return(RelateRectanglePhase2(r, bboxSect)); }
public override bool Evaluate(IShape indexedShape, IShape queryShape) { IRectangle bbox = indexedShape.BoundingBox; return(bbox.Relate(queryShape) == SpatialRelation.WITHIN || bbox.Equals(queryShape)); }