johnzero7 / XNALaraMesh

Blender addon Import/Export XPS Models, Poses
536 stars 94 forks source link

Simplify bin_ops.roundToMultiple Routine #42

Closed ldo closed 4 years ago

ldo commented 5 years ago

The bin_ops.roundToMultiple routine can be shortened as follows:

diff --git a/bin_ops.py b/bin_ops.py
index b8109ee..fc3d1cc 100644
--- a/bin_ops.py
+++ b/bin_ops.py
@@ -21,10 +21,7 @@ class TypeFormat:

 def roundToMultiple(numToRound, multiple):
-    remainder = numToRound % multiple
-    if (remainder == 0):
-        return numToRound
-    return numToRound + multiple - remainder
+    return (numToRound + multiple - 1) // multiple * multiple

Actually, given that it is only used to round to multiples of xps_const.ROUND_MULTIPLE, which is 4, it could be simplified even further.