Skip to content

Commit

Permalink
Overload vector4 math (#15)
Browse files Browse the repository at this point in the history
* Add math functions to Vector4

* Version bump
  • Loading branch information
kjy5 authored Mar 21, 2024
1 parent 8f33c60 commit bda7509
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
name: Build

on:
pull_request:
push:
branches:
- main
merge_group:

jobs:
build:
Expand All @@ -27,6 +29,7 @@ jobs:
run: python src/vbl_aquarium/build.py

- name: 📤 PR changes
if: github.ref == 'refs/heads/main'
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.PR_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion src/vbl_aquarium/__about__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.0.8"
__version__ = "0.0.9"
24 changes: 24 additions & 0 deletions src/vbl_aquarium/models/unity.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,27 @@ class Vector4(BaseModel):
y: float = 0.0
z: float = 0.0
w: float = 0.0

def __add__(self, other):
if isinstance(other, Vector4):
return Vector4(x=self.x + other.x, y=self.y + other.y, z=self.z + other.z, w=self.w + other.w)
error = f"unsupported operand type(s) for +: 'Vector4' and '{type(other)}'"
raise TypeError(error)

def __sub__(self, other):
if isinstance(other, Vector4):
return Vector4(x=self.x - other.x, y=self.y - other.y, z=self.z - other.z, w=self.w - other.w)
error = f"unsupported operand type(s) for -: 'Vector4' and '{type(other)}'"
raise TypeError(error)

def __mul__(self, other):
if isinstance(other, (int, float)):
return Vector4(x=self.x * other, y=self.y * other, z=self.z * other, w=self.w * other)
error = f"unsupported operand type(s) for *: 'Vector4' and '{type(other)}'"
raise TypeError(error)

def __truediv__(self, other):
if isinstance(other, (int, float)):
return Vector4(x=self.x / other, y=self.y / other, z=self.z / other, w=self.w / other)
error = f"unsupported operand type(s) for /: 'Vector4' and '{type(other)}'"
raise TypeError(error)

0 comments on commit bda7509

Please sign in to comment.