Improved JavaDoc.
[sixth-3d.git] / src / main / java / eu / svjatoslav / sixth / e3d / geometry / Point3D.java
index 4cae6ae..e2c9868 100755 (executable)
@@ -1,12 +1,7 @@
 /*
- * Sixth 3D engine. Copyright ©2012-2018, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 3 of the GNU Lesser General Public License
- * or later as published by the Free Software Foundation.
- *
+ * Sixth 3D engine. Author: Svjatoslav Agejenko. 
+ * This project is released under Creative Commons Zero (CC0) license.
  */
-
 package eu.svjatoslav.sixth.e3d.geometry;
 
 import static java.lang.Math.*;
@@ -15,9 +10,9 @@ import static java.lang.Math.*;
  * Used to represent point in a 3D space or vector.
  */
 
-public class Point3D extends Point2D implements Cloneable {
+public class Point3D implements Cloneable {
 
-    public double z;
+    public double x, y, z;
 
     public Point3D() {
     }
@@ -40,27 +35,35 @@ public class Point3D extends Point2D implements Cloneable {
         this.z = z;
     }
 
-    public Point3D(final Point3D parentPoint) {
-        x = parentPoint.x;
-        y = parentPoint.y;
-        z = parentPoint.z;
+    /**
+     * Creates new current point by cloning coordinates from parent point.
+     */
+    public Point3D(final Point3D parent) {
+        x = parent.x;
+        y = parent.y;
+        z = parent.z;
     }
 
-    public Point3D add(final Point3D direction) {
-        super.add(direction);
-        z += direction.z;
+    /**
+     * Add other point to current point.
+     *
+     * @return current point.
+     */
+    public Point3D add(final Point3D otherPoint) {
+        x += otherPoint.x;
+        y += otherPoint.y;
+        z += otherPoint.z;
         return this;
     }
 
-    @Override
     public Point3D clone() {
         return new Point3D(this);
     }
 
-    public Point3D clone(final Point3D source) {
-        x = source.x;
-        y = source.y;
-        z = source.z;
+    public Point3D clone(final Point3D parent) {
+        x = parent.x;
+        y = parent.y;
+        z = parent.z;
         return this;
     }
 
@@ -71,7 +74,6 @@ public class Point3D extends Point2D implements Cloneable {
         return this;
     }
 
-    @Override
     public boolean isZero() {
         return (x == 0) && (y == 0) && (z == 0);
     }
@@ -84,6 +86,10 @@ public class Point3D extends Point2D implements Cloneable {
         return Math.atan2(y - anotherPoint.y, z - anotherPoint.z);
     }
 
+    public double getAngleXY(final Point3D anotherPoint) {
+        return Math.atan2(x - anotherPoint.x, y - anotherPoint.y);
+    }
+
     /**
      * Compute distance to another point.
      */
@@ -95,12 +101,10 @@ public class Point3D extends Point2D implements Cloneable {
         return sqrt(((xDelta * xDelta) + (yDelta * yDelta) + (zDelta * zDelta)));
     }
 
-    @Override
     public double getVectorLength() {
         return sqrt(((x * x) + (y * y) + (z * z)));
     }
 
-    @Override
     public Point3D invert() {
         x = -x;
         y = -y;
@@ -131,7 +135,6 @@ public class Point3D extends Point2D implements Cloneable {
         z = z2 + center.z;
     }
 
-    @Override
     public void roundToInteger() {
         x = (int) x;
         y = (int) y;
@@ -158,9 +161,15 @@ public class Point3D extends Point2D implements Cloneable {
         this.z = z;
     }
 
-    public Point3D subtract(final Point3D direction) {
-        super.subtract(direction);
-        z -= direction.z;
+    /**
+     * Subtract other point from current point.
+     *
+     * @return current point.
+     */
+    public Point3D subtract(final Point3D otherPoint) {
+        x -= otherPoint.x;
+        y -= otherPoint.y;
+        z -= otherPoint.z;
         return this;
     }
 
@@ -169,36 +178,48 @@ public class Point3D extends Point2D implements Cloneable {
         return "x:" + x + " y:" + y + " z:" + z;
     }
 
+    /**
+     * @return current point.
+     */
     public Point3D translateX(final double xIncrement) {
         x += xIncrement;
         return this;
     }
 
+    /**
+     * @return current point.
+     */
     public Point3D translateY(final double yIncrement) {
         y += yIncrement;
         return this;
     }
 
+    /**
+     * @return current point.
+     */
     public Point3D translateZ(final double zIncrement) {
         z += zIncrement;
         return this;
     }
 
+    /**
+     * Here we assume that Z coordinate is distance to the viewer.
+     * If Z is positive, then point is in front of the viewer, and therefore it is visible.
+     *
+     * @return point visibility status.
+     */
     public boolean isVisible() {
-
-        if (z > 0)
-            return true;
-
-        // if ((z > 0) && (x > -1000) && (y > -1000) && (x < 2000) && (y <
-        // 2000))
-        // return true;
-
-        return false;
+        return z > 0;
     }
 
-    @Override
+    /**
+     * Resets point to 0 coordinate in X, Y and Z axis.
+     *
+     * @return current point.
+     */
     public Point3D zero() {
-        super.zero();
+        x = 0;
+        y = 0;
         z = 0;
         return this;
     }