-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPoints.java
More file actions
195 lines (152 loc) · 6.13 KB
/
Points.java
File metadata and controls
195 lines (152 loc) · 6.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
package javaxt.geospatial.geometry;
//******************************************************************************
//** Points Class
//******************************************************************************
/**
* Used to manage an array of points (Point)
*
******************************************************************************/
public class Points { // implements Geometry
private java.util.Vector<Point> points = new java.util.Vector<Point>();
//**************************************************************************
//** Creates a new instance of Points
//**************************************************************************
public Points(Point[] points){
for (int i=0; i<points.length; i++){
Point point = points[i];
if (point!=null) this.points.add(point);
}
}
public Points(){
}
public Point[] getArray(){
Point[] arr = new Point[points.size()];
if (arr.length>0){
for (int i=0; i<arr.length; i++){
arr[i] = points.get(i);
}
}
return arr;
}
public Point[] getPoints(){
return getArray();
}
//**************************************************************************
//** getFirstPoint
//**************************************************************************
/** Returns the first point in the point array */
public Point getFirstPoint(){
Point[] Points = getPoints();
if (Points!=null){
return Points[0];
}
else{
return null;
}
}
//**************************************************************************
//** getLastPoint
//**************************************************************************
/** Returns the last point in the point array */
public Point getLastPoint(){
Point[] Points = getPoints();
if (Points!=null){
return Points[Points.length-1];
}
else{
return null;
}
}
//**************************************************************************
//** getLength
//**************************************************************************
/** Returns the length of the point array */
public int getLength(){
Point[] Points = getPoints();
if (Points!=null){
return Points.length;
}
else{
return -1;
}
}
//**************************************************************************
//** addPoint
//**************************************************************************
/** Used to append a point to an array of points */
public Point[] addPoint(Point point){
if (point!=null) points.add(point);
return getPoints();
}
//**************************************************************************
//** addPoint
//**************************************************************************
/** Used to append a point to an array of points */
public Point[] addPoint(double x, double y){
return addPoint(new Point(x,y));
}
//**************************************************************************
//** addPoints
//**************************************************************************
/** Used to append a point or multiple points to an array of points.
* Attempts to convert input string into coordinate tuples.
*/
/*
public Point[] addPoints(String Coordinates){
Parser CoordinateParser = new Parser(Coordinates);
return addPoints((Points)CoordinateParser.getGeometry());
}
*/
//**************************************************************************
//** addPoints
//**************************************************************************
/** Used to append a point or multiple points to an array of points. */
public Point[] addPoints(Points points){
return addPoints(points.getArray());
}
//**************************************************************************
//** addPoints
//**************************************************************************
/** Used to append a point or multiple points to an array of points. */
public Point[] addPoints(Point[] arr){
for (int i=0; i<arr.length; i++){
addPoint(arr[i]);
}
return getPoints();
}
//**************************************************************************
//** toString
//**************************************************************************
/** Used to convert a line to a String */
public String toString(){
Point[] Points = getPoints();
if (Points==null) return "";
else{
StringBuffer Coordinates = new StringBuffer();
for (int i=0; i<Points.length; i++){
Coordinates.append(Points[i].toString() + " ");
}
return Coordinates.toString().trim();
}
}
//**************************************************************************
//** toString
//**************************************************************************
/** Used to convert a line to a String */
public String toString(String CoordinateSeparator, String TupleSeparator){
Point[] Points = getPoints();
if (Points==null) return "";
else{
StringBuffer Coordinates = new StringBuffer();
for (int i=0; i<Points.length; i++){
Coordinates.append(Points[i].toString(CoordinateSeparator) +
TupleSeparator);
}
String ret = Coordinates.toString(); //.trim();
if (ret.endsWith(TupleSeparator)){
ret = ret.substring(0, (ret.length()-TupleSeparator.length()));
}
return ret;
}
}
}