Plane { public Plane set(double x, double y, double z, double distance) { this.normal.x = x; this.normal.y = y; this.normal.z = z; this.distance = distance; this.normalizeIfNeeded(); return this; } Plane();  Plane(double x, double y, double z, double distance);  Plane(Plane plane); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); double distanceToPoint(Vec3 point); Plane set(double x, double y, double z, double distance); Plane set(Plane plane); Plane transformByMatrix(Matrix4 matrix); double dot(Vec3 vector); boolean intersectsSegment(Vec3 endPoint1, Vec3 endPoint2); int onSameSide(Vec3 pointA, Vec3 pointB); Vec3[] clip(Vec3 pointA, Vec3 pointB);  }
@Test public void testSet() throws Exception { Vec3 n = new Vec3(3, 4, 5).normalize(); double distance = 6; Plane plane = new Plane(0, 0, 1, 10); plane.set(n.x, n.y, n.z, distance); assertEquals("normal", n, plane.normal); assertEquals("distance", distance, plane.distance, 0); }
@Test public void testSet_NotNormalizedValues() { Vec3 n = new Vec3(3, 4, 5); Vec3 nExpected = new Vec3(n).normalize(); double distance = 6; double distanceExpected = distance / n.magnitude(); Plane plane = new Plane(0, 0, 1, 10); plane.set(n.x, n.y, n.z, distance); assertEquals("normal x", plane.normal.x, nExpected.x, 0); assertEquals("normal y", plane.normal.y, nExpected.y, 0); assertEquals("normal z", plane.normal.z, nExpected.z, 0); assertEquals("distance", plane.distance, distanceExpected, 0); }
@Test public void testSet_ZeroValues() { Plane plane = new Plane(0, 0, 1, 10); plane.set(0, 0, 0, 0); assertEquals("normal x", plane.normal.x, 0, 0); assertEquals("normal y", plane.normal.y, 0, 0); assertEquals("normal z", plane.normal.z, 0, 0); assertEquals("distance", plane.distance, 0, 0); }
@Test public void testSet_Plane() throws Exception { Vec3 n = new Vec3(3, 4, 5).normalize(); double distance = 6; Plane plane1 = new Plane(0, 0, 1, 10); Plane plane2 = new Plane(n.x, n.y, n.z, distance); plane1.set(plane2); assertEquals("normal", n, plane1.normal); assertEquals("distance", distance, plane1.distance, 0); }