Skip to content
Merged
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
8 changes: 7 additions & 1 deletion codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ coverage:
round: down
range: "70...100"
status:
project:
default:
# basic
target: auto
threshold: 5%
base: auto
patch: off

parsers:
Expand All @@ -16,4 +22,4 @@ parsers:
method: no
macro: no

comment: false
comment: false
2 changes: 1 addition & 1 deletion docs/source/requirements_docs.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
scipy
numpy
shapely
shapely>=2.0
matplotlib>=3.4
more_itertools
triangle
Expand Down
2 changes: 1 addition & 1 deletion examples/01-advanced/05_trapz_approximation.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# Shapely `Polygon` object.
import numpy as np
import matplotlib.pyplot as plt
from shapely.geometry import Polygon
from shapely import Polygon
import sectionproperties.pre.geometry as geometry
import sectionproperties.pre.pre as pre
import sectionproperties.pre.library.primitive_sections as sections
Expand Down
10 changes: 2 additions & 8 deletions sectionproperties/analysis/section.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@
import sectionproperties.analysis.solver as solver
import sectionproperties.post.post as post

from shapely.geometry import Polygon
from shapely import Polygon, Point
from shapely.strtree import STRtree
from shapely.geometry import Point


class Section:
Expand Down Expand Up @@ -194,7 +193,6 @@ def __init__(
Polygon(self.geometry.mesh["vertices"][tri][0:3])
for tri in self.geometry.mesh["triangles"]
]
self.poly_mesh_idx = dict((id(poly), i) for i, poly in enumerate(p_mesh))
self.mesh_search_tree = STRtree(p_mesh)

# initialise class storing section properties
Expand Down Expand Up @@ -2260,11 +2258,7 @@ def get_stress_at_points(

for pt in pts:
query_geom = Point(pt)
tri_ids = [
self.poly_mesh_idx[id(poly)]
for poly in self.mesh_search_tree.query(query_geom)
if poly.intersects(query_geom)
]
tri_ids = self.mesh_search_tree.query(query_geom, predicate="intersects")
if len(tri_ids) == 0:
sig = None
elif len(tri_ids) == 1:
Expand Down
14 changes: 7 additions & 7 deletions sectionproperties/pre/bisect_section.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Tuple, Union, List, Optional

import numpy as np
import shapely
from shapely import LineString, GeometryCollection, Polygon


def create_line_segment(
Expand All @@ -23,19 +23,19 @@ def create_line_segment(

scale_factor_1 = (b_1 - p_x) / vector[0]
y_1 = scale_factor_1 * vector[1] + p_y
return shapely.geometry.LineString([(b_1, y_1), (b_2, y_2)])
return LineString([(b_1, y_1), (b_2, y_2)])
else: # Vertical line
scale_factor_2 = (b_2 - p_y) / vector[1]
x_2 = scale_factor_2 * vector[0] + p_x

scale_factor_1 = (b_1 - p_y) / vector[1]
x_1 = scale_factor_1 * vector[0] + p_x
return shapely.geometry.LineString([(x_1, b_1), (x_2, b_2)])
return LineString([(x_1, b_1), (x_2, b_2)])


def group_top_and_bottom_polys(
polys: shapely.geometry.GeometryCollection,
line: shapely.geometry.LineString,
polys: GeometryCollection,
line: LineString,
) -> Tuple[list, list]:
"""
Returns tuple of two lists representing the list of Polygons in 'polys' on the "top" side of 'line' and the
Expand Down Expand Up @@ -67,7 +67,7 @@ def group_top_and_bottom_polys(


def line_mx_plus_b(
line: shapely.geometry.LineString,
line: LineString,
) -> Tuple[float, float]:
"""
Returns a tuple representing the values of "m" and "b" from the definition of 'line' as "y = mx + b".
Expand Down Expand Up @@ -120,7 +120,7 @@ def line_intersection(


def sum_poly_areas(
lop: List[shapely.geometry.Polygon],
lop: List[Polygon],
) -> float:
"""
Returns a float representing the total area of all polygons
Expand Down
24 changes: 12 additions & 12 deletions sectionproperties/pre/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
import pathlib
import more_itertools
import numpy as np
from shapely.geometry import (
from shapely import (
Polygon,
MultiPolygon,
LineString,
LinearRing,
Point,
box,
GeometryCollection,
box,
affinity,
)
from shapely.ops import split, unary_union
import shapely
import matplotlib
import matplotlib.pyplot as plt
import sectionproperties.pre.pre as pre
Expand Down Expand Up @@ -51,7 +51,7 @@ class Geometry:

def __init__(
self,
geom: shapely.geometry.Polygon,
geom: Polygon,
material: pre.Material = pre.DEFAULT_MATERIAL,
control_points: Optional[Union[Point, List[float, float]]] = None,
tol=12,
Expand Down Expand Up @@ -544,11 +544,11 @@ def shift_section(
# Move assigned control point
new_ctrl_point = None
if self.assigned_control_point:
new_ctrl_point = shapely.affinity.translate(
new_ctrl_point = affinity.translate(
self.assigned_control_point, x_offset, y_offset
).coords[0]
new_geom = Geometry(
shapely.affinity.translate(self.geom, x_offset, y_offset),
affinity.translate(self.geom, x_offset, y_offset),
self.material,
new_ctrl_point,
)
Expand Down Expand Up @@ -585,11 +585,11 @@ def rotate_section(
rotate_point = rot_point
if rot_point == "center":
rotate_point = box(*self.geom.bounds).centroid
new_ctrl_point = shapely.affinity.rotate(
new_ctrl_point = affinity.rotate(
self.assigned_control_point, angle, rotate_point, use_radians
).coords[0]
new_geom = Geometry(
shapely.affinity.rotate(self.geom, angle, rot_point, use_radians),
affinity.rotate(self.geom, angle, rot_point, use_radians),
self.material,
new_ctrl_point,
)
Expand Down Expand Up @@ -625,13 +625,13 @@ def mirror_section(
x_mirror = -x_mirror
elif axis == "y":
y_mirror = -y_mirror
mirrored_geom = shapely.affinity.scale(
mirrored_geom = affinity.scale(
self.geom, xfact=y_mirror, yfact=x_mirror, zfact=1.0, origin=mirror_point
)

new_ctrl_point = None
if self.assigned_control_point:
new_ctrl_point = shapely.affinity.scale(
new_ctrl_point = affinity.scale(
self.assigned_control_point,
xfact=y_mirror,
yfact=x_mirror,
Expand Down Expand Up @@ -677,7 +677,7 @@ def split_section(
The following example splits a 200PFC section about the y-axis::

import sectionproperties.pre.library.steel_sections as steel_sections
from shapely.geometry import LineString
from shapely import LineString

geometry = steel_sections.channel_section(d=200, b=75, t_f=12, t_w=6, r=12, n_r=8)
right_geom, left_geom = geometry.split_section((0, 0), (0, 1))
Expand Down Expand Up @@ -1672,7 +1672,7 @@ def split_section(
The following example splits a 200PFC section about the y-axis::

import sectionproperties.pre.library.steel_sections as steel_sections
from shapely.geometry import LineString
from shapely import LineString

geometry = steel_sections.channel_section(d=200, b=75, t_f=12, t_w=6, r=12, n_r=8)
right_geom, left_geom = geometry.split_section((0, 0), (0, 1))
Expand Down
2 changes: 1 addition & 1 deletion sectionproperties/pre/library/bridge_sections.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import numpy as np
from shapely.geometry import Polygon
from shapely import Polygon
import sectionproperties.pre.geometry as geometry
import sectionproperties.pre.pre as pre

Expand Down
2 changes: 1 addition & 1 deletion sectionproperties/pre/library/nastran_sections.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import numpy as np
from shapely.geometry import Polygon
from shapely import Polygon
import sectionproperties.pre.geometry as geometry
import sectionproperties.pre.pre as pre
from sectionproperties.pre.library.utils import draw_radius
Expand Down
2 changes: 1 addition & 1 deletion sectionproperties/pre/library/primitive_sections.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import numpy as np
from shapely.geometry import Polygon
from shapely import Polygon
import sectionproperties.pre.geometry as geometry
import sectionproperties.pre.pre as pre
from sectionproperties.pre.library.utils import draw_radius
Expand Down
2 changes: 1 addition & 1 deletion sectionproperties/pre/library/steel_sections.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import numpy as np
from shapely.geometry import Polygon
from shapely import Polygon
import sectionproperties.pre.geometry as geometry
import sectionproperties.pre.pre as pre
from sectionproperties.pre.library.utils import draw_radius, rotate
Expand Down
2 changes: 1 addition & 1 deletion sectionproperties/pre/rhino.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pathlib
from typing import List, Union
from shapely.geometry.polygon import Polygon
from shapely import Polygon
from rhino_shapely_interop.importers import RhImporter


Expand Down
2 changes: 1 addition & 1 deletion sectionproperties/tests/test_offset.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import sectionproperties.pre.library.primitive_sections as sections
import sectionproperties.pre.library.steel_sections as steel_sections
from sectionproperties.analysis.section import Section
from shapely.geometry import Polygon
from shapely import Polygon
from sectionproperties.pre.geometry import Geometry


Expand Down
20 changes: 10 additions & 10 deletions sectionproperties/tests/test_sections.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
from sectionproperties.analysis.section import Section
from sectionproperties.pre.pre import DEFAULT_MATERIAL, Material
from sectionproperties.pre.rhino import load_3dm, load_brep_encoding
from shapely.geometry import (
from shapely import (
Polygon,
MultiPolygon,
LineString,
Point,
GeometryCollection,
box,
wkt,
)
from shapely import wkt
import json

big_sq = rectangular_section(d=300, b=250)
Expand Down Expand Up @@ -133,7 +133,7 @@ def test_geometry_from_points():
holes=holes,
material=material,
)
wkt_test_geom = shapely.wkt.loads(
wkt_test_geom = wkt.loads(
"POLYGON ((6 10, 6 -10, -6 -10, -6 10, 6 10), (-4 4, 4 4, 4 8, -4 8, -4 4), (4 -8, 4 -4, -4 -4, -4 -8, 4 -8))"
)
assert (new_geom.geom - wkt_test_geom) == Polygon()
Expand Down Expand Up @@ -195,7 +195,7 @@ def test_compound_geometry_from_points():
new_geom = CompoundGeometry.from_points(
points, facets, control_points, materials=materials
)
wkt_test_geom = shapely.wkt.loads(
wkt_test_geom = wkt.loads(
"MULTIPOLYGON (((-0.05 -2, 0.05 -2, 0.05 -0.05, 1 -0.05, 1 0.05, -0.05 0.05, -0.05 -2)), ((-1 -2, 1 -2, 1 -2.1, -1 -2.1, -1 -2)))"
)
assert (new_geom.geom - wkt_test_geom) == Polygon()
Expand Down Expand Up @@ -283,7 +283,7 @@ def test_multi_nested_compound_geometry_from_points():
holes=holes,
materials=materials,
)
wkt_test_geom = shapely.wkt.loads(
wkt_test_geom = wkt.loads(
"MULTIPOLYGON (((50 50, 50 -50, -50 -50, -50 50, 50 50), (12.5 12.5, -12.5 12.5, -12.5 -12.5, 12.5 -12.5, 12.5 12.5)), ((-37.5 -37.5, -37.5 37.5, 37.5 37.5, 37.5 -37.5, -37.5 -37.5), (12.5 12.5, -12.5 12.5, -12.5 -12.5, 12.5 -12.5, 12.5 12.5)), ((-25 -25, -25 25, 25 25, 25 -25, -25 -25), (12.5 12.5, -12.5 12.5, -12.5 -12.5, 12.5 -12.5, 12.5 12.5)))"
)
assert (nested_compound.geom - wkt_test_geom) == Polygon()
Expand Down Expand Up @@ -447,17 +447,17 @@ def test_mirror_section():


def test_filter_non_polygons():
point1 = Point([0, 0])
point2 = Point([1, 1])
point3 = Point([1, 0])
point1 = (0, 0)
point2 = (1, 1)
point3 = (1, 0)
line = LineString([point1, point2])
poly = Polygon([point1, point2, point3])
multi_poly = MultiPolygon([poly, poly])
collection = GeometryCollection([poly, point1, line])
collection = GeometryCollection([poly, Point(point1), line])
out = filter_non_polygons(collection)
assert filter_non_polygons(poly) == poly
assert filter_non_polygons(multi_poly) == multi_poly
assert filter_non_polygons(point1) == Polygon()
assert filter_non_polygons(Point(point1)) == Polygon()
assert filter_non_polygons(line) == Polygon()
assert filter_non_polygons(collection) == poly

Expand Down
2 changes: 1 addition & 1 deletion sectionproperties/tests/test_validation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest_check as check
from shapely.geometry import Polygon
from shapely import Polygon
from sectionproperties.pre.geometry import Geometry
import sectionproperties.pre.library.primitive_sections as sections
import sectionproperties.pre.library.steel_sections as steel_sections
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ install_requires =
scipy
more_itertools
matplotlib>=3.4
shapely
shapely>=2.0
triangle
cad_to_shapely>=0.3
rich
Expand Down