Skip to content

Commit d491677

Browse files
Fixed bug in patch_euclid.set_length(); it was only operating on x & y, but not z. How didn't this break anything years ago? Also, patched Vector2 class as well as Vector3
1 parent bae18ae commit d491677

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

solid/patch_euclid.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,31 @@
11
import euclid3
2-
from euclid3 import *
2+
from euclid3 import Vector3, Vector2, Line3
33

44
# NOTE: The PyEuclid on PyPi doesn't include several elements added to
55
# the module as of 13 Feb 2013. Add them here until euclid supports them
66

7-
def as_arr_local(self):
7+
def as_arr_local2(self):
8+
return [self.x, self.y]
9+
10+
def as_arr_local3(self):
811
return [self.x, self.y, self.z]
912

10-
def set_length_local(self, length):
13+
def set_length_local2(self, length):
14+
d = self.magnitude()
15+
if d:
16+
factor = length / d
17+
self.x *= factor
18+
self.y *= factor
19+
20+
return self
21+
22+
def set_length_local3(self, length):
1123
d = self.magnitude()
1224
if d:
1325
factor = length / d
1426
self.x *= factor
1527
self.y *= factor
28+
self.z *= factor
1629

1730
return self
1831

@@ -30,8 +43,14 @@ def _intersect_line3_line3(A, B):
3043

3144
def run_euclid_patch():
3245
if 'as_arr' not in dir(Vector3):
33-
Vector3.as_arr = as_arr_local
46+
Vector3.as_arr = as_arr_local3
47+
if 'as_arr' not in dir(Vector2):
48+
Vector2.as_arr = as_arr_local2
49+
3450
if 'set_length' not in dir(Vector3):
35-
Vector3.set_length = set_length_local
51+
Vector3.set_length = set_length_local3
52+
if 'set_length' not in dir(Vector2):
53+
Vector2.set_length = set_length_local2
54+
3655
if '_intersect_line3' not in dir(Line3):
3756
Line3._intersect_line3 = _intersect_line3_line3

0 commit comments

Comments
 (0)