public RectangleImpl(Point lowerLeft, Point upperRight) { this.minX = lowerLeft.GetX(); this.maxX = upperRight.GetX(); this.minY = lowerLeft.GetY(); this.maxY = upperRight.GetY(); }
/// <summary> /// All {@link Point} implementations should use this definition of {@link Object#hashCode()}. /// </summary> /// <param name="thiz"></param> /// <returns></returns> public static int GetHashCode(Point thiz) { if (thiz == null) throw new ArgumentNullException("thiz"); long temp = thiz.GetX() != +0.0d ? BitConverter.DoubleToInt64Bits(thiz.GetX()) : 0L; int result = (int)(temp ^ ((uint)temp >> 32)); temp = thiz.GetY() != +0.0d ? BitConverter.DoubleToInt64Bits(thiz.GetY()) : 0L; result = 31 * result + (int)(temp ^ ((uint)temp >> 32)); return result; }
static public void Test_A2(Point point) { double x = point.GetX(); double y = point.GetY(); double z = point.GetZ(); Debug.Assert(Program.IsApprox(x, 636784.74, 0.01)); Debug.Assert(Program.IsApprox(y, 849106.66, 0.01)); Debug.Assert(Program.IsApprox(z, 426.71, 0.01)); double time = point.GetTime(); Debug.Assert(Program.IsApprox(time, 245382.13595, 0.00001)); Debug.Assert(point.GetIntensity() == 118); Debug.Assert(point.GetReturnNumber() == 1); Debug.Assert(point.GetNumberOfReturns() == 1); Classification classif = point.GetClassification(); Debug.Assert(classif.GetClassName() == "Unclassified"); Debug.Assert(!classif.IsKeyPoint()); Debug.Assert(!classif.IsSynthetic()); Debug.Assert(!classif.IsWithheld()); Color color = point.GetColor(); Debug.Assert(color.GetRed() == 112); Debug.Assert(color.GetGreen() == 97); Debug.Assert(color.GetBlue() == 114); }
public override Rectangle CalcBoxByDistFromPt(Point from, double distDEG, SpatialContext ctx, Rectangle reuse) { double minX = from.GetX() - distDEG; double maxX = from.GetX() + distDEG; double minY = from.GetY() - distDEG; double maxY = from.GetY() + distDEG; if (reuse == null) { return ctx.MakeRectangle(minX, maxX, minY, maxY); } else { reuse.Reset(minX, maxX, minY, maxY); return reuse; } }
/// <summary> /// All {@link Point} implementations should use this definition of {@link Object#equals(Object)}. /// </summary> /// <param name="thiz"></param> /// <param name="o"></param> /// <returns></returns> public static bool Equals(Point thiz, Object o) { if (thiz == null) throw new ArgumentNullException("thiz"); if (thiz == o) return true; var point = o as Point; if (point == null) return false; return thiz.GetX().Equals(point.GetX()) && thiz.GetY().Equals(point.GetY()); }
public Field[] CreateIndexableFields(Point point) { FieldType doubleFieldType = new FieldType(DoubleField.TYPE_NOT_STORED) { NumericPrecisionStep = precisionStep }; var f = new Field[] { new DoubleField(fieldNameX, point.GetX(), doubleFieldType), new DoubleField(fieldNameY, point.GetY(), doubleFieldType) }; return f; }
/* NGeohash round-trip for given precision. */ private Point alignGeohash(Point p) { return GeohashUtils.Decode(GeohashUtils.EncodeLatLon(p.GetY(), p.GetX(), maxLength), ctx); }
public override double Distance(Point from, double toX, double toY) { double result = 0; double v = from.GetX() - toX; result += (v * v); v = from.GetY() - toY; result += (v * v); if (squared) return result; return Math.Sqrt(result); }
public AbstractField[] CreateIndexableFields(Point point) { var f = new AbstractField[2]; var f0 = new NumericField(fieldNameX, precisionStep, Field.Store.NO, true) {OmitNorms = true, OmitTermFreqAndPositions = true}; f0.SetDoubleValue(point.GetX()); f[0] = f0; var f1 = new NumericField(fieldNameY, precisionStep, Field.Store.NO, true) {OmitNorms = true, OmitTermFreqAndPositions = true}; f1.SetDoubleValue(point.GetY()); f[1] = f1; return f; }
public override Point PointOnBearing(Point from, double distDEG, double bearingDEG, SpatialContext ctx, Point reuse) { if (distDEG == 0) { if (reuse == null) return from; reuse.Reset(from.GetX(), from.GetY()); return reuse; } double bearingRAD = DistanceUtils.ToRadians(bearingDEG); double x = from.GetX() + Math.Sin(bearingRAD)*distDEG; double y = from.GetY() + Math.Cos(bearingRAD)*distDEG; if (reuse == null) { return ctx.MakePoint(x, y); } else { reuse.Reset(x, y); return reuse; } }
public SpatialRelation Relate(Point point, SpatialContext ctx) { return Contains(point.GetX(), point.GetY()) ? SpatialRelation.CONTAINS : SpatialRelation.DISJOINT; }
public SpatialRelation Relate(Point point, SpatialContext ctx) { if (point.GetY() > GetMaxY() || point.GetY() < GetMinY()) return SpatialRelation.DISJOINT; // all the below logic is rather unfortunate but some dateline cases demand it double minX = this.minX; double maxX = this.maxX; double pX = point.GetX(); if (ctx.IsGeo()) { //unwrap dateline and normalize +180 to become -180 double rawWidth = maxX - minX; if (rawWidth < 0) { maxX = minX + (rawWidth + 360); } //shift to potentially overlap if (pX < minX) { pX += 360; } else if (pX > maxX) { pX -= 360; } else { return SpatialRelation.CONTAINS; //short-circuit } } if (pX < minX || pX > maxX) return SpatialRelation.DISJOINT; return SpatialRelation.CONTAINS; }
public override Rectangle CalcBoxByDistFromPt(Point from, double distDEG, SpatialContext ctx, Rectangle reuse) { return DistanceUtils.CalcBoxByDistFromPtDEG(from.GetY(), from.GetX(), distDEG, ctx, reuse); }
private void checkBBox(Point ctr, double distKm) { String msg = "ctr: " + ctr + " distKm: " + distKm; double dist = distKm * DistanceUtils.KM_TO_DEG; Rectangle 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.GetWidth() >= 180) { double deg = dc().Distance(ctr, r.GetMinX(), r.GetMaxY() == 90 ? 90 : -90); double calcDistKm = deg * DistanceUtils.DEG_TO_KM; Assert.True(/*msg,*/ calcDistKm <= distKm + EPS); //horizAxisLat is meaningless in this context } else { Point tPt = FindClosestPointOnVertToPoint(r.GetMinX(), r.GetMinY(), r.GetMaxY(), ctr); double calcDistKm = dc().Distance(ctr, tPt) * DistanceUtils.DEG_TO_KM; CustomAssert.EqualWithDelta(/*msg,*/ distKm, calcDistKm, EPS); CustomAssert.EqualWithDelta(/*msg,*/ tPt.GetY(), horizAxisLat, EPS); } //vertical double topDistKm = dc().Distance(ctr, ctr.GetX(), r.GetMaxY()) * DistanceUtils.DEG_TO_KM; if (r.GetMaxY() == 90) Assert.True(/*msg,*/ topDistKm <= distKm + EPS); else CustomAssert.EqualWithDelta(msg, distKm, topDistKm, EPS); double botDistKm = dc().Distance(ctr, ctr.GetX(), r.GetMinY()) * DistanceUtils.DEG_TO_KM; if (r.GetMinY() == -90) Assert.True(/*msg,*/ botDistKm <= distKm + EPS); else CustomAssert.EqualWithDelta(/*msg,*/ distKm, botDistKm, EPS); }
/// <summary> /// Construct a rectangle. The parameters will be normalized. /// </summary> /// <param name="lowerLeft"></param> /// <param name="upperRight"></param> /// <returns></returns> public Rectangle MakeRectangle(Point lowerLeft, Point upperRight) { return MakeRectangle(lowerLeft.GetX(), upperRight.GetX(), lowerLeft.GetY(), upperRight.GetY()); }
protected internal override Cell GetCell(Point p, int level) { return new GhCell(this, GeohashUtils.EncodeLatLon(p.GetY(), p.GetX (), level)); }
protected override Node GetNode(Point p, int level) { return new GhCell(GeohashUtils.EncodeLatLon(p.GetY(), p.GetX(), level), this);//args are lat,lon (y,x) }
public RectangleImpl(Point lowerLeft, Point upperRight, SpatialContext ctx) : this(lowerLeft.GetX(), upperRight.GetX(), lowerLeft.GetY(), upperRight.GetY(), ctx) { }
protected internal override Cell GetCell(Point p, int level) { IList<Cell> cells = new List<Cell>(1); Build(xmid, ymid, 0, cells, new StringBuilder(), ctx.MakePoint(p.GetX(), p.GetY()), level); return cells[0]; }
public override double CalcBoxByDistFromPt_yHorizAxisDEG(Point from, double distance, SpatialContext ctx) { return DistanceUtils.CalcBoxByDistFromPt_latHorizAxisDEG(from.GetY(), from.GetX(), distance, radius); }
protected override Node GetNode(Point p, int level) { var cells = new List<Node>(1); Build(xmid, ymid, 0, cells, new StringBuilder(), ctx.MakePoint(p.GetX(), p.GetY()), level); return cells[0];//note cells could be longer if p on edge }
private void CheckBBox(Point ctr, double dist) { String msg = "ctr: " + ctr + " dist: " + dist; Rectangle r = dc().CalcBoxByDistFromPt(ctr, dist, ctx); double horizAxisLat = dc().CalcBoxByDistFromPt_yHorizAxisDEG(ctr, dist, ctx); if (!Double.IsNaN(horizAxisLat)) Assert.True(r.RelateYRange(horizAxisLat, horizAxisLat, ctx).Intersects()); //horizontal if (r.GetWidth() >= 180) { double calcDist = dc().Distance(ctr, r.GetMinX(), r.GetMaxY() == 90 ? 90 : -90); Assert.True(calcDist <= dist + EPS, msg); //horizAxisLat is meaningless in this context } else { Point tPt = FindClosestPointOnVertToPoint(r.GetMinX(), r.GetMinY(), r.GetMaxY(), ctr); double calcDist = dc().Distance(ctr, tPt); CustomAssert.EqualWithDelta(/*msg,*/ dist, calcDist, EPS); CustomAssert.EqualWithDelta(/*msg,*/ tPt.GetY(), horizAxisLat, EPS); } //vertical double topDist = dc().Distance(ctr, ctr.GetX(), r.GetMaxY()); if (r.GetMaxY() == 90) Assert.True(topDist <= dist + EPS, msg); else CustomAssert.EqualWithDelta(dist, topDist, EPS); double botDist = dc().Distance(ctr, ctr.GetX(), r.GetMinY()); if (r.GetMinY() == -90) Assert.True(botDist <= dist + EPS, msg); else CustomAssert.EqualWithDelta(/*msg,*/ dist, botDist, EPS); }