Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
117 additions
and
144 deletions.
There are no files selected for viewing
114 changes: 114 additions & 0 deletions
114
community/spatial-index/src/main/java/org/neo4j/gis/spatial/index/curves/SearchEnvelope.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/* | ||
* Copyright (c) 2002-2018 "Neo Technology," | ||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.gis.spatial.index.curves; | ||
|
||
import org.neo4j.gis.spatial.index.Envelope; | ||
|
||
/** | ||
* N-dimensional searchEnvelope | ||
*/ | ||
class SearchEnvelope | ||
{ | ||
long[] min; // inclusive lower bounds | ||
long[] max; // exclusive upper bounds | ||
int nbrDim; | ||
|
||
SearchEnvelope( SpaceFillingCurve curve, Envelope referenceEnvelope ) | ||
{ | ||
this.min = curve.getNormalizedCoord( referenceEnvelope.getMin() ); | ||
this.max = curve.getNormalizedCoord( referenceEnvelope.getMax() ); | ||
this.nbrDim = referenceEnvelope.getDimension(); | ||
for ( int i = 0; i < nbrDim; i++ ) | ||
{ | ||
this.max[i] += 1; | ||
} | ||
} | ||
|
||
private SearchEnvelope( long[] min, long[] max ) | ||
{ | ||
this.min = min; | ||
this.max = max; | ||
this.nbrDim = min.length; | ||
} | ||
|
||
SearchEnvelope( long min, long max, int nbrDim ) | ||
{ | ||
this.nbrDim = nbrDim; | ||
this.min = new long[nbrDim]; | ||
this.max = new long[nbrDim]; | ||
|
||
for ( int dim = 0; dim < nbrDim; dim++ ) | ||
{ | ||
this.min[dim] = min; | ||
this.max[dim] = max; | ||
} | ||
} | ||
|
||
SearchEnvelope quadrant( int[] quadNbrs ) | ||
{ | ||
long[] newMin = new long[nbrDim]; | ||
long[] newMax = new long[nbrDim]; | ||
|
||
for ( int dim = 0; dim < nbrDim; dim++ ) | ||
{ | ||
long extent = (max[dim] - min[dim]) / 2; | ||
newMin[dim] = this.min[dim] + quadNbrs[dim] * extent; | ||
newMax[dim] = this.min[dim] + (quadNbrs[dim] + 1) * extent; | ||
} | ||
return new SearchEnvelope( newMin, newMax ); | ||
} | ||
|
||
boolean contains( long[] coord ) | ||
{ | ||
for ( int dim = 0; dim < nbrDim; dim++ ) | ||
{ | ||
if ( coord[dim] < min[dim] || coord[dim] >= max[dim] ) | ||
{ | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
boolean intersects( SearchEnvelope other ) | ||
{ | ||
for ( int dim = 0; dim < nbrDim; dim++ ) | ||
{ | ||
if ( this.max[dim] <= other.min[dim] || other.max[dim] <= this.min[dim] ) | ||
{ | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
double fractionOf( SearchEnvelope other ) | ||
{ | ||
double fraction = 1.0; | ||
for ( int i = 0; i < min.length; i++ ) | ||
{ | ||
long min = Math.max( this.min[i], other.min[i] ); | ||
long max = Math.min( this.max[i], other.max[i] ); | ||
final double innerFraction = (double) (max - min) / (double) (other.max[i] - other.min[i]); | ||
fraction *= innerFraction; | ||
} | ||
return fraction; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters