Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion prettyvec.nimble
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[Package]
name = "prettyvec"
author = "prettybauble"
version = "1.0.0"
version = "1.0.1"
description = "Small library for working with vectors"
license = "MIT"
srcDir = "src"
Expand Down
4 changes: 4 additions & 0 deletions src/prettyvec/vec2/vec2_math.nim
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ func `*`*(a, b: Vec2Obj): Vec2Obj =
vec2(a.x * b.x, a.y * b.y)


func `-`*(a: Vec2Obj): Vec2Obj =
## Negates the vector
vec2(-a.x, -a.y)

func `-`*(a: Vec2Obj, b: float): Vec2Obj =
vec2(a.x - b, a.y - b)

Expand Down
4 changes: 4 additions & 0 deletions src/prettyvec/vec3/vec3_math.nim
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ func `*`*(a, b: Vec3Obj): Vec3Obj =
vec3(a.x * b.x, a.y * b.y, a.z * b.z)


func `-`*(a: Vec3Obj): Vec3Obj =
## Negates the vector
vec3(-a.x, -a.y, -a.z)

func `-`*(a: Vec3Obj, b: float): Vec3Obj =
vec3(a.x - b, a.y - b, a.z - b)

Expand Down
4 changes: 4 additions & 0 deletions tests/test1.nim
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ suite "Vec2":
assert vec2(1) - 5 == vec2(-4)
assert vec2(1) / 5 == vec2(0.2)

assert -vec2(1, -2) == vec2(-1, 2)

test "basic math":
assert sqrt(vec2(4)) == vec2(2)
assert pow(vec2(2), 3) == vec2(8, 8)
Expand All @@ -42,6 +44,8 @@ suite "Vec3":
assert vec3(1) - 5 == vec3(-4)
assert vec3(1) / 5 == vec3(0.2)

assert -vec3(1, -2, 3) == vec3(-1, 2, -3)

test "basic math":
assert sqrt(vec3(4)) == vec3(2)
assert pow(vec3(4), 3) == vec3(64)
Expand Down