You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by sy...@apache.org on 2012/09/21 13:57:37 UTC
svn commit: r1388446 [2/2] - in /lucene.net/trunk: lib/Spatial4n/NET35/
lib/Spatial4n/NET40/ src/contrib/Spatial/BBox/ src/contrib/Spatial/Prefix/
src/contrib/Spatial/Prefix/Tree/ src/contrib/Spatial/Queries/
test/contrib/Spatial/ test/contrib/Spatial/...
Modified: lucene.net/trunk/lib/Spatial4n/NET40/Spatial4n.Core.XML
URL: http://svn.apache.org/viewvc/lucene.net/trunk/lib/Spatial4n/NET40/Spatial4n.Core.XML?rev=1388446&r1=1388445&r2=1388446&view=diff
==============================================================================
--- lucene.net/trunk/lib/Spatial4n/NET40/Spatial4n.Core.XML (original)
+++ lucene.net/trunk/lib/Spatial4n/NET40/Spatial4n.Core.XML Fri Sep 21 11:57:35 2012
@@ -64,7 +64,7 @@
@param upperRight If true, return the coords for the upper right corner, else return the lower left.
@return The point, either the upperLeft or the lower right
</member>
- <member name="M:Spatial4n.Core.Distance.DistanceUtils.PointOnBearingRAD(System.Double,System.Double,System.Double,System.Double,System.Double[])">
+ <member name="M:Spatial4n.Core.Distance.DistanceUtils.PointOnBearingRAD(System.Double,System.Double,System.Double,System.Double,Spatial4n.Core.Context.SpatialContext,Spatial4n.Core.Shapes.Point)">
Given a start point (startLat, startLon) and a bearing on a sphere of radius <i>sphereRadius</i>, return the destination point.
@@ -75,18 +75,6 @@
@param result A preallocated array to hold the results. If null, a new one is constructed.
@return The destination point, in radians. First entry is latitude, second is longitude
</member>
- <member name="M:Spatial4n.Core.Distance.DistanceUtils.NormLatRAD(System.Double[])">
- <summary>
-
- </summary>
- <param name="latLng">The lat/lon, in radians. lat in position 0, lon in position 1</param>
- </member>
- <member name="M:Spatial4n.Core.Distance.DistanceUtils.NormLngRAD(System.Double[])">
- <summary>
- Returns a normalized Lng rectangle shape for the bounding box
- </summary>
- <param name="latLng">The lat/lon, in radians, lat in position 0, lon in position 1</param>
- </member>
<!-- Badly formed XML comment ignored for member "M:Spatial4n.Core.Distance.DistanceUtils.NormLonDEG(System.Double)" -->
<member name="M:Spatial4n.Core.Distance.DistanceUtils.NormLatDEG(System.Double)">
<summary>
@@ -95,12 +83,10 @@
<param name="lat_deg"></param>
<returns></returns>
</member>
- <member name="M:Spatial4n.Core.Distance.DistanceUtils.CalcBoxByDistFromPt_deltaLonDEG(System.Double,System.Double,System.Double,System.Double)">
+ <member name="M:Spatial4n.Core.Distance.DistanceUtils.CalcBoxByDistFromPt_deltaLonDEG(System.Double,System.Double,System.Double)">
<summary>
The delta longitude of a point-distance. In other words, half the width of
the bounding box of a circle.
- <p/>
- <code>distance</code> and <code>radius</code> should be in the same units.
</summary>
<param name="lat"></param>
<param name="lon"></param>
@@ -108,20 +94,17 @@
<param name="radius"></param>
<returns></returns>
</member>
- <member name="M:Spatial4n.Core.Distance.DistanceUtils.CalcBoxByDistFromPt_latHorizAxisDEG(System.Double,System.Double,System.Double,System.Double)">
+ <member name="M:Spatial4n.Core.Distance.DistanceUtils.CalcBoxByDistFromPt_latHorizAxisDEG(System.Double,System.Double,System.Double)">
<summary>
The latitude of the horizontal axis (e.g. left-right line)
of a circle. The horizontal axis of a circle passes through its furthest
left-most and right-most edges. On a 2D plane, this result is always
<code>from.getY()</code> but, perhaps surprisingly, on a sphere it is going
to be slightly different.
- <p/>
- <code>distance</code> and <code>radius</code> should be in the same units.
</summary>
<param name="lat"></param>
<param name="lon"></param>
<param name="distance"></param>
- <param name="radius"></param>
<returns></returns>
</member>
<member name="M:Spatial4n.Core.Distance.DistanceUtils.DistSquaredCartesian(System.Double[],System.Double[])">
@@ -206,7 +189,7 @@
Not commutative! WITHIN.inverse().inverse() != WITHIN.
</member>
<!-- Badly formed XML comment ignored for member "T:Spatial4n.Core.Shapes.Shape" -->
- <member name="M:Spatial4n.Core.Shapes.Shape.Relate(Spatial4n.Core.Shapes.Shape,Spatial4n.Core.Context.SpatialContext)">
+ <member name="M:Spatial4n.Core.Shapes.Shape.Relate(Spatial4n.Core.Shapes.Shape)">
<summary>
Describe the relationship between the two objects. For example
<ul>
@@ -223,7 +206,6 @@
If the shapes are equal then the result is CONTAINS (preferred) or WITHIN.
</summary>
<param name="other"></param>
- <param name="ctx"></param>
<returns></returns>
</member>
<member name="M:Spatial4n.Core.Shapes.Shape.GetBoundingBox">
@@ -279,42 +261,25 @@
<param name="toY"></param>
<returns></returns>
</member>
- <member name="M:Spatial4n.Core.Distance.DistanceCalculator.PointOnBearing(Spatial4n.Core.Shapes.Point,System.Double,System.Double,Spatial4n.Core.Context.SpatialContext)">
+ <member name="M:Spatial4n.Core.Distance.DistanceCalculator.PointOnBearing(Spatial4n.Core.Shapes.Point,System.Double,System.Double,Spatial4n.Core.Context.SpatialContext,Spatial4n.Core.Shapes.Point)">
<summary>
Calculates where a destination point is given an origin (<code>from</code>)
distance, and bearing (given in degrees -- 0-360).
</summary>
<param name="from"></param>
- <param name="distance"></param>
+ <param name="distDEG"></param>
<param name="bearingDEG"></param>
<param name="ctx"></param>
+ <param name="reuse"> </param>
<returns></returns>
</member>
- <member name="M:Spatial4n.Core.Distance.DistanceCalculator.DistanceToDegrees(System.Double)">
- <summary>
- Converts a distance (in units of the sphere's radius, e.g. km) to degrees
- (0-360). A spherical earth model is assumed for geospatial. This is not
- implemented for non-geospatial.
- </summary>
- <param name="distance"></param>
- <returns></returns>
- </member>
- <member name="M:Spatial4n.Core.Distance.DistanceCalculator.DegreesToDistance(System.Double)">
- <summary>
- Converts distance-degrees (0-360, e.g. as a length around the sphere) to
- distance (in units of the sphere's radius, e.g. km). This is the opposite
- of {@link #distanceToDegrees(double)}.
- </summary>
- <param name="degrees"></param>
- <returns></returns>
- </member>
- <member name="M:Spatial4n.Core.Distance.DistanceCalculator.CalcBoxByDistFromPt(Spatial4n.Core.Shapes.Point,System.Double,Spatial4n.Core.Context.SpatialContext)">
+ <member name="M:Spatial4n.Core.Distance.DistanceCalculator.CalcBoxByDistFromPt(Spatial4n.Core.Shapes.Point,System.Double,Spatial4n.Core.Context.SpatialContext,Spatial4n.Core.Shapes.Rectangle)">
<summary>
Calculates the bounding box of a circle, as specified by its center point
and distance.
</summary>
<param name="from"></param>
- <param name="distance"></param>
+ <param name="distDEG"></param>
<param name="ctx"></param>
<returns></returns>
</member>
@@ -327,7 +292,7 @@
to be slightly different.
</summary>
<param name="from"></param>
- <param name="distance"></param>
+ <param name="distDEG"></param>
<param name="ctx"></param>
<returns></returns>
</member>
@@ -336,6 +301,17 @@
A circle, also known as a point-radius since that is what it is comprised of.
</summary>
</member>
+ <member name="M:Spatial4n.Core.Shapes.Circle.Reset(System.Double,System.Double,System.Double)">
+ <summary>
+ Expert: Resets the state of this shape given the arguments. This is a
+ performance feature to avoid excessive Shape object allocation as well as
+ some argument error checking. Mutable shapes is error-prone so use with
+ care.
+ </summary>
+ <param name="x"></param>
+ <param name="y"></param>
+ <param name="radiusDEG"></param>
+ </member>
<member name="M:Spatial4n.Core.Shapes.Circle.GetRadius">
<summary>
The distance from the point's center to its edge, measured in
@@ -360,47 +336,6 @@
<member name="M:Spatial4n.Core.Context.SpatialContextFactory.NewSpatialContext">
Subclasses should simply construct the instance from the initialized configuration.
</member>
- <member name="T:Spatial4n.Core.Distance.DistanceUnits">
- <summary>
- Class representing difference distance units, currently only kilometers and
- miles
- </summary>
- </member>
- <member name="M:Spatial4n.Core.Distance.DistanceUnits.#ctor(System.String,System.Double)">
- <summary>
- Creates a new DistanceUnit that represents the given unit
- </summary>
- <param name="units">Distance unit in String form</param>
- <param name="earthRadius">Radius of the Earth in the specific distance unit</param>
- </member>
- <member name="M:Spatial4n.Core.Distance.DistanceUnits.FindDistanceUnit(System.String)">
- <summary>
- Returns the DistanceUnit which represents the given unit
- </summary>
- <param name="unit">Unit whose DistanceUnit should be found</param>
- <returns>DistanceUnit representing the unit</returns>
- <throws>IllegalArgumentException if no DistanceUnit which represents the given unit is found</throws>
- </member>
- <member name="M:Spatial4n.Core.Distance.DistanceUnits.Convert(System.Double,Spatial4n.Core.Distance.DistanceUnits)">
- <summary>
- Converts the given distance in given DistanceUnit, to a distance in the unit represented by {@code this}
- </summary>
- <param name="distance">Distance to convert</param>
- <param name="from">Unit to convert the distance from</param>
- <returns>Given distance converted to the distance in the given unit</returns>
- </member>
- <member name="M:Spatial4n.Core.Distance.DistanceUnits.GetUnits">
- <summary>
- Returns the string representation of the distance unit
- </summary>
- <returns>String representation of the distance unit</returns>
- </member>
- <member name="M:Spatial4n.Core.Distance.DistanceUnits.EarthRadius">
- <summary>
- Returns the <a href="http://en.wikipedia.org/wiki/Earth_radius">average earth radius</a>
- </summary>
- <returns>the average earth radius</returns>
- </member>
<!-- Badly formed XML comment ignored for member "T:Spatial4n.Core.Shapes.Impl.RectangleImpl" -->
<member name="M:Spatial4n.Core.Shapes.Rectangle.GetCrossesDateLine">
<summary>
@@ -408,6 +343,18 @@
</summary>
<returns></returns>
</member>
+ <member name="M:Spatial4n.Core.Shapes.Rectangle.Reset(System.Double,System.Double,System.Double,System.Double)">
+ <summary>
+ Expert: Resets the state of this shape given the arguments. This is a
+ performance feature to avoid excessive Shape object allocation as well as
+ some argument error checking. Mutable shapes is error-prone so use with
+ care.
+ </summary>
+ <param name="minX"></param>
+ <param name="maxX"></param>
+ <param name="minY"></param>
+ <param name="maxY"></param>
+ </member>
<member name="M:Spatial4n.Core.Shapes.Impl.RectangleImpl.Equals(Spatial4n.Core.Shapes.Rectangle,System.Object)">
<summary>
All {@link Rectangle} implementations should use this definition of {@link Object#equals(Object)}.
@@ -421,7 +368,13 @@
A circle as it exists on the surface of a sphere.
</summary>
</member>
- <!-- Badly formed XML comment ignored for member "T:Spatial4n.Core.Shapes.Impl.CircleImpl" -->
+ <member name="T:Spatial4n.Core.Shapes.Impl.CircleImpl">
+ <summary>
+ A circle, also known as a point-radius, based on a
+ {@link com.spatial4j.core.distance.DistanceCalculator} which does all the work. This implementation
+ implementation should work for both cartesian 2D and geodetic sphere surfaces.
+ </summary>
+ </member>
<member name="M:Spatial4n.Core.Shapes.Impl.CircleImpl.GetYAxis">
<summary>
The <code>Y</code> coordinate of where the circle axis intersect.
@@ -441,13 +394,12 @@
<param name="thiz"></param>
<returns></returns>
</member>
- <member name="M:Spatial4n.Core.Shapes.Impl.GeoCircle.RelateRectanglePhase2(Spatial4n.Core.Shapes.Rectangle,Spatial4n.Core.Shapes.SpatialRelation,Spatial4n.Core.Context.SpatialContext)">
+ <member name="M:Spatial4n.Core.Shapes.Impl.GeoCircle.RelateRectanglePhase2(Spatial4n.Core.Shapes.Rectangle,Spatial4n.Core.Shapes.SpatialRelation)">
<summary>
Called after bounding box is intersected.
</summary>
<param name="r"></param>
<param name="bboxSect">INTERSECTS or CONTAINS from enclosingBox's intersection</param>
- <param name="ctx"></param>
<returns>DISJOINT, CONTAINS, or INTERSECTS (not WITHIN)</returns>
</member>
<member name="M:Spatial4n.Core.Shapes.Impl.GeoCircle.NumCornersIntersect(Spatial4n.Core.Shapes.Rectangle)">
@@ -497,6 +449,7 @@
</summary>
</member>
<!-- Badly formed XML comment ignored for member "T:Spatial4n.Core.Shapes.Point" -->
+ <!-- Badly formed XML comment ignored for member "M:Spatial4n.Core.Shapes.Point.Reset(System.Double,System.Double)" -->
<member name="M:Spatial4n.Core.Shapes.Point.GetX">
<summary>
The X coordinate, or Longitude in geospatial contexts.
@@ -509,6 +462,14 @@
</summary>
<returns></returns>
</member>
+ <member name="M:Spatial4n.Core.Shapes.Impl.PointImpl.#ctor(System.Double,System.Double,Spatial4n.Core.Context.SpatialContext)">
+ <summary>
+ A simple constructor without normalization / validation.
+ </summary>
+ <param name="x"></param>
+ <param name="y"></param>
+ <param name="ctx"></param>
+ </member>
<member name="M:Spatial4n.Core.Shapes.Impl.PointImpl.Equals(Spatial4n.Core.Shapes.Point,System.Object)">
<summary>
All {@link Point} implementations should use this definition of {@link Object#equals(Object)}.
@@ -568,48 +529,47 @@
</member>
<!-- Badly formed XML comment ignored for member "M:Spatial4n.Core.Io.ParseUtils.ParseLatitudeLongitude(System.Double[],System.String)" -->
<!-- Badly formed XML comment ignored for member "T:Spatial4n.Core.Context.SpatialContext" -->
- <member name="F:Spatial4n.Core.Context.SpatialContext.GEO_KM">
+ <member name="F:Spatial4n.Core.Context.SpatialContext.GEO">
<summary>
- A popular default SpatialContext implementation based on kilometer distance.
+ A popular default SpatialContext implementation for geospatial.
</summary>
</member>
- <member name="M:Spatial4n.Core.Context.SpatialContext.#ctor(Spatial4n.Core.Distance.DistanceUnits,Spatial4n.Core.Distance.DistanceCalculator,Spatial4n.Core.Shapes.Rectangle)">
+ <member name="M:Spatial4n.Core.Context.SpatialContext.#ctor(System.Boolean,Spatial4n.Core.Distance.DistanceCalculator,Spatial4n.Core.Shapes.Rectangle)">
<summary>
</summary>
- <param name="units">Required; and establishes geo vs cartesian.</param>
+ <param name="geo">Establishes geo vs cartesian / Euclidean.</param>
<param name="calculator">Optional; defaults to Haversine or cartesian depending on units.</param>
<param name="worldBounds">Optional; defaults to GEO_WORLDBOUNDS or MAX_WORLDBOUNDS depending on units.</param>
</member>
- <member name="M:Spatial4n.Core.Context.SpatialContext.NormX(System.Double)">
+ <!-- Badly formed XML comment ignored for member "M:Spatial4n.Core.Context.SpatialContext.GetWorldBounds" -->
+ <member name="M:Spatial4n.Core.Context.SpatialContext.IsGeo">
<summary>
- If {@link #isGeo()} then calls {@link DistanceUtils#normLonDEG(double)}.
+ Is this a geospatial context (true) or simply 2d spatial (false).
</summary>
- <param name="x"></param>
<returns></returns>
</member>
- <member name="M:Spatial4n.Core.Context.SpatialContext.NormY(System.Double)">
+ <member name="M:Spatial4n.Core.Context.SpatialContext.VerifyX(System.Double)">
<summary>
- If {@link #isGeo()} then calls {@link DistanceUtils#normLatDEG(double)}
+ Ensure fits in {@link #getWorldBounds()}
</summary>
- <param name="y"></param>
- <returns></returns>
+ <param name="x"></param>
</member>
- <member name="M:Spatial4n.Core.Context.SpatialContext.IsGeo">
+ <member name="M:Spatial4n.Core.Context.SpatialContext.VerifyY(System.Double)">
<summary>
- Is this a geospatial context (true) or simply 2d spatial (false).
+ Ensure fits in {@link #getWorldBounds()}
</summary>
- <returns></returns>
+ <param name="y"></param>
</member>
<member name="M:Spatial4n.Core.Context.SpatialContext.MakePoint(System.Double,System.Double)">
<summary>
- Construct a point. The parameters will be normalized.
+ Construct a point.
</summary>
<param name="x"></param>
<param name="y"></param>
<returns></returns>
</member>
- <member name="M:Spatial4n.Core.Context.SpatialContext.MakeRect(Spatial4n.Core.Shapes.Point,Spatial4n.Core.Shapes.Point)">
+ <member name="M:Spatial4n.Core.Context.SpatialContext.MakeRectangle(Spatial4n.Core.Shapes.Point,Spatial4n.Core.Shapes.Point)">
<summary>
Construct a rectangle. The parameters will be normalized.
</summary>
@@ -617,9 +577,11 @@
<param name="upperRight"></param>
<returns></returns>
</member>
- <member name="M:Spatial4n.Core.Context.SpatialContext.MakeRect(System.Double,System.Double,System.Double,System.Double)">
+ <member name="M:Spatial4n.Core.Context.SpatialContext.MakeRectangle(System.Double,System.Double,System.Double,System.Double)">
<summary>
- Construct a rectangle. The parameters will be normalized.
+ Construct a rectangle. If just one longitude is on the dateline (+/- 180)
+ then potentially adjust its sign to ensure the rectangle does not cross the
+ dateline.
</summary>
<param name="minX"></param>
<param name="maxX"></param>
@@ -627,22 +589,7 @@
<param name="maxY"></param>
<returns></returns>
</member>
- <member name="M:Spatial4n.Core.Context.SpatialContext.MakeCircle(System.Double,System.Double,System.Double)">
- <summary>
- Construct a circle. The parameters will be normalized.
- </summary>
- <param name="x"></param>
- <param name="y"></param>
- <param name="distance"></param>
- <returns></returns>
- </member>
- <member name="M:Spatial4n.Core.Context.SpatialContext.MakeCircle(Spatial4n.Core.Shapes.Point,System.Double)">
- <summary>
-
- </summary>
- <param name="point"></param>
- <param name="distance">The units of "distance" should be the same as {@link #GetUnits()}.</param>
- <returns></returns>
- </member>
+ <!-- Badly formed XML comment ignored for member "M:Spatial4n.Core.Context.SpatialContext.MakeCircle(System.Double,System.Double,System.Double)" -->
+ <!-- Badly formed XML comment ignored for member "M:Spatial4n.Core.Context.SpatialContext.MakeCircle(Spatial4n.Core.Shapes.Point,System.Double)" -->
</members>
</doc>
Modified: lucene.net/trunk/lib/Spatial4n/NET40/Spatial4n.Core.dll
URL: http://svn.apache.org/viewvc/lucene.net/trunk/lib/Spatial4n/NET40/Spatial4n.Core.dll?rev=1388446&r1=1388445&r2=1388446&view=diff
==============================================================================
Binary files - no diff available.
Modified: lucene.net/trunk/lib/Spatial4n/NET40/Spatial4n.Core.pdb
URL: http://svn.apache.org/viewvc/lucene.net/trunk/lib/Spatial4n/NET40/Spatial4n.Core.pdb?rev=1388446&r1=1388445&r2=1388446&view=diff
==============================================================================
Binary files - no diff available.
Modified: lucene.net/trunk/src/contrib/Spatial/BBox/AreaSimilarity.cs
URL: http://svn.apache.org/viewvc/lucene.net/trunk/src/contrib/Spatial/BBox/AreaSimilarity.cs?rev=1388446&r1=1388445&r2=1388446&view=diff
==============================================================================
--- lucene.net/trunk/src/contrib/Spatial/BBox/AreaSimilarity.cs (original)
+++ lucene.net/trunk/src/contrib/Spatial/BBox/AreaSimilarity.cs Fri Sep 21 11:57:35 2012
@@ -54,18 +54,16 @@ namespace Lucene.Net.Spatial.BBox
/**
* Properties associated with the query envelope
*/
- private readonly SpatialContext ctx;
private readonly Rectangle queryExtent;
private readonly double queryArea;
private readonly double targetPower;
private readonly double queryPower;
- public AreaSimilarity(SpatialContext ctx, Rectangle queryExtent, double queryPower, double targetPower)
+ public AreaSimilarity(Rectangle queryExtent, double queryPower, double targetPower)
{
- this.ctx = ctx;
this.queryExtent = queryExtent;
- this.queryArea = queryExtent.GetArea(ctx);
+ this.queryArea = queryExtent.GetArea(null);
this.queryPower = queryPower;
this.targetPower = targetPower;
@@ -78,8 +76,8 @@ namespace Lucene.Net.Spatial.BBox
// }
}
- public AreaSimilarity(SpatialContext ctx, Rectangle queryExtent)
- : this(ctx, queryExtent, 2.0, 0.5)
+ public AreaSimilarity(Rectangle queryExtent)
+ : this(queryExtent, 2.0, 0.5)
{
}
@@ -94,7 +92,7 @@ namespace Lucene.Net.Spatial.BBox
{
return 0;
}
- double targetArea = target.GetArea(ctx);
+ double targetArea = target.GetArea(null);
if (targetArea <= 0)
{
return 0;
Modified: lucene.net/trunk/src/contrib/Spatial/BBox/BBoxSimilarityValueSource.cs
URL: http://svn.apache.org/viewvc/lucene.net/trunk/src/contrib/Spatial/BBox/BBoxSimilarityValueSource.cs?rev=1388446&r1=1388445&r2=1388446&view=diff
==============================================================================
--- lucene.net/trunk/src/contrib/Spatial/BBox/BBoxSimilarityValueSource.cs (original)
+++ lucene.net/trunk/src/contrib/Spatial/BBox/BBoxSimilarityValueSource.cs Fri Sep 21 11:57:35 2012
@@ -38,7 +38,8 @@ namespace Lucene.Net.Spatial.BBox
private class BBoxSimilarityValueSourceDocValues : DocValues
{
private readonly BBoxSimilarityValueSource _enclosingInstance;
- private readonly double[] minX;
+ private readonly Rectangle rect;
+ private readonly double[] minX;
private readonly double[] minY;
private readonly double[] maxX;
private readonly double[] maxY;
@@ -48,8 +49,9 @@ namespace Lucene.Net.Spatial.BBox
public BBoxSimilarityValueSourceDocValues(IndexReader reader, BBoxSimilarityValueSource enclosingInstance)
{
_enclosingInstance = enclosingInstance;
+ rect = _enclosingInstance.strategy.GetSpatialContext().MakeRectangle(0, 0, 0, 0); //reused
- minX = FieldCache_Fields.DEFAULT.GetDoubles(reader, enclosingInstance.strategy.field_minX/*, true*/);
+ minX = FieldCache_Fields.DEFAULT.GetDoubles(reader, enclosingInstance.strategy.field_minX/*, true*/);
minY = FieldCache_Fields.DEFAULT.GetDoubles(reader, enclosingInstance.strategy.field_minY/*, true*/);
maxX = FieldCache_Fields.DEFAULT.GetDoubles(reader, enclosingInstance.strategy.field_maxX/*, true*/);
maxY = FieldCache_Fields.DEFAULT.GetDoubles(reader, enclosingInstance.strategy.field_maxY/*, true*/);
@@ -63,7 +65,7 @@ namespace Lucene.Net.Spatial.BBox
// make sure it has minX and area
if (validMinX.Get(doc) && validMaxX.Get(doc))
{
- Rectangle rect = new RectangleImpl(
+ rect.Reset(
minX[doc], maxX[doc],
minY[doc], maxY[doc]);
return (float)_enclosingInstance.similarity.Score(rect, null);
@@ -76,7 +78,7 @@ namespace Lucene.Net.Spatial.BBox
// make sure it has minX and area
if (validMinX.Get(doc) && validMaxX.Get(doc))
{
- Rectangle rect = new RectangleImpl(
+ rect.Reset(
minX[doc], maxX[doc],
minY[doc], maxY[doc]);
var exp = new Explanation();
Modified: lucene.net/trunk/src/contrib/Spatial/BBox/BBoxStrategy.cs
URL: http://svn.apache.org/viewvc/lucene.net/trunk/src/contrib/Spatial/BBox/BBoxStrategy.cs?rev=1388446&r1=1388445&r2=1388446&view=diff
==============================================================================
--- lucene.net/trunk/src/contrib/Spatial/BBox/BBoxStrategy.cs (original)
+++ lucene.net/trunk/src/contrib/Spatial/BBox/BBoxStrategy.cs Fri Sep 21 11:57:35 2012
@@ -93,7 +93,7 @@ namespace Lucene.Net.Spatial.BBox
public override ValueSource MakeValueSource(SpatialArgs args)
{
- return new BBoxSimilarityValueSource(this, new AreaSimilarity(ctx, args.GetShape().GetBoundingBox(), queryPower, targetPower));
+ return new BBoxSimilarityValueSource(this, new AreaSimilarity(args.GetShape().GetBoundingBox(), queryPower, targetPower));
}
public override Query MakeQuery(SpatialArgs args)
Modified: lucene.net/trunk/src/contrib/Spatial/Prefix/RecursivePrefixTreeFilter.cs
URL: http://svn.apache.org/viewvc/lucene.net/trunk/src/contrib/Spatial/Prefix/RecursivePrefixTreeFilter.cs?rev=1388446&r1=1388445&r2=1388446&view=diff
==============================================================================
--- lucene.net/trunk/src/contrib/Spatial/Prefix/RecursivePrefixTreeFilter.cs (original)
+++ lucene.net/trunk/src/contrib/Spatial/Prefix/RecursivePrefixTreeFilter.cs Fri Sep 21 11:57:35 2012
@@ -144,7 +144,7 @@ if (!scan) {
{
//TODO should put more thought into implications of box vs point
Shape cShape = termLevel == grid.GetMaxLevels() ? scanCell.GetCenter() : scanCell.GetShape();
- if (queryShape.Relate(cShape, grid.GetSpatialContext()) == SpatialRelation.DISJOINT)
+ if (queryShape.Relate(cShape) == SpatialRelation.DISJOINT)
continue;
terms.Docs(bits);
Modified: lucene.net/trunk/src/contrib/Spatial/Prefix/Tree/GeohashPrefixTree.cs
URL: http://svn.apache.org/viewvc/lucene.net/trunk/src/contrib/Spatial/Prefix/Tree/GeohashPrefixTree.cs?rev=1388446&r1=1388445&r2=1388446&view=diff
==============================================================================
--- lucene.net/trunk/src/contrib/Spatial/Prefix/Tree/GeohashPrefixTree.cs (original)
+++ lucene.net/trunk/src/contrib/Spatial/Prefix/Tree/GeohashPrefixTree.cs Fri Sep 21 11:57:35 2012
@@ -23,131 +23,131 @@ using Spatial4n.Core.Util;
namespace Lucene.Net.Spatial.Prefix.Tree
{
- /// <summary>
- /// A SpatialPrefixGrid based on Geohashes. Uses {@link GeohashUtils} to do all the geohash work.
- /// </summary>
- public class GeohashPrefixTree : SpatialPrefixTree
- {
- public class Factory : SpatialPrefixTreeFactory
- {
- protected override int GetLevelForDistance(double degrees)
- {
- var grid = new GeohashPrefixTree(ctx, GeohashPrefixTree.GetMaxLevelsPossible());
- return grid.GetLevelForDistance(degrees) + 1;//returns 1 greater
- }
-
- protected override SpatialPrefixTree NewSPT()
- {
- return new GeohashPrefixTree(ctx, maxLevels != null ? maxLevels.Value : GeohashPrefixTree.GetMaxLevelsPossible());
- }
- }
-
-
- public GeohashPrefixTree(SpatialContext ctx, int maxLevels)
- : base(ctx, maxLevels)
- {
- Rectangle bounds = ctx.GetWorldBounds();
- if (bounds.GetMinX() != -180)
- throw new ArgumentException("Geohash only supports lat-lon world bounds. Got " + bounds);
- int MAXP = GetMaxLevelsPossible();
- if (maxLevels <= 0 || maxLevels > MAXP)
- throw new ArgumentException("maxLen must be [1-" + MAXP + "] but got " + maxLevels);
-
- }
-
- /// <summary>
- /// Any more than this and there's no point (double lat & lon are the same).
- /// </summary>
- /// <returns></returns>
- public static int GetMaxLevelsPossible()
- {
- return GeohashUtils.MAX_PRECISION;
- }
-
- public override int GetLevelForDistance(double dist)
- {
- int level = GeohashUtils.LookupHashLenForWidthHeight(dist, dist);
- return Math.Max(Math.Min(level, maxLevels), 1);
- }
-
- 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 override Node GetNode(string token)
- {
- return new GhCell(token, this);
- }
-
- public override Node GetNode(byte[] bytes, int offset, int len)
- {
- throw new System.NotImplementedException();
- }
-
- public override IList<Node> GetNodes(Shape shape, int detailLevel, bool inclParents)
- {
- var s = shape as Point;
- return (s != null) ? base.GetNodesAltPoint(s, detailLevel, inclParents) : base.GetNodes(shape, detailLevel, inclParents);
- }
-
- public class GhCell : Node
- {
- public GhCell(String token, GeohashPrefixTree enclosingInstance)
- : base(enclosingInstance, token)
- {
- }
-
- public override void Reset(string newToken)
- {
- base.Reset(newToken);
- shape = null;
- }
-
- public override IList<Node> GetSubCells()
- {
- String[] hashes = GeohashUtils.GetSubGeohashes(GetGeohash());//sorted
- var cells = new List<Node>(hashes.Length);
-
- var enclosingInstance = (GeohashPrefixTree)spatialPrefixTree;
- foreach (String hash in hashes)
- {
- cells.Add(new GhCell(hash, enclosingInstance));
- }
- return cells;
- }
-
- public override int GetSubCellsSize()
- {
- return 32;//8x4
- }
-
- public override Node GetSubCell(Point p)
- {
- return ((GeohashPrefixTree)spatialPrefixTree).GetNode(p, GetLevel() + 1); //not performant!
- }
-
- private Shape shape;//cache
-
- public override Shape GetShape()
- {
- if (shape == null)
- {
- shape = GeohashUtils.DecodeBoundary(GetGeohash(), ((GeohashPrefixTree)spatialPrefixTree).ctx);
- }
- return shape;
- }
-
- public override Point GetCenter()
- {
- return GeohashUtils.Decode(GetGeohash(), ((GeohashPrefixTree)spatialPrefixTree).ctx);
- }
-
- private String GetGeohash()
- {
- return GetTokenString();
- }
+ /// <summary>
+ /// A SpatialPrefixGrid based on Geohashes. Uses {@link GeohashUtils} to do all the geohash work.
+ /// </summary>
+ public class GeohashPrefixTree : SpatialPrefixTree
+ {
+ public class Factory : SpatialPrefixTreeFactory
+ {
+ protected override int GetLevelForDistance(double degrees)
+ {
+ var grid = new GeohashPrefixTree(ctx, GeohashPrefixTree.GetMaxLevelsPossible());
+ return grid.GetLevelForDistance(degrees);
+ }
+
+ protected override SpatialPrefixTree NewSPT()
+ {
+ return new GeohashPrefixTree(ctx, maxLevels != null ? maxLevels.Value : GeohashPrefixTree.GetMaxLevelsPossible());
+ }
+ }
+
+
+ public GeohashPrefixTree(SpatialContext ctx, int maxLevels)
+ : base(ctx, maxLevels)
+ {
+ Rectangle bounds = ctx.GetWorldBounds();
+ if (bounds.GetMinX() != -180)
+ throw new ArgumentException("Geohash only supports lat-lon world bounds. Got " + bounds);
+ int MAXP = GetMaxLevelsPossible();
+ if (maxLevels <= 0 || maxLevels > MAXP)
+ throw new ArgumentException("maxLen must be [1-" + MAXP + "] but got " + maxLevels);
+
+ }
+
+ /// <summary>
+ /// Any more than this and there's no point (double lat & lon are the same).
+ /// </summary>
+ /// <returns></returns>
+ public static int GetMaxLevelsPossible()
+ {
+ return GeohashUtils.MAX_PRECISION;
+ }
+
+ public override int GetLevelForDistance(double dist)
+ {
+ int level = GeohashUtils.LookupHashLenForWidthHeight(dist, dist);
+ return Math.Max(Math.Min(level, maxLevels), 1);
+ }
+
+ 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 override Node GetNode(string token)
+ {
+ return new GhCell(token, this);
+ }
+
+ public override Node GetNode(byte[] bytes, int offset, int len)
+ {
+ throw new System.NotImplementedException();
+ }
+
+ public override IList<Node> GetNodes(Shape shape, int detailLevel, bool inclParents)
+ {
+ var s = shape as Point;
+ return (s != null) ? base.GetNodesAltPoint(s, detailLevel, inclParents) : base.GetNodes(shape, detailLevel, inclParents);
+ }
+
+ public class GhCell : Node
+ {
+ public GhCell(String token, GeohashPrefixTree enclosingInstance)
+ : base(enclosingInstance, token)
+ {
+ }
+
+ public override void Reset(string newToken)
+ {
+ base.Reset(newToken);
+ shape = null;
+ }
+
+ public override IList<Node> GetSubCells()
+ {
+ String[] hashes = GeohashUtils.GetSubGeohashes(GetGeohash());//sorted
+ var cells = new List<Node>(hashes.Length);
+
+ var enclosingInstance = (GeohashPrefixTree)spatialPrefixTree;
+ foreach (String hash in hashes)
+ {
+ cells.Add(new GhCell(hash, enclosingInstance));
+ }
+ return cells;
+ }
+
+ public override int GetSubCellsSize()
+ {
+ return 32;//8x4
+ }
+
+ public override Node GetSubCell(Point p)
+ {
+ return ((GeohashPrefixTree)spatialPrefixTree).GetNode(p, GetLevel() + 1); //not performant!
+ }
+
+ private Shape shape;//cache
+
+ public override Shape GetShape()
+ {
+ if (shape == null)
+ {
+ shape = GeohashUtils.DecodeBoundary(GetGeohash(), ((GeohashPrefixTree)spatialPrefixTree).ctx);
+ }
+ return shape;
+ }
+
+ public override Point GetCenter()
+ {
+ return GeohashUtils.Decode(GetGeohash(), ((GeohashPrefixTree)spatialPrefixTree).ctx);
+ }
+
+ private String GetGeohash()
+ {
+ return GetTokenString();
+ }
- }//class GhCell
- }
+ }//class GhCell
+ }
}
Modified: lucene.net/trunk/src/contrib/Spatial/Prefix/Tree/Node.cs
URL: http://svn.apache.org/viewvc/lucene.net/trunk/src/contrib/Spatial/Prefix/Tree/Node.cs?rev=1388446&r1=1388445&r2=1388446&view=diff
==============================================================================
--- lucene.net/trunk/src/contrib/Spatial/Prefix/Tree/Node.cs (original)
+++ lucene.net/trunk/src/contrib/Spatial/Prefix/Tree/Node.cs Fri Sep 21 11:57:35 2012
@@ -158,7 +158,7 @@ namespace Lucene.Net.Spatial.Prefix.Tree
var copy = new List<Node>(cells.Count);//copy since cells contractually isn't modifiable
foreach (var cell in cells)
{
- var rel = cell.GetShape().Relate(shapeFilter, spatialPrefixTree.ctx);
+ SpatialRelation rel = cell.GetShape().Relate(shapeFilter);
if (rel == SpatialRelation.DISJOINT)
continue;
cell.shapeRel = rel;
Modified: lucene.net/trunk/src/contrib/Spatial/Prefix/Tree/QuadPrefixTree.cs
URL: http://svn.apache.org/viewvc/lucene.net/trunk/src/contrib/Spatial/Prefix/Tree/QuadPrefixTree.cs?rev=1388446&r1=1388445&r2=1388446&view=diff
==============================================================================
--- lucene.net/trunk/src/contrib/Spatial/Prefix/Tree/QuadPrefixTree.cs (original)
+++ lucene.net/trunk/src/contrib/Spatial/Prefix/Tree/QuadPrefixTree.cs Fri Sep 21 11:57:35 2012
@@ -33,7 +33,7 @@ namespace Lucene.Net.Spatial.Prefix.Tree
protected override int GetLevelForDistance(double degrees)
{
var grid = new QuadPrefixTree(ctx, MAX_LEVELS_POSSIBLE);
- return grid.GetLevelForDistance(degrees) + 1; //returns 1 greater
+ return grid.GetLevelForDistance(degrees);
}
protected override SpatialPrefixTree NewSPT()
@@ -111,12 +111,12 @@ namespace Lucene.Net.Spatial.Prefix.Tree
public override int GetLevelForDistance(double dist)
{
- for (int i = 1; i < maxLevels; i++)
+ for (int i = 0; i < maxLevels - 1; i++)
{
//note: level[i] is actually a lookup for level i+1
- if (dist > levelW[i] || dist > levelH[i])
+ if (dist > levelW[i] && dist > levelH[i])
{
- return i;
+ return i + 1;
}
}
return maxLevels;
@@ -125,7 +125,7 @@ namespace Lucene.Net.Spatial.Prefix.Tree
protected override Node GetNode(Point p, int level)
{
var cells = new List<Node>(1);
- Build(xmid, ymid, 0, cells, new StringBuilder(), new PointImpl(p.GetX(), p.GetY()), level);
+ 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
}
@@ -182,8 +182,8 @@ namespace Lucene.Net.Spatial.Prefix.Tree
double h = levelH[level] / 2;
int strlen = str.Length;
- Rectangle rectangle = ctx.MakeRect(cx - w, cx + w, cy - h, cy + h);
- SpatialRelation v = shape.Relate(rectangle, ctx);
+ Rectangle rectangle = ctx.MakeRectangle(cx - w, cx + w, cy - h, cy + h);
+ SpatialRelation v = shape.Relate(rectangle);
if (SpatialRelation.CONTAINS == v)
{
str.Append(c);
@@ -308,7 +308,7 @@ namespace Lucene.Net.Spatial.Prefix.Tree
width = tree.gridW;
height = tree.gridH;
}
- return tree.ctx.MakeRect(xmin, xmin + width, ymin, ymin + height);
+ return spatialPrefixTree.ctx.MakeRectangle(xmin, xmin + width, ymin, ymin + height);
}
}//QuadCell
Modified: lucene.net/trunk/src/contrib/Spatial/Prefix/Tree/SpatialPrefixTree.cs
URL: http://svn.apache.org/viewvc/lucene.net/trunk/src/contrib/Spatial/Prefix/Tree/SpatialPrefixTree.cs?rev=1388446&r1=1388445&r2=1388446&view=diff
==============================================================================
--- lucene.net/trunk/src/contrib/Spatial/Prefix/Tree/SpatialPrefixTree.cs (original)
+++ lucene.net/trunk/src/contrib/Spatial/Prefix/Tree/SpatialPrefixTree.cs Fri Sep 21 11:57:35 2012
@@ -59,40 +59,40 @@ namespace Lucene.Net.Spatial.Prefix.Tree
return GetType().Name + "(maxLevels:" + maxLevels + ",ctx:" + ctx + ")";
}
- /**
- * See {@link com.spatial4j.core.query.SpatialArgs#getDistPrecision()}.
- * A grid level looked up via {@link #getLevelForDistance(double)} is returned.
- *
- * @param shape
- * @param precision 0-0.5
- * @return 1-maxLevels
- */
- public int GetMaxLevelForPrecision(Shape shape, double precision)
- {
- if (precision < 0 || precision > 0.5)
- {
- throw new ArgumentException("Precision " + precision + " must be between [0-0.5]", "precision");
- }
- if (precision == 0 || shape is Point)
- {
- return maxLevels;
- }
- double bboxArea = shape.GetBoundingBox().GetArea(null);
- if (bboxArea == 0)
- {
- return maxLevels;
- }
- double avgSideLenFromCenter = Math.Sqrt(bboxArea) / 2;
- return GetLevelForDistance(avgSideLenFromCenter * precision);
- }
-
- /**
- * Returns the level of the smallest grid size with a side length that is greater or equal to the provided
- * distance.
- *
- * @param dist >= 0
- * @return level [1-maxLevels]
- */
+ /// <summary>
+ /// See {@link com.spatial4j.core.query.SpatialArgs#getDistPrecision()}.
+ /// A grid level looked up via {@link #getLevelForDistance(double)} is returned.
+ /// </summary>
+ /// <param name="shape"></param>
+ /// <param name="precision">0 to 0.5</param>
+ /// <returns>1 to maxLevels</returns>
+ public int GetMaxLevelForPrecision(Shape shape, double precision)
+ {
+ if (precision < 0 || precision > 0.5)
+ {
+ throw new ArgumentException("Precision " + precision + " must be between [0 to 0.5]", "precision");
+ }
+ if (precision == 0 || shape is Point)
+ {
+ return maxLevels;
+ }
+ Rectangle bbox = shape.GetBoundingBox();
+ //The diagonal distance should be the same computed from any opposite corner,
+ // and this is the longest distance that might be occurring within the shape.
+ double diagonalDist = ctx.GetDistCalc().Distance(
+ ctx.MakePoint(bbox.GetMinX(), bbox.GetMinY()), bbox.GetMaxX(), bbox.GetMaxY());
+ return GetLevelForDistance(diagonalDist*0.5*precision);
+ }
+
+ /// <summary>
+ /// Returns the level of the largest grid in which its longest side is less
+ /// than or equal to the provided distance (in degrees). Consequently {@link
+ /// dist} acts as an error epsilon declaring the amount of detail needed in the
+ /// grid, such that you can get a grid with just the right amount of
+ /// precision.
+ /// </summary>
+ /// <param name="dist">>= 0</param>
+ /// <returns>level [1 to maxLevels]</returns>
public abstract int GetLevelForDistance(double dist);
//TODO double getDistanceForLevel(int level)
Modified: lucene.net/trunk/src/contrib/Spatial/Prefix/Tree/SpatialPrefixTreeFactory.cs
URL: http://svn.apache.org/viewvc/lucene.net/trunk/src/contrib/Spatial/Prefix/Tree/SpatialPrefixTreeFactory.cs?rev=1388446&r1=1388445&r2=1388446&view=diff
==============================================================================
--- lucene.net/trunk/src/contrib/Spatial/Prefix/Tree/SpatialPrefixTreeFactory.cs (original)
+++ lucene.net/trunk/src/contrib/Spatial/Prefix/Tree/SpatialPrefixTreeFactory.cs Fri Sep 21 11:57:35 2012
@@ -63,32 +63,34 @@ namespace Lucene.Net.Spatial.Prefix.Tree
InitMaxLevels();
}
- protected void InitMaxLevels()
- {
- String mlStr;
- if (args.TryGetValue("maxLevels", out mlStr) && mlStr != null)
- {
- maxLevels = int.Parse(mlStr);
- return;
- }
+ protected void InitMaxLevels()
+ {
+ String mlStr;
+ if (args.TryGetValue("maxLevels", out mlStr) && mlStr != null)
+ {
+ maxLevels = int.Parse(mlStr);
+ return;
+ }
- double degrees;
- if (!args.TryGetValue("maxDetailDist", out mlStr) || mlStr == null)
- {
- if (!ctx.IsGeo())
- {
- return; //let default to max
- }
- degrees = DistanceUtils.Dist2Degrees(DEFAULT_GEO_MAX_DETAIL_KM, DistanceUnits.KILOMETERS.EarthRadius());
- }
- else
- {
- degrees = DistanceUtils.Dist2Degrees(double.Parse(mlStr), ctx.GetUnits().EarthRadius());
- }
- maxLevels = GetLevelForDistance(degrees) + 1; //returns 1 greater
- }
+ double degrees;
+ if (!args.TryGetValue("maxDetailDist", out mlStr) || mlStr == null)
+ {
+ if (!ctx.IsGeo())
+ return; //let default to max
+ degrees = DistanceUtils.Dist2Degrees(DEFAULT_GEO_MAX_DETAIL_KM, DistanceUtils.EARTH_MEAN_RADIUS_KM);
+ }
+ else
+ {
+ degrees = Double.Parse(mlStr);
+ if (ctx.IsGeo())
+ {
+ degrees = DistanceUtils.Dist2Degrees(degrees, DistanceUtils.EARTH_MEAN_RADIUS_KM);
+ }
+ }
+ maxLevels = GetLevelForDistance(degrees);
+ }
- /** Calls {@link SpatialPrefixTree#getLevelForDistance(double)}. */
+ /** Calls {@link SpatialPrefixTree#getLevelForDistance(double)}. */
protected abstract int GetLevelForDistance(double degrees);
protected abstract SpatialPrefixTree NewSPT();
Modified: lucene.net/trunk/src/contrib/Spatial/Queries/SpatialArgs.cs
URL: http://svn.apache.org/viewvc/lucene.net/trunk/src/contrib/Spatial/Queries/SpatialArgs.cs?rev=1388446&r1=1388445&r2=1388446&view=diff
==============================================================================
--- lucene.net/trunk/src/contrib/Spatial/Queries/SpatialArgs.cs (original)
+++ lucene.net/trunk/src/contrib/Spatial/Queries/SpatialArgs.cs Fri Sep 21 11:57:35 2012
@@ -61,7 +61,7 @@ namespace Lucene.Net.Spatial.Queries
{
if (Operation.IsTargetNeedsArea() && !shape.HasArea())
{
- throw new InvalidSpatialArgument(Operation + " only supports geometry with area");
+ throw new ArgumentException(Operation + " only supports geometry with area");
}
}
@@ -96,13 +96,14 @@ namespace Lucene.Net.Spatial.Queries
}
/// <summary>
- /// The fraction of the distance from the center of the query shape to its nearest edge that is considered acceptable
- /// error. The algorithm for computing the distance to the nearest edge is actually a little different. It normalizes
- /// the shape to a square given it's bounding box area:
- /// <pre>sqrt(shape.bbox.area)/2</pre>
- /// And the error distance is beyond the shape such that the shape is a minimum shape.
+ /// A measure of acceptable error of the shape. It is specified as the
+ /// fraction of the distance from the center of the query shape to its furthest
+ /// bounding box corner. This effectively inflates the size of the shape but
+ /// should not shrink it.
+ /// <p/>
+ /// The default is {@link #DEFAULT_DIST_PRECISION}
/// </summary>
- /// <returns></returns>
+ /// <returns>0 to 0.5</returns>
public Double GetDistPrecision()
{
return distPrecision;
Modified: lucene.net/trunk/src/contrib/Spatial/Queries/SpatialArgsParser.cs
URL: http://svn.apache.org/viewvc/lucene.net/trunk/src/contrib/Spatial/Queries/SpatialArgsParser.cs?rev=1388446&r1=1388445&r2=1388446&view=diff
==============================================================================
--- lucene.net/trunk/src/contrib/Spatial/Queries/SpatialArgsParser.cs (original)
+++ lucene.net/trunk/src/contrib/Spatial/Queries/SpatialArgsParser.cs Fri Sep 21 11:57:35 2012
@@ -19,6 +19,8 @@ using System;
using System.Collections.Generic;
using Spatial4n.Core.Context;
using Spatial4n.Core.Exceptions;
+using Spatial4n.Core.Io;
+using Spatial4n.Core.Shapes;
namespace Lucene.Net.Spatial.Queries
{
@@ -31,7 +33,7 @@ namespace Lucene.Net.Spatial.Queries
if (idx < 0 || idx > edx)
{
- throw new InvalidSpatialArgument("missing parens: " + v);
+ throw new ArgumentException("missing parens: " + v);
}
SpatialOperation op = SpatialOperation.Get(v.Substring(0, idx).Trim());
@@ -41,10 +43,10 @@ namespace Lucene.Net.Spatial.Queries
String body = v.Substring(idx + 1, edx - (idx + 1)).Trim();
if (body.Length < 1)
{
- throw new InvalidSpatialArgument("missing body : " + v);
+ throw new ArgumentException("missing body : " + v);
}
- var shape = ctx.ReadShape(body);
+ Shape shape = new ShapeReadWriter(ctx).ReadShape(body);
var args = new SpatialArgs(op, shape);
if (v.Length > (edx + 1))
@@ -56,7 +58,7 @@ namespace Lucene.Net.Spatial.Queries
args.SetDistPrecision(ReadDouble(aa["distPrec"]));
if (aa.Count > 3)
{
- throw new InvalidSpatialArgument("unused parameters: " + aa);
+ throw new ArgumentException("unused parameters: " + aa);
}
}
}
Modified: lucene.net/trunk/src/contrib/Spatial/Queries/SpatialOperation.cs
URL: http://svn.apache.org/viewvc/lucene.net/trunk/src/contrib/Spatial/Queries/SpatialOperation.cs?rev=1388446&r1=1388445&r2=1388446&view=diff
==============================================================================
--- lucene.net/trunk/src/contrib/Spatial/Queries/SpatialOperation.cs (original)
+++ lucene.net/trunk/src/contrib/Spatial/Queries/SpatialOperation.cs Fri Sep 21 11:57:35 2012
@@ -60,7 +60,7 @@ namespace Lucene.Net.Spatial.Queries
if (!registry.TryGetValue(v, out op) || op == null)
{
if (!registry.TryGetValue(v.ToUpper(CultureInfo.CreateSpecificCulture("en-US")), out op) || op == null)
- throw new InvalidSpatialArgument("Unknown Operation: " + v);
+ throw new ArgumentException("Unknown Operation: " + v, v);
}
return op;
}
Modified: lucene.net/trunk/test/contrib/Spatial/PortedSolr3Test.cs
URL: http://svn.apache.org/viewvc/lucene.net/trunk/test/contrib/Spatial/PortedSolr3Test.cs?rev=1388446&r1=1388445&r2=1388446&view=diff
==============================================================================
--- lucene.net/trunk/test/contrib/Spatial/PortedSolr3Test.cs (original)
+++ lucene.net/trunk/test/contrib/Spatial/PortedSolr3Test.cs Fri Sep 21 11:57:35 2012
@@ -42,7 +42,7 @@ namespace Lucene.Net.Contrib.Spatial.Tes
{
var ctorArgs = new List<Param>();
- SpatialContext ctx = SpatialContext.GEO_KM;
+ SpatialContext ctx = SpatialContext.GEO;
SpatialPrefixTree grid = new GeohashPrefixTree(ctx, 12);
SpatialStrategy strategy = new RecursivePrefixTreeStrategy(grid, "recursive_geohash");
@@ -107,6 +107,7 @@ namespace Lucene.Net.Contrib.Spatial.Tes
setupDocs();
//Try some edge cases
+ //NOTE: 2nd arg is distance in kilometers
checkHitsCircle("1,1", 175, 3, 5, 6, 7);
checkHitsCircle("0,179.8", 200, 2, 8, 9);
checkHitsCircle("89.8, 50", 200, 2, 10, 11); //this goes over the north pole
Modified: lucene.net/trunk/test/contrib/Spatial/Prefix/TestRecursivePrefixTreeStrategy.cs
URL: http://svn.apache.org/viewvc/lucene.net/trunk/test/contrib/Spatial/Prefix/TestRecursivePrefixTreeStrategy.cs?rev=1388446&r1=1388445&r2=1388446&view=diff
==============================================================================
--- lucene.net/trunk/test/contrib/Spatial/Prefix/TestRecursivePrefixTreeStrategy.cs (original)
+++ lucene.net/trunk/test/contrib/Spatial/Prefix/TestRecursivePrefixTreeStrategy.cs Fri Sep 21 11:57:35 2012
@@ -44,26 +44,6 @@ namespace Lucene.Net.Contrib.Spatial.Tes
}
[Test]
- public void testPointAndRadius()
- {
- init(GeohashPrefixTree.GetMaxLevelsPossible());
-
- addDocument(newDoc("spatials/1", ctx.MakePoint(2.8028712999999925, 48.3708044))); //lon, lat
- commit();
-
- Point queryShape = ctx.MakePoint(2.4632387000000335, 48.6003516);
- checkHits(queryShape, 35.75, 1, null);
- checkHits(queryShape, 30, 0, null);
- checkHits(queryShape, 33, 0, null);
- checkHits(queryShape, 34, 0, null);
-
- checkHits(queryShape, 35.75, 1, null, 0.025);
- checkHits(queryShape, 30, 0, null, 0.025);
- checkHits(queryShape, 33, 0, null, 0.025);
- checkHits(queryShape, 34, 0, null, 0.025);
- }
-
- [Test]
public void testFilterWithVariableScanLevel()
{
init(GeohashPrefixTree.GetMaxLevelsPossible());
@@ -77,7 +57,48 @@ namespace Lucene.Net.Contrib.Spatial.Tes
}
}
- [Test]
+ [Test]
+ public void testOneMeterPrecision()
+ {
+ init(GeohashPrefixTree.GetMaxLevelsPossible());
+ GeohashPrefixTree grid = (GeohashPrefixTree) ((RecursivePrefixTreeStrategy) strategy).GetGrid();
+ //DWS: I know this to be true. 11 is needed for one meter
+ assertEquals(11, grid.GetLevelForDistance(ctx.GetDistCalc().DistanceToDegrees(0.001)));
+ }
+
+ [Test]
+ public void testPrecision()
+ {
+ init(GeohashPrefixTree.GetMaxLevelsPossible());
+
+ Point iPt = ctx.MakePoint(2.8028712999999925, 48.3708044); //lon, lat
+ addDocument(newDoc("iPt", iPt));
+ commit();
+
+ Point qPt = ctx.MakePoint(2.4632387000000335, 48.6003516);
+
+ const double DIST = 35.75; //35.7499...
+ assertEquals(DIST, ctx.GetDistCalc().Distance(iPt, qPt), 0.001);
+
+ //distPrec will affect the query shape precision. The indexed precision
+ // was set to nearly zilch via init(GeohashPrefixTree.getMaxLevelsPossible());
+ const double distPrec = 0.025; //the suggested default, by the way
+ const double distMult = 1 + distPrec;
+
+ assertTrue(35.74*distMult >= DIST);
+ checkHits(q(qPt, 35.74, distPrec), 1, null);
+
+ assertTrue(30*distMult < DIST);
+ checkHits(q(qPt, 30, distPrec), 0, null);
+
+ assertTrue(33*distMult < DIST);
+ checkHits(q(qPt, 33, distPrec), 0, null);
+
+ assertTrue(34*distMult < DIST);
+ checkHits(q(qPt, 34, distPrec), 0, null);
+ }
+
+ [Test]
public void geohashRecursiveRandom()
{
init(12);
@@ -120,9 +141,9 @@ namespace Lucene.Net.Contrib.Spatial.Tes
qcYoff + clusterCenter.GetY());
double[] distRange = calcDistRange(queryCenter, clusterCenter, sideDegree);
//4.1 query a small box getting nothing
- checkHits(queryCenter, distRange[0] * 0.99, 0, null);
+ checkHits(q(queryCenter, distRange[0] * 0.99), 0, null);
//4.2 Query a large box enclosing the cluster, getting everything
- checkHits(queryCenter, distRange[1] * 1.01, points.Count, null);
+ checkHits(q(queryCenter, distRange[1] * 1.01), points.Count, null);
//4.3 Query a medium box getting some (calculate the correct solution and verify)
double queryDist = distRange[0] + (distRange[1] - distRange[0]) / 2;//average
@@ -141,7 +162,7 @@ namespace Lucene.Net.Contrib.Spatial.Tes
ids = ids_new;
//assert ids_sz > 0 (can't because randomness keeps us from being able to)
- checkHits(queryCenter, queryDist, ids.Length, ids);
+ checkHits(q(queryCenter, queryDist), ids.Length, ids);
}
}
@@ -151,14 +172,18 @@ namespace Lucene.Net.Contrib.Spatial.Tes
}//randomTest()
- //TODO can we use super.runTestQueries() ?
- private void checkHits(Point pt, double dist, int assertNumFound, int[] assertIds, double distPrecison = 0.0)
+ private SpatialArgs q(Point pt, double dist, double distPrec = 0.0)
+ {
+ Shape shape = ctx.MakeCircle(pt, dist);
+ var args = new SpatialArgs(SpatialOperation.Intersects, shape);
+ args.SetDistPrecision(distPrec);
+ return args;
+ }
+
+ private void checkHits(SpatialArgs args, int assertNumFound, int[] assertIds)
{
- Shape shape = ctx.MakeCircle(pt, dist);
- SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects, shape);
- args.SetDistPrecision(distPrecison);
SearchResults got = executeQuery(strategy.MakeQuery(args), 100);
- Assert.AreEqual(assertNumFound, got.numFound, "" + shape);
+ assertEquals("" + args, assertNumFound, got.numFound);
if (assertIds != null)
{
var gotIds = new HashSet<int>();
@@ -173,7 +198,6 @@ namespace Lucene.Net.Contrib.Spatial.Tes
}
}
- //
private Document newDoc(String id, Shape shape)
{
Document doc = new Document();
Modified: lucene.net/trunk/test/core/Util/LuceneTestCase.cs
URL: http://svn.apache.org/viewvc/lucene.net/trunk/test/core/Util/LuceneTestCase.cs?rev=1388446&r1=1388445&r2=1388446&view=diff
==============================================================================
--- lucene.net/trunk/test/core/Util/LuceneTestCase.cs (original)
+++ lucene.net/trunk/test/core/Util/LuceneTestCase.cs Fri Sep 21 11:57:35 2012
@@ -241,5 +241,27 @@ namespace Lucene.Net.Util
// static members
[NonSerialized]
private static readonly System.Random seedRnd = new System.Random();
- }
+
+ #region Java porting shortcuts
+ protected static void assertEquals(string msg, object obj1, object obj2)
+ {
+ Assert.AreEqual(obj1, obj2, msg);
+ }
+
+ protected static void assertEquals(object obj1, object obj2)
+ {
+ Assert.AreEqual(obj1, obj2);
+ }
+
+ protected static void assertEquals(double d1, double d2, double delta)
+ {
+ Assert.AreEqual(d1, d2, delta);
+ }
+
+ protected static void assertTrue(bool cnd)
+ {
+ Assert.IsTrue(cnd);
+ }
+ #endregion
+ }
}