public class MortonCode extends Object
The planar Morton (Z-order) curve is a continuous space-filling curve. The Morton curve defines an ordering of the points in the positive quadrant of the plane. The index of a point along the Morton curve is called the Morton code.
A sequence of subsets of the Morton curve can be defined by a level number. Each level subset occupies a square range. The curve at level n Mn contains 2n + 1 points. It fills the range square of side 2level. Curve points have ordinates in the range [0, 2level - 1]. The code for a given point is identical at all levels. The level simply determines the number of points in the curve subset and the size of the range square.
This implementation represents codes using 32-bit integers. This allows levels 0 to 16 to be handled. The class supports encoding points and decoding the point for a given code value.
The Morton order has the property that it tends to preserve locality. This means that codes which are near in value will have spatially proximate points. The converse is not always true - the delta between codes for nearby points is not always small. But the average delta is small enough that the Morton order is an effective way of linearizing space to support range queries.
MortonCurveBuilder
,
HilbertCode
Modifier and Type | Field and Description |
---|---|
static int |
MAX_LEVEL
The maximum curve level that can be represented.
|
Constructor and Description |
---|
MortonCode() |
Modifier and Type | Method and Description |
---|---|
static Coordinate |
decode(int index)
Computes the point on the Morton curve
for a given index.
|
static int |
encode(int x,
int y)
Computes the index of the point (x,y)
in the Morton curve ordering.
|
static int |
level(int numPoints)
The level of the finite Morton curve which contains at least
the given number of points.
|
static int |
maxOrdinate(int level)
The maximum ordinate value for points
in the curve for the given level.
|
static int |
size(int level)
The number of points in the curve for the given level.
|
public static final int MAX_LEVEL
public static int size(int level)
level
- the level of the curvepublic static int maxOrdinate(int level)
level
- the level of the curvepublic static int level(int numPoints)
numPoints
- the number of points requiredpublic static int encode(int x, int y)
x
- the x ordinate of the pointy
- the y ordinate of the pointpublic static Coordinate decode(int index)
index
- the index of the point on the curveCopyright © 2024. All rights reserved.