Skip to content

Commit

Permalink
Scale/scaled
Browse files Browse the repository at this point in the history
  • Loading branch information
gonzalocasas committed Oct 15, 2024
1 parent 805b968 commit 7959604
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

* Fixed `RuntimeError` when using `compas_rhino.unload_modules` in CPython`.
* Fixed `scaled` in `Box`.
* Changed argument names of `Box.scale()` to `x`, `y`, `z`, instead of `factor` and made `y` and `z` optional to keep positional arguments backwards compatible.

### Removed

Expand Down
24 changes: 14 additions & 10 deletions src/compas/geometry/shapes/box.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,22 +558,29 @@ def to_brep(self):
# self.ysize *= scaley
# self.zsize *= scalez

def scale(self, factor):
def scale(self, x, y=None, z=None):
"""Scale the box.
Parameters
----------
factor : float
The scaling factor.
x : float
The scaling factor in x-direction. If no other factor is specified,
this factor will be used for all directions.
y : float, optional
The scaling factor in the y-direction.
Defaults to ``x``.
z : float, optional
The scaling factor in the z-direction.
Defaults to ``x``.
Returns
-------
None
"""
self.xsize *= factor
self.ysize *= factor
self.zsize *= factor
self.xsize *= x
self.ysize *= y if y is not None else x
self.zsize *= z if z is not None else x

def scaled(self, x, y=None, z=None):
"""Returns a scaled copy of the box.
Expand All @@ -591,10 +598,7 @@ def scaled(self, x, y=None, z=None):
"""
box = self.copy()
box.xsize *= x
box.ysize *= y if y is not None else x
box.zsize *= z if z is not None else x

box.scale(x, y, z)
return box

# ==========================================================================
Expand Down
3 changes: 3 additions & 0 deletions tests/compas/geometry/test_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ def test_box_scale(default_box):

def test_box_scaled(default_box):
new_box = default_box.scaled(2.0, 4.0, 2.0)
assert default_box.xsize == 1.0
assert default_box.ysize == 2.0
assert default_box.zsize == 3.0
assert new_box.xsize == 2.0
assert new_box.ysize == 8.0
assert new_box.zsize == 6.0

0 comments on commit 7959604

Please sign in to comment.