@Test public void testMergeStartEnd() { Segment s1 = new Segment(0, 0, -1, -1, true); Segment s2 = new Segment(1, 1, 0, 0, true); s1.merge(s2, MergePoint.START_END); assertEquals(2, s1.getNumCoordinates()); assertEquals(1, s1.xStart, 0d); assertEquals(1, s1.yStart, 0d); assertEquals(-1, s1.xEnd, 0d); assertEquals(-1, s1.yEnd, 0d); }
private void mergeStartEnd(Segment other) { int lengthOther = other.idxLast - other.idxFirst - 2; if (idxFirst < lengthOther) { int extra = lengthOther - idxFirst; double[] newOrdinates = new double[ordinates.length + extra]; System.arraycopy(ordinates, 0, newOrdinates, extra, ordinates.length); this.ordinates = newOrdinates; idxFirst += extra; idxLast += extra; assert isConsistent(); } if (simplify && sameSlope(dxStart, dyStart, other.dxEnd, other.dyEnd)) { idxFirst += 2; } for (int i = other.idxLast - 2; i > other.idxFirst;) { double y = other.ordinates[--i]; double x = other.ordinates[--i]; ordinates[--idxFirst] = y; ordinates[--idxFirst] = x; } this.xStart = other.xStart; this.yStart = other.yStart; this.dxStart = other.dxEnd; this.dyStart = other.dyEnd; }
Segment { private void mergeStartEnd(Segment other) { int lengthOther = other.idxLast - other.idxFirst - 2; if (idxFirst < lengthOther) { int extra = lengthOther - idxFirst; double[] newOrdinates = new double[ordinates.length + extra]; System.arraycopy(ordinates, 0, newOrdinates, extra, ordinates.length); this.ordinates = newOrdinates; idxFirst += extra; idxLast += extra; assert isConsistent(); } if (simplify && sameSlope(dxStart, dyStart, other.dxEnd, other.dyEnd)) { idxFirst += 2; } for (int i = other.idxLast - 2; i > other.idxFirst;) { double y = other.ordinates[--i]; double x = other.ordinates[--i]; ordinates[--idxFirst] = y; ordinates[--idxFirst] = x; } this.xStart = other.xStart; this.yStart = other.yStart; this.dxStart = other.dxEnd; this.dyStart = other.dyEnd; } }
Segment { private void mergeStartEnd(Segment other) { int lengthOther = other.idxLast - other.idxFirst - 2; if (idxFirst < lengthOther) { int extra = lengthOther - idxFirst; double[] newOrdinates = new double[ordinates.length + extra]; System.arraycopy(ordinates, 0, newOrdinates, extra, ordinates.length); this.ordinates = newOrdinates; idxFirst += extra; idxLast += extra; assert isConsistent(); } if (simplify && sameSlope(dxStart, dyStart, other.dxEnd, other.dyEnd)) { idxFirst += 2; } for (int i = other.idxLast - 2; i > other.idxFirst;) { double y = other.ordinates[--i]; double x = other.ordinates[--i]; ordinates[--idxFirst] = y; ordinates[--idxFirst] = x; } this.xStart = other.xStart; this.yStart = other.yStart; this.dxStart = other.dxEnd; this.dyStart = other.dyEnd; } Segment();  Segment(double x1, double y1, double x2, double y2, int initialSize, boolean simplify);   Segment(double x1, double y1, double x2, double y2, boolean simplify); }
Segment { private void mergeStartEnd(Segment other) { int lengthOther = other.idxLast - other.idxFirst - 2; if (idxFirst < lengthOther) { int extra = lengthOther - idxFirst; double[] newOrdinates = new double[ordinates.length + extra]; System.arraycopy(ordinates, 0, newOrdinates, extra, ordinates.length); this.ordinates = newOrdinates; idxFirst += extra; idxLast += extra; assert isConsistent(); } if (simplify && sameSlope(dxStart, dyStart, other.dxEnd, other.dyEnd)) { idxFirst += 2; } for (int i = other.idxLast - 2; i > other.idxFirst;) { double y = other.ordinates[--i]; double x = other.ordinates[--i]; ordinates[--idxFirst] = y; ordinates[--idxFirst] = x; } this.xStart = other.xStart; this.yStart = other.yStart; this.dxStart = other.dxEnd; this.dyStart = other.dyEnd; } Segment();  Segment(double x1, double y1, double x2, double y2, int initialSize, boolean simplify);   Segment(double x1, double y1, double x2, double y2, boolean simplify); void setXY(double x1, double y1, double x2, double y2); void addAfterEnd(double x, double y); void addBeforeStart(double x, double y); LineString toLineString(); void merge(Segment other, MergePoint mergePoint); @Override String toString(); }
Segment { private void mergeStartEnd(Segment other) { int lengthOther = other.idxLast - other.idxFirst - 2; if (idxFirst < lengthOther) { int extra = lengthOther - idxFirst; double[] newOrdinates = new double[ordinates.length + extra]; System.arraycopy(ordinates, 0, newOrdinates, extra, ordinates.length); this.ordinates = newOrdinates; idxFirst += extra; idxLast += extra; assert isConsistent(); } if (simplify && sameSlope(dxStart, dyStart, other.dxEnd, other.dyEnd)) { idxFirst += 2; } for (int i = other.idxLast - 2; i > other.idxFirst;) { double y = other.ordinates[--i]; double x = other.ordinates[--i]; ordinates[--idxFirst] = y; ordinates[--idxFirst] = x; } this.xStart = other.xStart; this.yStart = other.yStart; this.dxStart = other.dxEnd; this.dyStart = other.dyEnd; } Segment();  Segment(double x1, double y1, double x2, double y2, int initialSize, boolean simplify);   Segment(double x1, double y1, double x2, double y2, boolean simplify); void setXY(double x1, double y1, double x2, double y2); void addAfterEnd(double x, double y); void addBeforeStart(double x, double y); LineString toLineString(); void merge(Segment other, MergePoint mergePoint); @Override String toString();  }