Skip to content

Commit

Permalink
Add nor and len2 methods for vectors
Browse files Browse the repository at this point in the history
  • Loading branch information
XyperCode committed Jul 1, 2023
1 parent 690a493 commit d102683
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ public double dot(double v) {
return this.x * v + this.y * v;
}

public double len2 () {
return this.x * this.x + this.y * this.y;
}

public Vec2d nor () {
final double len2 = this.len2();
if (len2 == 0f || len2 == 1f) return this;
return this.mul(1f / (float)Math.sqrt(len2));
}

public double dst(Vec2d vec) {
double a = vec.x - this.x;
double b = vec.y - this.y;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ public float dot(float v) {
return this.x * v + this.y * v;
}

public float len2 () {
return this.x * this.x + this.y * this.y;
}

public Vec2f nor () {
final float len2 = this.len2();
if (len2 == 0f || len2 == 1f) return this;
return this.mul(1f / (float)Math.sqrt(len2));
}

public double dst(Vec2f vec) {
float a = vec.x - this.x;
float b = vec.y - this.y;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ public double dot(double v) {
return this.x * v + this.y * v + this.z * v;
}

public double len2 () {
return this.x * this.x + this.y * this.y + this.z * this.z;
}

public Vec3d nor () {
final double len2 = this.len2();
if (len2 == 0f || len2 == 1f) return this;
return this.mul(1f / (float)Math.sqrt(len2));
}

public double dst(Vec3d vec) {
double a = vec.x - this.x;
double b = vec.y - this.y;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ public float dot(float v) {
return this.x * v + this.y * v + this.z * v;
}

public float len2 () {
return this.x * this.x + this.y * this.y + this.z * this.z;
}

public Vec3f nor () {
final float len2 = this.len2();
if (len2 == 0f || len2 == 1f) return this;
return this.mul(1f / (float)Math.sqrt(len2));
}

public double dst(Vec3f vec) {
float a = vec.x - this.x;
float b = vec.y - this.y;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ public double dot(double v) {
return this.x * v + this.y * v + this.z * v + this.w * v;
}

public double len2 () {
return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
}

public Vec4d nor () {
final double len2 = this.len2();
if (len2 == 0f || len2 == 1f) return this;
return this.mul(1f / (float)Math.sqrt(len2));
}

public double dst(Vec4d vec) {
double a = vec.x - this.x;
double b = vec.y - this.y;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,16 @@ public float dot(float v) {
return this.x * v + this.y * v + this.z * v + this.w * v;
}

public float len2 () {
return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
}

public Vec4f nor () {
final float len2 = this.len2();
if (len2 == 0f || len2 == 1f) return this;
return this.mul(1f / (float)Math.sqrt(len2));
}

public double dst(Vec4f vec) {
float a = vec.x - this.x;
float b = vec.y - this.y;
Expand Down

0 comments on commit d102683

Please sign in to comment.