/** * Tests if this line segment contains {@link Double#NaN}. * * @return {@code true} if {@link #getFirstEndpoint()} and/or {@link #getSecondEndpoint()} contains * {@link Double#NaN}, {@code false} otherwise. */ @Override default boolean containsNaN() { return getFirstEndpoint().containsNaN() || getSecondEndpoint().containsNaN(); }
/** * Sets this line segment to be same as the given line segment. * * @param other the other line segment to copy. Not modified. */ @Override public void set(LineSegment2D other) { LineSegment2DBasics.super.set(other); }
/** * Swaps this line segment's endpoints. */ default void flipDirection() { double x = getFirstEndpointX(); double y = getFirstEndpointY(); setFirstEndpoint(getSecondEndpoint()); setSecondEndpoint(x, y); }
/** * Redefines this line segments with new endpoints. * * @param firstEndpointX x-coordinate of the new first endpoint. * @param firstEndpointY y-coordinate of the new first endpoint. * @param secondEndpointX x-coordinate of the new second endpoint. * @param secondEndpointY y-coordinate of the new second endpoint. */ default void set(double firstEndpointX, double firstEndpointY, double secondEndpointX, double secondEndpointY) { setFirstEndpoint(firstEndpointX, firstEndpointY); setSecondEndpoint(secondEndpointX, secondEndpointY); }
/** * Translates this line segment by the given (x, y). * <p> * Note that the length and direction of this line segment remains unchanged. * </p> * * @param x the distance to translate this line along the x-axis. * @param y the distance to translate this line along the y-axis. */ default void translate(double x, double y) { setFirstEndpoint(getFirstEndpointX() + x, getFirstEndpointY() + y); setSecondEndpoint(getSecondEndpointX() + x, getSecondEndpointY() + y); }
/** * Translates this line segment perpendicularly to its direction. * * @param shiftToLeft defines to which side this line segment is to be translated. * @param distanceToShift the distance this line segment is to be shifted. */ default void shift(boolean shiftToLeft, double distanceToShift) { double vectorX = getSecondEndpointX() - getFirstEndpointX(); double vectorY = getSecondEndpointY() - getFirstEndpointY(); double length = length(); double orthogonalVectorX = -vectorY / length; double orthogonalVectorY = vectorX / length; if (!shiftToLeft) { orthogonalVectorX = -orthogonalVectorX; orthogonalVectorY = -orthogonalVectorY; } orthogonalVectorX = distanceToShift * orthogonalVectorX; orthogonalVectorY = distanceToShift * orthogonalVectorY; translate(orthogonalVectorX, orthogonalVectorY); }
/** * Redefines this line segment with a new first endpoint and a vector going from the first to the * second endpoint. * * @param firstEndpoint new first endpoint. Not modified. * @param fromFirstToSecondEndpoint vector going from the first to the second endpoint. Not * modified. */ default void set(Point3DReadOnly firstEndpoint, Vector3DReadOnly fromFirstToSecondEndpoint) { setFirstEndpoint(firstEndpoint); setSecondEndpoint(firstEndpoint); getSecondEndpoint().add(fromFirstToSecondEndpoint.getX(), fromFirstToSecondEndpoint.getY()); }
/** * Changes the first endpoint of this line segment. * * @param referenceFrame the reference frame in which the given coordinates are expressed. * @param firstEndpointX x-coordinate of the new first endpoint. * @param firstEndpointY y-coordinate of the new first endpoint. * @throws ReferenceFrameMismatchException if {@code this.getReferenceFrame() != referenceFrame}. */ default void setFirstEndpoint(ReferenceFrame referenceFrame, double firstEndpointX, double firstEndpointY) { checkReferenceFrameMatch(referenceFrame); LineSegment2DBasics.super.setFirstEndpoint(firstEndpointX, firstEndpointY); }
/** * Changes the second endpoint of this line segment. * * @param referenceFrame the reference frame in which the given coordinates are expressed. * @param secondEndpoint new second endpoint of this line segment. Not modified. * @throws ReferenceFrameMismatchException if {@code this.getReferenceFrame() != referenceFrame}. */ default void setSecondEndpoint(ReferenceFrame referenceFrame, Point2DReadOnly secondEndpoint) { checkReferenceFrameMatch(referenceFrame); LineSegment2DBasics.super.setSecondEndpoint(secondEndpoint); }
/** * Changes the first endpoint of this line segment. * * @param firstEndpointX x-coordinate of the new first endpoint. * @param firstEndpointY y-coordinate of the new first endpoint. */ default void setFirstEndpoint(double firstEndpointX, double firstEndpointY) { getFirstEndpoint().set(firstEndpointX, firstEndpointY); }
/** * Changes the second endpoint of this line segment. * * @param secondEndpointX x-coordinate of the new second endpoint. * @param secondEndpointY y-coordinate of the new second endpoint. */ default void setSecondEndpoint(double secondEndpointX, double secondEndpointY) { getSecondEndpoint().set(secondEndpointX, secondEndpointY); }
/** * Translates this line segment by the given (x, y, z) contained in {@code translation}. * <p> * Note that the length and direction of this line segment remains unchanged. * </p> * * @param translation the translation to add to each endpoint of this line segment. Not modified. * @throws ReferenceFrameMismatchException if {@code this} and {@code translation} are not expressed * in the same reference frame. */ default void translate(FrameTuple2DReadOnly translation) { checkReferenceFrameMatch(translation); LineSegment2DBasics.super.translate(translation); } }
/** * Transforms this line segment using the given homogeneous transformation matrix. * * @param transform the transform to apply on the endpoints of this line segment. Not modified. * @throws NotAMatrix2DException if the rotation part of {@code transform} is not a transformation * in the XY-plane. */ @Override default void applyTransform(Transform transform) { applyTransform(transform, true); }
/** * Transforms this line segment using the inverse of the given homogeneous transformation matrix. * * @param transform the transform to apply on the endpoints of this line segment. Not modified. * @throws NotAMatrix2DException if the rotation part of {@code transform} is not a transformation * in the XY-plane. */ @Override default void applyInverseTransform(Transform transform) { applyInverseTransform(transform, true); }
/** * Tests on a per-component basis on both endpoints if this line segment is equal to {@code other} * with the tolerance {@code epsilon}. * * @param other the query. Not modified. * @param epsilon the tolerance to use. * @return {@code true} if the two line segments are equal, {@code false} otherwise. */ @Override public boolean epsilonEquals(LineSegment2D other, double epsilon) { return LineSegment2DBasics.super.epsilonEquals(other, epsilon); }
/** * Redefines this line segment with new endpoints. * * @param firstEndpoint new endpoint of this line segment. Not modified * @param secondEndpoint new second endpoint of this line segment. Not modified. */ default void set(Point2DReadOnly firstEndpoint, Point2DReadOnly secondEndpoint) { setFirstEndpoint(firstEndpoint); setSecondEndpoint(secondEndpoint); }
/** * Changes the first endpoint of this line segment. * * @param referenceFrame the reference frame in which the given coordinates are expressed. * @param firstEndpoint new endpoint of this line segment. Not modified. * @throws ReferenceFrameMismatchException if {@code this.getReferenceFrame() != referenceFrame}. */ default void setFirstEndpoint(ReferenceFrame referenceFrame, Point2DReadOnly firstEndpoint) { checkReferenceFrameMatch(referenceFrame); LineSegment2DBasics.super.setFirstEndpoint(firstEndpoint); }
/** * Changes the second endpoint of this line segment. * * @param referenceFrame the reference frame in which the given coordinates are expressed. * @param secondEndpoint new second endpoint of this line segment. Not modified. * @throws ReferenceFrameMismatchException if {@code this.getReferenceFrame() != referenceFrame}. */ default void setSecondEndpoint(ReferenceFrame referenceFrame, Point3DReadOnly secondEndpoint) { checkReferenceFrameMatch(referenceFrame); LineSegment2DBasics.super.setSecondEndpoint(secondEndpoint); }
/** * Translates this line segment by the given (x, y) contained in {@code translation}. * <p> * Note that the length and direction of this line segment remains unchanged. * </p> * * @param translation the translation to add to each endpoint of this line segment. Not modified. */ default void translate(Tuple2DReadOnly translation) { translate(translation.getX(), translation.getY()); }
/** * Sets both endpoints of this line segment to zero. */ @Override default void setToZero() { getFirstEndpoint().setToZero(); getSecondEndpoint().setToZero(); }