internal readonly int[] levelN; // number public QuadPrefixTree(SpatialContext ctx, IRectangle bounds, int maxLevels) : base(ctx, maxLevels) { xmin = bounds.MinX; xmax = bounds.MaxX; ymin = bounds.MinY; ymax = bounds.MaxY; levelW = new double[maxLevels]; levelH = new double[maxLevels]; levelS = new int[maxLevels]; levelN = new int[maxLevels]; gridW = xmax - xmin; gridH = ymax - ymin; this.xmid = xmin + gridW / 2.0; this.ymid = ymin + gridH / 2.0; levelW[0] = gridW / 2.0; levelH[0] = gridH / 2.0; levelS[0] = 2; levelN[0] = 4; for (int i = 1; i < levelW.Length; i++) { levelW[i] = levelW[i - 1] / 2.0; levelH[i] = levelH[i - 1] / 2.0; levelS[i] = levelS[i - 1] * 2; levelN[i] = levelN[i - 1] * 4; } }
public ILine[] GetLines(IRectangle rectangle) { const uint linesInARectangle = 4; var lines = new ILine[linesInARectangle]; lines[0] = _factory.CreateLine(rectangle.StartingPoint.XCoordinate, rectangle.StartingPoint.YCoordinate, rectangle.EndingPoint.XCoordinate, rectangle.StartingPoint.YCoordinate); lines[1] = _factory.CreateLine(rectangle.EndingPoint.XCoordinate, rectangle.StartingPoint.YCoordinate, rectangle.EndingPoint.XCoordinate, rectangle.EndingPoint.YCoordinate); lines[2] = _factory.CreateLine(rectangle.EndingPoint.XCoordinate, rectangle.EndingPoint.YCoordinate, rectangle.StartingPoint.XCoordinate, rectangle.EndingPoint.YCoordinate); lines[3] = _factory.CreateLine(rectangle.StartingPoint.XCoordinate, rectangle.EndingPoint.YCoordinate, rectangle.StartingPoint.XCoordinate, rectangle.StartingPoint.YCoordinate); return lines; }
public Algorithm( IPoints points, IRectangle rect, StrategyType type = StrategyType.Grid, ILog2 log = null) { _log = log ?? new NoLog(); Rectangle = rect; Points = points.Data; Singles = new List<IP>(); Knn = new NearestNeighbor(); GridContainer = new GridContainer(Rectangle, Points); switch (type) { case StrategyType.Naive: Strategy = new NaiveStrategy(_log); break; case StrategyType.Grid: Strategy = new GridStrategy(_log); break; case StrategyType.KdTree: Strategy = new KdTreeStrategy(Points); break; default: throw new NotImplementedException("Unknown strategy"); } //_log.Info(MethodBase.GetCurrentMethod(), "object init"); }
public bool AreAdjacent(IRectangle rectangle, IRectangle anotherRectangle) { //If any lines are inside another rectangle it can't be adjacent if(_decomposer.GetLines(anotherRectangle).Any(line => rectangle.Contains(line.StartingPoint) && rectangle.Contains(line.EndingPoint))) return false; if (_decomposer.GetLines(rectangle).Any(line => anotherRectangle.Contains(line.StartingPoint) && anotherRectangle.Contains(line.EndingPoint))) return false; //If rectangles intersect they are not adjacent if (_intersectionService.Solve(rectangle, anotherRectangle).HasIntersection) return false; //For two rectangles to be adjacent the must share exactly 1 one or have 1 line exist in another var matchingLines = new List<ILine>(); foreach (var line in _decomposer.GetLines(rectangle)) { foreach (var anotherLine in _decomposer.GetLines(anotherRectangle)) { if (line.Contains(anotherLine) || anotherLine.Contains(line)) { if(line.Contains(anotherLine) && !matchingLines.Contains(anotherLine)) matchingLines.Add(anotherLine); if(anotherLine.Contains(line) && !matchingLines.Contains(line)) matchingLines.Add(line); } } } return matchingLines.Count == 1; }
public GridContainer(IRectangle rect, IEnumerable<IP> points) { _rect = rect; DX = rect.Square; DY = rect.Square; Grid = new Grid(rect.XGrid, rect.YGrid); foreach (var p in points) UpdatePosition(p); }
public SizeGripDecorator (IRectangle rectangle) : base (rectangle) { if (rectangle.IsHResizable) this.gripPositions |= SizeGripPositions.EastWest; if (rectangle.IsVResizable) this.gripPositions |= SizeGripPositions.NorthSouth; }
public bool Contains(IRectangle rectangle) { if(_outerRectangle == null) throw new NullReferenceException(vanBrackel_Rectangles_Resources.ContainmentServiceNotInitializedMessage); if (_rectangleIntersectionService.Solve(_outerRectangle, rectangle).HasIntersection) return false; return CalculateContainment(_outerRectangle, rectangle); }
private static PointF GetConnectionPointPosition (IRectangle rect, ConnectionPoint point) { switch (point) { case ConnectionPoint.North: return new PointF(rect.X + rect.ActualWidth / 2, rect.Y); case ConnectionPoint.East: return new PointF(rect.X + rect.ActualWidth, rect.Y + rect.ActualHeight / 2); case ConnectionPoint.South: return new PointF(rect.X + rect.ActualWidth / 2, rect.Y + rect.ActualHeight); case ConnectionPoint.West: return new PointF(rect.X, rect.Y + rect.ActualHeight / 2); } return new PointF(rect.X + rect.ActualWidth / 2, rect.Y + rect.ActualHeight / 2); }
private Point GetTopLeftCorner(IRectangle rectangle) { return new Point( rectangle.StartingPoint.XCoordinate < rectangle.EndingPoint.XCoordinate ? rectangle.StartingPoint.XCoordinate : rectangle.EndingPoint.XCoordinate, rectangle.StartingPoint.YCoordinate > rectangle.EndingPoint.YCoordinate ? rectangle.StartingPoint.YCoordinate : rectangle.EndingPoint.YCoordinate ); }
private static Point GetLowerRightCorner(IRectangle rectangle) { return new Point( rectangle.StartingPoint.XCoordinate > rectangle.EndingPoint.XCoordinate ? rectangle.StartingPoint.XCoordinate : rectangle.EndingPoint.XCoordinate, rectangle.StartingPoint.YCoordinate < rectangle.EndingPoint.YCoordinate ? rectangle.StartingPoint.YCoordinate : rectangle.EndingPoint.YCoordinate ); }
protected override IShape GenerateRandomShape(IPoint nearP) { IRectangle nearR = RandomRectangle(nearP); IList <IPoint> corners = outerInstance.QuadrantCorners(nearR); int r4 = outerInstance.random.Next(3 + 1);//0..3 IPoint pA = corners[r4]; IPoint pB = corners[(r4 + 2) % 4]; double maxBuf = Math.Max(nearR.Width, nearR.Height); double buf = Math.Abs(RandomGaussian()) * maxBuf / 4; buf = outerInstance.random.Next((int)Divisible(buf) + 1); return(new BufferedLine(pA, pB, buf, ctx)); }
public override void Paint(IRenderContext ctx, Graphics g) { IRectangle rect = Bounds.ToRectD().GetEnlarged(3); var rectangleVisual = new RectangleVisual(rect) { Pen = new Pen(Brushes.DarkGray) { DashStyle = DashStyle.Dot, Width = 2 } }; rectangleVisual.Paint(ctx, g); }
public bool RenderToggleButton(string uniqueId, IRectangle drawingGeometry, bool isDown, string caption, IStyle style) { Record( "RenderToggleButton", PrepareParam(uniqueId), PrepareParam(drawingGeometry), PrepareParam(isDown), PrepareParam(caption), PrepareParam(style) ); return(false); }
public IRectangle GetRectTiles(int _scale, IRectangleD _rect) { IRectangle rectFix = GetRectPixels(_scale, _rect); rectFix.XMax = rectFix.XMax - 1; rectFix.YMax = rectFix.YMax - 1; rectFix.XMin = rectFix.XMin / m_TileSizeX; rectFix.YMin = rectFix.YMin / m_TileSizeY; rectFix.XMax = rectFix.XMax / m_TileSizeX; rectFix.YMax = rectFix.YMax / m_TileSizeY; return(rectFix); }
protected virtual IRectangle randomRectangle() { IRectangle WB = ctx.WorldBounds; int rW = (int)randomGaussianMeanMax(10, WB.Width); double xMin = randomIntBetween((int)WB.MinX, (int)WB.MaxX - rW); double xMax = xMin + rW; int yH = (int)randomGaussianMeanMax(Math.Min(rW, WB.Height), WB.Height); double yMin = randomIntBetween((int)WB.MinY, (int)WB.MaxY - yH); double yMax = yMin + yH; return(ctx.MakeRectangle(xMin, xMax, yMin, yMax)); }
public SizeGripDecorator(IRectangle rectangle) : base(rectangle) { if (rectangle.IsHResizable) { this.gripPositions |= SizeGripPositions.EastWest; } if (rectangle.IsVResizable) { this.gripPositions |= SizeGripPositions.NorthSouth; } }
public string RenderTextField(string uniqueId, bool enabled, IRectangle drawingGeometry, string content, IStyle style) { Record( "RenderTextField", PrepareParam(uniqueId), PrepareParam(enabled), PrepareParam(drawingGeometry), PrepareParam(content), PrepareParam(style) ); return(""); }
protected virtual void TestRectIntersect() { //This test loops past the dateline for some variables but the makeNormRect() // method ensures the rect is valid. const double INCR = 45; const double Y = 20; for (double left = -180; left < 180; left += INCR) { for (double right = left; right - left <= 360; right += INCR) { IRectangle r = MakeNormRect(left, right, -Y, Y); //test contains (which also tests within) for (double left2 = left; left2 <= right; left2 += INCR) { for (double right2 = left2; right2 <= right; right2 += INCR) { IRectangle r2 = MakeNormRect(left2, right2, -Y, Y); AssertRelation(null, SpatialRelation.CONTAINS, r, r2); //test point contains AssertRelation(null, SpatialRelation.CONTAINS, r, r2.Center); } } //test disjoint for (double left2 = right + INCR; left2 - left < 360; left2 += INCR) { //test point disjoint AssertRelation(null, SpatialRelation.DISJOINT, r, ctx.MakePoint( NormX(left2), random.Next(-90, 90))); for (double right2 = left2; right2 - left < 360; right2 += INCR) { IRectangle r2 = MakeNormRect(left2, right2, -Y, Y); AssertRelation(null, SpatialRelation.DISJOINT, r, r2); } } //test intersect for (double left2 = left + INCR; left2 <= right; left2 += INCR) { for (double right2 = right + INCR; right2 - left < 360; right2 += INCR) { IRectangle r2 = MakeNormRect(left2, right2, -Y, Y); AssertRelation(null, SpatialRelation.INTERSECTS, r, r2); } } } } }
private void CheckBBox(IPoint ctr, double distKm) { string msg = "ctr: " + ctr + " distKm: " + distKm; double dist = distKm * DistanceUtils.KM_TO_DEG; IRectangle r = Dc().CalcBoxByDistFromPt(ctr, dist, ctx, null); double horizAxisLat = Dc().CalcBoxByDistFromPt_yHorizAxisDEG(ctr, dist, ctx); if (!double.IsNaN(horizAxisLat)) { Assert.True(r.RelateYRange(horizAxisLat, horizAxisLat).Intersects()); } //horizontal if (r.Width >= 180) { double deg = Dc().Distance(ctr, r.MinX, r.MaxY == 90 ? 90 : -90); double calcDistKm = deg * DistanceUtils.DEG_TO_KM; Assert.True(/*msg,*/ calcDistKm <= distKm + EPS); //horizAxisLat is meaningless in this context } else { IPoint tPt = FindClosestPointOnVertToPoint(r.MinX, r.MinY, r.MaxY, ctr); double calcDistKm = Dc().Distance(ctr, tPt) * DistanceUtils.DEG_TO_KM; CustomAssert.EqualWithDelta(/*msg,*/ distKm, calcDistKm, EPS); CustomAssert.EqualWithDelta(/*msg,*/ tPt.Y, horizAxisLat, EPS); } //vertical double topDistKm = Dc().Distance(ctr, ctr.X, r.MaxY) * DistanceUtils.DEG_TO_KM; if (r.MaxY == 90) { Assert.True(/*msg,*/ topDistKm <= distKm + EPS); } else { CustomAssert.EqualWithDelta(msg, distKm, topDistKm, EPS); } double botDistKm = Dc().Distance(ctr, ctr.X, r.MinY) * DistanceUtils.DEG_TO_KM; if (r.MinY == -90) { Assert.True(/*msg,*/ botDistKm <= distKm + EPS); } else { CustomAssert.EqualWithDelta(/*msg,*/ distKm, botDistKm, EPS); } }
private CollisionPenetration CollisionPenetration( IRectangle struckObject, IRectangle movingObject, IRectangle movingObjectLastFrame) { var penetrations = new List <CollisionPenetration>(); if (movingObject.Left <= struckObject.Right && struckObject.Right <= movingObjectLastFrame.Left) { penetrations.Add(new CollisionPenetration { Depth = new Vector2(movingObject.Left - struckObject.Right, 0), From = Direction.Left }); } if (movingObjectLastFrame.Right <= struckObject.Left && struckObject.Left <= movingObject.Right) { penetrations.Add(new CollisionPenetration { Depth = new Vector2(movingObject.Right - struckObject.Left, 0), From = Direction.Right }); } if (movingObjectLastFrame.Bottom <= struckObject.Top && struckObject.Top <= movingObject.Bottom) { penetrations.Add(new CollisionPenetration { Depth = new Vector2(0, movingObject.Bottom - struckObject.Top), From = Direction.Top }); } if (movingObject.Top <= struckObject.Bottom && struckObject.Bottom <= movingObjectLastFrame.Top) { penetrations.Add(new CollisionPenetration { Depth = new Vector2(0, movingObject.Top - struckObject.Bottom), From = Direction.Bottom }); } if (!penetrations.Any()) { return(new CollisionPenetration { Depth = Vector2.Zero, From = Direction.Unknown }); } return(penetrations.OrderBy(p => Math.Abs(p.Depth.X) + Math.Abs(p.Depth.Y)).FirstOrDefault()); }
private RenderingTemplate BuildNewRenderingTemplate(IRectangle range) { return(new RenderingTemplate { Range = range, Content = templateTable.GetTablePart(range), MergedCells = templateTable.MergedCells .Where(rect => rect.Intersects(range)) .Select(rect => rect.ToRelativeCoordinates(range.UpperLeft)), Columns = templateTable.Columns .Where(column => column.Index >= range.UpperLeft.ColumnIndex && column.Index <= range.LowerRight.ColumnIndex) }); }
public WSNChannel(IRectangle from, IRectangle to) : base(from, to) { if (from != null && to != null) ID = getPureId(); // Default value Kind = ChannelKind.Real; SendingRate = 10; Type = ChannelType.Broadcast; SubIdList = new List<int>(); Neighbor = false; CongestionLevel = CGNLevel.Low; }
public override void Draw(IDrawManager drawManager, IRectangle destinationRectangle) { var border = new Border(destinationRectangle, BorderThickness); drawManager.Draw(TopLeftRegion, ToRect(border.TopLeft)); drawManager.Draw(TopRegion, ToRect(border.Top)); drawManager.Draw(TopRightRegion, ToRect(border.TopRight)); drawManager.Draw(LeftRegion, ToRect(border.Left)); drawManager.Draw(CentreRegion, ToRect(border.Centre)); drawManager.Draw(RightRegion, ToRect(border.Right)); drawManager.Draw(BottomLeftRegion, ToRect(border.BottomLeft)); drawManager.Draw(BottomRegion, ToRect(border.Bottom)); drawManager.Draw(BottomRightRegion, ToRect(border.BottomRight)); }
public static bool ContainsPoint(this IRectangle rectangle, int x, int y) { if (x < rectangle.X || x > rectangle.X + rectangle.Width) { return(false); } if (y < rectangle.Y || y > rectangle.Y + rectangle.Height) { return(false); } return(true); }
public float RenderVSlider(string uniqueId, bool enabled, IRectangle drawingGeometry, float value, float min, float max) { Record( "RenderVSlider", PrepareParam(uniqueId), PrepareParam(enabled), PrepareParam(drawingGeometry), PrepareParam(value), PrepareParam(min), PrepareParam(max) ); return(0); }
// получить координаты для конечной точки, тут высчитывается середина private static PointF GetConnectionPointPosition(IRectangle rect, ConnectionPoint point) { switch (point) { case ConnectionPoint.North: return(new PointF(rect.X + rect.ActualWidth / 2, rect.Y)); case ConnectionPoint.East: return(new PointF(rect.X + rect.ActualWidth, rect.Y + ((((NodeCanvasItem)rect).Collapsed) ? rect.ActualHeight / 2 : 32))); case ConnectionPoint.South: return(new PointF(rect.X + rect.ActualWidth / 2, rect.Y + rect.ActualHeight)); case ConnectionPoint.West: return(new PointF(rect.X, rect.Y + rect.ActualHeight / 2)); } return(new PointF(rect.X + rect.ActualWidth / 2, rect.Y + rect.ActualHeight / 2)); // Center }
/// <summary> /// Returns either 0 for none, 1 for some, or 4 for all. /// </summary> private int NumCornersIntersect(IRectangle r) { //We play some logic games to avoid calling contains() which can be expensive. // for partial, we exit early with 1 and ignore bool. bool b = (Contains(r.MinX, r.MinY)); if (Contains(r.MinX, r.MaxY)) { if (!b) { return(1); //partial } } else { if (b) { return(1); //partial } } if (Contains(r.MaxX, r.MinY)) { if (!b) { return(1); //partial } } else { if (b) { return(1); //partial } } if (Contains(r.MaxX, r.MaxY)) { if (!b) { return(1); //partial } } else { if (b) { return(1); //partial } } return(b ? 4 : 0); }
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()); }
private static PointF GetConnectionPointPosition(IRectangle rect, ConnectionPoint point) { switch (point) { case ConnectionPoint.North: return(new PointF(rect.X + rect.ActualWidth / 2, rect.Y)); case ConnectionPoint.East: return(new PointF(rect.X + rect.ActualWidth, rect.Y + rect.ActualHeight / 2)); case ConnectionPoint.South: return(new PointF(rect.X + rect.ActualWidth / 2, rect.Y + rect.ActualHeight)); case ConnectionPoint.West: return(new PointF(rect.X, rect.Y + rect.ActualHeight / 2)); } return(new PointF(rect.X + rect.ActualWidth / 2, rect.Y + rect.ActualHeight / 2)); }
public virtual void LoadFromXML(XmlElement xmlElement, LTSCanvas canvas) { //string startingState = xmlElement.ChildNodes[0].InnerText; //this.from = canvas.FindState(startingState); //string endState = xmlElement.ChildNodes[1].InnerText; //this.to = canvas.FindState(endState); //this.Transition.Select = xmlElement.ChildNodes[2].InnerText; //this.Transition.Event = xmlElement.ChildNodes[3].InnerText; //this.Transition.ClockGuard = xmlElement.ChildNodes[4].InnerText; //this.Transition.Guard = xmlElement.ChildNodes[5].InnerText; //this.Transition.Program = xmlElement.ChildNodes[6].InnerText; //this.Transition.ClockReset = xmlElement.ChildNodes[7].InnerText; //this.Transition.Width = this.Transition.GetWidthOfLabel(); //for (int i = 8; i < xmlElement.ChildNodes.Count - 1; i++) //{ // NailItem nail = new NailItem(this); // nail.LoadFromXml(xmlElement.ChildNodes[i] as XmlElement); // this.nails.Add(nail); //} //this.transition.LoadFromXml(xmlElement.ChildNodes[xmlElement.ChildNodes.Count - 1] as XmlElement); string startingState = xmlElement.SelectSingleNode("./" + FROM_NODE_NAME).InnerText; this.from = canvas.FindState(startingState); string endState = xmlElement.SelectSingleNode("./" + TO_NODE_NAME).InnerText; this.to = canvas.FindState(endState); this.Transition.Select = xmlElement.SelectSingleNode("./" + SELECT_NODE_NAME).InnerText; this.Transition.Event = xmlElement.SelectSingleNode("./" + EVENT_NODE_NAME).InnerText; this.Transition.ClockGuard = xmlElement.SelectSingleNode("./" + CLOCK_GUARD_NODE_NAME).InnerText; this.Transition.Guard = xmlElement.SelectSingleNode("./" + GUARD_NODE_NAME).InnerText; this.Transition.Program = xmlElement.SelectSingleNode("./" + PROGRAM_NODE_NAME).InnerText; this.Transition.ClockReset = xmlElement.SelectSingleNode("./" + CLOCK_RESET_NODE_NAME).InnerText; this.Transition.Width = this.Transition.GetWidthOfLabel(); XmlNodeList nails = xmlElement.SelectNodes("./" + NAIL_NODE_NAME); if (nails != null) { foreach (XmlElement xmlNail in nails) { NailItem nail = new NailItem(this); nail.LoadFromXml(xmlNail); this.nails.Add(nail); } } this.transition.LoadFromXml((XmlElement)xmlElement.SelectSingleNode("./" + LABEL_NODE_NAME)); }
public Polygon(IRectangle rectangle) : base(SpatialShapeType.Polygon) { if (rectangle == null) { throw new ArgumentNullException(nameof(rectangle)); } Vertices ??= new List <Coordinates>(); Vertices.Add(new Coordinates(rectangle.MaxY, rectangle.MaxX)); Vertices.Add(new Coordinates(rectangle.MaxY, rectangle.MinY)); Vertices.Add(new Coordinates(rectangle.MinY, rectangle.MaxX)); Vertices.Add(new Coordinates(rectangle.MinY, rectangle.MinX)); }
protected override VisualGroup CreateVisual(IRenderContext context, IStripe stripe) { IRectangle layout = stripe.Layout.ToRectD(); GeneralPath outline = CreatePath(stripe, layout); var visual = outline.CreatePath(StripeDescriptor.BackgroundBrush, new Pen(StripeDescriptor.BorderBrush, StripeDescriptor.BorderThickness.Left), null, FillMode.Always); var cc = new VisualGroup(); cc.Add(visual); cc.SetCanvasArrangeRect(layout.ToRectD()); return(cc); }
private void ValidateWorld(double r1MinX, double r1MaxX, double r2MinX, double r2MaxX) { ctx = SpatialContext.GEO; IRectangle r1 = ctx.MakeRectangle(r1MinX, r1MaxX, -10, 10); IRectangle r2 = ctx.MakeRectangle(r2MinX, r2MaxX, -10, 10); ShapeCollection /*<Rectangle>*/ s = new ShapeCollection/*<Rectangle>*/ (new IShape[] { r1, r2 }, ctx); Assert.Equal(Range.LongitudeRange.WORLD_180E180W, new Range.LongitudeRange(s.BoundingBox)); //flip r1, r2 order s = new ShapeCollection/*<Rectangle>*/ (new IShape[] { r2, r1 }, ctx); Assert.Equal(Range.LongitudeRange.WORLD_180E180W, new Range.LongitudeRange(s.BoundingBox)); }
// @Rule //public TestLog testLog = TestLog.instance; //SpatialContext.GEO ;// public static void LogShapes(BufferedLine line, IRectangle rect) { string lineWKT = "LINESTRING(" + line.A.X + " " + line.A.Y + "," + line.B.X + " " + line.B.Y + ")"; Console.WriteLine( "GEOMETRYCOLLECTION(" + lineWKT + "," + RectToWkt(line.BoundingBox ) + ")"); string rectWKT = RectToWkt(rect); Console.WriteLine(rectWKT); }
public static IRectangle GetRectangleDiagonal() { IRectangle rectangle = Factory.GetInstanceIRectangle(); Point diagonalStart = new Point(); Point diagonalEnd = new Point(); /* get input from user start point */ Console.Write("Enter diagonal start co-ordinates x1,y1: "); string coOrdinate = Console.ReadLine(); string[] coOrdinateValues = coOrdinate.Split(','); /* parsing check and setting null if parsing fails */ int parseStorageX = 0, parseStorageY = 0; if (coOrdinateValues.Count() == 2 && InputValidator.IsInt(coOrdinateValues[0], ref parseStorageX) & InputValidator.IsInt(coOrdinateValues[1], ref parseStorageY)) { diagonalStart.X = parseStorageX; diagonalStart.Y = parseStorageY; rectangle.diagonalStartPoint = diagonalStart; } else { rectangle = null; return(rectangle); } /* get input from user end point */ Console.Write("Enter diagonal end co-ordinates x2,y2: "); coOrdinate = Console.ReadLine(); coOrdinateValues = coOrdinate.Split(','); /* parsing check and setting null if parsing fails */ parseStorageX = 0; parseStorageY = 0; if (coOrdinateValues.Count() == 2 && InputValidator.IsInt(coOrdinateValues[0], ref parseStorageX) & InputValidator.IsInt(coOrdinateValues[1], ref parseStorageY)) { diagonalEnd.X = parseStorageX; diagonalEnd.Y = parseStorageY; rectangle.diagonalEndPoint = diagonalEnd; } else { rectangle = null; return(rectangle); } return(rectangle); } //GetRectangle
public static Boolean AreRectsEqual <TRect>(TRect left, IRectangle right) where TRect : IRectangle { if (ReferenceEquals(left, right)) { return(true); } return(left.Width.AreEqualEnough(right.Width) && left.Height.AreEqualEnough(right.Height) && left.Left.AreEqualEnough(right.Left) && left.Top.AreEqualEnough(right.Top)); }
public static void Main() { Shape s = new Shape(); // s.Area(10, 10); // error - ambiguous !!! // s.IRectangle.Area(10, 10); // error // s.ITriangle.Area(10, 10); // error ((IRectangle)s).Area(20, 20); // 캐스팅-업 ((ITriangle)s).Area(20, 20); // 캐스팅-업 IRectangle r = s; // 인터페이스로 캐스팅-업 ITriangle t = s; // 인터페이스로 캐스팅-업 r.Area(30, 30); t.Area(30, 30); }
/// <summary> /// Constructs a query to retrieve documents that fully contain the input envelope. /// </summary> private Query MakeDisjoint(IRectangle bbox) { if (bbox.CrossesDateLine) { throw new NotSupportedException("MakeDisjoint doesn't handle dateline cross"); } Query qX = RangeQuery(fieldNameX, bbox.MinX, bbox.MaxX); Query qY = RangeQuery(fieldNameY, bbox.MinY, bbox.MaxY); var bq = new BooleanQuery(); bq.Add(qX, BooleanClause.Occur.MUST_NOT); bq.Add(qY, BooleanClause.Occur.MUST_NOT); return(bq); }
public void RenderLabel(string uniqueId, IRectangle drawingGeometry, string text, IStyle style, bool hasDropShadow, IRgbaColor dropShadowRgbaColor, float dropShadowOffsetX, float dropShadowOffsetY) { Record( "RenderLabel", PrepareParam(uniqueId), PrepareParam(drawingGeometry), PrepareParam(text), PrepareParam(style), PrepareParam(hasDropShadow), PrepareParam(dropShadowRgbaColor), PrepareParam(dropShadowOffsetX), PrepareParam(dropShadowOffsetY) ); }
protected virtual IPoint RandomPointIn(IShape shape) { if (!shape.HasArea)// or try the center? { throw new InvalidOperationException("Need area to define shape!"); } IRectangle bbox = shape.BoundingBox; IPoint p; do { p = RandomPointIn(bbox); } while (!bbox.Relate(p).Intersects()); return(p); }
// possibly consider hilbert curve // http://en.wikipedia.org/wiki/Hilbert_curve // http://blog.notdot.net/2009/11/Damn-Cool-Algorithms-Spatial-indexing-with-Quadtrees-and-Hilbert-Curves // if we actually use the range property in the query, this could be useful private void CheckBattenberg( char c, double cx, double cy, int level, IList <Cell> matches, StringBuilder str, IShape shape, int maxLevel) { if (Debugging.AssertsEnabled) { Debugging.Assert(str.Length == level); } double w = levelW[level] / 2; double h = levelH[level] / 2; int strlen = str.Length; IRectangle rectangle = m_ctx.MakeRectangle(cx - w, cx + w, cy - h, cy + h); SpatialRelation v = shape.Relate(rectangle); if (SpatialRelation.CONTAINS == v) { str.Append(c); //str.append(SpatialPrefixGrid.COVER); matches.Add(new QuadCell(this, str.ToString(), v.Transpose())); } else if (SpatialRelation.DISJOINT == v) { // nothing } else // SpatialRelation.WITHIN, SpatialRelation.INTERSECTS { str.Append(c); int nextLevel = level + 1; if (nextLevel >= maxLevel) { //str.append(SpatialPrefixGrid.INTERSECTS); matches.Add(new QuadCell(this, str.ToString(), v.Transpose())); } else { Build(cx, cy, nextLevel, matches, str, shape, maxLevel); } } str.Length = strlen; }
/// <summary> /// Given a cell having the specified level, returns the distance from opposite /// corners. /// </summary> /// <remarks> /// Given a cell having the specified level, returns the distance from opposite /// corners. Since this might very depending on where the cell is, this method /// may over-estimate. /// </remarks> /// <param name="level">[1 to maxLevels]</param> /// <returns>> 0</returns> public virtual double GetDistanceForLevel(int level) { if (level < 1 || level > MaxLevels) { throw new ArgumentException("Level must be in 1 to maxLevels range"); } //TODO cache for each level Cell cell = GetCell(ctx.WorldBounds.Center, level); IRectangle bbox = cell.Shape.BoundingBox; double width = bbox.Width; double height = bbox.Height; //Use standard cartesian hypotenuse. For geospatial, this answer is larger // than the correct one but it's okay to over-estimate. return(Math.Sqrt(width * width + height * height)); }
public bool Equals(IRectangle obj) { if (!(obj is Rectangle)) return false; var rect = (Rectangle)obj; bool result = true; result &= _valid.Equals(rect._valid); result &= Left.Equals(rect.Left); result &= Top.Equals(rect.Top); result &= Width.Equals(rect.Width); result &= Height.Equals(rect.Height); return result; }
public float IntersectionDistance (PointF origin, IRectangle rect) { PointF dest = CreateDestinationPoint(origin); float dist = -1; switch (direction) { case Direction.Left: dist = (origin.X - rect.X + rect.ActualWidth); break; case Direction.Right: dist = rect.X - origin.X; break; case Direction.Up: dist = (origin.Y - rect.Y + rect.ActualHeight); break; case Direction.Down: dist = rect.Y - origin.Y; break; } return dist; }
private bool CalculateContainment(IRectangle outerRectangle, IRectangle rectangle) { var outerTopLeftCorner = GetTopLeftCorner(outerRectangle); var outerLowerRightCorner = GetLowerRightCorner(outerRectangle); var innerTopLeftCorner = GetTopLeftCorner(rectangle); var innerLowerRightCorner = GetLowerRightCorner(rectangle); if (outerTopLeftCorner.YCoordinate < innerTopLeftCorner.YCoordinate) return false; if (outerTopLeftCorner.XCoordinate > innerTopLeftCorner.XCoordinate) return false; if (outerLowerRightCorner.XCoordinate < innerLowerRightCorner.XCoordinate) return false; if (outerLowerRightCorner.YCoordinate > innerLowerRightCorner.YCoordinate) return false; return true; }
public static IList<INative> HitTest( IList<INative> children, IRectangle rectangle) { double x = Math.Min(rectangle.Point1.X, rectangle.Point2.X); double y = Math.Min(rectangle.Point1.Y, rectangle.Point2.Y); double width = Math.Abs(rectangle.Point2.X - rectangle.Point1.X); double height = Math.Abs(rectangle.Point2.Y - rectangle.Point1.Y); var selectionVertices = new Vector2[] { new Vector2(x, y), new Vector2(x + width, y), new Vector2(x + width, y + height), new Vector2(x, y + height) }; var overlapping = children .Where(c => { if (c.Bounds != null) { var vertices = c.Bounds.GetVertices(); if (vertices != null) { return SAT.Overlap(selectionVertices, vertices); } return false; } return false; }).ToList(); foreach (var child in overlapping) { child.Bounds.Show(); } return overlapping; }
public bool IntersectsWith (PointF origin, IRectangle rect) { PointF dest = CreateDestinationPoint(origin); bool xIntersects = false; bool yIntersects = false; if (direction == Direction.Left || direction == Direction.Right) { float y = origin.Y; float x1 = Math.Min(origin.X, dest.X); float x2 = Math.Max(origin.X, dest.X); yIntersects = (rect.Y <= y && rect.Y + rect.ActualHeight >= y); xIntersects = (x2 < rect.X || x1 > rect.X + rect.ActualWidth); } else { float x = origin.X; float y1 = Math.Min(origin.Y, dest.Y); float y2 = Math.Max(origin.Y, dest.Y); xIntersects = (rect.X <= x && rect.X + rect.ActualWidth >= x); yIntersects = (y2 < rect.Y || y1 > rect.Y + rect.ActualHeight); } return xIntersects && yIntersects; }
/// <summary> /// Sets the symbol type to geographic and generates a size that is 1/100 the width of the specified extents. /// </summary> /// <param name="selected"></param> /// <param name="extents"></param> public PointSymbolizer(bool selected, IRectangle extents) { Configure(); base.ScaleMode = ScaleMode.Geographic; base.Smoothing = false; ISymbol s = _symbols[0]; if (s == null) return; s.Size.Width = extents.Width / 100; s.Size.Height = extents.Width / 100; ISimpleSymbol ss = _symbols[0] as ISimpleSymbol; if (ss != null && selected) ss.Color = Color.Cyan; }
public void Draw(IDrawManager drawManager, string text, IRectangle destinationRectangle) { if(!string.IsNullOrEmpty(text)) drawManager.DrawText(text, destinationRectangle, this); }
private void Draw(TextureRegion textureRegion, IRectangle destinationRectangle) { var texture = _textureMap[textureRegion.TextureAtlas.TextureName]; if(texture != null) { var sourceRectangle = new Rectangle(textureRegion.X, textureRegion.Y, textureRegion.Width, textureRegion.Height); _spriteBatch.Draw(texture, ToRectangle(destinationRectangle), sourceRectangle, Color.White); } }
private void Write(IRectangle rectangle) { Write(NativeType.Rectangle); _writer.Write(rectangle.Id); Write(rectangle.Point1); Write(rectangle.Point2); Write(rectangle.Stroke); _writer.Write(rectangle.StrokeThickness); Write(rectangle.Fill); }
public void DrawText(string text, IRectangle destinationRectangle, TextStyle style) { var textPosition = AlignText(text, ToRectangle(destinationRectangle), style); _fontRenderer.DrawText(_spriteBatch, textPosition.X, textPosition.Y, text, style.Colour); }
private void Process(IRectangle rectangle) { rectangle.Id = NextId(); Process(rectangle.Point1); Process(rectangle.Point2); }
public virtual void Draw(IDrawManager drawManager, IRectangle destinationRectangle) { drawManager.Draw(this, destinationRectangle); }
/// <summary> /// Creates a new instanec of a default point scheme category where the geographic symbol size has been /// scaled to the specified extent. /// </summary> /// <param name="extent">The geographic extent that is 100 times wider than the geographic size of the points.</param> public PointCategory(IRectangle extent) { Symbolizer = new PointSymbolizer(false, extent); SelectionSymbolizer = new PointSymbolizer(true, extent); }
public FocusDecorator (IRectangle rectangle) : base (rectangle) {}
private void Reset(IRectangle rectangle) { rectangle.Id = 0; Reset(rectangle.Point1); Reset(rectangle.Point2); }
protected RectangleDecorator (IRectangle rectangle) { this.rect = rectangle; }
public PNArc(IRectangle from, IRectangle to) : base(from, to) { }