Code with Misuse: |
class SubLine { /** Get the intersection of the instance and another sub-line. * <p> * This method is related to the {@link Line#intersection(Line) * intersection} method in the {@link Line Line} class, but in addition * to compute the point along infinite lines, it also checks the point * lies on both sub-line ranges. * </p> * @param subLine other sub-line which may intersect instance * @param includeEndPoints if true, endpoints are considered to belong to * instance (i.e. they are closed sets) and may be returned, otherwise endpoints * are considered to not belong to instance (i.e. they are open sets) and intersection * occurring on endpoints lead to null being returned * @return the intersection point if there is one, null if the sub-lines don't intersect */ public Vector2D intersection(final SubLine subLine, final boolean includeEndPoints) {
// retrieve the underlying lines Line line1 = (Line) getHyperplane(); Line line2 = (Line) subLine.getHyperplane();
// compute the intersection on infinite line Vector2D v2D = line1.intersection(line2);
// check location of point with respect to first sub-line Location loc1 = getRemainingRegion().checkPoint(line1.toSubSpace(v2D));
// check location of point with respect to second sub-line Location loc2 = subLine.getRemainingRegion().checkPoint(line2.toSubSpace(v2D));
if (includeEndPoints) { return ((loc1 != Location.OUTSIDE) && (loc2 != Location.OUTSIDE)) ? v2D : null; } else { return ((loc1 == Location.INSIDE) && (loc2 == Location.INSIDE)) ? v2D : null; }
}
}
|