Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sourcery refactored master branch #207

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

sourcery-ai[bot]
Copy link

@sourcery-ai sourcery-ai bot commented Mar 19, 2022

Branch master refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

To manually merge these changes, make sure you're on the master branch, then run:

git fetch origin sourcery/master
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@@ -37,6 +37,7 @@

"""Script to render latex figure for each equation found in readme.md"""

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 52-52 refactored with the following changes:

Comment on lines -64 to +83
latexfile = open(laxtex_tmp_file, "w")
latexfile.write("\\documentclass[preview]{standalone}")
# latexfile.write('\\input{header.tex}')
latexfile.write("\\usepackage{wasysym}")
latexfile.write("\\usepackage{amssymb}")
latexfile.write("\n\\begin{document}")
latexfile.write(" %s" % formula)
latexfile.write("\n\\end{document} ")
latexfile.close()
with open(laxtex_tmp_file, "w") as latexfile:
latexfile.write("\\documentclass[preview]{standalone}")
# latexfile.write('\\input{header.tex}')
latexfile.write("\\usepackage{wasysym}")
latexfile.write("\\usepackage{amssymb}")
latexfile.write("\n\\begin{document}")
latexfile.write(f" {formula}")
latexfile.write("\n\\end{document} ")
os.system('pdflatex -output-directory="%s" %s' % (dirpath, laxtex_tmp_file))
if file.startswith("https://rawgithub.com") or file.startswith(
"https://raw.githack.com"
):
file = "./" + re.findall(r"""/master/(.*)""", file)[0]
if file[-3:] == "svg":
os.system("pdf2svg %s %s" % (pdf_tmp_file, file))
os.system(f"pdf2svg {pdf_tmp_file} {file}")
elif file[-3:] == "pdf":
shutil.copyfile(pdf_tmp_file, file)
else:
os.system("convert -density 100 %s -quality 90 %s" % (pdf_tmp_file, file))
os.system(f"convert -density 100 {pdf_tmp_file} -quality 90 {file}")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function formula_as_file refactored with the following changes:

Comment on lines -94 to +97
raise Exception("equation image file %s already used" % eqn[1])
raise Exception(f"equation image file {eqn[1]} already used")

listname.add(eqn[1])
print("creating %s" % eqn[1])
print(f"creating {eqn[1]}")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 94-97 refactored with the following changes:

@@ -1,5 +1,6 @@
"""Setup script for the DEODR project."""

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 30-31 refactored with the following changes:

Comment on lines -26 to +27
assert not (image is None)
assert not (z_buffer is None)
assert image is not None
assert z_buffer is not None
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function renderScene refactored with the following changes:

  • Simplify logical expression using De Morgan identities (de-morgan)

if self.clockwise:
n = -np.cross(u, v)
else:
n = np.cross(u, v)
n = -np.cross(u, v) if self.clockwise else np.cross(u, v)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TriMeshAdjacencies.compute_face_normals refactored with the following changes:

Comment on lines -145 to +142
face_normals_b = self._vertices_faces.T * n_b
return face_normals_b
return self._vertices_faces.T * n_b
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TriMeshAdjacencies.compute_vertex_normals_backward refactored with the following changes:

Comment on lines -155 to +151
if self.clockwise:
face_visible = np.cross(u, v) > 0
else:
face_visible = np.cross(u, v) < 0
face_visible = np.cross(u, v) > 0 if self.clockwise else np.cross(u, v) < 0
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TriMeshAdjacencies.edge_on_silhouette refactored with the following changes:

Comment on lines -191 to +185
if self.vertices is not None:

if self.adjacencies.is_closed:
self.check_orientation()
if self.vertices is not None and self.adjacencies.is_closed:
self.check_orientation()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TriMesh.compute_adjacencies refactored with the following changes:

Comment on lines -286 to +280
self.textured = not (self.texture is None)
self.textured = self.texture is not None
self.nb_colors = nb_colors
if nb_colors is None:
if texture is None:
self.nb_colors = colors.shape[1]
else:
self.nb_colors = texture.shape[2]
self.nb_colors = colors.shape[1] if texture is None else texture.shape[2]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ColoredTriMesh.__init__ refactored with the following changes:

  • Simplify logical expression using De Morgan identities (de-morgan)
  • Replace if statement with if expression (assign-if-exp)

Comment on lines -433 to -436
trimesh_mesh = trimesh.Trimesh(
return trimesh.Trimesh(
vertices=new_vertices, faces=new_faces, visual=visual
)
return trimesh_mesh
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ColoredTriMesh.to_trimesh refactored with the following changes:

Comment on lines -83 to +92
if display:
cv2.imshow("animation", cv2.resize(combined_image, None, fx=2, fy=2))
if save_images:
imsave(
os.path.join(iterfolder, f"depth_hand_iter_{niter}.png"),
combined_image,
)
if display:
cv2.imshow("animation", cv2.resize(combined_image, None, fx=2, fy=2))
if save_images:
imsave(
os.path.join(iterfolder, f"depth_hand_iter_{niter}.png"),
combined_image,
)
cv2.waitKey(1)

with open(
os.path.join(
iterfolder,
"depth_image_fitting_result_%s.json"
% str(datetime.datetime.now()).replace(":", "_"),
),
"w",
) as f:
with open(os.path.join(iterfolder, f'depth_image_fitting_result_{str(datetime.datetime.now()).replace(":", "_")}.json'), "w") as f:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function run refactored with the following changes:

Comment on lines -135 to +151
if self.mode in ["camera_centered", "object_centered_trackball"]:
if np.abs(self.y_last - y) >= np.abs(self.x_last - x):
self.camera.extrinsic[2, 3] += self.z_translation_speed * (
self.y_last - y
)
else:
self.rotate(
[
0,
0,
-self.rotation_speed * (self.x_last - x),
]
)
self.x_last = x
self.y_last = y
if self.mode not in ["camera_centered", "object_centered_trackball"]:
raise (BaseException(f"unknown camera mode {self.mode}"))

if np.abs(self.y_last - y) >= np.abs(self.x_last - x):
self.camera.extrinsic[2, 3] += self.z_translation_speed * (
self.y_last - y
)
else:
raise (BaseException(f"unknown camera mode {self.mode}"))
self.rotate(
[
0,
0,
-self.rotation_speed * (self.x_last - x),
]
)
self.x_last = x
self.y_last = y
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Interactor.mouse_callback refactored with the following changes:

Comment on lines -174 to +173
help_str = ""
help_str += "Mouse:\n"
help_str = "" + "Mouse:\n"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Interactor.print_help refactored with the following changes:

Comment on lines -432 to +428
help_str = ""
help_str += "-----------------\n"
help_str = "" + "-----------------\n"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Viewer.print_help refactored with the following changes:

Comment on lines -89 to +85
self.textured = not (self.texture is None)
self.textured = self.texture is not None
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ColoredTriMeshPytorch.__init__ refactored with the following changes:

  • Simplify logical expression using De Morgan identities (de-morgan)

if self.clockwise:
n = -tf.linalg.cross(u, v)
else:
n = tf.linalg.cross(u, v)
n = -tf.linalg.cross(u, v) if self.clockwise else tf.linalg.cross(u, v)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TriMeshAdjacenciesTensorflow.compute_face_normals refactored with the following changes:

Comment on lines -71 to +68
self.textured = not (self.texture is None)
self.textured = self.texture is not None
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ColoredTriMeshTensorflow.__init__ refactored with the following changes:

  • Simplify logical expression using De Morgan identities (de-morgan)

Comment on lines +31 to +33
eps = 0.001

clockwise = True
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function test_upper_left_pixel_center_coordinates refactored with the following changes:

if not os.name == "nt": # did not manage to install mesa on windows github action
if os.name != "nt": # did not manage to install mesa on windows github action
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function test_render_mesh_moderngl refactored with the following changes:

  • Simplify logical expression using De Morgan identities (de-morgan)

@sourcery-ai
Copy link
Author

sourcery-ai bot commented Mar 19, 2022

Sourcery Code Quality Report

Merging this PR leaves code quality unchanged.

Quality metrics Before After Change
Complexity 5.35 ⭐ 5.10 ⭐ -0.25 👍
Method Length 87.08 🙂 86.72 🙂 -0.36 👍
Working memory 12.47 😞 12.54 😞 0.07 👎
Quality 57.08% 🙂 57.08% 🙂 0.00%
Other metrics Before After Change
Lines 4238 4161 -77
Changed files Quality Before Quality After Quality Change
create_latex_images.py 75.33% ⭐ 74.38% 🙂 -0.95% 👎
setup.py 52.91% 🙂 53.03% 🙂 0.12% 👍
deodr/differentiable_renderer.py 49.79% 😞 49.89% 😞 0.10% 👍
deodr/mesh_fitter.py 64.97% 🙂 64.93% 🙂 -0.04% 👎
deodr/tools.py 71.96% 🙂 72.06% 🙂 0.10% 👍
deodr/triangulated_mesh.py 63.43% 🙂 63.23% 🙂 -0.20% 👎
deodr/examples/depth_image_hand_fitting.py 32.49% 😞 33.75% 😞 1.26% 👍
deodr/examples/mesh_viewer.py 64.89% 🙂 64.83% 🙂 -0.06% 👎
deodr/examples/rgb_image_hand_fitting.py 32.21% 😞 33.47% 😞 1.26% 👍
deodr/examples/rgb_multiview_hand.py 28.69% 😞 30.22% 😞 1.53% 👍
deodr/examples/triangle_soup_fitting.py 34.25% 😞 34.72% 😞 0.47% 👍
deodr/opengl/moderngl.py 66.32% 🙂 66.64% 🙂 0.32% 👍
deodr/opengl/pyrender.py 66.22% 🙂 64.97% 🙂 -1.25% 👎
deodr/pytorch/triangulated_mesh_pytorch.py 84.54% ⭐ 85.55% ⭐ 1.01% 👍
deodr/tensorflow/triangulated_mesh_tensorflow.py 85.38% ⭐ 86.31% ⭐ 0.93% 👍
tests/test_pixel_center_coordinates.py 36.97% 😞 36.97% 😞 0.00%
tests/test_render_mesh.py 71.77% 🙂 71.79% 🙂 0.02% 👍

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
deodr/differentiable_renderer.py Scene3D.render_deferred 17 🙂 535 ⛔ 25 ⛔ 19.93% ⛔ Try splitting into smaller methods. Extract out complex expressions
deodr/examples/mesh_viewer.py Interactor.mouse_callback 26 😞 441 ⛔ 15 😞 20.98% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
deodr/examples/rgb_image_hand_fitting.py run 18 🙂 539 ⛔ 16 ⛔ 24.64% ⛔ Try splitting into smaller methods. Extract out complex expressions
deodr/examples/depth_image_hand_fitting.py run 18 🙂 437 ⛔ 16 ⛔ 25.22% 😞 Try splitting into smaller methods. Extract out complex expressions
deodr/examples/triangle_soup_fitting.py run 11 🙂 388 ⛔ 26 ⛔ 25.84% 😞 Try splitting into smaller methods. Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Help us improve this quality report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0 participants