@@ -0,0 +1,2659 @@
+package org.primesoft.ascinoid.asciinoid.engine;%0A%0A/**%0A * 2D plane%0A * Based on CPlane from %22Programowanie gier w OpenGL%22 by Dave Astle%0A *%0A * Ax + By + Cz - D = 0%0A *%0A * @author SBPrime%0A */%0Apublic class CPlane %7B%0A    /**%0A     * Vector normal to plane%0A     */%0A    private final CVector m_normal;%0A%0A    /**%0A     * Plane offset%0A     */%0A    private final double m_offset;%0A%0A    public CVector getN() %7B%0A        return m_normal;%0A    %7D%0A%0A    public double getD() %7B%0A        return m_offset;%0A    %7D%0A%0A    public CPlane() %7B%0A        this(1, 0, 0, 0);%0A    %7D%0A%0A    public CPlane(double a, double b, double c) %7B%0A        this(a, b, c, 0);%0A    %7D%0A%0A    public CPlane(double a, double b, double c, double d) %7B%0A        this(new CVector(a, b, c), d);%0A    %7D%0A%0A    public CPlane(CVector normal) %7B%0A        this(normal, 0);%0A    %7D%0A%0A    public CPlane(CVector normal, double d) %7B%0A        m_normal = normal.clone();%0A        m_offset = d;%0A    %7D%0A%0A    public CPlane(CPlane plane) %7B%0A        m_normal = plane.m_normal.clone();%0A        m_offset = plane.m_offset;%0A    %7D%0A%0A    public CPlane(CVector vertexA, CVector vertexB, CVector vertexC) %7B%0A        CVector normalA = CVector.sub(vertexC, vertexA).normalize();%0A        CVector normalB = CVector.sub(vertexC, vertexB).normalize();%0A%0A        m_normal = CVector.cross(normalA, normalB).normalize();%0A        m_offset = vertexA.inv().dot(m_normal);%0A    %7D%0A%0A    /**%0A     * Checks if provided point is on plane%0A     *%0A     * @param point%0A     * @return%0A     */%0A    public boolean isPointOnPlane(CVector point) %7B%0A        return distanceToPlane(point) == 0;%0A    %7D%0A%0A    /**%0A     * Calculate the distance from the plane%0A     *%0A     * @param point%0A     * @return%0A     */%0A    public double distanceToPlane(CVector point) %7B%0A        return CVector.dot(m_normal, point) + m_offset;%0A    %7D%0A%0A    /**%0A     * Calculates the plane and ray intersection%0A     * @param rayPos%0A     * @param rayDir%0A     * @return%0A     */%0A    public CVector rayIntersection(CVector rayPos, CVector rayDir) %7B%0A        double a = CVector.dot(m_normal, rayDir);%0A        if (a == 0) %7B%0A            // The ray is parallel to plane%0A            return rayPos;%0A        %7D%0A%0A        return CVector.sub(rayPos, CVector.mul(rayDir, distanceToPlane(rayPos) / a));%0A    %7D%0A%0A%0A    @Override%0A    public final int hashCode() %7B%0A        long longHash = Double.doubleToRawLongBits(m_offset);%0A        return (int) (longHash %5E (longHash %3E%3E%3E 32)) %5E m_normal.hashCode();%0A    %7D%0A%0A    @Override%0A    public boolean equals(Object obj) %7B%0A        if (!(obj instanceof CPlane)) %7B%0A            return false;%0A        %7D%0A%0A        CPlane other = (CPlane) obj;%0A%0A        return other.m_offset == m_offset && other.m_normal.equals(m_normal);%0A    %7D%0A%7D

Add 2d plane