@@ -0,0 +1,1512 @@
+package sge.math;%0A%0A/**%0A * Two Dimensional Line Segment (finite).%0A */%0Apublic class Line2D %7B%0A%0A    public final Vector2 start;%0A    public final Vector2 end;%0A%0A    public Line2D (Vector2 start, Vector2 end) %7B%0A        this.start = start;%0A        this.end = end;%0A    %7D%0A%0A    public float getLengthSqr () %7B%0A        return end.sub(start).getLengthSqr();%0A    %7D%0A%0A    public float getLength () %7B%0A        return end.sub(start).getLength();%0A    %7D%0A%0A    public Vector2 getCenter () %7B%0A        return start.add(end.scale(0.5f));%0A    %7D%0A%0A    /**%0A     * Test if this Line2D intersects another Line2D. If there is an%0A     * intersection, return the point at which the intersects occurs,%0A     * otherwise return null.%0A     *%0A     * @param other Line2D to test for intersection.%0A     * @return Vector2 Intersection point, or null if no intersection.%0A     */%0A    public Vector2 intersects (Line2D other) %7B%0A        Vector2 line1 = end.sub(start);%0A        Vector2 line2 = other.end.sub(other.start);%0A%0A        // ls1 + line1 * a == ls2 + line2 * b%0A        float cross = line1.cross(line2);%0A        if (cross == 0.0f) %7B%0A            return null;%0A        %7D%0A%0A        Vector2 dStart = other.start.sub(start);%0A        float a = dStart.cross(line2) / cross;%0A        float b = dStart.cross(line1) / cross;%0A%0A        if (0f %3C a && a %3C 1f && 0f %3C b && b %3C 1f)%0A            return start.add(line1.scale(a));%0A%0A        return null;%0A    %7D%0A%0A    @Override%0A    public String toString () %7B%0A        return String.format(%22%3CLine2D %25s -%3E %25s%3E%22, start, end);%0A    %7D%0A%7D%0A

Add 2D Line + intersection test