/* Spatial Operations & Editing Tools for uDig * * Axios Engineering under a funding contract with: * Diputación Foral de Gipuzkoa, Ordenación Territorial * * http://b5m.gipuzkoa.net * http://www.axios.es * * (C) 2006, Diputación Foral de Gipuzkoa, Ordenación Territorial (DFG-OT). * DFG-OT agrees to licence under Lesser General Public License (LGPL). * * You can redistribute it and/or modify it under the terms of the * GNU Lesser General Public License as published by the Free Software * Foundation; version 2.1 of the License. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. */ package es.axios.udig.ui.editingtools.precisionparallels.internal; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import java.util.List; import org.junit.Test; import com.vividsolutions.jts.algorithm.CGAlgorithms; import com.vividsolutions.jts.geom.Coordinate; import com.vividsolutions.jts.geom.Geometry; import com.vividsolutions.jts.geom.GeometryFactory; import com.vividsolutions.jts.geom.LineSegment; import com.vividsolutions.jts.geom.LineString; import com.vividsolutions.jts.geom.LinearRing; import com.vividsolutions.jts.geom.Point; import com.vividsolutions.jts.geomgraph.Position; import com.vividsolutions.jts.io.ParseException; import com.vividsolutions.jts.io.WKTReader; import es.axios.udig.ui.editingtools.precisionparallels.internal.OffsetBuilder.OffsetPosition; /** * @author Aritz Davila (www.axios.es) * @author Mauricio Pazos (www.axios.es) * */ public class ParallelContextTest { private Coordinate[] inputCoordinates = null; private int startPosition = Position.LEFT; private OffsetPosition offsetPosition = null; private List<Geometry> outputCoordinates = null; protected Coordinate initialCoordinate = null; private static final double DEPRECIATE_VALUE = 6.0E-3; private Geometry read(final String wkt) { WKTReader reader = new WKTReader(); Geometry geometry; try { geometry = reader.read(wkt); } catch (ParseException e) { throw (RuntimeException) new RuntimeException().initCause(e); } return geometry; } @Test public void testInsideNoTurn() { LineString line = (LineString) read("LINESTRING(1 20, 5 10, 10 10, 12 13)"); initialCoordinate = new Coordinate(5.7, 20.4); inputCoordinates = line.getCoordinates(); double distance = calculateDistanceAndCurrentPostion(); OffsetBuilder builder = new OffsetBuilder(offsetPosition, startPosition, DEPRECIATE_VALUE); outputCoordinates = builder.getLineCurve(inputCoordinates, distance, line.getFactory()); assertNotNull(outputCoordinates); assertEquals(outputCoordinates.get(0).getCoordinates().length, 3); System.out.println(outputCoordinates.toString()); } @Test public void testInsideNoTurn2() { // LineString line = (LineString) read("LINESTRING(10 20, 15 10, 17 10, // 22 20)"); LineString line = (LineString) read("LINESTRING(10 15, 12 10, 20 10)"); initialCoordinate = new Coordinate(16, 14); inputCoordinates = line.getCoordinates(); double distance = calculateDistanceAndCurrentPostion(); OffsetBuilder builder = new OffsetBuilder(offsetPosition, startPosition, DEPRECIATE_VALUE); outputCoordinates = builder.getLineCurve(inputCoordinates, distance, line.getFactory()); assertNotNull(outputCoordinates); assertEquals(outputCoordinates.get(0).getCoordinates().length, 3); System.out.println(outputCoordinates.toString()); } @Test public void singleLine() { LineString line = (LineString) read("LINESTRING(10 20, 22 20)"); initialCoordinate = new Coordinate(16, 14); inputCoordinates = line.getCoordinates(); double distance = calculateDistanceAndCurrentPostion(); OffsetBuilder builder = new OffsetBuilder(offsetPosition, startPosition, DEPRECIATE_VALUE); outputCoordinates = builder.getLineCurve(inputCoordinates, distance, line.getFactory()); assertNotNull(outputCoordinates); assertEquals(outputCoordinates.get(0).getCoordinates().length, 2); System.out.println(outputCoordinates.toString()); } @Test public void squareInside() { LineString line = (LineString) read("LINESTRING(5 10, 5 20, 10 20, 10 10, 5 10)"); initialCoordinate = new Coordinate(7, 14); inputCoordinates = line.getCoordinates(); double distance = calculateDistanceAndCurrentPostion(); OffsetBuilder builder = new OffsetBuilder(offsetPosition, startPosition, DEPRECIATE_VALUE); outputCoordinates = builder.getLineCurve(inputCoordinates, distance, line.getFactory()); assertNotNull(outputCoordinates); assertEquals(outputCoordinates.get(0).getCoordinates().length, 5); System.out.println(outputCoordinates.toString()); } @Test public void squareOutside() { LineString line = (LineString) read("LINESTRING(5 10, 5 20, 10 20, 10 10, 5 10)"); initialCoordinate = new Coordinate(3, 15); inputCoordinates = line.getCoordinates(); double distance = calculateDistanceAndCurrentPostion(); OffsetBuilder builder = new OffsetBuilder(offsetPosition, startPosition, DEPRECIATE_VALUE); outputCoordinates = builder.getLineCurve(inputCoordinates, distance, line.getFactory()); assertNotNull(outputCoordinates); assertEquals(outputCoordinates.get(0).getCoordinates().length, 5); System.out.println(outputCoordinates.toString()); } private double calculateDistanceAndCurrentPostion() { LineSegment seg = new LineSegment(); LineSegment closestSeg = new LineSegment(); double distance, closestDistance = Double.MAX_VALUE; // get the closest segment. for (int i = 0; i < inputCoordinates.length - 1; i++) { seg.setCoordinates(inputCoordinates[i], inputCoordinates[i + 1]); distance = CGAlgorithms.distancePointLine(initialCoordinate, inputCoordinates[i], inputCoordinates[i + 1]); if (distance < closestDistance) { closestDistance = distance; closestSeg = new LineSegment(inputCoordinates[i], inputCoordinates[i + 1]); } } startPosition = Position.LEFT; int segmentOrientation = CGAlgorithms.computeOrientation(closestSeg.p0, closestSeg.p1, initialCoordinate); // offset position respect the first segment and the initial point. // Useful when is only one segment. offsetPosition = (segmentOrientation == -1) ? OffsetPosition.POSITION_UNDER : OffsetPosition.POSITION_UPPER; int refLineOrientation, length; boolean outsideTurn = true; length = inputCoordinates.length; if (length > 2) { if (segmentOrientation == 1) { refLineOrientation = CGAlgorithms.computeOrientation(inputCoordinates[0], inputCoordinates[1], inputCoordinates[2]); outsideTurn = (refLineOrientation == CGAlgorithms.CLOCKWISE && 1 == Position.LEFT) || (refLineOrientation == CGAlgorithms.COUNTERCLOCKWISE && 1 == Position.RIGHT); offsetPosition = (outsideTurn) ? OffsetPosition.POSITION_UPPER : OffsetPosition.POSITION_UNDER; startPosition = (outsideTurn) ? Position.LEFT : Position.RIGHT; } else { refLineOrientation = CGAlgorithms.computeOrientation(inputCoordinates[length - 1], inputCoordinates[length - 2], inputCoordinates[length - 3]); outsideTurn = (refLineOrientation == CGAlgorithms.CLOCKWISE && 1 == Position.LEFT) || (refLineOrientation == CGAlgorithms.COUNTERCLOCKWISE && 1 == Position.RIGHT); offsetPosition = (outsideTurn) ? OffsetPosition.POSITION_UPPER : OffsetPosition.POSITION_UNDER; startPosition = (outsideTurn) ? Position.RIGHT : Position.LEFT; } } return closestDistance; } private boolean calculateDistanceZero(LineString inputLine) { // retrieve ramdon coordinate initialCoordinate = inputLine.getCoordinate(); inputCoordinates = inputLine.getCoordinates(); // use the function to set the offsetPosition double distance = calculateDistanceAndCurrentPostion(); // now set the real distance value distance = 0; OffsetBuilder builder = new OffsetBuilder(offsetPosition, startPosition, DEPRECIATE_VALUE); outputCoordinates = builder.getLineCurve(inputCoordinates, distance, inputLine.getFactory()); System.out.println(outputCoordinates.toString()); assertNotNull(outputCoordinates); return outputCoordinates.get(0).equals(inputLine); } @Test public void exampleFeature1Inside() { LineString line = (LineString) read("LINESTRING (579617.8828 4785770, 579618.14 4785769.76, 579618.3946 4785770.0378, 579619.5649 4785771.3389, 579621.06 4785770, 579626.64 4785765.03, 579625.24 4785763.48, 579638.31 4785751.58, 579639.75 4785753.16, 579647.01 4785746.79, 579645.6 4785745.16, 579652.23 4785739.17, 579646.33 4785732.55, 579641.52 4785736.75, 579639.61 4785738.48, 579635.85 4785734.35, 579628.83 4785740.69, 579632.51 4785744.75, 579621.54 4785754.71, 579619.83 4785752.81, 579617.51 4785754.8, 579615.5700000001 4785752.54, 579614.47 4785753.56, 579608.54 4785758.98, 579612.14 4785763.17, 579605.62 4785769.08, 579606.366 4785769.9831, 579611.481 4785775.758, 579617.8828 4785770)"); assertTrue(calculateDistanceZero(line)); initialCoordinate = new Coordinate(579609.402035, 4785767.482242657); inputCoordinates = line.getCoordinates(); // use the function to set the offsetPosition double distance = calculateDistanceAndCurrentPostion(); // now set the real distance value distance = 2.5; OffsetBuilder builder = new OffsetBuilder(offsetPosition, startPosition, DEPRECIATE_VALUE); outputCoordinates = builder.getLineCurve(inputCoordinates, distance, line.getFactory()); LinearRing teoricalLine = (LinearRing) read("LINEARRING (579609.1002282355 4785769.29957639, 579615.6227323378 4785763.387306566, 579612.0161881015 4785759.189689803, 579615.3599421424 4785756.133509886, 579617.2407964263 4785758.324608176, 579619.6047838295 4785756.296877602, 579621.3614914695 4785758.248774979, 579636.0398750171 4785744.921819635, 579632.3643022542 4785740.866704033, 579635.6776755081 4785737.874284313, 579639.4400978928 4785742.006945071, 579643.181447194 4785738.618183661, 579646.1102082571 4785736.0608455185, 579648.7115291357 4785738.979615725, 579642.1085963205 4785744.94516136, 579643.4951586141 4785746.548066707, 579639.9452209828 4785749.662819147, 579638.4745607326 4785748.049178039, 579621.7156867348 4785763.307831488, 579623.0973376647 4785764.837516446, 579619.7562792544 4785767.813333703, 579619.7554066391 4785767.812363559, 579619.7503138809 4785767.8169242535, 579618.2787014917 4785766.211213641, 579616.193946319 4785768.156552839, 579611.6821595577 4785772.214609663, 579609.1002282355 4785769.29957639)"); System.out.println(outputCoordinates.toString()); assertNotNull(outputCoordinates); assertTrue(outputCoordinates.get(0).equals(teoricalLine)); } @Test public void exampleFeature1Outside() { LineString line = (LineString) read("LINESTRING (579617.8828 4785770, 579618.14 4785769.76, 579618.3946 4785770.0378, 579619.5649 4785771.3389, 579621.06 4785770, 579626.64 4785765.03, 579625.24 4785763.48, 579638.31 4785751.58, 579639.75 4785753.16, 579647.01 4785746.79, 579645.6 4785745.16, 579652.23 4785739.17, 579646.33 4785732.55, 579641.52 4785736.75, 579639.61 4785738.48, 579635.85 4785734.35, 579628.83 4785740.69, 579632.51 4785744.75, 579621.54 4785754.71, 579619.83 4785752.81, 579617.51 4785754.8, 579615.5700000001 4785752.54, 579614.47 4785753.56, 579608.54 4785758.98, 579612.14 4785763.17, 579605.62 4785769.08, 579606.366 4785769.9831, 579611.481 4785775.758, 579617.8828 4785770)"); assertTrue(calculateDistanceZero(line)); initialCoordinate = new Coordinate(579610.0534348169, 4785756.2455958165); inputCoordinates = line.getCoordinates(); // use the function to set the offsetPosition double distance = calculateDistanceAndCurrentPostion(); // now set the real distance value distance = 4; OffsetBuilder builder = new OffsetBuilder(offsetPosition, startPosition, DEPRECIATE_VALUE); outputCoordinates = builder.getLineCurve(inputCoordinates, distance, line.getFactory()); LinearRing teoricalLine = (LinearRing) read("LINEARRING (579617.8478966047 4785775.411330094, 579611.1591447076 4785781.42742454, 579603.3259766334 4785772.583678242, 579600.103067393 4785768.682057151, 579606.5676282598 4785762.822309493, 579602.9780990378 4785758.644496316, 579611.7607799452 4785750.617155586, 579615.8979366771 4785746.780882983, 579617.9407257183 4785749.160626917, 579620.1903458722 4785747.230995837, 579621.8256136485 4785749.047960033, 579626.8621999725 4785744.475088584, 579623.175116393 4785740.407273549, 579636.125719187 4785728.711145098, 579639.8987003822 4785732.855403699, 579646.681666789 4785726.93264717, 579657.8595533828 4785739.474614839, 579651.1862458866 4785745.503741823, 579652.6337462175 4785747.177093269, 579639.4376464275 4785758.755489366, 579638.0467028277 4785757.229315138, 579630.8789012246 4785763.75546962, 579632.3082597364 4785765.337973687, 579623.7244689841 4785772.983393048, 579619.2600893768 4785776.981358305, 579617.8478966047 4785775.411330094)"); System.out.println(outputCoordinates.toString()); assertNotNull(outputCoordinates); assertTrue(outputCoordinates.get(0).equals(teoricalLine)); } @Test public void exampleFeature2Outside() { LineString line = (LineString) read("LINESTRING (579412.9578 4786108.9604, 579414.4079 4786107.039, 579416.4832 4786108.6054, 579420.16 4786103.734, 579412.208 4786097.694, 579408.4814 4786102.5658, 579411.4746 4786104.825, 579410.012 4786106.7369, 579407.0188 4786104.4778, 579403.314 4786109.321, 579411.4279 4786115.3031, 579415.033 4786110.5267, 579412.9578 4786108.9604)"); assertTrue(calculateDistanceZero(line)); initialCoordinate = new Coordinate(579415.802096082, 4786114.102259244); inputCoordinates = line.getCoordinates(); // use the function to set the offsetPosition double distance = calculateDistanceAndCurrentPostion(); // now set the real distance value distance = 2; OffsetBuilder builder = new OffsetBuilder(offsetPosition, startPosition, DEPRECIATE_VALUE); outputCoordinates = builder.getLineCurve(inputCoordinates, distance, line.getFactory()); LinearRing teoricalLine = (LinearRing) read("LINEARRING (579406.6375929341 4786101.684381821, 579411.8304616003 4786094.895722569, 579422.9575474282 4786103.347382328, 579416.8746575186 4786111.406615874, 579416.874622561 4786111.4065894885, 579411.8328403374 4786118.086450966, 579400.4886278246 4786109.722752416, 579406.6375782153 4786101.684370712, 579406.6375929341 4786101.684381821)"); System.out.println(outputCoordinates.toString()); assertNotNull(outputCoordinates); assertTrue(outputCoordinates.get(0).equals(teoricalLine)); } @Test public void exampleFeature3Outside() { LineString line = (LineString) read("LINESTRING (579572.1592 4786261.4138, 579564.6933 4786263.5607, 579564.955 4786264.464, 579563.1868 4786264.9659, 579560.274 4786254.705, 579548.001 4786258.189, 579518.672 4786266.584, 579521.2787 4786276.5665, 579515.273 4786278.121, 579517.38 4786286.017, 579534.4541 4786281.1864, 579535.3910000001 4786284.4979, 579529.5037 4786286.1635, 579531.7394 4786294.066, 579526.5594 4786295.5315, 579529.512 4786305.8221, 579525.187 4786307.063, 579545.04 4786376.373, 579594.304 4786362.441, 579590.904 4786350.175, 579569.4064 4786356.384, 579561.4092 4786328.2454, 579582.6035 4786322.2219, 579574.291 4786292.974, 579571.5426 4786293.7626, 579566.258 4786275.765, 579542.2231000001 4786282.565, 579541.2862 4786279.2535, 579567.122 4786271.944, 579565.7242 4786267.119, 579573.183 4786264.974, 579572.1592 4786261.4138)"); assertTrue(calculateDistanceZero(line)); initialCoordinate = new Coordinate(579580.73863408, 4786305.006140342); inputCoordinates = line.getCoordinates(); // use the function to set the offsetPosition double distance = calculateDistanceAndCurrentPostion(); // now set the real distance value distance = 3; OffsetBuilder builder = new OffsetBuilder(offsetPosition, startPosition, DEPRECIATE_VALUE); outputCoordinates = builder.getLineCurve(inputCoordinates, distance, line.getFactory()); LinearRing teoricalLine = (LinearRing) read("LINEARRING (579526.4968322017 4786286.555422526, 579528.0360256635 4786291.995989834, 579522.8452950697 4786293.464525681, 579525.8009604613 4786303.765809391, 579521.4772506832 4786305.006339208, 579542.9792990726 4786380.073431026, 579597.9921826394 4786364.5156303225, 579592.9849627498 4786346.451348215, 579571.4684695052 4786352.665805018, 579565.1150629191 4786330.31098501, 579586.309365536 4786324.287484266, 579576.3545049905 4786289.260865831, 579573.5810806704 4786290.056646073, 579569.0204492984 4786274.524643807, 579570.8435394429 4786274.00885264, 579569.442128493 4786269.171388172, 579576.8952504928 4786267.028021051, 579574.2132577118 4786257.70156012, 579564.9956236493 4786260.352190128, 579562.3407183823 4786250.9997740835, 579547.1785947686 4786255.303924549, 579515.0288665281 4786264.506317013, 579517.6164382689 4786274.4155643, 579511.5951410279 4786275.97410145, 579515.2665385929 4786289.732694318, 579526.4968322017 4786286.555422526)"); System.out.println(outputCoordinates.toString()); assertNotNull(outputCoordinates); assertTrue(outputCoordinates.get(0).equals(teoricalLine)); } @Test public void exampleFeature3Inside() { LineString line = (LineString) read("LINESTRING (579572.1592 4786261.4138, 579564.6933 4786263.5607, 579564.955 4786264.464, 579563.1868 4786264.9659, 579560.274 4786254.705, 579548.001 4786258.189, 579518.672 4786266.584, 579521.2787 4786276.5665, 579515.273 4786278.121, 579517.38 4786286.017, 579534.4541 4786281.1864, 579535.3910000001 4786284.4979, 579529.5037 4786286.1635, 579531.7394 4786294.066, 579526.5594 4786295.5315, 579529.512 4786305.8221, 579525.187 4786307.063, 579545.04 4786376.373, 579594.304 4786362.441, 579590.904 4786350.175, 579569.4064 4786356.384, 579561.4092 4786328.2454, 579582.6035 4786322.2219, 579574.291 4786292.974, 579571.5426 4786293.7626, 579566.258 4786275.765, 579542.2231000001 4786282.565, 579541.2862 4786279.2535, 579567.122 4786271.944, 579565.7242 4786267.119, 579573.183 4786264.974, 579572.1592 4786261.4138)"); assertTrue(calculateDistanceZero(line)); initialCoordinate = new Coordinate(579567.631653841, 4786290.07027914); inputCoordinates = line.getCoordinates(); // use the function to set the offsetPosition double distance = calculateDistanceAndCurrentPostion(); // now set the real distance value distance = 2.7; OffsetBuilder builder = new OffsetBuilder(offsetPosition, startPosition, DEPRECIATE_VALUE); outputCoordinates = builder.getLineCurve(inputCoordinates, distance, line.getFactory()); LinearRing teoricalLine = (LinearRing) read("LINEARRING (579563.1089230772 4786267.79466745, 579563.7726145011 4786270.085632624, 579537.9531369046 4786277.390514666, 579540.3601180979 4786285.898058932, 579564.4205695152 4786279.090829875, 579569.7079673967 4786297.097958535, 579572.4338455085 4786296.315820754, 579579.2682210176 4786320.3628741605, 579558.0739233729 4786326.386373492, 579567.5505374451 4786359.730375483, 579589.031133525 4786353.526286606, 579590.9846356243 4786360.573832708, 579546.8946308346 4786373.042612076, 579528.5257743852 4786308.913994713, 579532.8519355849 4786307.672761549, 579529.9020944374 4786297.391776887, 579535.0724369027 4786295.929009149, 579532.8367375754 4786288.026511527, 579538.7240680658 4786286.360902901, 579536.3170833812 4786277.853346297, 579519.2821152665 4786282.672875114, 579518.583073075 4786280.053208695, 579524.5747355579 4786278.502342129, 579521.9508201246 4786268.453914688, 579548.7411645435 4786260.785567953, 579558.413953456 4786258.039703325, 579561.3267349021 4786268.300537965, 579563.1089230772 4786267.79466745)"); System.out.println(outputCoordinates.toString()); assertNotNull(outputCoordinates); assertTrue(outputCoordinates.get(0).equals(teoricalLine)); } @Test public void exampleFeature4outside() { LineString line = (LineString) read("LINESTRING (580624.851 4786744.748, 580628.3427 4786738.9257, 580630.194 4786740.036, 580635.5212 4786731.1015, 580633.6950000001 4786729.9911, 580626.758 4786725.738, 580634.449 4786712.988, 580621.363 4786705.144, 580623.36 4786702.026, 580628.816 4786705.226, 580634.9639 4786694.9745, 580636.127 4786695.672, 580641.3 4786687.202, 580637.285 4786684.868, 580636.6091 4786685.995, 580633.791 4786684.305, 580645.1297 4786665.4785, 580646.186 4786666.112, 580647.223 4786664.356, 580615.998 4786645.63, 580593.454 4786683.452, 580606.0142 4786690.9386, 580604.96 4786692.65, 580595.04 4786688.48, 580588.5157999999 4786699.1705, 580594.25 4786702.67, 580586.75 4786714.96, 580587.6867 4786715.5341, 580586.3752 4786717.6739, 580587.0336 4786718.0746, 580589.4140999999 4786719.5493, 580589.568 4786719.291, 580606.1221 4786729.5467, 580604.233 4786732.596, 580606.3533 4786733.9096, 580604.277 4786737.261, 580612.561 4786742.322, 580614.6165 4786739.0042, 580616.587 4786740.225, 580616.8462 4786739.7889, 580624.851 4786744.748)"); assertTrue(calculateDistanceZero(line)); initialCoordinate = new Coordinate(580597.1158271276, 4786726.980194898); inputCoordinates = line.getCoordinates(); // use the function to set the offsetPosition double distance = calculateDistanceAndCurrentPostion(); // now set the real distance value distance = 5; OffsetBuilder builder = new OffsetBuilder(offsetPosition, startPosition, DEPRECIATE_VALUE); outputCoordinates = builder.getLineCurve(inputCoordinates, distance, line.getFactory()); LinearRing teoricalLine = (LinearRing) read("LINEARRING (580633.7415508684 4786706.73448299, 580641.3201845983 4786711.277261758, 580633.6033987377 4786724.07000909, 580636.3005676832 4786725.7236532075, 580642.3543237429 4786729.404570263, 580631.921331827 4786746.902236256, 580630.0590860875 4786745.78537165, 580626.5300409783 4786751.669943444, 580618.5422924375 4786746.721407093, 580618.2830503156 4786747.157577963, 580616.2336154716 4786745.887874813, 580614.1944951273 4786749.1792362705, 580597.3768639563 4786738.904727416, 580599.469639835 4786735.52673335, 580597.3493794628 4786734.213157901, 580599.238462925 4786731.163884595, 580591.2594075722 4786726.22065011, 580591.1055726466 4786726.478840892, 580584.4172772076 4786722.335497357, 580579.4911610886 4786719.337479846, 580580.810856351 4786717.184308726, 580579.8823873665 4786716.615253486, 580587.3774434772 4786704.333354873, 580581.6431566596 4786700.833801889, 580589.9670175416 4786687.194392497, 580586.5990727852 4786685.186904144, 580614.2699940718 4786638.763483948, 580654.0536562816 4786662.622214406, 580647.9315161423 4786672.989117091, 580646.838034003 4786672.333317664, 580641.3490639707 4786681.44706918, 580648.2304194558 4786685.447339093, 580637.8089963165 4786702.510833003, 580636.6803940214 4786701.834020948, 580633.7415508684 4786706.73448299)"); System.out.println(outputCoordinates.toString()); assertNotNull(outputCoordinates); assertTrue(outputCoordinates.get(0).equals(teoricalLine)); } @Test public void exampleFeature4inside() { LineString line = (LineString) read("LINESTRING (580624.851 4786744.748, 580628.3427 4786738.9257, 580630.194 4786740.036, 580635.5212 4786731.1015, 580633.6950000001 4786729.9911, 580626.758 4786725.738, 580634.449 4786712.988, 580621.363 4786705.144, 580623.36 4786702.026, 580628.816 4786705.226, 580634.9639 4786694.9745, 580636.127 4786695.672, 580641.3 4786687.202, 580637.285 4786684.868, 580636.6091 4786685.995, 580633.791 4786684.305, 580645.1297 4786665.4785, 580646.186 4786666.112, 580647.223 4786664.356, 580615.998 4786645.63, 580593.454 4786683.452, 580606.0142 4786690.9386, 580604.96 4786692.65, 580595.04 4786688.48, 580588.5157999999 4786699.1705, 580594.25 4786702.67, 580586.75 4786714.96, 580587.6867 4786715.5341, 580586.3752 4786717.6739, 580587.0336 4786718.0746, 580589.4140999999 4786719.5493, 580589.568 4786719.291, 580606.1221 4786729.5467, 580604.233 4786732.596, 580606.3533 4786733.9096, 580604.277 4786737.261, 580612.561 4786742.322, 580614.6165 4786739.0042, 580616.587 4786740.225, 580616.8462 4786739.7889, 580624.851 4786744.748)"); assertTrue(calculateDistanceZero(line)); initialCoordinate = new Coordinate(580611.3868846495, 4786656.292021806); inputCoordinates = line.getCoordinates(); // use the function to set the offsetPosition double distance = calculateDistanceAndCurrentPostion(); // now set the real distance value distance = 3; OffsetBuilder builder = new OffsetBuilder(offsetPosition, startPosition, DEPRECIATE_VALUE); outputCoordinates = builder.getLineCurve(inputCoordinates, distance, line.getFactory()); LinearRing teoricalLine = (LinearRing) read("LINEARRING (580623.8435754129 4786740.594833933, 580627.3128683476 4786734.80989701, 580629.1576009038 4786735.916258247, 580631.4228967216 4786732.117023098, 580622.6507607576 4786726.738794546, 580630.3262892409 4786714.014442945, 580617.1700066003 4786706.128314179, 580622.389514474 4786697.978877247, 580627.7711324833 4786701.135251446, 580633.9340035869 4786690.85878743, 580635.11780221 4786691.568700199, 580636.445413753 4786689.394938403, 580629.670386521 4786685.331989598, 580642.0612230089 4786664.758547923, 580617.0348035572 4786649.749909631, 580597.5669563292 4786682.411057513, 580610.1649991806 4786689.920214024, 580606.1664868966 4786696.411443321, 580596.2564482358 4786692.245630698, 580592.6393860043 4786698.172518866, 580598.3735339139 4786701.671987076, 580590.8705675803 4786713.966847908, 580591.8122061895 4786714.543974764, 580590.6535234825 4786716.4344431255, 580610.252282245 4786728.576389243, 580608.3631723225 4786731.625705259, 580610.4834960991 4786732.93931999, 580608.4170816261 4786736.274763551, 580611.5809029235 4786738.207658237, 580613.6462307172 4786734.873995112, 580615.5693698111 4786736.065453222, 580615.8285445375 4786735.629395745, 580623.8435754129 4786740.594833933)"); System.out.println(outputCoordinates.toString()); assertNotNull(outputCoordinates); assertTrue(outputCoordinates.get(0).equals(teoricalLine)); } @Test public void exampleFeature5outside() { LineString line = (LineString) read("LINESTRING (579651.75 4786512.58, 579622.71 4786438.99, 579557.91 4786464.55, 579559.71 4786469.13, 579553.8200000001 4786471.44, 579551.65 4786465.9, 579549.28 4786466.82, 579548.83 4786465.66, 579531.34 4786472.44, 579531.84 4786473.75, 579530.41 4786474.29, 579523.11 4786454.95, 579505.27 4786461.68, 579525.51 4786513.38, 579539.22 4786508.01, 579541.74 4786514.45, 579567.39 4786504.41, 579572.69 4786517.95, 579577.63 4786516.01, 579579.15 4786519.89, 579600.7 4786511.44, 579604.39 4786520.87, 579625.71 4786512.52, 579629.19 4786521.41, 579651.75 4786512.58)"); assertTrue(calculateDistanceZero(line)); initialCoordinate = new Coordinate(579579.8304298479, 4786436.780092208); inputCoordinates = line.getCoordinates(); // use the function to set the offsetPosition double distance = calculateDistanceAndCurrentPostion(); // now set the real distance value distance = 5; OffsetBuilder builder = new OffsetBuilder(offsetPosition, startPosition, DEPRECIATE_VALUE); outputCoordinates = builder.getLineCurve(inputCoordinates, distance, line.getFactory()); LinearRing teoricalLine = (LinearRing) read("LINEARRING (579658.241444656 4786515.408588693, 579625.5258826594 4786432.5043804515, 579554.8573944278 4786460.379173031, 579554.487562013 4786459.434992581, 579552.1327776525 4786460.349086088, 579551.6836194616 4786459.1912560845, 579532.8159484047 4786466.505310388, 579526.0225026619 4786448.507332215, 579498.7685670165 4786458.788665561, 579522.6771312796 4786519.859454711, 579536.3863841632 4786514.489747345, 579538.9059703269 4786520.928689764, 579564.5564889554 4786510.888486761, 579569.8585271646 4786524.4336938085, 579574.7998188197 4786522.493186559, 579576.3188681451 4786526.370759836, 579597.8670580825 4786517.921469583, 579601.5563306441 4786527.349610574, 579622.876923133 4786518.999378524, 579626.3565275135 4786527.8883678755, 579658.241444656 4786515.408588693)"); System.out.println(outputCoordinates.toString()); assertNotNull(outputCoordinates); assertTrue(outputCoordinates.get(0).equals(teoricalLine)); } @Test public void exampleFeature6inside() { LineString line = (LineString) read("LINESTRING (579545.1699 4786235.1558, 579542.5899 4786226.3705, 579544.764 4786225.732, 579543.754 4786222.229, 579536.2035000001 4786224.375, 579533.825 4786225.882, 579534.8813 4786229.6283, 579534.51 4786229.733, 579533.951 4786230.7884, 579533.6239 4786231.9371, 579533.5431 4786233.1287, 579533.712 4786234.311, 579534.6945 4786238.2115, 579545.1699 4786235.1558)"); assertTrue(calculateDistanceZero(line)); initialCoordinate = new Coordinate(579542.8614704317, 4786231.648683341); inputCoordinates = line.getCoordinates(); // use the function to set the offsetPosition double distance = calculateDistanceAndCurrentPostion(); // now set the real distance value distance = 2; OffsetBuilder builder = new OffsetBuilder(offsetPosition, startPosition, DEPRECIATE_VALUE); outputCoordinates = builder.getLineCurve(inputCoordinates, distance, line.getFactory()); LinearRing teoricalLine = (LinearRing) read("LINEARRING (579540.1967199836 4786225.319260796, 579542.6863682005 4786233.796898967, 579536.1269438184 4786235.710299226, 579535.6770558874 4786233.924255588, 579535.5527501027 4786233.054115095, 579535.6050782296 4786232.282404749, 579535.8168983398 4786231.538541219, 579535.876716623 4786231.425603445, 579537.3489884307 4786231.010448964, 579536.154415767 4786226.773747678, 579537.0290821904 4786226.219565504, 579540.1967199836 4786225.319260796)"); System.out.println(outputCoordinates.toString()); assertNotNull(outputCoordinates); assertTrue(outputCoordinates.get(0).equals(teoricalLine)); } @Test public void exampleFeature7inside() { LineString line = (LineString) read("LINESTRING (579646.6108451859 4785792.294417069, 579639.2892696827 4785786.803235442, 579631.5261539223 4785790.480500802, 579629.4832287222 4785800.695126804, 579642.0808287198 4785798.353979901, 579641.6559 4785797.8119, 579641.3289 4785797.15, 579641.501 4785796.432, 579644.3319999999 4785794.0599, 579646.6108451859 4785792.294417069)"); assertTrue(calculateDistanceZero(line)); initialCoordinate = new Coordinate(579632.8415831904, 4785799.512469941); inputCoordinates = line.getCoordinates(); // use the function to set the offsetPosition double distance = calculateDistanceAndCurrentPostion(); // now set the real distance value distance = 3; OffsetBuilder builder = new OffsetBuilder(offsetPosition, startPosition, DEPRECIATE_VALUE); outputCoordinates = builder.getLineCurve(inputCoordinates, distance, line.getFactory()); // LinearRing teoricalLine = (LinearRing) read("LINEARRING (579540.1967199836 4786225.319260796, 579542.6863682005 4786233.796898967, 579536.1269438184 4786235.710299226, 579535.6770558874 4786233.924255588, 579535.5527501027 4786233.054115095, 579535.6050782296 4786232.282404749, 579535.8168983398 4786231.538541219, 579535.876716623 4786231.425603445, 579537.3489884307 4786231.010448964, 579536.154415767 4786226.773747678, 579537.0290821904 4786226.219565504, 579540.1967199836 4786225.319260796)"); System.out.println(outputCoordinates.toString()); assertNotNull(outputCoordinates); // assertTrue(outputCoordinates.get(0).equals(teoricalLine)); } @Test public void exampleBigFeature1Outside() { LineString line = (LineString) read("LINESTRING (579466.76 4785418.6, 579468.08 4785417.69, 579469.14 4785419.48, 579469.75 4785419.07, 579467.39 4785409.69, 579469.27 4785409.12, 579467.13 4785401.73, 579465.472 4785396.628, 579463.6417 4785391.5853, 579461.6414 4785386.6076, 579459.4733 4785381.7006, 579457.14 4785376.87, 579448.41 4785361.19, 579439.52 4785348.38, 579430.27 4785337.44, 579428.75 4785338.84, 579422.14 4785331.56, 579421.49 4785331.9, 579427.13 4785342.5, 579425.52 4785343.35, 579424.39 4785341.23, 579422.0700000001 4785342.48, 579421.51 4785341.44, 579390.2 4785358.42, 579390.75 4785359.42, 579388.5 4785360.66, 579398.26 4785378.65, 579385.63 4785385.78, 579391.02 4785395.62, 579392.95 4785394.52, 579401.2 4785409.64, 579399.23 4785410.67, 579404.49 4785420.34, 579412.92 4785415.85, 579418.08 4785417.34, 579416.22 4785423.9, 579423.33 4785426.03, 579426.39 4785416.21, 579428.24 4785416.76, 579431.14 4785406.65, 579437.36 4785408.42, 579435.29 4785415.67, 579456.31 4785421.94, 579458.47 4785414.82, 579464.81 4785416.69, 579461.81 4785426.75, 579463.75 4785427.32, 579460.8 4785437.23, 579467.86 4785439.29, 579470.95 4785428.98, 579468.64 4785428.17, 579469.88 4785424.17, 579466.76 4785418.6)"); assertTrue(calculateDistanceZero(line)); initialCoordinate = new Coordinate(579449.3506998476, 4785359.713616236); inputCoordinates = line.getCoordinates(); // use the function to set the offsetPosition double distance = calculateDistanceAndCurrentPostion(); // now set the real distance value distance = 2; OffsetBuilder builder = new OffsetBuilder(offsetPosition, startPosition, DEPRECIATE_VALUE); outputCoordinates = builder.getLineCurve(inputCoordinates, distance, line.getFactory()); LinearRing teoricalLine = (LinearRing) read("LINEARRING (579423.2941533194 4785339.548608929, 579418.7782894584 4785331.061347063, 579422.5820869936 4785329.071668347, 579428.876659225 4785336.004268324, 579430.449931036 4785334.555202183, 579441.1087673445 4785347.161436692, 579450.1093874552 4785360.130834175, 579458.9156629585 4785375.9478330165, 579461.2889743937 4785380.86126816, 579463.4845078448 4785385.830357521, 579465.5101178597 4785390.871040904, 579467.3635852408 4785395.977569868, 579469.0420788857 4785401.142632943, 579471.7404620409 4785410.460881314, 579469.7947111026 4785411.050816439, 579472.032620918 4785419.945559688, 579470.4150820347 4785421.032757955, 579472.0446113507 4785423.941885612, 579471.1211977984 4785426.920639006, 579473.4141323646 4785427.724655024, 579469.2057904839 4785441.766080522, 579458.3094113447 4785438.586683776, 579461.260482892 4785428.6730841035, 579459.319542368 4785428.102807764, 579462.3201431634 4785418.040793097, 579459.8077251503 4785417.299748667, 579457.6459565331 4785424.425578553, 579432.8241837653 4785417.021557846, 579434.8872768116 4785409.795748867, 579432.5121822286 4785409.119877901, 579429.6056849025 4785419.252528924, 579427.7121863473 4785418.689596921, 579424.6509551121 4785428.5135481395, 579413.7582888842 4785425.250344333, 579415.6129095431 4785418.709316633, 579413.1443589361 4785417.996498724, 579403.6804083588 4785423.037203125, 579396.50159782 4785409.8396559935, 579398.4692554827 4785408.8108806675, 579392.1702209765 4785397.266468336, 579390.2431208788 4785398.3648155425, 579382.9273142059 4785385.009057164, 579395.5642476412 4785377.87514304, 579385.7946006911 4785359.867361417, 579388.0345521588 4785358.632899274, 579387.4780112645 4785357.621006739, 579422.319907559 4785338.725593164, 579422.882498832 4785339.770405528, 579423.2941533194 4785339.548608929)"); System.out.println(outputCoordinates.toString()); assertNotNull(outputCoordinates); assertTrue(outputCoordinates.get(0).equals(teoricalLine)); } @Test public void exampleBigFeature1Inside() { LineString line = (LineString) read("LINESTRING (579466.76 4785418.6, 579468.08 4785417.69, 579469.14 4785419.48, 579469.75 4785419.07, 579467.39 4785409.69, 579469.27 4785409.12, 579467.13 4785401.73, 579465.472 4785396.628, 579463.6417 4785391.5853, 579461.6414 4785386.6076, 579459.4733 4785381.7006, 579457.14 4785376.87, 579448.41 4785361.19, 579439.52 4785348.38, 579430.27 4785337.44, 579428.75 4785338.84, 579422.14 4785331.56, 579421.49 4785331.9, 579427.13 4785342.5, 579425.52 4785343.35, 579424.39 4785341.23, 579422.0700000001 4785342.48, 579421.51 4785341.44, 579390.2 4785358.42, 579390.75 4785359.42, 579388.5 4785360.66, 579398.26 4785378.65, 579385.63 4785385.78, 579391.02 4785395.62, 579392.95 4785394.52, 579401.2 4785409.64, 579399.23 4785410.67, 579404.49 4785420.34, 579412.92 4785415.85, 579418.08 4785417.34, 579416.22 4785423.9, 579423.33 4785426.03, 579426.39 4785416.21, 579428.24 4785416.76, 579431.14 4785406.65, 579437.36 4785408.42, 579435.29 4785415.67, 579456.31 4785421.94, 579458.47 4785414.82, 579464.81 4785416.69, 579461.81 4785426.75, 579463.75 4785427.32, 579460.8 4785437.23, 579467.86 4785439.29, 579470.95 4785428.98, 579468.64 4785428.17, 579469.88 4785424.17, 579466.76 4785418.6)"); assertTrue(calculateDistanceZero(line)); initialCoordinate = new Coordinate(579443.8804365521, 4785416.289813829); inputCoordinates = line.getCoordinates(); // use the function to set the offsetPosition double distance = calculateDistanceAndCurrentPostion(); // now set the real distance value distance = 1; OffsetBuilder builder = new OffsetBuilder(offsetPosition, startPosition, DEPRECIATE_VALUE); outputCoordinates = builder.getLineCurve(inputCoordinates, distance, line.getFactory()); LinearRing teoricalLine = (LinearRing) read("LINEARRING (579468.0680986132 4785416.483600281, 579465.4422967522 4785418.293812169, 579468.7976943245 4785424.284057194, 579467.3994011006 4785428.794680497, 579469.7179338175 4785429.607672489, 579467.187104758 4785438.051959739, 579462.0452943277 4785436.551658113, 579464.9947585539 4785426.643457948, 579463.0552288161 4785426.073596118, 579466.0549284182 4785416.014603453, 579457.8011374245 4785413.580125667, 579455.6420217333 4785420.6972107235, 579436.5229081175 4785414.994221077, 579438.5963615943 4785407.732125566, 579430.4539088857 4785405.41506105, 579427.5571575488 4785415.513735537, 579425.7289068267 4785414.970201539, 579422.669522444 4785424.78822593, 579417.4508555578 4785423.2248278335, 579419.3135452284 4785416.655341684, 579412.807820532 4785414.776750637, 579404.8947958205 4785418.991398437, 579400.59420109 4785411.085172003, 579402.565372259 4785410.054559666, 579393.3398895117 4785393.146765831, 579391.4084395602 4785394.247592228, 579386.9813428968 4785386.165471419, 579399.6078761794 4785379.037428481, 579389.8526996546 4785361.056319292, 579392.1077239206 4785359.813550363, 579391.5609943677 4785358.819496631, 579421.1050462208 4785342.797203419, 579421.6637505839 4785343.834797236, 579423.9800188193 4785342.586807885, 579425.106047169 4785344.699356646, 579428.4840522514 4785342.915937815, 579424.7810127875 4785335.956324638, 579428.6866703875 4785340.257865838, 579430.1800344824 4785338.882398909, 579438.7256163275 4785348.9892816525, 579447.5603062721 4785361.7195829125, 579456.2521685173 4785377.331083485, 579458.5654628054 4785382.120265925, 579460.7198460775 4785386.996221239, 579462.7074910725 4785391.942429555, 579464.5262073795 4785396.953215065, 579466.1739605559 4785402.023683526, 579468.0347689795 4785408.449559343, 579466.1876444487 4785409.009591781, 579468.0680986132 4785416.483600281)"); System.out.println(outputCoordinates.toString()); assertNotNull(outputCoordinates); assertTrue(outputCoordinates.get(0).equals(teoricalLine)); } private final double LOW_DISTANCE = 1.0E-4; private void isEqualWithoutPrecision(LineString teoricalLine, GeometryFactory gf) { // retrieve the first coordinate. Geometry first = gf.createPoint(outputCoordinates.get(0).getCoordinates()[0]); // find it on the resultLine Coordinate[] teoricalCoords = teoricalLine.getCoordinates(); int startIndex = 0; double lowestDist = Double.MAX_VALUE; double actualDist = 0; // the last coordinate and the first will be the same, so keep outside // the last one. for (int i = 0; i < teoricalCoords.length - 1; i++) { Point actualPoint = gf.createPoint(teoricalCoords[i]); actualDist = first.distance(actualPoint); if (actualDist < lowestDist) { lowestDist = actualDist; startIndex = i; } } // after knowing where is the first index, find out the current // direction, if it's forward or backward boolean isForward = findDirection(gf, startIndex, teoricalCoords); // now that we know where we have to start and which direction to take, // let's start comparing the coordinates. int outputIndex = 0; Coordinate[] outCoords = outputCoordinates.get(0).getCoordinates(); for (int i = startIndex;;) { Geometry outPoint = gf.createPoint(outCoords[outputIndex]); Geometry teoricalPoint = gf.createPoint(teoricalCoords[i]); double distance = outPoint.distance(teoricalPoint); System.out.println("REAL DIST: " + distance); assertTrue("Those points are too far from each other, so aren't equal.", distance < LOW_DISTANCE); outputIndex++; if (outputIndex == outCoords.length) { // it has done a complete loop. break; } if (isForward) { i = (i == teoricalCoords.length - 2) ? i = 0 : i + 1; } else { i = (i == 0) ? i = teoricalCoords.length - 2 : i - 1; } } } private boolean findDirection(GeometryFactory gf, int startIndex, Coordinate[] coords) { boolean isForward; Geometry second = gf.createPoint(outputCoordinates.get(0).getCoordinates()[1]); Point forwardPoint = gf.createPoint(coords[startIndex + 1]); Point backwardPoint = (startIndex == 0) ? gf.createPoint(coords[coords.length - 2]) : gf .createPoint(coords[startIndex - 1]); // choose coords.length-2 because length-1 is the same as length 0. double distForward = second.distance(forwardPoint); double distBackward = second.distance(backwardPoint); if (distForward < distBackward) { isForward = true; } else { isForward = false; } return isForward; } @Test public void exampleFeature1InsideNoPrecision() { LineString line = (LineString) read("LINESTRING (579617.8828 4785770, 579618.14 4785769.76, 579618.3946 4785770.0378, 579619.5649 4785771.3389, 579621.06 4785770, 579626.64 4785765.03, 579625.24 4785763.48, 579638.31 4785751.58, 579639.75 4785753.16, 579647.01 4785746.79, 579645.6 4785745.16, 579652.23 4785739.17, 579646.33 4785732.55, 579641.52 4785736.75, 579639.61 4785738.48, 579635.85 4785734.35, 579628.83 4785740.69, 579632.51 4785744.75, 579621.54 4785754.71, 579619.83 4785752.81, 579617.51 4785754.8, 579615.5700000001 4785752.54, 579614.47 4785753.56, 579608.54 4785758.98, 579612.14 4785763.17, 579605.62 4785769.08, 579606.366 4785769.9831, 579611.481 4785775.758, 579617.8828 4785770)"); assertTrue(calculateDistanceZero(line)); initialCoordinate = new Coordinate(579609.402035, 4785767.482242657); inputCoordinates = line.getCoordinates(); // use the function to set the offsetPosition double distance = calculateDistanceAndCurrentPostion(); // now set the real distance value distance = 2.5; OffsetBuilder builder = new OffsetBuilder(offsetPosition, startPosition, DEPRECIATE_VALUE); outputCoordinates = builder.getLineCurve(inputCoordinates, distance, line.getFactory()); LinearRing teoricalLine = (LinearRing) read("LINEARRING (579619.7503138809 4785767.8169242535, 579618.2787014917 4785766.211213641, 579616.193946319 4785768.156552839, 579611.6821595577 4785772.214609663, 579609.1002282355 4785769.29957639, 579615.6227323378 4785763.387306566, 579612.0161881015 4785759.189689803, 579615.3599421425 4785756.133509886, 579617.2407964263 4785758.324608176, 579619.6047838295 4785756.296877602, 579621.3614914695 4785758.248774979, 579636.0398750171 4785744.921819635, 579632.3643022542 4785740.866704033, 579635.6776755081 4785737.874284313, 579639.4400978928 4785742.006945071, 579643.181447194 4785738.618183661, 579646.1102082571 4785736.0608455185, 579648.7115291357 4785738.979615725, 579642.1085963205 4785744.94516136, 579643.4951586141 4785746.548066707, 579639.9452209828 4785749.662819147, 579638.4745607326 4785748.049178039, 579621.7156867348 4785763.307831488, 579623.0973376647 4785764.837516446, 579619.7562792544 4785767.813333703, 579619.7554066391 4785767.812363559, 579619.7503138809 4785767.8169242535)"); System.out.println(outputCoordinates.toString()); assertNotNull(outputCoordinates); isEqualWithoutPrecision(teoricalLine, teoricalLine.getFactory()); } @Test public void exampleFeature1OutsideNoPrecision() { LineString line = (LineString) read("LINESTRING (579617.8828 4785770, 579618.14 4785769.76, 579618.3946 4785770.0378, 579619.5649 4785771.3389, 579621.06 4785770, 579626.64 4785765.03, 579625.24 4785763.48, 579638.31 4785751.58, 579639.75 4785753.16, 579647.01 4785746.79, 579645.6 4785745.16, 579652.23 4785739.17, 579646.33 4785732.55, 579641.52 4785736.75, 579639.61 4785738.48, 579635.85 4785734.35, 579628.83 4785740.69, 579632.51 4785744.75, 579621.54 4785754.71, 579619.83 4785752.81, 579617.51 4785754.8, 579615.5700000001 4785752.54, 579614.47 4785753.56, 579608.54 4785758.98, 579612.14 4785763.17, 579605.62 4785769.08, 579606.366 4785769.9831, 579611.481 4785775.758, 579617.8828 4785770)"); assertTrue(calculateDistanceZero(line)); initialCoordinate = new Coordinate(579610.0534348169, 4785756.2455958165); inputCoordinates = line.getCoordinates(); // use the function to set the offsetPosition double distance = calculateDistanceAndCurrentPostion(); // now set the real distance value distance = 4; OffsetBuilder builder = new OffsetBuilder(offsetPosition, startPosition, DEPRECIATE_VALUE); outputCoordinates = builder.getLineCurve(inputCoordinates, distance, line.getFactory()); LinearRing teoricalLine = (LinearRing) read("LINEARRING (579617.8478966047 4785775.411330094, 579611.1591447076 4785781.42742454, 579603.3259766334 4785772.583678242, 579600.103067393 4785768.682057151, 579606.5676282598 4785762.822309493, 579602.9780990378 4785758.644496316, 579611.7607799452 4785750.617155586, 579615.8979366771 4785746.780882983, 579617.9407257183 4785749.160626917, 579620.1903458722 4785747.230995837, 579621.8256136485 4785749.047960033, 579626.8621999725 4785744.475088584, 579623.175116393 4785740.407273549, 579636.125719187 4785728.711145098, 579639.8987003822 4785732.855403699, 579646.681666789 4785726.93264717, 579657.8595533828 4785739.474614839, 579651.1862458866 4785745.503741823, 579652.6337462175 4785747.177093269, 579639.4376464275 4785758.755489366, 579638.0467028277 4785757.229315138, 579630.8789012246 4785763.75546962, 579632.3082597364 4785765.337973687, 579623.7244689841 4785772.983393048, 579619.2600893768 4785776.981358305, 579617.8478966047 4785775.411330094)"); System.out.println(outputCoordinates.toString()); assertNotNull(outputCoordinates); isEqualWithoutPrecision(teoricalLine, teoricalLine.getFactory()); } @Test public void exampleFeature2OutsideNoPrecision() { LineString line = (LineString) read("LINESTRING (579412.9578 4786108.9604, 579414.4079 4786107.039, 579416.4832 4786108.6054, 579420.16 4786103.734, 579412.208 4786097.694, 579408.4814 4786102.5658, 579411.4746 4786104.825, 579410.012 4786106.7369, 579407.0188 4786104.4778, 579403.314 4786109.321, 579411.4279 4786115.3031, 579415.033 4786110.5267, 579412.9578 4786108.9604)"); assertTrue(calculateDistanceZero(line)); initialCoordinate = new Coordinate(579415.802096082, 4786114.102259244); inputCoordinates = line.getCoordinates(); // use the function to set the offsetPosition double distance = calculateDistanceAndCurrentPostion(); // now set the real distance value distance = 2; OffsetBuilder builder = new OffsetBuilder(offsetPosition, startPosition, DEPRECIATE_VALUE); outputCoordinates = builder.getLineCurve(inputCoordinates, distance, line.getFactory()); LinearRing teoricalLine = (LinearRing) read("LINEARRING (579406.6375929341 4786101.684381821, 579411.8304616003 4786094.895722569, 579422.9575474282 4786103.347382328, 579416.8746575186 4786111.406615874, 579416.874622561 4786111.4065894885, 579411.8328403374 4786118.086450966, 579400.4886278246 4786109.722752416, 579406.6375782153 4786101.684370712, 579406.6375929341 4786101.684381821)"); System.out.println(outputCoordinates.toString()); assertNotNull(outputCoordinates); isEqualWithoutPrecision(teoricalLine, teoricalLine.getFactory()); } @Test public void exampleFeature3OutsideNoPrecision() { LineString line = (LineString) read("LINESTRING (579572.1592 4786261.4138, 579564.6933 4786263.5607, 579564.955 4786264.464, 579563.1868 4786264.9659, 579560.274 4786254.705, 579548.001 4786258.189, 579518.672 4786266.584, 579521.2787 4786276.5665, 579515.273 4786278.121, 579517.38 4786286.017, 579534.4541 4786281.1864, 579535.3910000001 4786284.4979, 579529.5037 4786286.1635, 579531.7394 4786294.066, 579526.5594 4786295.5315, 579529.512 4786305.8221, 579525.187 4786307.063, 579545.04 4786376.373, 579594.304 4786362.441, 579590.904 4786350.175, 579569.4064 4786356.384, 579561.4092 4786328.2454, 579582.6035 4786322.2219, 579574.291 4786292.974, 579571.5426 4786293.7626, 579566.258 4786275.765, 579542.2231000001 4786282.565, 579541.2862 4786279.2535, 579567.122 4786271.944, 579565.7242 4786267.119, 579573.183 4786264.974, 579572.1592 4786261.4138)"); assertTrue(calculateDistanceZero(line)); initialCoordinate = new Coordinate(579580.73863408, 4786305.006140342); inputCoordinates = line.getCoordinates(); // use the function to set the offsetPosition double distance = calculateDistanceAndCurrentPostion(); // now set the real distance value distance = 3; OffsetBuilder builder = new OffsetBuilder(offsetPosition, startPosition, DEPRECIATE_VALUE); outputCoordinates = builder.getLineCurve(inputCoordinates, distance, line.getFactory()); LinearRing teoricalLine = (LinearRing) read("LINEARRING (579526.4968322017 4786286.555422526, 579528.0360256635 4786291.995989834, 579522.8452950697 4786293.464525681, 579525.8009604613 4786303.765809391, 579521.4772506832 4786305.006339208, 579542.9792990726 4786380.073431026, 579597.9921826394 4786364.5156303225, 579592.9849627498 4786346.451348215, 579571.4684695052 4786352.665805018, 579565.1150629191 4786330.31098501, 579586.309365536 4786324.287484266, 579576.3545049905 4786289.260865831, 579573.5810806704 4786290.056646073, 579569.0204492984 4786274.524643807, 579570.8435394429 4786274.00885264, 579569.442128493 4786269.171388172, 579576.8952504928 4786267.028021051, 579574.2132577118 4786257.70156012, 579564.9956236493 4786260.352190128, 579562.3407183823 4786250.9997740835, 579547.1785947686 4786255.303924549, 579515.0288665281 4786264.506317013, 579517.6164382689 4786274.4155643, 579511.5951410279 4786275.97410145, 579515.2665385929 4786289.732694318, 579526.4968322017 4786286.555422526)"); System.out.println(outputCoordinates.toString()); assertNotNull(outputCoordinates); isEqualWithoutPrecision(teoricalLine, teoricalLine.getFactory()); } @Test public void exampleFeature3InsideNoPrecision() { LineString line = (LineString) read("LINESTRING (579572.1592 4786261.4138, 579564.6933 4786263.5607, 579564.955 4786264.464, 579563.1868 4786264.9659, 579560.274 4786254.705, 579548.001 4786258.189, 579518.672 4786266.584, 579521.2787 4786276.5665, 579515.273 4786278.121, 579517.38 4786286.017, 579534.4541 4786281.1864, 579535.3910000001 4786284.4979, 579529.5037 4786286.1635, 579531.7394 4786294.066, 579526.5594 4786295.5315, 579529.512 4786305.8221, 579525.187 4786307.063, 579545.04 4786376.373, 579594.304 4786362.441, 579590.904 4786350.175, 579569.4064 4786356.384, 579561.4092 4786328.2454, 579582.6035 4786322.2219, 579574.291 4786292.974, 579571.5426 4786293.7626, 579566.258 4786275.765, 579542.2231000001 4786282.565, 579541.2862 4786279.2535, 579567.122 4786271.944, 579565.7242 4786267.119, 579573.183 4786264.974, 579572.1592 4786261.4138)"); assertTrue(calculateDistanceZero(line)); initialCoordinate = new Coordinate(579567.631653841, 4786290.07027914); inputCoordinates = line.getCoordinates(); // use the function to set the offsetPosition double distance = calculateDistanceAndCurrentPostion(); // now set the real distance value distance = 2.7; OffsetBuilder builder = new OffsetBuilder(offsetPosition, startPosition, DEPRECIATE_VALUE); outputCoordinates = builder.getLineCurve(inputCoordinates, distance, line.getFactory()); LinearRing teoricalLine = (LinearRing) read("LINEARRING (579563.1089230772 4786267.79466745, 579563.7726145011 4786270.085632624, 579537.9531369046 4786277.390514666, 579540.3601180979 4786285.898058932, 579564.4205695152 4786279.090829875, 579569.7079673967 4786297.097958535, 579572.4338455085 4786296.315820754, 579579.2682210176 4786320.3628741605, 579558.0739233729 4786326.386373492, 579567.5505374451 4786359.730375483, 579589.031133525 4786353.526286606, 579590.9846356243 4786360.573832708, 579546.8946308346 4786373.042612076, 579528.5257743852 4786308.913994713, 579532.8519355849 4786307.672761549, 579529.9020944374 4786297.391776887, 579535.0724369027 4786295.929009149, 579532.8367375754 4786288.026511527, 579538.7240680658 4786286.360902901, 579536.3170833812 4786277.853346297, 579519.2821152665 4786282.672875114, 579518.583073075 4786280.053208695, 579524.5747355579 4786278.502342129, 579521.9508201246 4786268.453914688, 579548.7411645435 4786260.785567953, 579558.413953456 4786258.039703325, 579561.3267349021 4786268.300537965, 579563.1089230772 4786267.79466745)"); System.out.println(outputCoordinates.toString()); assertNotNull(outputCoordinates); isEqualWithoutPrecision(teoricalLine, teoricalLine.getFactory()); } @Test public void exampleFeature4outsideNoPrecision() { LineString line = (LineString) read("LINESTRING (580624.851 4786744.748, 580628.3427 4786738.9257, 580630.194 4786740.036, 580635.5212 4786731.1015, 580633.6950000001 4786729.9911, 580626.758 4786725.738, 580634.449 4786712.988, 580621.363 4786705.144, 580623.36 4786702.026, 580628.816 4786705.226, 580634.9639 4786694.9745, 580636.127 4786695.672, 580641.3 4786687.202, 580637.285 4786684.868, 580636.6091 4786685.995, 580633.791 4786684.305, 580645.1297 4786665.4785, 580646.186 4786666.112, 580647.223 4786664.356, 580615.998 4786645.63, 580593.454 4786683.452, 580606.0142 4786690.9386, 580604.96 4786692.65, 580595.04 4786688.48, 580588.5157999999 4786699.1705, 580594.25 4786702.67, 580586.75 4786714.96, 580587.6867 4786715.5341, 580586.3752 4786717.6739, 580587.0336 4786718.0746, 580589.4140999999 4786719.5493, 580589.568 4786719.291, 580606.1221 4786729.5467, 580604.233 4786732.596, 580606.3533 4786733.9096, 580604.277 4786737.261, 580612.561 4786742.322, 580614.6165 4786739.0042, 580616.587 4786740.225, 580616.8462 4786739.7889, 580624.851 4786744.748)"); assertTrue(calculateDistanceZero(line)); initialCoordinate = new Coordinate(580597.1158271276, 4786726.980194898); inputCoordinates = line.getCoordinates(); // use the function to set the offsetPosition double distance = calculateDistanceAndCurrentPostion(); // now set the real distance value distance = 5; OffsetBuilder builder = new OffsetBuilder(offsetPosition, startPosition, DEPRECIATE_VALUE); outputCoordinates = builder.getLineCurve(inputCoordinates, distance, line.getFactory()); LinearRing teoricalLine = (LinearRing) read("LINEARRING (580633.7415508684 4786706.73448299, 580641.3201845983 4786711.277261758, 580633.6033987377 4786724.07000909, 580636.3005676832 4786725.7236532075, 580642.3543237429 4786729.404570263, 580631.921331827 4786746.902236256, 580630.0590860875 4786745.78537165, 580626.5300409783 4786751.669943444, 580618.5422924375 4786746.721407093, 580618.2830503156 4786747.157577963, 580616.2336154716 4786745.887874813, 580614.1944951273 4786749.1792362705, 580597.3768639563 4786738.904727416, 580599.469639835 4786735.52673335, 580597.3493794628 4786734.213157901, 580599.238462925 4786731.163884595, 580591.2594075722 4786726.22065011, 580591.1055726466 4786726.478840892, 580584.4172772076 4786722.335497357, 580579.4911610886 4786719.337479846, 580580.810856351 4786717.184308726, 580579.8823873665 4786716.615253486, 580587.3774434772 4786704.333354873, 580581.6431566596 4786700.833801889, 580589.9670175416 4786687.194392497, 580586.5990727852 4786685.186904144, 580614.2699940718 4786638.763483948, 580654.0536562816 4786662.622214406, 580647.9315161423 4786672.989117091, 580646.838034003 4786672.333317664, 580641.3490639707 4786681.44706918, 580648.2304194558 4786685.447339093, 580637.8089963165 4786702.510833003, 580636.6803940214 4786701.834020948, 580633.7415508684 4786706.73448299)"); System.out.println(outputCoordinates.toString()); assertNotNull(outputCoordinates); isEqualWithoutPrecision(teoricalLine, teoricalLine.getFactory()); } @Test public void exampleFeature4insideNoPrecision() { LineString line = (LineString) read("LINESTRING (580624.851 4786744.748, 580628.3427 4786738.9257, 580630.194 4786740.036, 580635.5212 4786731.1015, 580633.6950000001 4786729.9911, 580626.758 4786725.738, 580634.449 4786712.988, 580621.363 4786705.144, 580623.36 4786702.026, 580628.816 4786705.226, 580634.9639 4786694.9745, 580636.127 4786695.672, 580641.3 4786687.202, 580637.285 4786684.868, 580636.6091 4786685.995, 580633.791 4786684.305, 580645.1297 4786665.4785, 580646.186 4786666.112, 580647.223 4786664.356, 580615.998 4786645.63, 580593.454 4786683.452, 580606.0142 4786690.9386, 580604.96 4786692.65, 580595.04 4786688.48, 580588.5157999999 4786699.1705, 580594.25 4786702.67, 580586.75 4786714.96, 580587.6867 4786715.5341, 580586.3752 4786717.6739, 580587.0336 4786718.0746, 580589.4140999999 4786719.5493, 580589.568 4786719.291, 580606.1221 4786729.5467, 580604.233 4786732.596, 580606.3533 4786733.9096, 580604.277 4786737.261, 580612.561 4786742.322, 580614.6165 4786739.0042, 580616.587 4786740.225, 580616.8462 4786739.7889, 580624.851 4786744.748)"); assertTrue(calculateDistanceZero(line)); initialCoordinate = new Coordinate(580611.3868846495, 4786656.292021806); inputCoordinates = line.getCoordinates(); // use the function to set the offsetPosition double distance = calculateDistanceAndCurrentPostion(); // now set the real distance value distance = 3; OffsetBuilder builder = new OffsetBuilder(offsetPosition, startPosition, DEPRECIATE_VALUE); outputCoordinates = builder.getLineCurve(inputCoordinates, distance, line.getFactory()); LinearRing teoricalLine = (LinearRing) read("LINEARRING (580623.8435754129 4786740.594833933, 580627.3128683476 4786734.80989701, 580629.1576009038 4786735.916258247, 580631.4228967216 4786732.117023098, 580622.6507607576 4786726.738794546, 580630.3262892409 4786714.014442945, 580617.1700066003 4786706.128314179, 580622.389514474 4786697.978877247, 580627.7711324833 4786701.135251446, 580633.9340035869 4786690.85878743, 580635.11780221 4786691.568700199, 580636.445413753 4786689.394938403, 580629.670386521 4786685.331989598, 580642.0612230089 4786664.758547923, 580617.0348035572 4786649.749909631, 580597.5669563292 4786682.411057513, 580610.1649991806 4786689.920214024, 580606.1664868966 4786696.411443321, 580596.2564482358 4786692.245630698, 580592.6393860043 4786698.172518866, 580598.3735339139 4786701.671987076, 580590.8705675803 4786713.966847908, 580591.8122061895 4786714.543974764, 580590.6535234825 4786716.4344431255, 580610.252282245 4786728.576389243, 580608.3631723225 4786731.625705259, 580610.4834960991 4786732.93931999, 580608.4170816261 4786736.274763551, 580611.5809029235 4786738.207658237, 580613.6462307172 4786734.873995112, 580615.5693698111 4786736.065453222, 580615.8285445375 4786735.629395745, 580623.8435754129 4786740.594833933)"); System.out.println(outputCoordinates.toString()); assertNotNull(outputCoordinates); isEqualWithoutPrecision(teoricalLine, teoricalLine.getFactory()); } @Test public void exampleFeature5outsideNoPrecision() { LineString line = (LineString) read("LINESTRING (579651.75 4786512.58, 579622.71 4786438.99, 579557.91 4786464.55, 579559.71 4786469.13, 579553.8200000001 4786471.44, 579551.65 4786465.9, 579549.28 4786466.82, 579548.83 4786465.66, 579531.34 4786472.44, 579531.84 4786473.75, 579530.41 4786474.29, 579523.11 4786454.95, 579505.27 4786461.68, 579525.51 4786513.38, 579539.22 4786508.01, 579541.74 4786514.45, 579567.39 4786504.41, 579572.69 4786517.95, 579577.63 4786516.01, 579579.15 4786519.89, 579600.7 4786511.44, 579604.39 4786520.87, 579625.71 4786512.52, 579629.19 4786521.41, 579651.75 4786512.58)"); assertTrue(calculateDistanceZero(line)); initialCoordinate = new Coordinate(579579.8304298479, 4786436.780092208); inputCoordinates = line.getCoordinates(); // use the function to set the offsetPosition double distance = calculateDistanceAndCurrentPostion(); // now set the real distance value distance = 5; OffsetBuilder builder = new OffsetBuilder(offsetPosition, startPosition, DEPRECIATE_VALUE); outputCoordinates = builder.getLineCurve(inputCoordinates, distance, line.getFactory()); LinearRing teoricalLine = (LinearRing) read("LINEARRING (579658.241444656 4786515.408588693, 579625.5258826594 4786432.5043804515, 579554.8573944278 4786460.379173031, 579554.487562013 4786459.434992581, 579552.1327776525 4786460.349086088, 579551.6836194616 4786459.1912560845, 579532.8159484047 4786466.505310388, 579526.0225026619 4786448.507332215, 579498.7685670165 4786458.788665561, 579522.6771312796 4786519.859454711, 579536.3863841632 4786514.489747345, 579538.9059703269 4786520.928689764, 579564.5564889554 4786510.888486761, 579569.8585271646 4786524.4336938085, 579574.7998188197 4786522.493186559, 579576.3188681451 4786526.370759836, 579597.8670580825 4786517.921469583, 579601.5563306441 4786527.349610574, 579622.876923133 4786518.999378524, 579626.3565275135 4786527.8883678755, 579658.241444656 4786515.408588693)"); System.out.println(outputCoordinates.toString()); assertNotNull(outputCoordinates); isEqualWithoutPrecision(teoricalLine, teoricalLine.getFactory()); } @Test public void exampleFeature6insideNoPrecision() { LineString line = (LineString) read("LINESTRING (579545.1699 4786235.1558, 579542.5899 4786226.3705, 579544.764 4786225.732, 579543.754 4786222.229, 579536.2035000001 4786224.375, 579533.825 4786225.882, 579534.8813 4786229.6283, 579534.51 4786229.733, 579533.951 4786230.7884, 579533.6239 4786231.9371, 579533.5431 4786233.1287, 579533.712 4786234.311, 579534.6945 4786238.2115, 579545.1699 4786235.1558)"); assertTrue(calculateDistanceZero(line)); initialCoordinate = new Coordinate(579542.8614704317, 4786231.648683341); inputCoordinates = line.getCoordinates(); // use the function to set the offsetPosition double distance = calculateDistanceAndCurrentPostion(); // now set the real distance value distance = 2; OffsetBuilder builder = new OffsetBuilder(offsetPosition, startPosition, DEPRECIATE_VALUE); outputCoordinates = builder.getLineCurve(inputCoordinates, distance, line.getFactory()); LinearRing teoricalLine = (LinearRing) read("LINEARRING (579540.1967199836 4786225.319260796, 579542.6863682005 4786233.796898967, 579536.1269438184 4786235.710299226, 579535.6770558874 4786233.924255588, 579535.5527501027 4786233.054115095, 579535.6050782296 4786232.282404749, 579535.8168983398 4786231.538541219, 579535.876716623 4786231.425603445, 579537.3489884307 4786231.010448964, 579536.154415767 4786226.773747678, 579537.0290821904 4786226.219565504, 579540.1967199836 4786225.319260796)"); System.out.println(outputCoordinates.toString()); assertNotNull(outputCoordinates); isEqualWithoutPrecision(teoricalLine, teoricalLine.getFactory()); } @Test public void exampleBigFeature1OutsideNoPrecision() { LineString line = (LineString) read("LINESTRING (579466.76 4785418.6, 579468.08 4785417.69, 579469.14 4785419.48, 579469.75 4785419.07, 579467.39 4785409.69, 579469.27 4785409.12, 579467.13 4785401.73, 579465.472 4785396.628, 579463.6417 4785391.5853, 579461.6414 4785386.6076, 579459.4733 4785381.7006, 579457.14 4785376.87, 579448.41 4785361.19, 579439.52 4785348.38, 579430.27 4785337.44, 579428.75 4785338.84, 579422.14 4785331.56, 579421.49 4785331.9, 579427.13 4785342.5, 579425.52 4785343.35, 579424.39 4785341.23, 579422.0700000001 4785342.48, 579421.51 4785341.44, 579390.2 4785358.42, 579390.75 4785359.42, 579388.5 4785360.66, 579398.26 4785378.65, 579385.63 4785385.78, 579391.02 4785395.62, 579392.95 4785394.52, 579401.2 4785409.64, 579399.23 4785410.67, 579404.49 4785420.34, 579412.92 4785415.85, 579418.08 4785417.34, 579416.22 4785423.9, 579423.33 4785426.03, 579426.39 4785416.21, 579428.24 4785416.76, 579431.14 4785406.65, 579437.36 4785408.42, 579435.29 4785415.67, 579456.31 4785421.94, 579458.47 4785414.82, 579464.81 4785416.69, 579461.81 4785426.75, 579463.75 4785427.32, 579460.8 4785437.23, 579467.86 4785439.29, 579470.95 4785428.98, 579468.64 4785428.17, 579469.88 4785424.17, 579466.76 4785418.6)"); assertTrue(calculateDistanceZero(line)); initialCoordinate = new Coordinate(579449.3506998476, 4785359.713616236); inputCoordinates = line.getCoordinates(); // use the function to set the offsetPosition double distance = calculateDistanceAndCurrentPostion(); // now set the real distance value distance = 2; OffsetBuilder builder = new OffsetBuilder(offsetPosition, startPosition, DEPRECIATE_VALUE); outputCoordinates = builder.getLineCurve(inputCoordinates, distance, line.getFactory()); LinearRing teoricalLine = (LinearRing) read("LINEARRING (579423.2941533194 4785339.548608929, 579418.7782894584 4785331.061347063, 579422.5820869936 4785329.071668347, 579428.876659225 4785336.004268324, 579430.449931036 4785334.555202183, 579441.1087673445 4785347.161436692, 579450.1093874552 4785360.130834175, 579458.9156629585 4785375.9478330165, 579461.2889743937 4785380.86126816, 579463.4845078448 4785385.830357521, 579465.5101178597 4785390.871040904, 579467.3635852408 4785395.977569868, 579469.0420788857 4785401.142632943, 579471.7404620409 4785410.460881314, 579469.7947111026 4785411.050816439, 579472.032620918 4785419.945559688, 579470.4150820347 4785421.032757955, 579472.0446113507 4785423.941885612, 579471.1211977984 4785426.920639006, 579473.4141323646 4785427.724655024, 579469.2057904839 4785441.766080522, 579458.3094113447 4785438.586683776, 579461.260482892 4785428.6730841035, 579459.319542368 4785428.102807764, 579462.3201431634 4785418.040793097, 579459.8077251503 4785417.299748667, 579457.6459565331 4785424.425578553, 579432.8241837653 4785417.021557846, 579434.8872768116 4785409.795748867, 579432.5121822286 4785409.119877901, 579429.6056849025 4785419.252528924, 579427.7121863473 4785418.689596921, 579424.6509551121 4785428.5135481395, 579413.7582888842 4785425.250344333, 579415.6129095431 4785418.709316633, 579413.1443589361 4785417.996498724, 579403.6804083588 4785423.037203125, 579396.50159782 4785409.8396559935, 579398.4692554827 4785408.8108806675, 579392.1702209765 4785397.266468336, 579390.2431208788 4785398.3648155425, 579382.9273142059 4785385.009057164, 579395.5642476412 4785377.87514304, 579385.7946006911 4785359.867361417, 579388.0345521588 4785358.632899274, 579387.4780112645 4785357.621006739, 579422.319907559 4785338.725593164, 579422.882498832 4785339.770405528, 579423.2941533194 4785339.548608929)"); System.out.println(outputCoordinates.toString()); assertNotNull(outputCoordinates); isEqualWithoutPrecision(teoricalLine, teoricalLine.getFactory()); } @Test public void exampleBigFeature1InsideNoPrecision() { LineString line = (LineString) read("LINESTRING (579466.76 4785418.6, 579468.08 4785417.69, 579469.14 4785419.48, 579469.75 4785419.07, 579467.39 4785409.69, 579469.27 4785409.12, 579467.13 4785401.73, 579465.472 4785396.628, 579463.6417 4785391.5853, 579461.6414 4785386.6076, 579459.4733 4785381.7006, 579457.14 4785376.87, 579448.41 4785361.19, 579439.52 4785348.38, 579430.27 4785337.44, 579428.75 4785338.84, 579422.14 4785331.56, 579421.49 4785331.9, 579427.13 4785342.5, 579425.52 4785343.35, 579424.39 4785341.23, 579422.0700000001 4785342.48, 579421.51 4785341.44, 579390.2 4785358.42, 579390.75 4785359.42, 579388.5 4785360.66, 579398.26 4785378.65, 579385.63 4785385.78, 579391.02 4785395.62, 579392.95 4785394.52, 579401.2 4785409.64, 579399.23 4785410.67, 579404.49 4785420.34, 579412.92 4785415.85, 579418.08 4785417.34, 579416.22 4785423.9, 579423.33 4785426.03, 579426.39 4785416.21, 579428.24 4785416.76, 579431.14 4785406.65, 579437.36 4785408.42, 579435.29 4785415.67, 579456.31 4785421.94, 579458.47 4785414.82, 579464.81 4785416.69, 579461.81 4785426.75, 579463.75 4785427.32, 579460.8 4785437.23, 579467.86 4785439.29, 579470.95 4785428.98, 579468.64 4785428.17, 579469.88 4785424.17, 579466.76 4785418.6)"); assertTrue(calculateDistanceZero(line)); initialCoordinate = new Coordinate(579443.8804365521, 4785416.289813829); inputCoordinates = line.getCoordinates(); // use the function to set the offsetPosition double distance = calculateDistanceAndCurrentPostion(); // now set the real distance value distance = 1; OffsetBuilder builder = new OffsetBuilder(offsetPosition, startPosition, DEPRECIATE_VALUE); outputCoordinates = builder.getLineCurve(inputCoordinates, distance, line.getFactory()); LinearRing teoricalLine = (LinearRing) read("LINEARRING (579468.0680986132 4785416.483600281, 579465.4422967522 4785418.293812169, 579468.7976943245 4785424.284057194, 579467.3994011006 4785428.794680497, 579469.7179338175 4785429.607672489, 579467.187104758 4785438.051959739, 579462.0452943277 4785436.551658113, 579464.9947585539 4785426.643457948, 579463.0552288161 4785426.073596118, 579466.0549284182 4785416.014603453, 579457.8011374245 4785413.580125667, 579455.6420217333 4785420.6972107235, 579436.5229081175 4785414.994221077, 579438.5963615943 4785407.732125566, 579430.4539088857 4785405.41506105, 579427.5571575488 4785415.513735537, 579425.7289068267 4785414.970201539, 579422.669522444 4785424.78822593, 579417.4508555578 4785423.2248278335, 579419.3135452284 4785416.655341684, 579412.807820532 4785414.776750637, 579404.8947958205 4785418.991398437, 579400.59420109 4785411.085172003, 579402.565372259 4785410.054559666, 579393.3398895117 4785393.146765831, 579391.4084395602 4785394.247592228, 579386.9813428968 4785386.165471419, 579399.6078761794 4785379.037428481, 579389.8526996546 4785361.056319292, 579392.1077239206 4785359.813550363, 579391.5609943677 4785358.819496631, 579421.1050462208 4785342.797203419, 579421.6637505839 4785343.834797236, 579423.9800188193 4785342.586807885, 579425.106047169 4785344.699356646, 579428.4840522514 4785342.915937815, 579424.7810127875 4785335.956324638, 579428.6866703875 4785340.257865838, 579430.1800344824 4785338.882398909, 579438.7256163275 4785348.9892816525, 579447.5603062721 4785361.7195829125, 579456.2521685173 4785377.331083485, 579458.5654628054 4785382.120265925, 579460.7198460775 4785386.996221239, 579462.7074910725 4785391.942429555, 579464.5262073795 4785396.953215065, 579466.1739605559 4785402.023683526, 579468.0347689795 4785408.449559343, 579466.1876444487 4785409.009591781, 579468.0680986132 4785416.483600281)"); System.out.println(outputCoordinates.toString()); assertNotNull(outputCoordinates); isEqualWithoutPrecision(teoricalLine, teoricalLine.getFactory()); } }