@Test public void testMergeEndEnd() { Segment s1 = new Segment(-1, -1, 0, 0, true); Segment s2 = new Segment(1, 1, 0, 0, true); s1.merge(s2, MergePoint.END_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 mergeEndEnd(Segment other) { int lengthOther = other.idxLast - other.idxFirst - 2; if (ordinates.length - idxLast < lengthOther) { int extra = lengthOther - ordinates.length + idxLast; double[] newOrdinates = new double[ordinates.length + extra]; System.arraycopy(ordinates, 0, newOrdinates, 0, ordinates.length); this.ordinates = newOrdinates; assert isConsistent(); } if (simplify && sameSlope(dxEnd, dyEnd, -other.dxEnd, -other.dyEnd)) { idxLast -= 2; } for (int i = other.idxLast - 2; i > other.idxFirst;) { double y = other.ordinates[--i]; double x = other.ordinates[--i]; ordinates[idxLast++] = x; ordinates[idxLast++] = y; } this.xEnd = other.xStart; this.yEnd = other.yStart; this.dxEnd = other.dxStart; this.dyEnd = other.dyStart; }
Segment { private void mergeEndEnd(Segment other) { int lengthOther = other.idxLast - other.idxFirst - 2; if (ordinates.length - idxLast < lengthOther) { int extra = lengthOther - ordinates.length + idxLast; double[] newOrdinates = new double[ordinates.length + extra]; System.arraycopy(ordinates, 0, newOrdinates, 0, ordinates.length); this.ordinates = newOrdinates; assert isConsistent(); } if (simplify && sameSlope(dxEnd, dyEnd, -other.dxEnd, -other.dyEnd)) { idxLast -= 2; } for (int i = other.idxLast - 2; i > other.idxFirst;) { double y = other.ordinates[--i]; double x = other.ordinates[--i]; ordinates[idxLast++] = x; ordinates[idxLast++] = y; } this.xEnd = other.xStart; this.yEnd = other.yStart; this.dxEnd = other.dxStart; this.dyEnd = other.dyStart; } }
Segment { private void mergeEndEnd(Segment other) { int lengthOther = other.idxLast - other.idxFirst - 2; if (ordinates.length - idxLast < lengthOther) { int extra = lengthOther - ordinates.length + idxLast; double[] newOrdinates = new double[ordinates.length + extra]; System.arraycopy(ordinates, 0, newOrdinates, 0, ordinates.length); this.ordinates = newOrdinates; assert isConsistent(); } if (simplify && sameSlope(dxEnd, dyEnd, -other.dxEnd, -other.dyEnd)) { idxLast -= 2; } for (int i = other.idxLast - 2; i > other.idxFirst;) { double y = other.ordinates[--i]; double x = other.ordinates[--i]; ordinates[idxLast++] = x; ordinates[idxLast++] = y; } this.xEnd = other.xStart; this.yEnd = other.yStart; this.dxEnd = other.dxStart; this.dyEnd = other.dyStart; } 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 mergeEndEnd(Segment other) { int lengthOther = other.idxLast - other.idxFirst - 2; if (ordinates.length - idxLast < lengthOther) { int extra = lengthOther - ordinates.length + idxLast; double[] newOrdinates = new double[ordinates.length + extra]; System.arraycopy(ordinates, 0, newOrdinates, 0, ordinates.length); this.ordinates = newOrdinates; assert isConsistent(); } if (simplify && sameSlope(dxEnd, dyEnd, -other.dxEnd, -other.dyEnd)) { idxLast -= 2; } for (int i = other.idxLast - 2; i > other.idxFirst;) { double y = other.ordinates[--i]; double x = other.ordinates[--i]; ordinates[idxLast++] = x; ordinates[idxLast++] = y; } this.xEnd = other.xStart; this.yEnd = other.yStart; this.dxEnd = other.dxStart; this.dyEnd = other.dyStart; } 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 mergeEndEnd(Segment other) { int lengthOther = other.idxLast - other.idxFirst - 2; if (ordinates.length - idxLast < lengthOther) { int extra = lengthOther - ordinates.length + idxLast; double[] newOrdinates = new double[ordinates.length + extra]; System.arraycopy(ordinates, 0, newOrdinates, 0, ordinates.length); this.ordinates = newOrdinates; assert isConsistent(); } if (simplify && sameSlope(dxEnd, dyEnd, -other.dxEnd, -other.dyEnd)) { idxLast -= 2; } for (int i = other.idxLast - 2; i > other.idxFirst;) { double y = other.ordinates[--i]; double x = other.ordinates[--i]; ordinates[idxLast++] = x; ordinates[idxLast++] = y; } this.xEnd = other.xStart; this.yEnd = other.yStart; this.dxEnd = other.dxStart; this.dyEnd = other.dyStart; } 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();  }