Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9296df8

Browse files
authored
Merge pull request #24985 from oscargus/deprecateproj3d
Deprecate unused/undocumented functions in proj3d
2 parents 1ad6cbf + dc4eb43 commit 9296df8

File tree

6 files changed

+64
-23
lines changed

6 files changed

+64
-23
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Functions in ``mpl_toolkits.mplot3d.proj3d``
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
The function ``transform`` is just an alias for ``proj_transform``,
5+
use the latter instead.
6+
7+
The following functions are either unused (so no longer required in Matplotlib)
8+
or considered private. If you rely on them, please make a copy of the code,
9+
including all functions that starts with a ``_`` (considered private).
10+
11+
* ``ortho_transformation``
12+
* ``persp_transformation``
13+
* ``proj_points``
14+
* ``proj_trans_points``
15+
* ``rot_x``
16+
* ``rotation_about_vector``
17+
* ``view_transformation``

lib/mpl_toolkits/mplot3d/art3d.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def set_3d_properties(self, z=0, zdir='z'):
148148
@artist.allow_rasterization
149149
def draw(self, renderer):
150150
position3d = np.array((self._x, self._y, self._z))
151-
proj = proj3d.proj_trans_points(
151+
proj = proj3d._proj_trans_points(
152152
[position3d, position3d + self._dir_vec], self.axes.M)
153153
dx = proj[0][1] - proj[0][0]
154154
dy = proj[1][1] - proj[1][0]
@@ -359,7 +359,7 @@ def do_3d_projection(self):
359359
"""
360360
Project the points according to renderer matrix.
361361
"""
362-
xyslist = [proj3d.proj_trans_points(points, self.axes.M)
362+
xyslist = [proj3d._proj_trans_points(points, self.axes.M)
363363
for points in self._segments3d]
364364
segments_2d = [np.column_stack([xs, ys]) for xs, ys, zs in xyslist]
365365
LineCollection.set_segments(self, segments_2d)

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ def _tunit_cube(self, vals=None, M=None):
249249
if M is None:
250250
M = self.M
251251
xyzs = self._unit_cube(vals)
252-
tcube = proj3d.proj_points(xyzs, M)
252+
tcube = proj3d._proj_points(xyzs, M)
253253
return tcube
254254

255255
@_api.deprecated("3.7")
@@ -918,15 +918,15 @@ def get_proj(self):
918918
if self._focal_length == np.inf:
919919
# Orthographic projection
920920
viewM = proj3d._view_transformation_uvw(u, v, w, eye)
921-
projM = proj3d.ortho_transformation(-self._dist, self._dist)
921+
projM = proj3d._ortho_transformation(-self._dist, self._dist)
922922
else:
923923
# Perspective projection
924924
# Scale the eye dist to compensate for the focal length zoom effect
925925
eye_focal = R + self._dist * ps * self._focal_length
926926
viewM = proj3d._view_transformation_uvw(u, v, w, eye_focal)
927-
projM = proj3d.persp_transformation(-self._dist,
928-
self._dist,
929-
self._focal_length)
927+
projM = proj3d._persp_transformation(-self._dist,
928+
self._dist,
929+
self._focal_length)
930930

931931
# Combine all the transformation matrices to get the final projection
932932
M0 = np.dot(viewM, worldM)

lib/mpl_toolkits/mplot3d/axis3d.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ def draw(self, renderer):
367367

368368
# Project the edge points along the current position and
369369
# create the line:
370-
pep = proj3d.proj_trans_points([edgep1, edgep2], self.axes.M)
370+
pep = proj3d._proj_trans_points([edgep1, edgep2], self.axes.M)
371371
pep = np.asarray(pep)
372372
self.line.set_data(pep[0], pep[1])
373373
self.line.draw(renderer)

lib/mpl_toolkits/mplot3d/proj3d.py

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import numpy as np
66
import numpy.linalg as linalg
77

8+
from matplotlib import _api
9+
810

911
def _line2d_seg_dist(p, s0, s1):
1012
"""
@@ -51,7 +53,15 @@ def world_transformation(xmin, xmax,
5153
[0, 0, 0, 1]])
5254

5355

56+
@_api.deprecated("3.8")
5457
def rotation_about_vector(v, angle):
58+
"""
59+
Produce a rotation matrix for an angle in radians about a vector.
60+
"""
61+
return _rotation_about_vector(v, angle)
62+
63+
64+
def _rotation_about_vector(v, angle):
5565
"""
5666
Produce a rotation matrix for an angle in radians about a vector.
5767
"""
@@ -101,7 +111,7 @@ def _view_axes(E, R, V, roll):
101111
# Save some computation for the default roll=0
102112
if roll != 0:
103113
# A positive rotation of the camera is a negative rotation of the world
104-
Rroll = rotation_about_vector(w, -roll)
114+
Rroll = _rotation_about_vector(w, -roll)
105115
u = np.dot(Rroll, u)
106116
v = np.dot(Rroll, v)
107117
return u, v, w
@@ -130,6 +140,7 @@ def _view_transformation_uvw(u, v, w, E):
130140
return M
131141

132142

143+
@_api.deprecated("3.8")
133144
def view_transformation(E, R, V, roll):
134145
"""
135146
Return the view transformation matrix.
@@ -150,7 +161,12 @@ def view_transformation(E, R, V, roll):
150161
return M
151162

152163

164+
@_api.deprecated("3.8")
153165
def persp_transformation(zfront, zback, focal_length):
166+
return _persp_transformation(zfront, zback, focal_length)
167+
168+
169+
def _persp_transformation(zfront, zback, focal_length):
154170
e = focal_length
155171
a = 1 # aspect ratio
156172
b = (zfront+zback)/(zfront-zback)
@@ -162,7 +178,12 @@ def persp_transformation(zfront, zback, focal_length):
162178
return proj_matrix
163179

164180

181+
@_api.deprecated("3.8")
165182
def ortho_transformation(zfront, zback):
183+
return _ortho_transformation(zfront, zback)
184+
185+
186+
def _ortho_transformation(zfront, zback):
166187
# note: w component in the resulting vector will be (zback-zfront), not 1
167188
a = -(zfront + zback)
168189
b = -(zfront - zback)
@@ -218,7 +239,9 @@ def proj_transform(xs, ys, zs, M):
218239
return _proj_transform_vec(vec, M)
219240

220241

221-
transform = proj_transform
242+
transform = _api.deprecated(
243+
"3.8", obj_type="function", name="transform",
244+
alternative="proj_transform")(proj_transform)
222245

223246

224247
def proj_transform_clip(xs, ys, zs, M):
@@ -231,15 +254,26 @@ def proj_transform_clip(xs, ys, zs, M):
231254
return _proj_transform_vec_clip(vec, M)
232255

233256

257+
@_api.deprecated("3.8")
234258
def proj_points(points, M):
235-
return np.column_stack(proj_trans_points(points, M))
259+
return _proj_points(points, M)
260+
236261

262+
def _proj_points(points, M):
263+
return np.column_stack(_proj_trans_points(points, M))
237264

265+
266+
@_api.deprecated("3.8")
238267
def proj_trans_points(points, M):
268+
return _proj_trans_points(points, M)
269+
270+
271+
def _proj_trans_points(points, M):
239272
xs, ys, zs = zip(*points)
240273
return proj_transform(xs, ys, zs, M)
241274

242275

276+
@_api.deprecated("3.8")
243277
def rot_x(V, alpha):
244278
cosa, sina = np.cos(alpha), np.sin(alpha)
245279
M1 = np.array([[1, 0, 0, 0],

lib/mpl_toolkits/mplot3d/tests/test_axes3d.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,7 @@ def _test_proj_make_M():
10161016
roll = 0
10171017
u, v, w = proj3d._view_axes(E, R, V, roll)
10181018
viewM = proj3d._view_transformation_uvw(u, v, w, E)
1019-
perspM = proj3d.persp_transformation(100, -100, 1)
1019+
perspM = proj3d._persp_transformation(100, -100, 1)
10201020
M = np.dot(perspM, viewM)
10211021
return M
10221022

@@ -1083,7 +1083,7 @@ def test_proj_axes_cube_ortho():
10831083
roll = 0
10841084
u, v, w = proj3d._view_axes(E, R, V, roll)
10851085
viewM = proj3d._view_transformation_uvw(u, v, w, E)
1086-
orthoM = proj3d.ortho_transformation(-1, 1)
1086+
orthoM = proj3d._ortho_transformation(-1, 1)
10871087
M = np.dot(orthoM, viewM)
10881088

10891089
ts = '0 1 2 3 0 4 5 6 7 4'.split()
@@ -1104,16 +1104,6 @@ def test_proj_axes_cube_ortho():
11041104
ax.set_ylim(-200, 200)
11051105

11061106

1107-
def test_rot():
1108-
V = [1, 0, 0, 1]
1109-
rotated_V = proj3d.rot_x(V, np.pi / 6)
1110-
np.testing.assert_allclose(rotated_V, [1, 0, 0, 1])
1111-
1112-
V = [0, 1, 0, 1]
1113-
rotated_V = proj3d.rot_x(V, np.pi / 6)
1114-
np.testing.assert_allclose(rotated_V, [0, np.sqrt(3) / 2, 0.5, 1])
1115-
1116-
11171107
def test_world():
11181108
xmin, xmax = 100, 120
11191109
ymin, ymax = -100, 100

0 commit comments

Comments
 (0)