Subversion Repositories hibernate-spatial

Rev

Rev 102 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
54 maesenka 1
/**
2
 * $Id$
3
 *
4
 * This file is part of Hibernate Spatial, an extension to the
5
 * hibernate ORM solution for geographic data.
6
 *
7
 * Copyright © 2007 Geovise BVBA
8
 * Copyright © 2007 K.U. Leuven LRD, Spatial Applications Division, Belgium
9
 *
10
 * This work was partially supported by the European Commission,
11
 * under the 6th Framework Programme, contract IST-2-004688-STP.
12
 *
13
 * This library is free software; you can redistribute it and/or
14
 * modify it under the terms of the GNU Lesser General Public
15
 * License as published by the Free Software Foundation; either
16
 * version 2.1 of the License, or (at your option) any later version.
17
 *
18
 * This library is distributed in the hope that it will be useful,
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21
 * Lesser General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU Lesser General Public
24
 * License along with this library; if not, write to the Free Software
25
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26
 *
27
 * For more information, visit: http://www.hibernatespatial.org/
28
 */
29
package org.hibernatespatial.test.mgeom;
30
 
31
import junit.framework.TestCase;
32
 
33
import org.hibernatespatial.mgeom.DoubleComparator;
34
import org.hibernatespatial.mgeom.MCoordinate;
35
import org.hibernatespatial.mgeom.MCoordinateSequenceFactory;
36
import org.hibernatespatial.mgeom.MGeometry;
37
import org.hibernatespatial.mgeom.MGeometryException;
38
import org.hibernatespatial.mgeom.MGeometryFactory;
39
import org.hibernatespatial.mgeom.MLineString;
40
 
41
import com.vividsolutions.jts.geom.Coordinate;
42
import com.vividsolutions.jts.geom.CoordinateSequence;
43
import com.vividsolutions.jts.geom.CoordinateSequenceComparator;
44
 
45
/**
46
 * @author Karel Maesen
47
 */
48
public class MLineStringTest extends TestCase {
49
 
50
	private MGeometryFactory mgeomFactory = new MGeometryFactory(
51
			MCoordinateSequenceFactory.instance());
52
 
53
	private MLineString controlledLine;
54
 
55
	private MLineString arbitraryLine;
56
 
57
	private MLineString nullLine;
58
 
59
	private MLineString ringLine;
60
 
61
	public static void main(String[] args) {
62
		junit.textui.TestRunner.run(MLineStringTest.class);
63
	}
64
 
65
	/*
66
	 * @see TestCase#setUp()
67
	 */
68
	protected void setUp() throws Exception {
69
		super.setUp();
70
		MCoordinate mc0 = MCoordinate.create2dWithMeasure(0.0, 0.0, 0.0);
71
		MCoordinate mc1 = MCoordinate.create2dWithMeasure(1.0, 0.0, 0.0);
72
		MCoordinate mc2 = MCoordinate.create2dWithMeasure(1.0, 1.0, 0.0);
73
		MCoordinate mc3 = MCoordinate.create2dWithMeasure(2.0, 1.0, 0.0);
74
 
75
		MCoordinate[] mcoar = new MCoordinate[] { mc0, mc1, mc2, mc3 };
76
		controlledLine = mgeomFactory.createMLineString(mcoar);
77
 
78
		mc0 = MCoordinate.create2dWithMeasure(0.0, 0.0, 0.0);
79
		mc1 = MCoordinate.create2dWithMeasure(1.0, 0.0, 0.0);
80
		mc2 = MCoordinate.create2dWithMeasure(1.0, 1.0, 0.0);
81
		mc3 = MCoordinate.create2dWithMeasure(0.0, 1.0, 0.0);
82
		MCoordinate mc4 = MCoordinate.create2dWithMeasure(0.0, 0.0, 0.0);
83
 
84
		mcoar = new MCoordinate[] { mc0, mc1, mc2, mc3, mc4 };
85
		ringLine = mgeomFactory.createMLineString(mcoar);
86
 
87
		int l = (int) Math.round(Math.random() * 250.0);
88
		l = Math.max(2, l);
89
		System.out.println("Size of arbitraryline ==" + l);
90
		mcoar = new MCoordinate[l];
91
		for (int i = 0; i < mcoar.length; i++) {
92
			double x = Math.random() * 100000.0;
93
			double y = Math.random() * 100000.0;
94
			double z = Double.NaN; // JTS doesn't support operations on the
95
			// z-coordinate value
96
			double m = Math.random() * 100000.0;
97
			mcoar[i] = new MCoordinate(x, y, z, m);
98
		}
99
		arbitraryLine = mgeomFactory.createMLineString(mcoar);
100
 
101
		mcoar = new MCoordinate[0];
102
		nullLine = mgeomFactory.createMLineString(mcoar);
103
	}
104
 
105
	/*
106
	 * @see TestCase#tearDown()
107
	 */
108
	protected void tearDown() throws Exception {
109
		super.tearDown();
110
	}
111
 
112
	/**
113
	 * Constructor for MLineStringTest.
114
	 *
115
	 * @param name
116
	 */
117
	public MLineStringTest(String name) {
118
		super(name);
119
	}
120
 
121
	//
122
	// public void testMLineString() {
123
 
124
	// }
125
 
126
	/*
127
	 * Class under test for Object clone()
128
	 */
129
 
130
	public void testClone() {
131
		MLineString mltest = (MLineString) arbitraryLine.clone();
132
 
133
		Coordinate[] testco = mltest.getCoordinates();
134
		Coordinate[] arco = arbitraryLine.getCoordinates();
135
		assertEquals(testco.length, arco.length);
136
		for (int i = 0; i < arco.length; i++) {
137
			// clones must have equal, but not identical coordinates
138
			assertEquals(arco[i], testco[i]);
139
			assertNotSame(arco[i], testco[i]);
140
		}
141
 
142
		mltest = (MLineString) nullLine.clone();
143
		assertEquals(mltest.isEmpty(), nullLine.isEmpty());
144
		assertTrue(mltest.isEmpty());
145
 
146
	}
147
 
148
	public void testGetClosestPoint() {
149
 
150
		try {
151
			if (!arbitraryLine.isMonotone(false)) {
152
				Coordinate mc = arbitraryLine.getClosestPoint(new Coordinate(
153
						1.0, 2.0), 0.1);
154
				assertTrue(false); // should never evaluate this
155
			}
156
		} catch (Exception e) {
157
			assertTrue(((MGeometryException) e).getType() == MGeometryException.OPERATION_REQUIRES_MONOTONE);
158
		}
159
 
160
		try {
161
			// check reaction on null string
162
			MCoordinate mc = nullLine.getClosestPoint(new Coordinate(0.0, 1.0),
163
					1.0);
164
			assertNull(mc);
165
 
166
			// must return the very same coordinate if the coordinate is a
167
			// coordinate of the line
168
			arbitraryLine.measureOnLength(false);
169
			int selp = (int) (arbitraryLine.getNumPoints() / 2);
170
			MCoordinate mcexp = (MCoordinate) arbitraryLine
171
					.getCoordinateN(selp);
172
			MCoordinate mctest = arbitraryLine.getClosestPoint(mcexp, 1);
173
			assertEquals(mcexp, mctest);
174
 
175
			// must not return a point that is beyond the tolerance
176
			mctest = controlledLine.getClosestPoint(
177
					new Coordinate(20.0, 20, 0), 1.0);
178
			assertNull(mctest);
179
 
180
			// check for cases of circular MGeometry: lowest measure should be
181
			// return.
182
			ringLine.measureOnLength(false);
183
			assertTrue(ringLine.isRing());
184
			assertTrue(ringLine.isMonotone(false));
185
			assertTrue(ringLine.getMeasureDirection() == MGeometry.INCREASING);
186
			MCoordinate expCo = MCoordinate.create2dWithMeasure(0.0, 0.0, 0.0);
187
			MCoordinate testCo = ringLine.getClosestPoint(expCo, 0.1);
188
			assertTrue(DoubleComparator.equals(testCo.m, expCo.m));
189
			ringLine.reverseMeasures();
190
			testCo = ringLine.getClosestPoint(expCo, 0.1);
191
			assertTrue(DoubleComparator.equals(testCo.m, expCo.m));
192
			ringLine.measureOnLength(false);
193
			int n = ringLine.getNumPoints() - 1;
194
			ringLine.setMeasureAtIndex(n, 100.0);
195
			ringLine.setMeasureAtIndex(0, 0.0);
196
			testCo = ringLine.getClosestPoint(expCo, 0.001);
197
			assertTrue(DoubleComparator.equals(testCo.m, 0.0));
198
 
199
			// get two neighbouring points along the arbitraryline
200
			arbitraryLine.measureOnLength(false);
201
			int elem1Indx = (int) (Math.random() * (arbitraryLine
202
					.getNumPoints() - 1));
203
			int elem2Indx = 0;
204
			if (elem1Indx == arbitraryLine.getNumPoints() - 1) {
205
				elem2Indx = elem1Indx - 1;
206
			} else {
207
				elem2Indx = elem1Indx + 1;
208
			}
209
			// test whether a coordinate between these two returns exactly
210
			MCoordinate mco1 = (MCoordinate) arbitraryLine
211
					.getCoordinateN(elem1Indx);
212
			MCoordinate mco2 = (MCoordinate) arbitraryLine
213
					.getCoordinateN(elem2Indx);
214
			double d = mco1.distance(mco2);
215
			double offset = Math.random();
216
			mcexp = MCoordinate.create2dWithMeasure(mco1.x + offset
217
					* (mco2.x - mco1.x), mco1.y + offset * (mco2.y - mco1.y),
218
					0.0);
219
			mctest = arbitraryLine.getClosestPoint(mcexp, d);
220
			mcexp.m = mco1.m + offset * (mco2.m - mco1.m);
221
			assertEquals(mcexp, mctest);
222
 
223
			double delta = Math.random();
224
 
225
			MCoordinate mcin = MCoordinate.create2dWithMeasure(mco1.x + offset
226
					* (mco2.x - mco1.x) + delta, mco1.y + offset
227
					* (mco2.y - mco1.y) + delta, 0.0);
228
 
229
			// returned point is on the line
230
			mctest = arbitraryLine.getClosestPoint(mcin, d);
231
			assertEquals(mcin.x, mctest.x, delta * Math.sqrt(2));
232
			assertEquals(mcin.y, mctest.y, delta * Math.sqrt(2));
233
		} catch (Exception e) {
234
			e.printStackTrace();
235
			assertTrue(false); // should never reach this point
236
		}
237
 
238
	}
239
 
240
	public void testGetCoordinateAtM() {
241
		// what if null string
242
		try {
243
			Coordinate mc = nullLine.getCoordinateAtM(2);
244
			assertNull(mc);
245
 
246
			// get two neighbouring points along the arbitraryline
247
			arbitraryLine.measureOnLength(false);
248
			int elem1Indx = (int) (Math.random() * (arbitraryLine
249
					.getNumPoints() - 1));
250
			int elem2Indx = 0;
251
			if (elem1Indx == arbitraryLine.getNumPoints() - 1) {
252
				elem2Indx = elem1Indx - 1;
253
			} else {
254
				elem2Indx = elem1Indx + 1;
255
			}
256
 
257
			// if m is value of a coordinate, the returned coordinate should
258
			// equal that coordinate
259
 
260
			MCoordinate mco1 = (MCoordinate) arbitraryLine
261
					.getCoordinateN(elem1Indx);
262
			MCoordinate mcotest = (MCoordinate) arbitraryLine
263
					.getCoordinateAtM(mco1.m);
264
			assertNotSame(mco1, mcotest);
265
			assertEquals(mco1, mcotest);
266
 
267
			MCoordinate mco2 = (MCoordinate) arbitraryLine
268
					.getCoordinateN(elem2Indx);
269
			double offset = Math.random();
270
			double newM = mco1.m + offset * (mco2.m - mco1.m);
271
			MCoordinate mcexp = new MCoordinate(mco1.x + offset
272
					* (mco2.x - mco1.x), mco1.y + offset * (mco2.y - mco1.y),
273
					Double.NaN, mco1.m + offset * (mco2.m - mco1.m));
274
			MCoordinate mctest = (MCoordinate) arbitraryLine
275
					.getCoordinateAtM(newM);
276
			assertEquals(mcexp, mctest);
277
		} catch (Exception e) {
278
			System.err.println(e);
279
		}
280
	}
281
 
282
	/*
283
	 * Class under test for String getGeometryType()
284
	 */
285
	public void testGetGeometryType() {
286
		assertEquals("MLineString", arbitraryLine.getGeometryType());
287
	}
288
 
289
	public void testGetMatCoordinate() {
290
		try {
291
			// what in case of the null string
292
			assertTrue(Double.isNaN(nullLine.getMatCoordinate(new Coordinate(
293
					1.0, 1.0), 1.0)));
294
 
295
			// get two neighbouring points along the arbitraryline
296
			arbitraryLine.measureOnLength(false);
297
			int elem1Indx = (int) (Math.random() * (arbitraryLine
298
					.getNumPoints() - 1));
299
			int elem2Indx = 0;
300
			if (elem1Indx == arbitraryLine.getNumPoints() - 1) {
301
				elem2Indx = elem1Indx - 1;
302
			} else {
303
				elem2Indx = elem1Indx + 1;
304
			}
305
 
306
			// if a coordinate of the geometry is passed, it should return
307
			// exactly that m-value
308
			MCoordinate mco1 = (MCoordinate) arbitraryLine
309
					.getCoordinateN(elem1Indx);
310
			double m = arbitraryLine.getMatCoordinate(mco1, 0.00001);
311
			assertEquals(mco1.m, m, DoubleComparator
312
					.defaultNumericalPrecision());
313
 
314
			// check for a coordinate between mco1 and mco2 (neighbouring
315
			// coordinates)
316
			MCoordinate mco2 = (MCoordinate) arbitraryLine
317
					.getCoordinateN(elem2Indx);
318
			double offset = Math.random();
319
			double expectedM = mco1.m + offset * (mco2.m - mco1.m);
320
			Coordinate mctest = new Coordinate(mco1.x + offset
321
					* (mco2.x - mco1.x), mco1.y + offset * (mco2.y - mco1.y));
322
 
323
			double testM = arbitraryLine.getMatCoordinate(mctest, offset);
324
			assertEquals(expectedM, testM, DoubleComparator
325
					.defaultNumericalPrecision());
326
		} catch (Exception e) {
327
			e.printStackTrace();
328
			assertTrue(false);// should never reach here
329
		}
330
	}
331
 
332
	public void testGetMatN() {
333
		// Implement getMatN().
334
	}
335
 
336
	public void testGetMaxM() {
337
		// Implement getMaxM().
338
	}
339
 
340
	public void testGetCoordinatesBetween() {
341
 
342
		try {
343
			// what if the null value is passed
344
			CoordinateSequence[] cs = nullLine.getCoordinatesBetween(0.0, 5.0);
345
			assertTrue(cs.length == 0);
346
 
347
			arbitraryLine.measureOnLength(false);
348
			// what if from/to is outside of the range of values
349
			double maxM = arbitraryLine.getMaxM();
350
			cs = arbitraryLine.getCoordinatesBetween(maxM + 1.0, maxM + 10.0);
351
 
352
			// check for several ascending M-values
353
			int minIdx = (int) (Math.random() * (arbitraryLine.getNumPoints() - 1));
354
			int maxIdx = Math.min((arbitraryLine.getNumPoints() - 1),
355
					minIdx + 10);
356
			double minM = ((MCoordinate) arbitraryLine.getCoordinateN(minIdx)).m;
357
			maxM = ((MCoordinate) arbitraryLine.getCoordinateN(maxIdx)).m;
358
			cs = arbitraryLine.getCoordinatesBetween(minM, maxM);
359
			assertNotNull(cs);
360
			assertTrue(cs.length > 0);
361
			Coordinate[] coar = cs[0].toCoordinateArray();
362
			int j = 0;
363
			for (int i = minIdx; i <= maxIdx; i++) {
364
				assertEquals((MCoordinate) arbitraryLine.getCoordinateN(i),
365
						coar[j]);
366
				j++;
367
			}
368
 
369
			// if we go in reverse we should meet all points in reverse order
370
			cs = arbitraryLine.getCoordinatesBetween(maxM, minM);
371
			assertNotNull(cs);
372
			assertTrue(cs.length > 0);
373
			coar = cs[0].toCoordinateArray();
374
			j = 0;
375
			for (int i = maxIdx; i >= minIdx; i--) {
376
				assertEquals((MCoordinate) arbitraryLine.getCoordinateN(i),
377
						coar[j]);
378
				j++;
379
			}
380
 
381
			minM = Math.max(0.0, minM - Math.random() * 10);
382
			cs = arbitraryLine.getCoordinatesBetween(minM, maxM);
383
			coar = cs[0].toCoordinateArray();
384
			MCoordinate mctest = (MCoordinate) coar[0];
385
			MCoordinate mcexp = (MCoordinate) arbitraryLine
386
					.getCoordinateAtM(minM);
387
			assertEquals(mcexp, mctest);
388
			assertEquals(mctest.m, minM, DoubleComparator
389
					.defaultNumericalPrecision());
390
 
391
			maxM = Math.min(arbitraryLine.getLength(), maxM + Math.random()
392
					* 10);
393
			cs = arbitraryLine.getCoordinatesBetween(minM, maxM);
394
			coar = cs[0].toCoordinateArray();
395
			mctest = (MCoordinate) coar[coar.length - 1];
396
			mcexp = (MCoordinate) arbitraryLine.getCoordinateAtM(maxM);
397
			assertEquals(mcexp, mctest);
398
			assertEquals(mctest.m, maxM, DoubleComparator
399
					.defaultNumericalPrecision());
400
 
401
		} catch (Exception e) {
402
			e.printStackTrace();
403
			assertTrue(false);// should never reach here
404
 
405
		}
406
	}
407
 
408
	public void testGetMeasureDirection() {
409
		assertTrue(nullLine.isMonotone(false));
410
 
411
		assertTrue(arbitraryLine.isMonotone(false)
412
				|| (!arbitraryLine.isMonotone(false) && arbitraryLine
413
						.getMeasureDirection() == MGeometry.NON_MONOTONE));
414
		arbitraryLine.measureOnLength(false);
415
		assertEquals(MGeometry.INCREASING, arbitraryLine.getMeasureDirection());
416
 
417
		arbitraryLine.reverseMeasures();
418
		assertEquals(MGeometry.DECREASING, arbitraryLine.getMeasureDirection());
419
 
420
		for (int i = 0; i < arbitraryLine.getNumPoints(); i++) {
421
			arbitraryLine.setMeasureAtIndex(i, 0.0);
422
		}
423
		assertEquals(MGeometry.CONSTANT, arbitraryLine.getMeasureDirection());
424
	}
425
 
426
	public void testGetMeasures() {
427
 
428
	}
429
 
430
	public void testGetMinM() {
431
 
432
	}
433
 
434
	public void testInterpolate() {
435
		MCoordinate mc0NaN = MCoordinate.create2d(0.0, 0.0);
436
		MCoordinate mc0 = MCoordinate.create2dWithMeasure(0.0, 0.0, 0.0);
437
		MCoordinate mc2NaN = MCoordinate.create2d(2.0, 0.0);
438
		MCoordinate mc5NaN = MCoordinate.create2d(5.0, 0.0);
439
		MCoordinate mc10NaN = MCoordinate.create2d(10.0, 0.0);
440
		MCoordinate mc10 = MCoordinate.create2dWithMeasure(10.0, 0.0, 10.0);
441
 
442
		// Internal coordinate measures are not defined, outer measures are
443
		// 0-10, total 2d length is 10
444
		MLineString line = mgeomFactory.createMLineString(new MCoordinate[] {
445
				mc0, mc2NaN, mc5NaN, mc10 });
446
		MLineString lineBeginNaN = mgeomFactory
447
				.createMLineString(new MCoordinate[] { mc0NaN, mc2NaN, mc5NaN,
448
						mc10 });
449
		MLineString lineEndNaN = mgeomFactory
450
				.createMLineString(new MCoordinate[] { mc0, mc2NaN, mc5NaN,
451
						mc10NaN });
452
 
453
		assertTrue(DoubleComparator.equals(line.getLength(), 10));
454
		assertTrue(DoubleComparator.equals(lineBeginNaN.getLength(), 10));
455
		assertTrue(DoubleComparator.equals(lineEndNaN.getLength(), 10));
456
 
457
		line.interpolate(mc0.m, mc10.m);
458
		lineBeginNaN.interpolate(mc0.m, mc10.m);
459
		lineEndNaN.interpolate(mc0.m, mc10.m);
460
 
461
		assertTrue(line.isMonotone(false));
462
		assertTrue(line.isMonotone(true));
463
		assertTrue(lineBeginNaN.isMonotone(false));
464
		assertTrue(lineBeginNaN.isMonotone(true));
465
		assertTrue(lineEndNaN.isMonotone(false));
466
		assertTrue(lineEndNaN.isMonotone(true));
467
 
468
		double[] expectedM = new double[] { mc0.m, 2.0, 5.0, mc10.m };
469
		for (int i = 0; i < expectedM.length; i++) {
470
			double actualMLine = line.getCoordinateSequence().getOrdinate(i,
471
					CoordinateSequence.M);
472
			double actualBeginNaN = lineBeginNaN.getCoordinateSequence()
473
					.getOrdinate(i, CoordinateSequence.M);
474
			double actualEndNaN = lineEndNaN.getCoordinateSequence()
475
					.getOrdinate(i, CoordinateSequence.M);
476
			assertTrue(DoubleComparator.equals(expectedM[i], actualMLine));
477
			assertTrue(DoubleComparator.equals(expectedM[i], actualBeginNaN));
478
			assertTrue(DoubleComparator.equals(expectedM[i], actualEndNaN));
479
		}
480
 
481
		// Test Continuous case by interpolating with begin and end measures
482
		// equal
483
		double continuousMeasure = 0.0D;
484
		line.interpolate(continuousMeasure, continuousMeasure);
485
		double[] measures = line.getMeasures();
486
		for (int i = 0; i < measures.length; i++)
487
			assertTrue(DoubleComparator.equals(measures[i], continuousMeasure));
488
	}
489
 
490
	public void testIsMonotone() {
491
		MCoordinate mc0NaN = MCoordinate.create2d(1.0, 0.0);
492
		MCoordinate mc0 = MCoordinate.create2dWithMeasure(0.0, 0.0, 0.0);
493
		MCoordinate mc1NaN = MCoordinate.create2d(1.0, 0.0);
494
		MCoordinate mc1 = MCoordinate.create2dWithMeasure(1.0, 0.0, 1.0);
495
		MCoordinate mc2NaN = MCoordinate.create2d(2.0, 0.0);
496
		MCoordinate mc2 = MCoordinate.create2dWithMeasure(2.0, 0.0, 2.0);
497
		MCoordinate mc3NaN = MCoordinate.create2d(3.0, 0.0);
498
		MCoordinate mc3 = MCoordinate.create2dWithMeasure(3.0, 0.0, 3.0);
499
 
500
		MLineString emptyLine = mgeomFactory
501
				.createMLineString(new MCoordinate[] {});
502
		MLineString orderedLine = mgeomFactory
503
				.createMLineString(new MCoordinate[] { mc0, mc1, mc2, mc3 });
504
		MLineString unorderedLine = mgeomFactory
505
				.createMLineString(new MCoordinate[] { mc0, mc2, mc1, mc3 });
506
		MLineString constantLine = mgeomFactory
507
				.createMLineString(new MCoordinate[] { mc2, mc2, mc2, mc2 });
508
		MLineString reverseOrderedLine = mgeomFactory
509
				.createMLineString(new MCoordinate[] { mc3, mc2, mc1, mc0 });
510
		MLineString reverseUnOrderedLine = mgeomFactory
511
				.createMLineString(new MCoordinate[] { mc3, mc1, mc2, mc0 });
512
		MLineString dupCoordLine = mgeomFactory
513
				.createMLineString(new MCoordinate[] { mc0, mc1, mc1, mc2 });
514
		MLineString reverseDupCoordLine = mgeomFactory
515
				.createMLineString(new MCoordinate[] { mc2, mc1, mc1, mc0 });
516
 
517
		assertTrue(emptyLine.isMonotone(false));
518
		assertTrue(emptyLine.isMonotone(true));
519
 
520
		assertTrue(orderedLine.isMonotone(false));
521
		assertTrue(orderedLine.isMonotone(true));
522
		// test reversing the ordered line
523
		orderedLine.reverseMeasures();
524
		assertTrue(orderedLine.isMonotone(false));
525
		assertTrue(orderedLine.isMonotone(true));
526
		// test shifting
527
		orderedLine.shiftMeasure(1.0);
528
		assertTrue(orderedLine.isMonotone(false));
529
		assertTrue(orderedLine.isMonotone(true));
530
		orderedLine.shiftMeasure(-1.0);
531
		assertTrue(orderedLine.isMonotone(false));
532
		assertTrue(orderedLine.isMonotone(true));
533
 
534
		assertFalse(unorderedLine.isMonotone(false));
535
		assertFalse(unorderedLine.isMonotone(true));
536
 
537
		assertTrue(constantLine.isMonotone(false));
538
		assertFalse(constantLine.isMonotone(true));
539
		// test shifting
540
		constantLine.shiftMeasure(1.0);
541
		assertTrue(constantLine.isMonotone(false));
542
		assertFalse(constantLine.isMonotone(true));
543
		constantLine.shiftMeasure(-1.0);
544
		assertTrue(constantLine.isMonotone(false));
545
		assertFalse(constantLine.isMonotone(true));
546
 
547
		assertTrue(reverseOrderedLine.isMonotone(false));
548
		assertTrue(reverseOrderedLine.isMonotone(true));
549
		// test reversing the line
550
		reverseOrderedLine.reverseMeasures();
551
		assertTrue(reverseOrderedLine.isMonotone(false));
552
		assertTrue(reverseOrderedLine.isMonotone(true));
553
		// test shifting
554
		reverseOrderedLine.shiftMeasure(1.0);
555
		assertTrue(reverseOrderedLine.isMonotone(false));
556
		assertTrue(reverseOrderedLine.isMonotone(true));
557
		reverseOrderedLine.shiftMeasure(-1.0);
558
		assertTrue(reverseOrderedLine.isMonotone(false));
559
		assertTrue(reverseOrderedLine.isMonotone(true));
560
 
561
		assertFalse(reverseUnOrderedLine.isMonotone(false));
562
		assertFalse(reverseUnOrderedLine.isMonotone(true));
563
 
564
		assertTrue(dupCoordLine.isMonotone(false));
565
		assertFalse(dupCoordLine.isMonotone(true));
566
		// test shifting
567
		dupCoordLine.shiftMeasure(1.0);
568
		assertTrue(dupCoordLine.isMonotone(false));
569
		assertFalse(dupCoordLine.isMonotone(true));
570
		dupCoordLine.shiftMeasure(-1.0);
571
		assertTrue(dupCoordLine.isMonotone(false));
572
		assertFalse(dupCoordLine.isMonotone(true));
573
 
574
		assertTrue(reverseDupCoordLine.isMonotone(false));
575
		assertFalse(reverseDupCoordLine.isMonotone(true));
576
		// test shifting
577
		reverseDupCoordLine.shiftMeasure(1.0);
578
		assertTrue(reverseDupCoordLine.isMonotone(false));
579
		assertFalse(reverseDupCoordLine.isMonotone(true));
580
		reverseDupCoordLine.shiftMeasure(-1.0);
581
		assertTrue(reverseDupCoordLine.isMonotone(false));
582
		assertFalse(reverseDupCoordLine.isMonotone(true));
583
 
584
		assertEquals(orderedLine.getMeasureDirection(), MGeometry.INCREASING);
585
		assertEquals(unorderedLine.getMeasureDirection(),
586
				MGeometry.NON_MONOTONE);
587
		assertEquals(reverseOrderedLine.getMeasureDirection(),
588
				MGeometry.DECREASING);
589
		assertEquals(dupCoordLine.getMeasureDirection(), MGeometry.INCREASING);
590
		assertEquals(reverseDupCoordLine.getMeasureDirection(),
591
				MGeometry.DECREASING);
592
 
593
		// Test scenario where there are NaN middle measures
594
		MLineString internalNaNLine = mgeomFactory
595
				.createMLineString(new MCoordinate[] { mc0, mc1NaN, mc2NaN, mc3 });
596
		MLineString beginNaNLine = mgeomFactory
597
				.createMLineString(new MCoordinate[] { mc0NaN, mc2, mc3 });
598
		MLineString endNaNLine = mgeomFactory
599
				.createMLineString(new MCoordinate[] { mc0, mc2, mc3NaN });
600
		MLineString beginEndNaNLine = mgeomFactory
601
				.createMLineString(new MCoordinate[] { mc0NaN, mc2, mc3NaN });
602
 
603
		assertFalse(internalNaNLine.isMonotone(false));
604
		assertFalse(internalNaNLine.isMonotone(true));
605
		internalNaNLine.measureOnLength(false);
606
		assertTrue(internalNaNLine.isMonotone(false));
607
		assertTrue(internalNaNLine.isMonotone(true));
608
 
609
		assertFalse(beginNaNLine.isMonotone(false));
610
		assertFalse(beginNaNLine.isMonotone(true));
611
		beginNaNLine.measureOnLength(false);
612
		assertTrue(beginNaNLine.isMonotone(false));
613
		assertTrue(beginNaNLine.isMonotone(true));
614
 
615
		assertFalse(endNaNLine.isMonotone(false));
616
		assertFalse(endNaNLine.isMonotone(true));
617
		endNaNLine.measureOnLength(false);
618
		assertTrue(endNaNLine.isMonotone(false));
619
		assertTrue(endNaNLine.isMonotone(true));
620
 
621
		assertFalse(beginEndNaNLine.isMonotone(false));
622
		assertFalse(beginEndNaNLine.isMonotone(true));
623
		beginEndNaNLine.measureOnLength(false);
624
		assertTrue(beginEndNaNLine.isMonotone(false));
625
		assertTrue(beginEndNaNLine.isMonotone(true));
626
	}
627
 
628
	public void testGetCoordinatesBetweenNonStrict() {
629
		try {
630
			CoordinateSequenceComparator coordCompare = new CoordinateSequenceComparator();
631
			MCoordinate mc0 = MCoordinate.create2dWithMeasure(0.0, 0.0, 0);
632
			MCoordinate mc1 = MCoordinate.create2dWithMeasure(0.0, 1.0, 1);
633
			MCoordinate mc2_1 = MCoordinate.create2dWithMeasure(0.0, 2.0, 1);
634
			MCoordinate mc2 = MCoordinate.create2dWithMeasure(0.0, 2.0, 2);
635
			MCoordinate mc3 = MCoordinate.create2dWithMeasure(0.0, 3.0, 3);
636
			MCoordinate mc4 = MCoordinate.create2dWithMeasure(0.0, 4.0, 4);
637
 
638
			// in this case, a 2nd and 3rd coordinates are the same instance,
639
			// giving one a duplicate internal measure
640
			// The state is monotone, and dynseg from measures 0-1 should yield
641
			// the equivalent of a similar
642
			// Line where the duplicate coordinate does not exist. In other
643
			// words the duplicate is essentially ignored.
644
			MLineString nonStrictDupPointLine = mgeomFactory
645
					.createMLineString(new MCoordinate[] { mc0, mc1, mc1, mc2,
646
							mc3 });
647
			MLineString strictLine = mgeomFactory
648
					.createMLineString(new MCoordinate[] { mc0, mc1, mc2, mc3 });
649
 
650
			CoordinateSequence[] nonStrictDupSeq = nonStrictDupPointLine
651
					.getCoordinatesBetween(mc0.m, mc2_1.m);
652
			CoordinateSequence[] strictSeq = strictLine.getCoordinatesBetween(
653
					mc0.m, mc1.m);
654
			assertEquals(nonStrictDupSeq.length, 1);
655
			assertEquals(strictSeq.length, 1);
656
			assertTrue(coordCompare.compare(nonStrictDupSeq[0], strictSeq[0]) == 0);
657
			assertEquals(strictSeq[0].size(), 2);
658
 
659
			// Test non-strict sequence where all coordinate x,y positions are
660
			// unique, but contains a
661
			// duplicate measure. The measure sequence in this test s
662
			// [0,1,1,3,4]
663
			MLineString nonStrictPointLine = mgeomFactory
664
					.createMLineString(new MCoordinate[] { mc0, mc1, mc2_1,
665
							mc3, mc4 });
666
			CoordinateSequence[] nonStrictSeq = nonStrictPointLine
667
					.getCoordinatesBetween(mc0.m, mc2_1.m);
668
			assertNotNull(nonStrictSeq);
669
 
670
			nonStrictSeq = nonStrictPointLine.getCoordinatesBetween(mc0.m,
671
					mc4.m);
672
			assertNotNull(nonStrictSeq);
673
 
674
			nonStrictSeq = nonStrictPointLine.getCoordinatesBetween(mc1.m,
675
					mc4.m);
676
			assertNotNull(nonStrictSeq);
677
 
678
			nonStrictSeq = nonStrictPointLine
679
					.getCoordinatesBetween(1.1D, mc4.m);
680
			assertNotNull(nonStrictSeq);
681
 
682
		} catch (MGeometryException e) {
683
			e.printStackTrace();
684
		}
685
	}
686
 
687
	public void testmeasureOnLength() {
688
		arbitraryLine.measureOnLength(false);
689
		double maxM = arbitraryLine.getMaxM();
690
		double minM = arbitraryLine.getMinM();
691
		assertEquals(maxM, arbitraryLine.getLength(), DoubleComparator
692
				.defaultNumericalPrecision());
693
		assertEquals(minM, 0.0d, DoubleComparator.defaultNumericalPrecision());
694
		MCoordinate mco = (MCoordinate) arbitraryLine
695
				.getCoordinateN(arbitraryLine.getNumPoints() - 1);
696
		assertEquals(mco.m, maxM, DoubleComparator.defaultNumericalPrecision());
697
		mco = (MCoordinate) arbitraryLine.getCoordinateN(0);
698
		assertEquals(mco.m, minM, DoubleComparator.defaultNumericalPrecision());
699
	}
700
 
701
	public void testReverseMeasures() {
702
 
703
		nullLine.reverseMeasures();
704
 
705
		arbitraryLine.measureOnLength(false);
706
		arbitraryLine.reverseMeasures();
707
		assertTrue(arbitraryLine.getMeasureDirection() == MGeometry.DECREASING);
708
		double mlast = arbitraryLine.getMatN(arbitraryLine.getNumPoints() - 1);
709
		arbitraryLine.reverseMeasures();
710
		assertTrue(arbitraryLine.getMeasureDirection() == MGeometry.INCREASING);
711
		double mfirst = arbitraryLine.getMatN(0);
712
		assertEquals(mlast, mfirst, DoubleComparator
713
				.defaultNumericalPrecision());
714
 
715
	}
716
 
717
	public void testSetMatN() {
718
		// TODO Implement setMeasureAtIndex().
719
	}
720
 
721
	public void testShiftMBy() {
722
		// TODO Implement shiftMeasure().
723
	}
724
 
725
	/*
726
	 * Class under test for String toString()
727
	 */
728
	public void testToString() {
729
		// TODO Implement toString().
730
	}
731
 
732
	public void testUnionM() {
733
		// TODO Implement unionM().
734
	}
735
 
736
	public void testVerifyMonotone() {
737
		// TODO Implement verifyMonotone().
738
	}
739
 
740
}