Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

* Updated minimum library version to `2.14.1` in Rhino8 GH components.
* Changed name of YAK package from `bluejay` to `compas`.
* Fixed broken `scaled()` method in `Sphere`, `Cylinder`, and `Capsule` classes by overriding to accept uniform scaling factor.

### Removed

Expand Down
18 changes: 18 additions & 0 deletions src/compas/geometry/shapes/capsule.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,24 @@ def scale(self, factor):
self.radius *= factor
self.height *= factor

def scaled(self, factor):
"""Returns a scaled copy of the capsule.

Parameters
----------
factor : float
The scaling factor.

Returns
-------
:class:`compas.geometry.Capsule`
The scaled capsule.

"""
capsule = self.copy()
capsule.scale(factor)
return capsule

# =============================================================================
# Methods
# =============================================================================
Expand Down
18 changes: 18 additions & 0 deletions src/compas/geometry/shapes/cylinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,24 @@ def scale(self, factor):
self.radius *= factor
self.height *= factor

def scaled(self, factor):
"""Returns a scaled copy of the cylinder.

Parameters
----------
factor : float
The scaling factor.

Returns
-------
:class:`compas.geometry.Cylinder`
The scaled cylinder.

"""
cylinder = self.copy()
cylinder.scale(factor)
return cylinder

# =============================================================================
# Methods
# =============================================================================
Expand Down
18 changes: 18 additions & 0 deletions src/compas/geometry/shapes/sphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,24 @@ def scale(self, factor):
"""
self.radius *= factor

def scaled(self, factor):
"""Returns a scaled copy of the sphere.

Parameters
----------
factor : float
The scaling factor.

Returns
-------
:class:`compas.geometry.Sphere`
The scaled sphere.

"""
sphere = self.copy()
sphere.scale(factor)
return sphere

# =============================================================================
# Methods
# =============================================================================
Expand Down
36 changes: 36 additions & 0 deletions tests/compas/geometry/test_capsule.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,39 @@ def test_capsule_discretization(capsule):
assert capsule.edges
assert capsule.faces
assert capsule.vertices


def test_capsule_scaled():
"""Test that Capsule.scaled() returns a scaled copy without modifying the original."""
capsule = Capsule(radius=5.0, height=10.0)

# Test uniform scaling
scaled_capsule = capsule.scaled(0.5)

# Original should be unchanged
assert capsule.radius == 5.0
assert capsule.height == 10.0

# Scaled copy should have scaled dimensions
assert scaled_capsule.radius == 2.5
assert scaled_capsule.height == 5.0

# Test scaling with factor > 1
scaled_capsule_2 = capsule.scaled(2.0)
assert scaled_capsule_2.radius == 10.0
assert scaled_capsule_2.height == 20.0
assert capsule.radius == 5.0 # Original still unchanged
assert capsule.height == 10.0


def test_capsule_scale():
"""Test that Capsule.scale() modifies the capsule in place."""
capsule = Capsule(radius=5.0, height=10.0)

# Test uniform scaling
capsule.scale(0.5)

# Capsule should be modified
assert capsule.radius == 2.5
assert capsule.height == 5.0

36 changes: 36 additions & 0 deletions tests/compas/geometry/test_cylinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,39 @@ def test_cylinder_discretization(cylinder):
assert cylinder.edges
assert cylinder.faces
assert cylinder.vertices


def test_cylinder_scaled():
"""Test that Cylinder.scaled() returns a scaled copy without modifying the original."""
cylinder = Cylinder(radius=5.0, height=10.0)

# Test uniform scaling
scaled_cylinder = cylinder.scaled(0.5)

# Original should be unchanged
assert cylinder.radius == 5.0
assert cylinder.height == 10.0

# Scaled copy should have scaled dimensions
assert scaled_cylinder.radius == 2.5
assert scaled_cylinder.height == 5.0

# Test scaling with factor > 1
scaled_cylinder_2 = cylinder.scaled(2.0)
assert scaled_cylinder_2.radius == 10.0
assert scaled_cylinder_2.height == 20.0
assert cylinder.radius == 5.0 # Original still unchanged
assert cylinder.height == 10.0


def test_cylinder_scale():
"""Test that Cylinder.scale() modifies the cylinder in place."""
cylinder = Cylinder(radius=5.0, height=10.0)

# Test uniform scaling
cylinder.scale(0.5)

# Cylinder should be modified
assert cylinder.radius == 2.5
assert cylinder.height == 5.0

31 changes: 31 additions & 0 deletions tests/compas/geometry/test_shpere.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,34 @@ def test_sphere_discretization(sphere):
assert len(sphere.edges) == expected_edge_count
assert len(sphere.faces) == expected_face_count
assert len(sphere.vertices) == expected_vertex_count


def test_sphere_scaled():
"""Test that Sphere.scaled() returns a scaled copy without modifying the original."""
sphere = Sphere(radius=10.0)

# Test uniform scaling
scaled_sphere = sphere.scaled(0.5)

# Original should be unchanged
assert sphere.radius == 10.0

# Scaled copy should have scaled radius
assert scaled_sphere.radius == 5.0

# Test scaling with factor > 1
scaled_sphere_2 = sphere.scaled(2.0)
assert scaled_sphere_2.radius == 20.0
assert sphere.radius == 10.0 # Original still unchanged


def test_sphere_scale():
"""Test that Sphere.scale() modifies the sphere in place."""
sphere = Sphere(radius=10.0)

# Test uniform scaling
sphere.scale(0.5)

# Sphere should be modified
assert sphere.radius == 5.0

Loading