Skip to content

Commit d211c12

Browse files
author
kashike
committed
Add from helper methods
1 parent 02b0c07 commit d211c12

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+954
-0
lines changed

src/main/template/float/com/flowpowered/math/imaginary/Complex_E_.template

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,43 @@ public class Complex#E# implements Imaginary#E#, Comparable<Complex#E#>, Seriali
518518
return "(" + x + ", " + y + ")";
519519
}
520520

521+
/**
522+
* Creates a new complex from the #e# real component.
523+
*
524+
* <p>The {@link #ZERO} constant is re-used when {@code x} is 0.</p>
525+
*
526+
* @param x The x (real) component
527+
* @return The complex created from the #e# real component
528+
*/
529+
public static Complex#E# fromReal(#e# x) {
530+
return x == 0 ? ZERO : new Complex#E#(x, 0);
531+
}
532+
533+
/**
534+
* Creates a new quaternion from the #e# imaginary components.
535+
*
536+
* <p>The {@link #ZERO} constant is re-used when {@code y} is 0.</p>
537+
*
538+
* @param y The y (imaginary) component
539+
* @return The complex created from the #e# imaginary component
540+
*/
541+
public static Complex#E# fromImaginary(#e# y) {
542+
return y == 0 ? ZERO : new Complex#E#(0, y);
543+
}
544+
545+
/**
546+
* Creates a new complex from the #e# components.
547+
*
548+
* <p>The {@link #ZERO} constant is re-used when both {@code x} and {@code z} are 0.</p>
549+
*
550+
* @param x The x (real) component
551+
* @param y The y (imaginary) component
552+
* @return The complex created from the #e# components
553+
*/
554+
public static Complex#E# from(#e# x, #e# y) {
555+
return x == 0 && y == 0 ? ZERO : new Complex#E#(x, y);
556+
}
557+
521558
/**
522559
* Creates a new complex from the angle defined from the first to the second vector.
523560
*

src/main/template/float/com/flowpowered/math/imaginary/Quaternion_E_.template

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,47 @@ public class Quaternion#E# implements Imaginary#E#, Comparable<Quaternion#E#>, S
572572
return "(" + x + ", " + y + ", " + z + ", " + w + ")";
573573
}
574574

575+
/**
576+
* Creates a new quaternion from the #e# real component.
577+
*
578+
* <p>The {@link #ZERO} constant is re-used when {@code w} is 0.</p>
579+
*
580+
* @param w The w (real) component
581+
* @return The quaternion created from the #e# real component
582+
*/
583+
public static Quaternion#E# fromReal(#e# w) {
584+
return w == 0 ? ZERO : new Quaternion#E#(0, 0, 0, w);
585+
}
586+
587+
/**
588+
* Creates a new quaternion from the #e# imaginary components.
589+
*
590+
* <p>The {@link #ZERO} constant is re-used when {@code x}, {@code y}, and {@code z} are 0.</p>
591+
*
592+
* @param x The x (imaginary) component
593+
* @param y The y (imaginary) component
594+
* @param z The z (imaginary) component
595+
* @return The quaternion created from the #e# imaginary components
596+
*/
597+
public static Quaternion#E# fromImaginary(#e# x, #e# y, #e# z) {
598+
return x == 0 && y == 0 && z == 0 ? ZERO : new Quaternion#E#(x, y, z, 0);
599+
}
600+
601+
/**
602+
* Creates a new quaternion from the #e# components.
603+
*
604+
* <p>The {@link #ZERO} constant is re-used when {@code x}, {@code y}, {@code z}, and {@code w} are 0.</p>
605+
*
606+
* @param x The x (imaginary) component
607+
* @param y The y (imaginary) component
608+
* @param z The z (imaginary) component
609+
* @param w The w (real) component
610+
* @return The quaternion created from the #e# components
611+
*/
612+
public static Quaternion#E# from(#e# x, #e# y, #e# z, #e# w) {
613+
return x == 0 && y == 0 && z == 0 && w == 0 ? ZERO : new Quaternion#E#(x, y, z, w);
614+
}
615+
575616
/**
576617
* Creates a new quaternion from the #EOverload# angles in degrees around the x, y and z axes.
577618
*

src/main/template/float/com/flowpowered/math/matrix/Matrix2_E_.template

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,18 @@ public class Matrix2#E# implements Matrix#E#, Serializable, Cloneable {
350350
return new Matrix2#E#(this);
351351
}
352352

353+
public static Matrix2#E# from(#e# n) {
354+
return n == 0 ? ZERO : new Matrix2#E#(n, n, n, n);
355+
}
356+
357+
public static Matrix2#E# from(#e# m00, #e# m01, #e# m10, #e# m11) {
358+
return m00 == 0 && m01 == 0 && m10 == 0 && m11 == 0 ? ZERO : new Matrix2#E#(m00, m01, m10, m11);
359+
}
360+
361+
public static Matrix2#E# fromDiagonal(#e# m00, #e# m11) {
362+
return m00 == 0 && m11 == 0 ? ZERO : new Matrix2#E#(m00, 0, 0, m11);
363+
}
364+
353365
public static Matrix2#E# createScaling(#EOverload# scale) {
354366
return createScaling((#e#) scale);
355367
}

src/main/template/float/com/flowpowered/math/matrix/Matrix3_E_.template

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,23 @@ public class Matrix3#E# implements Matrix#E#, Serializable, Cloneable {
448448
return new Matrix3#E#(this);
449449
}
450450

451+
public static Matrix3#E# from(#e# n) {
452+
return n == 0 ? ZERO : new Matrix3#E#(n, n, n, n, n, n, n, n, n);
453+
}
454+
455+
public static Matrix3#E# from(#e# m00, #e# m01, #e# m02,
456+
#e# m10, #e# m11, #e# m12,
457+
#e# m20, #e# m21, #e# m22) {
458+
return m00 == 0 && m01 == 0 && m02 == 0
459+
&& m10 == 0 && m11 == 0 && m12 == 0
460+
&& m20 == 0 && m21 == 0 && m22 == 0
461+
? ZERO : new Matrix3#E#(m00, m01, m02, m10, m11, m12, m20, m21, m22);
462+
}
463+
464+
public static Matrix3#E# fromDiagonal(#e# m00, #e# m11, #e# m22) {
465+
return m00 == 0 && m11 == 0 && m22 == 0 ? ZERO : new Matrix3#E#(m00, 0, 0, 0, m11, 0, 0, 0, m22);
466+
}
467+
451468
public static Matrix3#E# createScaling(#EOverload# scale) {
452469
return createScaling((#e#) scale);
453470
}

src/main/template/float/com/flowpowered/math/matrix/Matrix4_E_.template

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,31 @@ public class Matrix4#E# implements Matrix#E#, Serializable, Cloneable {
570570
return new Matrix4#E#(this);
571571
}
572572

573+
public static Matrix4#E# from(#e# n) {
574+
return n == 0 ? ZERO : new Matrix4#E#(n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n);
575+
}
576+
577+
public static Matrix4#E# from(#e# m00, #e# m01, #e# m02, #e# m03,
578+
#e# m10, #e# m11, #e# m12, #e# m13,
579+
#e# m20, #e# m21, #e# m22, #e# m23,
580+
#e# m30, #e# m31, #e# m32, #e# m33) {
581+
return m00 == 0 && m01 == 0 && m02 == 0 && m03 == 0
582+
&& m10 == 0 && m11 == 0 && m12 == 0 && m13 == 0
583+
&& m20 == 0 && m21 == 0 && m22 == 0 && m23 == 0
584+
&& m30 == 0 && m31 == 0 && m32 == 0 && m33 == 0
585+
? ZERO : new Matrix4#E#(m00, m01, m02, m03,
586+
m10, m11, m12, m13,
587+
m20, m21, m22, m23,
588+
m30, m31, m32, m33);
589+
}
590+
591+
public static Matrix4#E# fromDiagonal(#e# m00, #e# m11, #e# m22, #e# m33) {
592+
return m00 == 0 && m11 == 0 && m22 == 0 && m33 == 0 ? ZERO : new Matrix4#E#(m00, 0, 0, 0,
593+
0, m11, 0, 0,
594+
0, 0, m22, 0,
595+
0, 0, 0, m33);
596+
}
597+
573598
public static Matrix4#E# createScaling(#EOverload# scale) {
574599
return createScaling((#e#) scale);
575600
}

src/main/template/float/com/flowpowered/math/vector/Vector2_E_.template

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,14 @@ public class Vector2#E# implements Vector#E#, Comparable<Vector2#E#>, Serializab
378378
return "(" + x + ", " + y + ")";
379379
}
380380

381+
public static Vector2#E# from(#e# n) {
382+
return n == 0 ? ZERO : new Vector2#E#(n, n);
383+
}
384+
385+
public static Vector2#E# from(#e# x, #e# y) {
386+
return x == 0 && y == 0 ? ZERO : new Vector2#E#(x, y);
387+
}
388+
381389
/**
382390
* Gets the direction vector of a random angle using the random specified.
383391
*

src/main/template/float/com/flowpowered/math/vector/Vector3_E_.template

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,14 @@ public class Vector3#E# implements Vector#E#, Comparable<Vector3#E#>, Serializab
412412
return "(" + x + ", " + y + ", " + z + ")";
413413
}
414414

415+
public static Vector3#E# from(#e# n) {
416+
return n == 0 ? ZERO : new Vector3#E#(n, n, n);
417+
}
418+
419+
public static Vector3#E# from(#e# x, #e# y, #e# z) {
420+
return x == 0 && y == 0 && z == 0 ? ZERO : new Vector3#E#(x, y, z);
421+
}
422+
415423
/**
416424
* Gets the direction vector of a random pitch and yaw using the random specified.
417425
*

src/main/template/float/com/flowpowered/math/vector/Vector4_E_.template

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,4 +432,12 @@ public class Vector4#E# implements Vector#E#, Comparable<Vector4#E#>, Serializab
432432
public String toString() {
433433
return "(" + x + ", " + y + ", " + z + ", " + w + ")";
434434
}
435+
436+
public static Vector4#E# from(#e# n) {
437+
return n == 0 ? ZERO : new Vector4#E#(n, n, n, n);
438+
}
439+
440+
public static Vector4#E# from(#e# x, #e# y, #e# z, #e# w) {
441+
return x == 0 && y == 0 && z == 0 && w == 0 ? ZERO : new Vector4#E#(x, y, z, w);
442+
}
435443
}

src/main/template/integer/com/flowpowered/math/vector/Vector2_E_.template

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,4 +342,12 @@ public class Vector2#E# implements Vector#E#, Comparable<Vector2#E#>, Serializab
342342
public String toString() {
343343
return "(" + x + ", " + y + ")";
344344
}
345+
346+
public static Vector2#E# from(#e# n) {
347+
return n == 0 ? ZERO : new Vector2#E#(n, n);
348+
}
349+
350+
public static Vector2#E# from(#e# x, #e# y) {
351+
return x == 0 && y == 0 ? ZERO : new Vector2#E#(x, y);
352+
}
345353
}

src/main/template/integer/com/flowpowered/math/vector/Vector3_E_.template

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,4 +373,12 @@ public class Vector3#E# implements Vector#E#, Comparable<Vector3#E#>, Serializab
373373
public String toString() {
374374
return "(" + x + ", " + y + ", " + z + ")";
375375
}
376+
377+
public static Vector3#E# from(#e# n) {
378+
return n == 0 ? ZERO : new Vector3#E#(n, n, n);
379+
}
380+
381+
public static Vector3#E# from(#e# x, #e# y, #e# z) {
382+
return x == 0 && y == 0 && z == 0 ? ZERO : new Vector3#E#(x, y, z);
383+
}
376384
}

0 commit comments

Comments
 (0)