-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from Quafadas/scalarOps
Some simple scalar ops
- Loading branch information
Showing
5 changed files
with
120 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import ai.dragonfly.math.vector.Vec | ||
|
||
|
||
inline def assertVecEquals[N <: Int](inline v1: Vec[N], inline v2: Vec[N])(implicit loc: munit.Location): Unit = { | ||
var i: Int = 0; | ||
while (i < v1.dimension) { | ||
munit.Assertions.assertEquals(v1(i), v2(i)) | ||
i += 1 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import ai.dragonfly.math.vector.* | ||
import narr.* | ||
|
||
|
||
|
||
class SimpleOps extends munit.FunSuite: | ||
|
||
test("vector addition") { | ||
val v1 = Vec[2](1.5, 2.5) | ||
val v2 = Vec[2](2.5, 3.5) | ||
val vResult = Vec[2](4.0, 6.0) | ||
assertVecEquals(v1 + v2, vResult ) | ||
} | ||
test("vector subtraction") { | ||
val v1 = Vec[2](1.5, 2.5) | ||
val v2 = Vec[2](2.5, 3.5) | ||
|
||
val vResult = Vec[2](-1.0, -1.0) | ||
assertVecEquals(v1 - v2, vResult ) | ||
} | ||
|
||
|
||
test("scalar addition") { | ||
val v1 = Vec[3](1.5, 2.5, 3.5) | ||
val vResult = Vec[3](2.5, 3.5, 4.5) | ||
|
||
assertVecEquals( v1 + 1, vResult ) | ||
} | ||
|
||
test("scalar negation") { | ||
val v1 = Vec[3](1.5, 2.5, 3.5) | ||
val vResult = Vec[3](0.5, 1.5, 2.5) | ||
|
||
assertVecEquals( v1 - 1.0, vResult ) | ||
} | ||
|
||
test("scalar multiplication") { | ||
val v1 = Vec[3](1.5, 2.5, 3.5) | ||
val vResult = Vec[3](3.0, 5.0, 7.0) | ||
|
||
assertVecEquals( v1 * 2.0, vResult ) | ||
} | ||
|
||
test("scalar division") { | ||
val v1 = Vec[3](1.5, 2.5, 3.5) | ||
val vResult = Vec[3](0.75, 1.25, 1.75 ) | ||
|
||
assertVecEquals( v1 / 2.0, vResult ) | ||
} | ||
|
||
test("scalar min") { | ||
val v1 = Vec[3](1.5, 2.5, 3.5) | ||
val vResult = Vec[3](1.5, 2.0, 2.0 ) | ||
println( min(v1 , 2.0).csv() ) | ||
assertVecEquals( min(v1 , 2.0), vResult ) | ||
} | ||
|
||
test("scalar max") { | ||
val v1 = Vec[3](1.5, 2.5, 3.5) | ||
val vResult = Vec[3](2.0, 2.5, 3.5 ) | ||
assertVecEquals( max(v1 , 2.0), vResult ) | ||
} | ||
|
||
end SimpleOps | ||
|