001:
002: /*
003: * The JTS Topology Suite is a collection of Java classes that
004: * implement the fundamental operations required to validate a given
005: * geo-spatial data set to a known topological specification.
006: *
007: * Copyright (C) 2001 Vivid Solutions
008: *
009: * This library is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU Lesser General Public
011: * License as published by the Free Software Foundation; either
012: * version 2.1 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
022: *
023: * For more information, contact:
024: *
025: * Vivid Solutions
026: * Suite #1A
027: * 2328 Government Street
028: * Victoria BC V8T 5G5
029: * Canada
030: *
031: * (250)385-6040
032: * www.vividsolutions.com
033: */
034: package com.vividsolutions.jts.geom;
035:
036: /**
037: * Constants representing the dimensions of a point, a curve and a surface.
038: * Also, constants representing the dimensions of the empty geometry and
039: * non-empty geometries, and a wildcard dimension meaning "any dimension".
040: *
041: * @version 1.7
042: */
043: public class Dimension {
044:
045: /**
046: * Dimension value of a point (0).
047: */
048: public final static int P = 0;
049:
050: /**
051: * Dimension value of a curve (1).
052: */
053: public final static int L = 1;
054:
055: /**
056: * Dimension value of a surface (2).
057: */
058: public final static int A = 2;
059:
060: /**
061: * Dimension value of the empty geometry (-1).
062: */
063: public final static int FALSE = -1;
064:
065: /**
066: * Dimension value of non-empty geometries (= {P, L, A}).
067: */
068: public final static int TRUE = -2;
069:
070: /**
071: * Dimension value for any dimension (= {FALSE, TRUE}).
072: */
073: public final static int DONTCARE = -3;
074:
075: /**
076: * Converts the dimension value to a dimension symbol, for example, <code>TRUE => 'T'</code>
077: * .
078: *
079: *@param dimensionValue a number that can be stored in the <code>IntersectionMatrix</code>
080: * . Possible values are <code>{TRUE, FALSE, DONTCARE, 0, 1, 2}</code>.
081: *@return a character for use in the string representation of
082: * an <code>IntersectionMatrix</code>. Possible values are <code>{T, F, * , 0, 1, 2}</code>
083: * .
084: */
085: public static char toDimensionSymbol(int dimensionValue) {
086: switch (dimensionValue) {
087: case FALSE:
088: return 'F';
089: case TRUE:
090: return 'T';
091: case DONTCARE:
092: return '*';
093: case P:
094: return '0';
095: case L:
096: return '1';
097: case A:
098: return '2';
099: }
100: throw new IllegalArgumentException("Unknown dimension value: "
101: + dimensionValue);
102: }
103:
104: /**
105: * Converts the dimension symbol to a dimension value, for example, <code>'*' => DONTCARE</code>
106: * .
107: *
108: *@param dimensionSymbol a character for use in the string representation of
109: * an <code>IntersectionMatrix</code>. Possible values are <code>{T, F, * , 0, 1, 2}</code>
110: * .
111: *@return a number that can be stored in the <code>IntersectionMatrix</code>
112: * . Possible values are <code>{TRUE, FALSE, DONTCARE, 0, 1, 2}</code>.
113: */
114: public static int toDimensionValue(char dimensionSymbol) {
115: switch (Character.toUpperCase(dimensionSymbol)) {
116: case 'F':
117: return FALSE;
118: case 'T':
119: return TRUE;
120: case '*':
121: return DONTCARE;
122: case '0':
123: return P;
124: case '1':
125: return L;
126: case '2':
127: return A;
128: }
129: throw new IllegalArgumentException("Unknown dimension symbol: "
130: + dimensionSymbol);
131: }
132: }
|