-
Notifications
You must be signed in to change notification settings - Fork 54
Labels
bugSomething isn't workingSomething isn't workingsectionsDevelopment of sectionsDevelopment of sections
Description
Hi, I found some little bug when computing gross_properties for a section whose geometry is a MultiPolygon (e.g. disconnected rectangles), an AttributeError is raised because MultiPolygon has no exterior attribute. It’s a minor thing and I don’t think it’s necessary to create a new PR for this.
Location
structuralcodes/sections/_generic.py, method _calculate_gross_section_properties,
Problematic code
if isinstance(polygon, MultiPolygon):
gp.perimeter = 0.0
warnings.warn(
'Perimiter computation for a multi polygon is not defined.'
)
gp.perimeter = polygon.exterior.length # ← Always executed; fails with MultiPolygon
The if block sets gp.perimeter = 0.0 for MultiPolygon, but the next line always runs and accesses polygon.exterior, which does not exist on MultiPolygon.
Proposed fix
if isinstance(polygon, MultiPolygon):
gp.perimeter = 0.0
warnings.warn(
'Perimiter computation for a multi polygon is not defined.'
)
else:
gp.perimeter = polygon.exterior.length
Code example
from shapely import Polygon
from structuralcodes.geometry import CompoundGeometry, SurfaceGeometry
from structuralcodes.sections import GenericSection
from structuralcodes.materials.basic import ElasticMaterial
mat = ElasticMaterial(E=210000, density=7850)
rect1 = SurfaceGeometry(
poly=Polygon([(0, 0), (100, 0), (100, 10), (0, 10)]),
material=mat,
)
rect2 = SurfaceGeometry(
poly=Polygon([(0, 200), (100, 200), (100, 210), (0, 210)]),
material=mat,
)
compound = CompoundGeometry([rect1, rect2])
section = GenericSection(compound, integrator="marin")
gp = section.gross_properties
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingsectionsDevelopment of sectionsDevelopment of sections