Refactor comments

This commit is contained in:
2022-03-28 10:31:17 +02:00
parent dca869995a
commit fcacaa8657
9 changed files with 152 additions and 88 deletions

View File

@ -1,6 +1,8 @@
import codedraw.CodeDraw;
// This class represents vectors in a 3D vector space.
/**
* This class represents vectors in a 3D vector space.
*/
public class Vector3 {
private double x;
@ -21,7 +23,9 @@ public class Vector3 {
this.z = z;
}
// Returns the sum of this vector and vector 'v'.
/**
* Returns the sum of this vector and vector 'v'.
*/
public Vector3 plus(Vector3 v) {
Vector3 result = new Vector3();
result.x = x + v.x;
@ -30,7 +34,9 @@ public class Vector3 {
return result;
}
// Returns the product of this vector and 'd'.
/**
* Returns the product of this vector and 'd'.
*/
public Vector3 times(double d) {
Vector3 result = new Vector3();
result.x = x * d;
@ -39,7 +45,9 @@ public class Vector3 {
return result;
}
// Returns the sum of this vector and -1*v.
/**
* Returns the sum of this vector and -1*v.
*/
public Vector3 minus(Vector3 v) {
Vector3 result = new Vector3();
result.x = x - v.x;
@ -48,8 +56,10 @@ public class Vector3 {
return result;
}
// Returns the Euclidean distance of this vector
// to the specified vector 'v'.
/**
* Returns the Euclidean distance of this vector
* to the specified vector 'v'.
*/
public double distanceTo(Vector3 v) {
double dX = x - v.x;
double dY = y - v.y;
@ -57,13 +67,17 @@ public class Vector3 {
return Math.sqrt(dX * dX + dY * dY + dZ * dZ);
}
// Returns the length (norm) of this vector.
/**
* Returns the length (norm) of this vector.
*/
public double length() {
return distanceTo(new Vector3());
}
// Normalizes this vector: changes the length of this vector such that it becomes 1.
// The direction and orientation of the vector is not affected.
/**
* Normalizes this vector: changes the length of this vector such that it becomes 1.
* The direction and orientation of the vector is not affected.
*/
public void normalize() {
double length = length();
x /= length;
@ -71,8 +85,10 @@ public class Vector3 {
z /= length;
}
// Draws a filled circle with a specified radius centered at the (x,y) coordinates of this vector
// in the canvas associated with 'cd'. The z-coordinate is not used.
/**
* Draws a filled circle with a specified radius centered at the (x,y) coordinates of this vector
* in the canvas associated with 'cd'. The z-coordinate is not used.
*/
public void drawAsFilledCircle(CodeDraw cd, double radius) {
double x = cd.getWidth() * (this.x + Simulation.SECTION_SIZE / 2) / Simulation.SECTION_SIZE;
double y = cd.getWidth() * (this.y + Simulation.SECTION_SIZE / 2) / Simulation.SECTION_SIZE;
@ -80,11 +96,11 @@ public class Vector3 {
cd.fillCircle(x, y, Math.max(radius, 1.5));
}
// Returns the coordinates of this vector in brackets as a string
// in the form "[x,y,z]", e.g., "[1.48E11,0.0,0.0]".
/**
* Returns the coordinates of this vector in brackets as a string
* in the form "[x,y,z]", e.g., "[1.48E11,0.0,0.0]".
*/
public String toString() {
return String.format("[%f,%f,%f]", x, y, z);
}
}