projects
/
sixth-3d.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Updated readability of the code.
[sixth-3d.git]
/
src
/
main
/
java
/
eu
/
svjatoslav
/
sixth
/
e3d
/
geometry
/
Point2D.java
diff --git
a/src/main/java/eu/svjatoslav/sixth/e3d/geometry/Point2D.java
b/src/main/java/eu/svjatoslav/sixth/e3d/geometry/Point2D.java
index
a82382f
..
c272047
100755
(executable)
--- a/
src/main/java/eu/svjatoslav/sixth/e3d/geometry/Point2D.java
+++ b/
src/main/java/eu/svjatoslav/sixth/e3d/geometry/Point2D.java
@@
-6,6
+6,9
@@
package eu.svjatoslav.sixth.e3d.geometry;
import static java.lang.Math.sqrt;
import static java.lang.Math.sqrt;
+/**
+ * Used to represent point in a 2D space or vector.
+ */
public class Point2D implements Cloneable {
public double x, y;
public class Point2D implements Cloneable {
public double x, y;
@@
-23,8
+26,9
@@
public class Point2D implements Cloneable {
y = parent.y;
}
y = parent.y;
}
+
/**
/**
- * Add other point to current point.
+ * Add other point to current point.
Value of other point will not be changed.
*
* @return current point.
*/
*
* @return current point.
*/
@@
-34,6
+38,9
@@
public class Point2D implements Cloneable {
return this;
}
return this;
}
+ /**
+ * @return true if current point coordinates are equal to zero.
+ */
public boolean isZero() {
return (x == 0) && (y == 0);
}
public boolean isZero() {
return (x == 0) && (y == 0);
}
@@
-43,12
+50,22
@@
public class Point2D implements Cloneable {
return new Point2D(this);
}
return new Point2D(this);
}
- public void clone(final Point2D parent) {
- x = parent.x;
- y = parent.y;
+ /**
+ * Copy coordinates from other point to current point. Value of other point will not be changed.
+ */
+ public void clone(final Point2D otherPoint) {
+ x = otherPoint.x;
+ y = otherPoint.y;
}
}
- public Point2D getMiddle(final Point2D p1, final Point2D p2) {
+ /**
+ * Set current point to middle of two other points.
+ *
+ * @param p1 first point.
+ * @param p2 second point.
+ * @return current point.
+ */
+ public Point2D setToMiddle(final Point2D p1, final Point2D p2) {
x = (p1.x + p2.x) / 2d;
y = (p1.y + p2.y) / 2d;
return this;
x = (p1.x + p2.x) / 2d;
y = (p1.y + p2.y) / 2d;
return this;
@@
-60,6
+77,9
@@
public class Point2D implements Cloneable {
/**
* Compute distance to another point.
/**
* Compute distance to another point.
+ *
+ * @param anotherPoint point to compute distance to.
+ * @return distance from current point to another point.
*/
public double getDistanceTo(final Point2D anotherPoint) {
final double xDiff = x - anotherPoint.x;
*/
public double getDistanceTo(final Point2D anotherPoint) {
final double xDiff = x - anotherPoint.x;
@@
-68,23
+88,35
@@
public class Point2D implements Cloneable {
return sqrt(((xDiff * xDiff) + (yDiff * yDiff)));
}
return sqrt(((xDiff * xDiff) + (yDiff * yDiff)));
}
+ /**
+ * Calculate length of vector.
+ * @return length of vector.
+ */
public double getVectorLength() {
return sqrt(((x * x) + (y * y)));
}
public double getVectorLength() {
return sqrt(((x * x) + (y * y)));
}
+ /**
+ * Invert current point.
+ *
+ * @return current point.
+ */
public Point2D invert() {
x = -x;
y = -y;
return this;
}
public Point2D invert() {
x = -x;
y = -y;
return this;
}
+ /**
+ * Round current point coordinates to integer.
+ */
public void roundToInteger() {
x = (int) x;
y = (int) y;
}
/**
public void roundToInteger() {
x = (int) x;
y = (int) y;
}
/**
- * Subtract other point from current point.
+ * Subtract other point from current point.
Value of other point will not be changed.
*
* @return current point.
*/
*
* @return current point.
*/
@@
-94,10
+126,21
@@
public class Point2D implements Cloneable {
return this;
}
return this;
}
+ /**
+ * Convert current point to 3D point.
+ * Value of the z coordinate will be set to zero.
+ *
+ * @return 3D point.
+ */
public Point3D to3D() {
return new Point3D(x, y, 0);
}
public Point3D to3D() {
return new Point3D(x, y, 0);
}
+ /**
+ * Set current point to zero.
+ *
+ * @return current point.
+ */
public Point2D zero() {
x = 0;
y = 0;
public Point2D zero() {
x = 0;
y = 0;