/** * Tests on a per component basis, if this line 2D is exactly equal to {@code other}. * <p> * If the two lines have different frames, this method returns {@code false}. * </p> * * @param other the other line 2D to compare against this. Not modified. * @return {@code true} if the two lines are exactly equal component-wise and are expressed in * the same reference frame, {@code false} otherwise. */ default boolean equals(FrameLine2DReadOnly other) { if (other == null || getReferenceFrame() != other.getReferenceFrame()) return false; else return getPoint().equals(other.getPoint()) && getDirection().equals(other.getDirection()); } }
/** * Tests on a per-component basis on the point and vector if this line is equal to {@code other} * with the tolerance {@code epsilon}. This method will return {@code false} if the two lines are * physically the same but either the point or vector of each line is different. For instance, if * {@code this.point == other.point} and {@code this.direction == - other.direction}, the two * lines are physically the same but this method returns {@code false}. * <p> * If the two lines have different frames, this method returns {@code false}. * </p> * * @param other the query. Not modified. * @param epsilon the tolerance to use. * @return {@code true} if the two lines are equal and are expressed in the same reference frame, * {@code false} otherwise. */ default boolean epsilonEquals(FrameLine2DReadOnly other, double epsilon) { if (getReferenceFrame() != other.getReferenceFrame()) return false; if (!getPoint().epsilonEquals(other.getPoint(), epsilon)) return false; if (!getDirection().epsilonEquals(other.getDirection(), epsilon)) return false; return true; }
public static boolean isLineBetweenVertices(FrameLine2DReadOnly frameLine2d, FramePoint2DReadOnly leftVertex, FramePoint2DReadOnly rightVertex, boolean mustBeStrictlyBetween) { FramePoint2D lineStart = new FramePoint2D(frameLine2d.getPoint()); FrameVector2D lineDirection = new FrameVector2D(frameLine2d.getDirection()); double startToLeftVertexX = leftVertex.getX() - lineStart.getX(); double startToLeftVertexY = leftVertex.getY() - lineStart.getY(); double startToRightVertexX = rightVertex.getX() - lineStart.getX(); double startToRightVertexY = rightVertex.getY() - lineStart.getY(); // double crossProduct = vectorToEdge1X * vectorToEdge2Y - vectorToEdge1Y * vectorToEdge2X; double leftCrossProduct = lineDirection.getX() * startToLeftVertexY - lineDirection.getY() * startToLeftVertexX; double rightCrossProduct = lineDirection.getX() * startToRightVertexY - lineDirection.getY() * startToRightVertexX; if (mustBeStrictlyBetween) { if ((leftCrossProduct > 0.0) && (rightCrossProduct < 0.0)) return true; } else if ((leftCrossProduct >= 0.0) && (rightCrossProduct <= 0.0)) return true; return false; }