/** * Returns the <code>Position</code> of this <code>Point</code>. * * @return the <code>Position</code> of this <code>Point</code>. */ public P getPosition() { return getPositions().getPositionN(0) ; }
/** * Determines whether the specified {@code PositionSequence} is counter-clockwise. * <p/> * <p>Only the first three positions, are inspected to determine whether the sequence is counter-clockwise. * In case are less than three positions in the sequence, the method returns true.</p> * * @param positions a {@code PositionSequence} * @return true if the positions in the specified sequence are counter-clockwise, or if the sequence contains * less than three elements. */ public static boolean isCounterClockwise(PositionSequence<?> positions) { if (positions.size() < 3) return true; Position p0 = positions.getPositionN(0); Position p1 = positions.getPositionN(1); double det = 0; int positionsSize = positions.size(); int i = 2; while(i < positionsSize && det == 0) { Position p2 = positions.getPositionN(i); det = deltaDeterminant(p0, p1, p2); i++; } if (det == 0) { throw new IllegalArgumentException("Positions are collinear in 2D"); } return det > 0; }
void setCoordinate(int index, PositionSequence<?> positions) { points[2 * index] = positions.getPositionN(index).getCoordinate(0); points[2 * index + 1] = positions.getPositionN(index).getCoordinate(1); if (hasZValues()) { //TODO ensure this conditions is satisfied if (!hasVerticalAxis(crs)) throw new IllegalStateException(); zValues[index] = positions.getPositionN(index).getCoordinate(2); } if (hasMValues()) { if (!hasMeasureAxis(crs)) throw new IllegalStateException(); int idx = hasZValues() ? 3 : 2; mValues[index] = positions.getPositionN(index).getCoordinate(idx); } }
/** * Linearizes arcs and circles. * * @return linearized interpolation of arcs or circle */ protected <P extends Position> PositionSequence<P> linearize(PositionSequence<P> positions, boolean entireCirlce) { PositionSequence<P> result = null; int idx = 0; while (idx < positions.size() - 2) { //only iterate if we have at least three more points P p0 = positions.getPositionN(idx++); P p1 = positions.getPositionN(idx++); P p2 = positions.getPositionN(idx); //dont' increment, we repeat next iteration from this index CircularArcLinearizer<P> linearizer = new CircularArcLinearizer<P>(p0, p1, p2, LINEARIZER_EPSILON); PositionSequence<P> ps; if (entireCirlce) { ps = linearizer.linearizeCircle(); } else { ps = linearizer.linearize(); } // if this is not the first arcsegment, the first linearized // point is already in linearizedArc, so disregard this. if (result == null) { // this is the first iteration result = ps; } else { result = add(result, 0, ps, 1); } } return result; }
/** * Gets the CoordinateSequence corresponding to an element. * * @param i * @param sdoGeom * @return */ protected <P extends Position> PositionSequence<P> getElementCSeq(int i, SDOGeometry sdoGeom, boolean hasNextSE, CoordinateReferenceSystem<P> crs) { final ElementType type = sdoGeom.getInfo().getElementType(i); final Double[] elemOrdinates = extractOrdinatesOfElement(i, sdoGeom, hasNextSE); PositionSequence<P> cs; if (type.isStraightSegment()) { cs = convertOrdinateArray(elemOrdinates, sdoGeom, crs); } else if (type.isArcSegment() || type.isCircle()) { cs = linearize(convertOrdinateArray(elemOrdinates, sdoGeom, crs), type.isCircle()); } else if (type.isRect()) { cs = convertOrdinateArray(elemOrdinates, sdoGeom, crs); cs = env2Seq(cs.getPositionN(0), cs.getPositionN(1), type.isExteriorRing()); } else { throw new RuntimeException( "Unexpected Element type in compound: " + type ); } return cs; }