| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
package org.locationtech.jts.operation.distance3d; |
| 14 |
|
| 15 |
import org.locationtech.jts.geom.Coordinate; |
| 16 |
import org.locationtech.jts.geom.CoordinateSequence; |
| 17 |
import org.locationtech.jts.geom.Envelope; |
| 18 |
|
| 19 |
/** |
| 20 |
* A CoordinateSequence wrapper which |
| 21 |
* projects 3D coordinates into one of the |
| 22 |
* three Cartesian axis planes, |
| 23 |
* using the standard orthonormal projection |
| 24 |
* (i.e. simply selecting the appropriate ordinates into the XY ordinates). |
| 25 |
* The projected data is represented as 2D coordinates. |
| 26 |
* |
| 27 |
* @author mdavis |
| 28 |
* |
| 29 |
*/ |
| 30 |
public class AxisPlaneCoordinateSequence implements CoordinateSequence { |
| 31 |
|
| 32 |
/** |
| 33 |
* Creates a wrapper projecting to the XY plane. |
| 34 |
* |
| 35 |
* @param seq the sequence to be projected |
| 36 |
* @return a sequence which projects coordinates |
| 37 |
*/ |
| 38 |
public static CoordinateSequence projectToXY(CoordinateSequence seq) |
| 39 |
{ |
| 40 |
/** |
| 41 |
* This is just a no-op, but return a wrapper |
| 42 |
* to allow better testing |
| 43 |
*/ |
| 44 |
return new AxisPlaneCoordinateSequence(seq, XY_INDEX); |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* Creates a wrapper projecting to the XZ plane. |
| 49 |
* |
| 50 |
* @param seq the sequence to be projected |
| 51 |
* @return a sequence which projects coordinates |
| 52 |
*/ |
| 53 |
public static CoordinateSequence projectToXZ(CoordinateSequence seq) |
| 54 |
{ |
| 55 |
return new AxisPlaneCoordinateSequence(seq, XZ_INDEX); |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* Creates a wrapper projecting to the YZ plane. |
| 60 |
* |
| 61 |
* @param seq the sequence to be projected |
| 62 |
* @return a sequence which projects coordinates |
| 63 |
*/ |
| 64 |
public static CoordinateSequence projectToYZ(CoordinateSequence seq) |
| 65 |
{ |
| 66 |
return new AxisPlaneCoordinateSequence(seq, YZ_INDEX); |
| 67 |
} |
| 68 |
|
| 69 |
private static final int[] XY_INDEX = new int[] { 0,1 }; |
| 70 |
private static final int[] XZ_INDEX = new int[] { 0,2 }; |
| 71 |
private static final int[] YZ_INDEX = new int[] { 1,2 }; |
| 72 |
|
| 73 |
private CoordinateSequence seq; |
| 74 |
private int[] indexMap; |
| 75 |
|
| 76 |
private AxisPlaneCoordinateSequence(CoordinateSequence seq, int[] indexMap) { |
| 77 |
this.seq = seq; |
| 78 |
this.indexMap = indexMap; |
| 79 |
} |
| 80 |
|
| 81 |
public int getDimension() { |
| 82 |
return 2; |
| 83 |
} |
| 84 |
|
| 85 |
public Coordinate getCoordinate(int i) { |
| 86 |
return getCoordinateCopy(i); |
| 87 |
} |
| 88 |
|
| 89 |
public Coordinate getCoordinateCopy(int i) { |
| 90 |
return new Coordinate(getX(i), getY(i), getZ(i)); |
| 91 |
} |
| 92 |
|
| 93 |
public void getCoordinate(int index, Coordinate coord) { |
| 94 |
coord.x = getOrdinate(index, X); |
| 95 |
coord.y = getOrdinate(index, Y); |
| 96 |
coord.setZ(getOrdinate(index, Z)); |
| 97 |
} |
| 98 |
|
| 99 |
public double getX(int index) { |
| 100 |
return getOrdinate(index, X); |
| 101 |
} |
| 102 |
|
| 103 |
public double getY(int index) { |
| 104 |
return getOrdinate(index, Y); |
| 105 |
} |
| 106 |
|
| 107 |
public double getZ(int index) { |
| 108 |
return getOrdinate(index, Z); |
| 109 |
} |
| 110 |
|
| 111 |
public double getOrdinate(int index, int ordinateIndex) { |
| 112 |
|
| 113 |
if (ordinateIndex > 1) return 0; |
| 114 |
return seq.getOrdinate(index, indexMap[ordinateIndex]); |
| 115 |
} |
| 116 |
|
| 117 |
public int size() { |
| 118 |
return seq.size(); |
| 119 |
} |
| 120 |
|
| 121 |
public void setOrdinate(int index, int ordinateIndex, double value) { |
| 122 |
throw new UnsupportedOperationException(); |
| 123 |
} |
| 124 |
|
| 125 |
public Coordinate[] toCoordinateArray() { |
| 126 |
throw new UnsupportedOperationException(); |
| 127 |
} |
| 128 |
|
| 129 |
public Envelope expandEnvelope(Envelope env) { |
| 130 |
throw new UnsupportedOperationException(); |
| 131 |
} |
| 132 |
|
| 133 |
public Object clone() |
| 134 |
{ |
| 135 |
throw new UnsupportedOperationException(); |
| 136 |
} |
| 137 |
|
| 138 |
public AxisPlaneCoordinateSequence copy() |
| 139 |
{ |
| 140 |
throw new UnsupportedOperationException(); |
| 141 |
} |
| 142 |
} |
| 143 |
|