BlenderProc icon indicating copy to clipboard operation
BlenderProc copied to clipboard

Increase the usage of augmented assignment statements

Open elfring opened this issue 4 years ago • 0 comments

:eyes: Some source code analysis tools can help to find opportunities for improving software components. :thought_balloon: I propose to increase the usage of augmented assignment statements accordingly.

diff --git a/blenderproc/python/camera/CameraUtility.py b/blenderproc/python/camera/CameraUtility.py
index f8ceca16..943a0000 100644
--- a/blenderproc/python/camera/CameraUtility.py
+++ b/blenderproc/python/camera/CameraUtility.py
@@ -55,7 +55,7 @@ def rotation_from_forward_vec(forward_vec: Union[np.ndarray, Vector], up_axis: s
     """
     rotation_matrix = Vector(forward_vec).to_track_quat('-Z', up_axis).to_matrix()
     if inplane_rot is not None:
-        rotation_matrix = rotation_matrix @ Euler((0.0, 0.0, inplane_rot)).to_matrix()
+        rotation_matrix @= Euler((0.0, 0.0, inplane_rot)).to_matrix()
     return np.array(rotation_matrix)
 
 
diff --git a/blenderproc/python/camera/LensDistortionUtility.py b/blenderproc/python/camera/LensDistortionUtility.py
index 37a5836d..21c3037f 100644
--- a/blenderproc/python/camera/LensDistortionUtility.py
+++ b/blenderproc/python/camera/LensDistortionUtility.py
@@ -143,8 +143,8 @@ def set_lens_distortion(k1: float, k2: float, k3: float = 0.0, p1: float = 0.0,
                 raise Exception("The iterative distortion algorithm is unstable.")
 
         # update undistorted projection
-        x = x - (x_ - P_und[0, :])  # * factor
-        y = y - (y_ - P_und[1, :])  # * factor
+        x -= (x_ - P_und[0, :])  # * factor
+        y -= (y_ - P_und[1, :])  # * factor
 
     # u and v are now the pixel coordinates on the undistorted image that
     # will distort into the row,column coordinates of the distorted image
diff --git a/blenderproc/python/modules/materials/RockEssentialsTextureSampler.py b/blenderproc/python/modules/materials/RockEssentialsTextureSampler.py
index d43972bf..943697d4 100644
--- a/blenderproc/python/modules/materials/RockEssentialsTextureSampler.py
+++ b/blenderproc/python/modules/materials/RockEssentialsTextureSampler.py
@@ -224,4 +224,4 @@ def _set_textures(self, ground_tile, images, uv_scaling, ambient_occlusion, disp
 
         # and scale the texture
         for point in ground_tile.data.uv_layers.active.data[:]:
-            point.uv = point.uv * uv_scaling
+            point.uv *= uv_scaling
diff --git a/blenderproc/python/modules/provider/getter/Attribute.py b/blenderproc/python/modules/provider/getter/Attribute.py
index ebc293f0..f437c067 100644
--- a/blenderproc/python/modules/provider/getter/Attribute.py
+++ b/blenderproc/python/modules/provider/getter/Attribute.py
@@ -201,6 +201,6 @@ def _avg(self, raw_result):
         :return: The average value of all values of the input list.
         """
         ref_result = self._sum(raw_result)
-        ref_result = ref_result/float(len(raw_result))
+        ref_result /=float(len(raw_result))
 
         return ref_result
diff --git a/blenderproc/python/modules/provider/getter/AttributeMerger.py b/blenderproc/python/modules/provider/getter/AttributeMerger.py
index 09440834..ac13f8ac 100644
--- a/blenderproc/python/modules/provider/getter/AttributeMerger.py
+++ b/blenderproc/python/modules/provider/getter/AttributeMerger.py
@@ -153,6 +153,6 @@ def _avg(self, raw_result):
         :return: The average value of all values of the input list.
         """
         ref_result = self._sum(raw_result)
-        ref_result = ref_result/float(len(raw_result))
+        ref_result /=float(len(raw_result))
 
         return ref_result
diff --git a/blenderproc/python/modules/writer/Hdf5Writer.py b/blenderproc/python/modules/writer/Hdf5Writer.py
index 17ad8171..11c62b5b 100644
--- a/blenderproc/python/modules/writer/Hdf5Writer.py
+++ b/blenderproc/python/modules/writer/Hdf5Writer.py
@@ -77,7 +77,7 @@ def run(self):
                     # Build path (path attribute is format string)
                     file_path = output_type["path"]
                     if '%' in file_path:
-                        file_path = file_path % frame
+                        file_path %= frame
 
                     # Check if file exists
                     if not os.path.exists(file_path):
diff --git a/blenderproc/python/sampler/UpperRegionSampler.py b/blenderproc/python/sampler/UpperRegionSampler.py
index 5a6228cd..454b5501 100644
--- a/blenderproc/python/sampler/UpperRegionSampler.py
+++ b/blenderproc/python/sampler/UpperRegionSampler.py
@@ -66,7 +66,7 @@ def calc_vec_and_normals(face: List[np.ndarray]) -> Tuple[Tuple[np.ndarray, np.n
         vec1 = face[1] - face[0]
         vec2 = face[3] - face[0]
         normal = np.cross(vec1, vec2)
-        normal = normal / np.linalg.norm(normal)
+        normal /= np.linalg.norm(normal)
         return (vec1, vec2), normal
 
     # determine for each object in objects the region, where to sample on
diff --git a/blenderproc/python/writer/CocoWriterUtility.py b/blenderproc/python/writer/CocoWriterUtility.py
index 14061a00..29361ea8 100644
--- a/blenderproc/python/writer/CocoWriterUtility.py
+++ b/blenderproc/python/writer/CocoWriterUtility.py
@@ -451,7 +451,7 @@ def binary_mask_to_polygon(binary_mask: np.ndarray, tolerance: int = 0) -> List[
         padded_binary_mask = np.pad(binary_mask, pad_width=1, mode='constant', constant_values=0)
         contours = np.array(measure.find_contours(padded_binary_mask, 0.5))
         # Reverse padding
-        contours = contours - 1
+        contours -= 1
         for contour in contours:
             # Make sure contour is closed
             contour = CocoWriterUtility.close_contour(contour)
diff --git a/docs/change_csv_tables_docu.py b/docs/change_csv_tables_docu.py
index e377d688..439d4fc7 100644
--- a/docs/change_csv_tables_docu.py
+++ b/docs/change_csv_tables_docu.py
@@ -154,7 +154,7 @@ def add_description(self, line):
             line = first_part + line[line.rfind(self.ele_type) + len(self.ele_type)+1:]
         else:
             line = line[line.find("\"")+1: line.rfind("\"")].strip()
-        self.description = self.description + " " + line
+        self.description += " " + line
         self.description = self.description.replace("  ", " ")
 
     def set_default(self, line):

elfring avatar Nov 23 '21 21:11 elfring