You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Optimized Axes.coords_to_point
* Changed variable name to are_coordinates_transposed and added more commentaries
* Added some commas to the tuple in the last comment in Axes.coords_to_pointC
# if called like coords_to_point(1, 2, 3), then coords is a 1x3 array
2005
-
transposed=False
2006
-
ifcoords.ndim==1:
2007
-
# original implementation of coords_to_point for performance in the legacy case
2008
-
result=np.array(origin)
2009
-
foraxis, numberinzip(self.get_axes(), coords):
2010
-
result+=axis.number_to_point(number) -origin
2011
-
returnresult
2012
-
# if called like coords_to_point([1, 2, 3],[4, 5, 6]), then it shall be used as [1,4], [2,5], [3,6] and return the points as ([x_0,x_1],[y_0,y_1],[z_0,z_1])
2013
-
elifcoords.ndim==2:
2014
-
coords=coords.T
2015
-
transposed=True
2016
-
# if called like coords_to_point(np.array([[1, 2, 3],[4,5,6]])), reduce dimension by 1
2017
-
elifcoords.ndim==3:
2018
-
coords=np.squeeze(coords)
2019
-
# else the coords is a Nx1, Nx2, Nx3 array so we do not need to modify the array
2020
-
2021
-
points=origin+np.sum(
2022
-
[
2023
-
axis.number_to_point(number) -origin
2024
-
fornumber, axisinzip(coords.T, self.get_axes())
2025
-
],
2026
-
axis=0,
2027
-
)
2028
-
# if called with single coord, then return a point instead of a list of points
2029
-
iftransposed:
2030
-
returnpoints.T
2031
-
returnpoints
2003
+
# Is coords in the format ([[x1 y1 z1] [x2 y2 z2] ...])? (True)
2004
+
# Or is coords in the format (x, y, z) or ([x1 x2 ...], [y1 y2 ...], [z1 z2 ...])? (False)
2005
+
# The latter is preferred.
2006
+
are_coordinates_transposed=False
2007
+
2008
+
# If coords is in the format ([[x1 y1 z1] [x2 y2 z2] ...]):
2009
+
ifcoords.ndim==3:
2010
+
# Extract from original tuple: now coords looks like [[x y z]] or [[x1 y1 z1] [x2 y2 z2] ...].
2011
+
coords=coords[0]
2012
+
# If there's a single coord (coords = [[x y z]]), extract it so that
2013
+
# coords = [x y z] and coords_to_point returns a single point.
2014
+
ifcoords.shape[0] ==1:
2015
+
coords=coords[0]
2016
+
# Else, if coords looks more like [[x1 y1 z1] [x2 y2 z2] ...], transform them (by
2017
+
# transposing) into the format [[x1 x2 ...] [y1 y2 ...] [z1 z2 ...]] for later processing.
2018
+
else:
2019
+
coords=coords.T
2020
+
are_coordinates_transposed=True
2021
+
# Otherwise, coords already looked like (x, y, z) or ([x1 x2 ...], [y1 y2 ...], [z1 z2 ...]),
2022
+
# so no further processing is needed.
2023
+
2024
+
# Now coords should either look like [x y z] or [[x1 x2 ...] [y1 y2 ...] [z1 z2 ...]],
2025
+
# so it can be iterated directly. Each element is either a float representing a single
2026
+
# coordinate, or a float ndarray of coordinates corresponding to a single axis.
2027
+
# Although "points" and "nums" are in plural, there might be a single point or number.
2028
+
points=self.x_axis.number_to_point(coords[0])
2029
+
other_axes=self.axes.submobjects[1:]
2030
+
foraxis, numsinzip(other_axes, coords[1:]):
2031
+
points+=axis.number_to_point(nums) -origin
2032
+
2033
+
# Return points as is, except if coords originally looked like
2034
+
# ([x1 x2 ...], [y1 y2 ...], [z1 z2 ...]), which is determined by the conditions below. In
2035
+
# that case, the current implementation requires that the results have to be transposed.
0 commit comments