Skip to content

Commit 25ad14b

Browse files
committed
Added more arithmetic Vector operations
1 parent 201f9e1 commit 25ad14b

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

src/core/modules/mathlib/mathlib.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,18 @@ class VectorExt
8282
copy.NormalizeInPlace();
8383
return copy;
8484
}
85+
86+
static inline Vector __add__(Vector vecCopy, float val)
87+
{
88+
vecCopy += val;
89+
return vecCopy;
90+
}
91+
92+
static inline Vector __sub__(Vector vecCopy, float val)
93+
{
94+
vecCopy -= val;
95+
return vecCopy;
96+
}
8597
};
8698

8799

src/core/modules/mathlib/mathlib_wrap.cpp

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,29 @@ void export_vector(scope _mathlib)
132132

133133
.def(self == self)
134134
.def(self != self)
135+
135136
.def(self += self)
136137
.def(self -= self)
137138
.def(self *= self)
138-
.def(self *= float())
139139
.def(self /= self)
140-
.def(self /= float())
140+
141141
.def(self += float())
142142
.def(self -= float())
143+
.def(self *= float())
144+
.def(self /= float())
145+
146+
.def(self + self)
147+
.def(self - self)
148+
.def(self * self)
149+
.def(self / self)
150+
151+
.def("__add__", &VectorExt::__add__)
152+
.def("__sub__", &VectorExt::__sub__)
153+
.def(self * float())
154+
.def(self / float())
155+
156+
.def("__radd__", &VectorExt::__add__)
157+
.def(float() * self)
143158

144159
.def("negate",
145160
&Vector::Negate,
@@ -228,13 +243,6 @@ void export_vector(scope _mathlib)
228243
"Returns the vector's 2D length as a square product."
229244
)
230245

231-
.def(self + self)
232-
.def(self - self)
233-
.def(self * self)
234-
.def(self / self)
235-
.def(self * float())
236-
.def(self / float())
237-
238246
.def("cross",
239247
&Vector::Cross,
240248
"Returns the cross product between two vectors.",

0 commit comments

Comments
 (0)