Skip to content

Commit

Permalink
Add math functions to Vector4
Browse files Browse the repository at this point in the history
  • Loading branch information
kjy5 committed Mar 21, 2024
1 parent 8f33c60 commit 929ed80
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
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
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 929ed80

Please sign in to comment.