Skip to content

Commit 9a744a3

Browse files
committed
Matrix scaling methods
1 parent dfa4f41 commit 9a744a3

File tree

6 files changed

+109
-9
lines changed

6 files changed

+109
-9
lines changed

src/main/scala/vecmatlib/matrix/Mat3d.scala

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,15 @@ object Mat3d {
263263
)
264264

265265
/**
266-
* Returns a 3x3 scaling matrix with the given scale.
266+
* Returns a 3x3 scaling matrix with the given scale on all three axes.
267+
*
268+
* @param scale Scale on all three axes
269+
* @return A 3x3 scaling matrix
270+
*/
271+
def scaling(scale: Double): Mat3d = scaling(scale, scale, scale)
272+
273+
/**
274+
* Returns a 3x3 scaling matrix with the given scale on the x and y axes and a scale of 1 on the z axis.
267275
*
268276
* @param x Scale on the x axis
269277
* @param y Scale on the y axis
@@ -280,10 +288,10 @@ object Mat3d {
280288
def scaling(v: Vec3d): Mat3d = scaling(v.x, v.y, v.z)
281289

282290
/**
283-
* Returns a 3x3 scaling matrix with the given scale.
291+
* Returns a 3x3 scaling matrix with the given scale on the x and y axes and a scale of 1 on the z axis.
284292
*
285293
* @param v The scale vector
286294
* @return A 3x3 scaling matrix
287295
*/
288-
def scaling(v: Vec2d): Mat3d = scaling(v.x, v.y, 1.0f)
296+
def scaling(v: Vec2d): Mat3d = scaling(v.x, v.y)
289297
}

src/main/scala/vecmatlib/matrix/Mat3f.scala

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,15 @@ object Mat3f {
263263
)
264264

265265
/**
266-
* Returns a 3x3 scaling matrix with the given scale.
266+
* Returns a 3x3 scaling matrix with the given scale on all three axes.
267+
*
268+
* @param scale Scale on all three axes
269+
* @return A 3x3 scaling matrix
270+
*/
271+
def scaling(scale: Float): Mat3f = scaling(scale, scale, scale)
272+
273+
/**
274+
* Returns a 3x3 scaling matrix with the given scale on the x and y axes and a scale of 1 on the z axis.
267275
*
268276
* @param x Scale on the x axis
269277
* @param y Scale on the y axis
@@ -280,7 +288,7 @@ object Mat3f {
280288
def scaling(v: Vec3f): Mat3f = scaling(v.x, v.y, v.z)
281289

282290
/**
283-
* Returns a 3x3 scaling matrix with the given scale.
291+
* Returns a 3x3 scaling matrix with the given scale on the x and y axes and a scale of 1 on the z axis.
284292
*
285293
* @param v The scale vector
286294
* @return A 3x3 scaling matrix

src/main/scala/vecmatlib/matrix/Mat4d.scala

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

3-
import vecmatlib.vector.{Vec3d, Vec4d}
3+
import vecmatlib.vector.{Vec2d, Vec3d, Vec4d}
44

55
/**
66
* 4x4 double matrix.
@@ -239,6 +239,15 @@ object Mat4d {
239239
0.0, 0.0, 0.0, 1.0
240240
)
241241

242+
/**
243+
* Returns a 4x4 translation matrix with the given translation on the x and y axes.
244+
*
245+
* @param x X component of the translation
246+
* @param y Y component of the translation
247+
* @return A 4x4 translation matrix
248+
*/
249+
def translation(x: Double, y: Double): Mat4d = translation(x, y, 0.0)
250+
242251
/**
243252
* Returns a 4x4 translation matrix with the given translation.
244253
*
@@ -247,6 +256,14 @@ object Mat4d {
247256
*/
248257
def translation(v: Vec3d): Mat4d = translation(v.x, v.y, v.z)
249258

259+
/**
260+
* Returns a 4x4 translation matrix with the given translation on the x and y axes.
261+
*
262+
* @param v The translation vector
263+
* @return A 4x4 translation matrix
264+
*/
265+
def translation(v: Vec2d): Mat4d = translation(v.x, v.y)
266+
250267
/**
251268
* Returns a 4x4 rotation matrix with the given rotation on the x axis.
252269
*
@@ -319,11 +336,36 @@ object Mat4d {
319336
0.0, 0.0, 0.0, 1.0
320337
)
321338

339+
/**
340+
* Returns a 4x4 scaling matrix with the given scale on all three axes.
341+
*
342+
* @param scale Scale on all three axes
343+
* @return A 4x4 scaling matrix
344+
*/
345+
def scaling(scale: Double): Mat4d = scaling(scale, scale, scale)
346+
347+
/**
348+
* Returns a 4x4 scaling matrix with the given scale on the x and y axes and a scale of 1 on the z axis.
349+
*
350+
* @param x Scale on the x axis
351+
* @param y Scale on the y axis
352+
* @return A 4x4 scaling matrix
353+
*/
354+
def scaling(x: Double, y: Double): Mat4d = scaling(x, y, 1.0)
355+
322356
/**
323357
* Returns a 4x4 scaling matrix with the given scale.
324358
*
325359
* @param v The scale vector
326360
* @return A 4x4 scaling matrix
327361
*/
328362
def scaling(v: Vec3d): Mat4d = scaling(v.x, v.y, v.z)
363+
364+
/**
365+
* Returns a 4x4 scaling matrix with the given scale on the x and y axes and a scale of 1 on the z axis.
366+
*
367+
* @param v The scale vector
368+
* @return A 4x4 scaling matrix
369+
*/
370+
def scaling(v: Vec2d): Mat4d = scaling(v.x, v.y)
329371
}

src/main/scala/vecmatlib/matrix/Mat4f.scala

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

3-
import vecmatlib.vector.{Vec3f, Vec4f}
3+
import vecmatlib.vector.{Vec2f, Vec3f, Vec4f}
44

55
/**
66
* 4x4 float matrix.
@@ -239,6 +239,15 @@ object Mat4f {
239239
0.0f, 0.0f, 0.0f, 1.0f
240240
)
241241

242+
/**
243+
* Returns a 4x4 translation matrix with the given translation on the x and y axes.
244+
*
245+
* @param x X component of the translation
246+
* @param y Y component of the translation
247+
* @return A 4x4 translation matrix
248+
*/
249+
def translation(x: Float, y: Float): Mat4f = translation(x, y, 0.0f)
250+
242251
/**
243252
* Returns a 4x4 translation matrix with the given translation.
244253
*
@@ -247,6 +256,14 @@ object Mat4f {
247256
*/
248257
def translation(v: Vec3f): Mat4f = translation(v.x, v.y, v.z)
249258

259+
/**
260+
* Returns a 4x4 translation matrix with the given translation on the x and y axes.
261+
*
262+
* @param v The translation vector
263+
* @return A 4x4 translation matrix
264+
*/
265+
def translation(v: Vec2f): Mat4f = translation(v.x, v.y)
266+
250267
/**
251268
* Returns a 4x4 rotation matrix with the given rotation on the x axis.
252269
*
@@ -319,11 +336,36 @@ object Mat4f {
319336
0.0f, 0.0f, 0.0f, 1.0f
320337
)
321338

339+
/**
340+
* Returns a 4x4 scaling matrix with the given scale on all three axes.
341+
*
342+
* @param scale Scale on all three axes
343+
* @return A 4x4 scaling matrix
344+
*/
345+
def scaling(scale: Float): Mat4f = scaling(scale, scale, scale)
346+
347+
/**
348+
* Returns a 4x4 scaling matrix with the given scale on the x and y axes and a scale of 1 on the z axis.
349+
*
350+
* @param x Scale on the x axis
351+
* @param y Scale on the y axis
352+
* @return A 4x4 scaling matrix
353+
*/
354+
def scaling(x: Float, y: Float): Mat4f = scaling(x, y, 1.0f)
355+
322356
/**
323357
* Returns a 4x4 scaling matrix with the given scale.
324358
*
325359
* @param v The scale vector
326360
* @return A 4x4 scaling matrix
327361
*/
328362
def scaling(v: Vec3f): Mat4f = scaling(v.x, v.y, v.z)
363+
364+
/**
365+
* Returns a 4x4 scaling matrix with the given scale on the x and y axes and a scale of 1 on the z axis.
366+
*
367+
* @param v The scale vector
368+
* @return A 4x4 scaling matrix
369+
*/
370+
def scaling(v: Vec2f): Mat4f = scaling(v.x, v.y)
329371
}

src/test/scala/vecmatlib/matrix/Mat2fSuite.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package vecmatlib.matrix
22

33
import org.scalatest.funsuite.AnyFunSuite
4-
import vecmatlib.vector.{Vec2f, Vec3f}
4+
import vecmatlib.vector.Vec2f
55

66
class Mat2fSuite extends AnyFunSuite {
77

src/test/scala/vecmatlib/matrix/Mat3fSuite.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package vecmatlib.matrix
22

33
import org.scalatest.funsuite.AnyFunSuite
4-
import vecmatlib.vector.{Vec3d, Vec3f, Vec3i}
4+
import vecmatlib.vector.Vec3f
55

66
class Mat3fSuite extends AnyFunSuite {
77

0 commit comments

Comments
 (0)