| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
package org.locationtech.jts.geom; |
| 15 |
|
| 16 |
/** |
| 17 |
* Provides constants representing the dimensions of a point, a curve and a surface. |
| 18 |
* Also provides constants representing the dimensions of the empty geometry and |
| 19 |
* non-empty geometries, and the wildcard constant {@link #DONTCARE} meaning "any dimension". |
| 20 |
* These constants are used as the entries in {@link IntersectionMatrix}s. |
| 21 |
* |
| 22 |
* @version 1.7 |
| 23 |
*/ |
| 24 |
public class Dimension { |
| 25 |
|
| 26 |
/** |
| 27 |
* Dimension value of a point (0). |
| 28 |
*/ |
| 29 |
public final static int P = 0; |
| 30 |
|
| 31 |
/** |
| 32 |
* Dimension value of a curve (1). |
| 33 |
*/ |
| 34 |
public final static int L = 1; |
| 35 |
|
| 36 |
/** |
| 37 |
* Dimension value of a surface (2). |
| 38 |
*/ |
| 39 |
public final static int A = 2; |
| 40 |
|
| 41 |
/** |
| 42 |
* Dimension value of the empty geometry (-1). |
| 43 |
*/ |
| 44 |
public final static int FALSE = -1; |
| 45 |
|
| 46 |
/** |
| 47 |
* Dimension value of non-empty geometries (= {P, L, A}). |
| 48 |
*/ |
| 49 |
public final static int TRUE = -2; |
| 50 |
|
| 51 |
/** |
| 52 |
* Dimension value for any dimension (= {FALSE, TRUE}). |
| 53 |
*/ |
| 54 |
public final static int DONTCARE = -3; |
| 55 |
|
| 56 |
/** |
| 57 |
* Symbol for the FALSE pattern matrix entry |
| 58 |
*/ |
| 59 |
public final static char SYM_FALSE = 'F'; |
| 60 |
|
| 61 |
/** |
| 62 |
* Symbol for the TRUE pattern matrix entry |
| 63 |
*/ |
| 64 |
public final static char SYM_TRUE = 'T'; |
| 65 |
|
| 66 |
/** |
| 67 |
* Symbol for the DONTCARE pattern matrix entry |
| 68 |
*/ |
| 69 |
public final static char SYM_DONTCARE = '*'; |
| 70 |
|
| 71 |
/** |
| 72 |
* Symbol for the P (dimension 0) pattern matrix entry |
| 73 |
*/ |
| 74 |
public final static char SYM_P = '0'; |
| 75 |
|
| 76 |
/** |
| 77 |
* Symbol for the L (dimension 1) pattern matrix entry |
| 78 |
*/ |
| 79 |
public final static char SYM_L = '1'; |
| 80 |
|
| 81 |
/** |
| 82 |
* Symbol for the A (dimension 2) pattern matrix entry |
| 83 |
*/ |
| 84 |
public final static char SYM_A = '2'; |
| 85 |
|
| 86 |
/** |
| 87 |
* Converts the dimension value to a dimension symbol, for example, <code>TRUE => 'T'</code> |
| 88 |
* . |
| 89 |
* |
| 90 |
*@param dimensionValue a number that can be stored in the <code>IntersectionMatrix</code> |
| 91 |
* . Possible values are <code>{TRUE, FALSE, DONTCARE, 0, 1, 2}</code>. |
| 92 |
*@return a character for use in the string representation of |
| 93 |
* an <code>IntersectionMatrix</code>. Possible values are <code>{T, F, * , 0, 1, 2}</code> |
| 94 |
* . |
| 95 |
*/ |
| 96 |
public static char toDimensionSymbol(int dimensionValue) { |
| 97 |
switch (dimensionValue) { |
| 98 |
case FALSE: |
| 99 |
return SYM_FALSE; |
| 100 |
case TRUE: |
| 101 |
return SYM_TRUE; |
| 102 |
case DONTCARE: |
| 103 |
return SYM_DONTCARE; |
| 104 |
case P: |
| 105 |
return SYM_P; |
| 106 |
case L: |
| 107 |
return SYM_L; |
| 108 |
case A: |
| 109 |
return SYM_A; |
| 110 |
} |
| 111 |
throw new IllegalArgumentException("Unknown dimension value: " + dimensionValue); |
| 112 |
} |
| 113 |
|
| 114 |
/** |
| 115 |
* Converts the dimension symbol to a dimension value, for example, <code>'*' => DONTCARE</code> |
| 116 |
* . |
| 117 |
* |
| 118 |
*@param dimensionSymbol a character for use in the string representation of |
| 119 |
* an <code>IntersectionMatrix</code>. Possible values are <code>{T, F, * , 0, 1, 2}</code> |
| 120 |
* . |
| 121 |
*@return a number that can be stored in the <code>IntersectionMatrix</code> |
| 122 |
* . Possible values are <code>{TRUE, FALSE, DONTCARE, 0, 1, 2}</code>. |
| 123 |
*/ |
| 124 |
public static int toDimensionValue(char dimensionSymbol) { |
| 125 |
switch (Character.toUpperCase(dimensionSymbol)) { |
| 126 |
case SYM_FALSE: |
| 127 |
return FALSE; |
| 128 |
case SYM_TRUE: |
| 129 |
return TRUE; |
| 130 |
case SYM_DONTCARE: |
| 131 |
return DONTCARE; |
| 132 |
case SYM_P: |
| 133 |
return P; |
| 134 |
case SYM_L: |
| 135 |
return L; |
| 136 |
case SYM_A: |
| 137 |
return A; |
| 138 |
} |
| 139 |
throw new IllegalArgumentException("Unknown dimension symbol: " + dimensionSymbol); |
| 140 |
} |
| 141 |
} |
| 142 |
|
| 143 |
|
| 144 |
|