File tree Expand file tree Collapse file tree 6 files changed +157
-0
lines changed
src/compas/geometry/shapes Expand file tree Collapse file tree 6 files changed +157
-0
lines changed Original file line number Diff line number Diff line change @@ -348,6 +348,24 @@ def scale(self, factor):
348348 self .radius *= factor
349349 self .height *= factor
350350
351+ def scaled (self , factor ):
352+ """Returns a scaled copy of the capsule.
353+
354+ Parameters
355+ ----------
356+ factor : float
357+ The scaling factor.
358+
359+ Returns
360+ -------
361+ :class:`compas.geometry.Capsule`
362+ The scaled capsule.
363+
364+ """
365+ capsule = self .copy ()
366+ capsule .scale (factor )
367+ return capsule
368+
351369 # =============================================================================
352370 # Methods
353371 # =============================================================================
Original file line number Diff line number Diff line change @@ -318,6 +318,24 @@ def scale(self, factor):
318318 self .radius *= factor
319319 self .height *= factor
320320
321+ def scaled (self , factor ):
322+ """Returns a scaled copy of the cylinder.
323+
324+ Parameters
325+ ----------
326+ factor : float
327+ The scaling factor.
328+
329+ Returns
330+ -------
331+ :class:`compas.geometry.Cylinder`
332+ The scaled cylinder.
333+
334+ """
335+ cylinder = self .copy ()
336+ cylinder .scale (factor )
337+ return cylinder
338+
321339 # =============================================================================
322340 # Methods
323341 # =============================================================================
Original file line number Diff line number Diff line change @@ -280,6 +280,24 @@ def scale(self, factor):
280280 """
281281 self .radius *= factor
282282
283+ def scaled (self , factor ):
284+ """Returns a scaled copy of the sphere.
285+
286+ Parameters
287+ ----------
288+ factor : float
289+ The scaling factor.
290+
291+ Returns
292+ -------
293+ :class:`compas.geometry.Sphere`
294+ The scaled sphere.
295+
296+ """
297+ sphere = self .copy ()
298+ sphere .scale (factor )
299+ return sphere
300+
283301 # =============================================================================
284302 # Methods
285303 # =============================================================================
Original file line number Diff line number Diff line change @@ -14,3 +14,39 @@ def test_capsule_discretization(capsule):
1414 assert capsule .edges
1515 assert capsule .faces
1616 assert capsule .vertices
17+
18+
19+ def test_capsule_scaled ():
20+ """Test that Capsule.scaled() returns a scaled copy without modifying the original."""
21+ capsule = Capsule (radius = 5.0 , height = 10.0 )
22+
23+ # Test uniform scaling
24+ scaled_capsule = capsule .scaled (0.5 )
25+
26+ # Original should be unchanged
27+ assert capsule .radius == 5.0
28+ assert capsule .height == 10.0
29+
30+ # Scaled copy should have scaled dimensions
31+ assert scaled_capsule .radius == 2.5
32+ assert scaled_capsule .height == 5.0
33+
34+ # Test scaling with factor > 1
35+ scaled_capsule_2 = capsule .scaled (2.0 )
36+ assert scaled_capsule_2 .radius == 10.0
37+ assert scaled_capsule_2 .height == 20.0
38+ assert capsule .radius == 5.0 # Original still unchanged
39+ assert capsule .height == 10.0
40+
41+
42+ def test_capsule_scale ():
43+ """Test that Capsule.scale() modifies the capsule in place."""
44+ capsule = Capsule (radius = 5.0 , height = 10.0 )
45+
46+ # Test uniform scaling
47+ capsule .scale (0.5 )
48+
49+ # Capsule should be modified
50+ assert capsule .radius == 2.5
51+ assert capsule .height == 5.0
52+
Original file line number Diff line number Diff line change @@ -13,3 +13,39 @@ def test_cylinder_discretization(cylinder):
1313 assert cylinder .edges
1414 assert cylinder .faces
1515 assert cylinder .vertices
16+
17+
18+ def test_cylinder_scaled ():
19+ """Test that Cylinder.scaled() returns a scaled copy without modifying the original."""
20+ cylinder = Cylinder (radius = 5.0 , height = 10.0 )
21+
22+ # Test uniform scaling
23+ scaled_cylinder = cylinder .scaled (0.5 )
24+
25+ # Original should be unchanged
26+ assert cylinder .radius == 5.0
27+ assert cylinder .height == 10.0
28+
29+ # Scaled copy should have scaled dimensions
30+ assert scaled_cylinder .radius == 2.5
31+ assert scaled_cylinder .height == 5.0
32+
33+ # Test scaling with factor > 1
34+ scaled_cylinder_2 = cylinder .scaled (2.0 )
35+ assert scaled_cylinder_2 .radius == 10.0
36+ assert scaled_cylinder_2 .height == 20.0
37+ assert cylinder .radius == 5.0 # Original still unchanged
38+ assert cylinder .height == 10.0
39+
40+
41+ def test_cylinder_scale ():
42+ """Test that Cylinder.scale() modifies the cylinder in place."""
43+ cylinder = Cylinder (radius = 5.0 , height = 10.0 )
44+
45+ # Test uniform scaling
46+ cylinder .scale (0.5 )
47+
48+ # Cylinder should be modified
49+ assert cylinder .radius == 2.5
50+ assert cylinder .height == 5.0
51+
Original file line number Diff line number Diff line change @@ -17,3 +17,34 @@ def test_sphere_discretization(sphere):
1717 assert len (sphere .edges ) == expected_edge_count
1818 assert len (sphere .faces ) == expected_face_count
1919 assert len (sphere .vertices ) == expected_vertex_count
20+
21+
22+ def test_sphere_scaled ():
23+ """Test that Sphere.scaled() returns a scaled copy without modifying the original."""
24+ sphere = Sphere (radius = 10.0 )
25+
26+ # Test uniform scaling
27+ scaled_sphere = sphere .scaled (0.5 )
28+
29+ # Original should be unchanged
30+ assert sphere .radius == 10.0
31+
32+ # Scaled copy should have scaled radius
33+ assert scaled_sphere .radius == 5.0
34+
35+ # Test scaling with factor > 1
36+ scaled_sphere_2 = sphere .scaled (2.0 )
37+ assert scaled_sphere_2 .radius == 20.0
38+ assert sphere .radius == 10.0 # Original still unchanged
39+
40+
41+ def test_sphere_scale ():
42+ """Test that Sphere.scale() modifies the sphere in place."""
43+ sphere = Sphere (radius = 10.0 )
44+
45+ # Test uniform scaling
46+ sphere .scale (0.5 )
47+
48+ # Sphere should be modified
49+ assert sphere .radius == 5.0
50+
You can’t perform that action at this time.
0 commit comments