Skip to content

Commit e9dbd0f

Browse files
committed
Added convenience methods for matrices
1 parent 43cc430 commit e9dbd0f

File tree

3 files changed

+65
-1
lines changed

3 files changed

+65
-1
lines changed

src/main/scala/io/github/hexagonnico/vecmatlib/matrix/Mat4d.scala

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,16 @@ case class Mat4d(
131131
*/
132132
override def *(v: Vec4d): Vec4d = Vec4d(this.row0 dot v, this.row1 dot v, this.row2 dot v, this.row3 dot v)
133133

134+
/**
135+
* Returns the product of this matrix by the given vector.
136+
* Allows a more convenient way to multiply vectors by transformation matrices.
137+
*
138+
* @param v The X, Y, and Z components of the vector by which this matrix is multiplied
139+
* @param w The W component of the vector by which this matrix is multiplied
140+
* @return The product of this matrix by the given vector
141+
*/
142+
def *(v: Vec3d, w: Double): Vec4d = this * (v.x, v.y, v.z, w)
143+
134144
/**
135145
* Returns the product of this matrix by the vector with the given components.
136146
*
@@ -153,6 +163,18 @@ case class Mat4d(
153163
*/
154164
def multiply(x: Double, y: Double, z: Double, w: Double): Vec4d = this * Vec4d(x, y, z, w)
155165

166+
/**
167+
* Returns the product of this matrix by the given vector.
168+
* Allows a more convenient way to multiply vectors by transformation matrices.
169+
*
170+
* This method can be used in place of the '*' operator for better interoperability with Java.
171+
*
172+
* @param v The X, Y, and Z components of the vector by which this matrix is multiplied
173+
* @param w The W component of the vector by which this matrix is multiplied
174+
* @return The product of this matrix by the given vector
175+
*/
176+
def multiply(v: Vec3d, w: Double): Vec4d = this * (v, w)
177+
156178
/**
157179
* Returns the product between this matrix and the given one.
158180
*

src/main/scala/io/github/hexagonnico/vecmatlib/matrix/Mat4f.scala

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,16 @@ case class Mat4f(
131131
*/
132132
override def *(v: Vec4f): Vec4f = Vec4f(this.row0 dot v, this.row1 dot v, this.row2 dot v, this.row3 dot v)
133133

134+
/**
135+
* Returns the product of this matrix by the given vector.
136+
* Allows a more convenient way to multiply vectors by transformation matrices.
137+
*
138+
* @param v The X, Y, and Z components of the vector by which this matrix is multiplied
139+
* @param w The W component of the vector by which this matrix is multiplied
140+
* @return The product of this matrix by the given vector
141+
*/
142+
def *(v: Vec3f, w: Float): Vec4f = this * (v.x, v.y, v.z, w)
143+
134144
/**
135145
* Returns the product of this matrix by the vector with the given components.
136146
*
@@ -153,6 +163,18 @@ case class Mat4f(
153163
*/
154164
def multiply(x: Float, y: Float, z: Float, w: Float): Vec4f = this * Vec4f(x, y, z, w)
155165

166+
/**
167+
* Returns the product of this matrix by the given vector.
168+
* Allows a more convenient way to multiply vectors by transformation matrices.
169+
*
170+
* This method can be used in place of the '*' operator for better interoperability with Java.
171+
*
172+
* @param v The X, Y, and Z components of the vector by which this matrix is multiplied
173+
* @param w The W component of the vector by which this matrix is multiplied
174+
* @return The product of this matrix by the given vector
175+
*/
176+
def multiply(v: Vec3f, w: Float): Vec4f = this * (v, w)
177+
156178
/**
157179
* Returns the product between this matrix and the given one.
158180
*

src/main/scala/io/github/hexagonnico/vecmatlib/matrix/Mat4i.scala

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package io.github.hexagonnico.vecmatlib.matrix
22

3-
import io.github.hexagonnico.vecmatlib.vector.Vec4i
3+
import io.github.hexagonnico.vecmatlib.vector.{Vec3i, Vec4i}
44

55
/**
66
* 4x4 int matrix.
@@ -131,6 +131,15 @@ case class Mat4i(
131131
*/
132132
override def *(v: Vec4i): Vec4i = Vec4i(this.row0 dot v, this.row1 dot v, this.row2 dot v, this.row3 dot v)
133133

134+
/**
135+
* Returns the product of this matrix by the given vector.
136+
*
137+
* @param v The X, Y, and Z components of the vector by which this matrix is multiplied
138+
* @param w The W component of the vector by which this matrix is multiplied
139+
* @return The product of this matrix by the given vector
140+
*/
141+
def *(v: Vec3i, w: Int): Vec4i = this * (v.x, v.y, v.z, w)
142+
134143
/**
135144
* Returns the product of this matrix by the vector with the given components.
136145
*
@@ -153,6 +162,17 @@ case class Mat4i(
153162
*/
154163
def multiply(x: Int, y: Int, z: Int, w: Int): Vec4i = this * Vec4i(x, y, z, w)
155164

165+
/**
166+
* Returns the product of this matrix by the given vector.
167+
*
168+
* This method can be used in place of the '*' operator for better interoperability with Java.
169+
*
170+
* @param v The X, Y, and Z components of the vector by which this matrix is multiplied
171+
* @param w The W component of the vector by which this matrix is multiplied
172+
* @return The product of this matrix by the given vector
173+
*/
174+
def multiply(v: Vec3i, w: Int): Vec4i = this * (v, w)
175+
156176
/**
157177
* Returns the product between this matrix and the given one.
158178
*

0 commit comments

Comments
 (0)