Skip to content

Commit 5dcead8

Browse files
Merge pull request #260 from robbievanleeuwen/shapely_fix
Fix shapely imports; fix test_filter_non_polygons
2 parents ca86307 + 91c584b commit 5dcead8

File tree

15 files changed

+48
-48
lines changed

15 files changed

+48
-48
lines changed

codecov.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ coverage:
66
round: down
77
range: "70...100"
88
status:
9+
project:
10+
default:
11+
# basic
12+
target: auto
13+
threshold: 5%
14+
base: auto
915
patch: off
1016

1117
parsers:
@@ -16,4 +22,4 @@ parsers:
1622
method: no
1723
macro: no
1824

19-
comment: false
25+
comment: false

docs/source/requirements_docs.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
scipy
22
numpy
3-
shapely
3+
shapely>=2.0
44
matplotlib>=3.4
55
more_itertools
66
triangle

examples/01-advanced/05_trapz_approximation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
# Shapely `Polygon` object.
2626
import numpy as np
2727
import matplotlib.pyplot as plt
28-
from shapely.geometry import Polygon
28+
from shapely import Polygon
2929
import sectionproperties.pre.geometry as geometry
3030
import sectionproperties.pre.pre as pre
3131
import sectionproperties.pre.library.primitive_sections as sections

sectionproperties/analysis/section.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@
2727
import sectionproperties.analysis.solver as solver
2828
import sectionproperties.post.post as post
2929

30-
from shapely.geometry import Polygon
30+
from shapely import Polygon, Point
3131
from shapely.strtree import STRtree
32-
from shapely.geometry import Point
3332

3433

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

200198
# initialise class storing section properties
@@ -2260,11 +2258,7 @@ def get_stress_at_points(
22602258

22612259
for pt in pts:
22622260
query_geom = Point(pt)
2263-
tri_ids = [
2264-
self.poly_mesh_idx[id(poly)]
2265-
for poly in self.mesh_search_tree.query(query_geom)
2266-
if poly.intersects(query_geom)
2267-
]
2261+
tri_ids = self.mesh_search_tree.query(query_geom, predicate="intersects")
22682262
if len(tri_ids) == 0:
22692263
sig = None
22702264
elif len(tri_ids) == 1:

sectionproperties/pre/bisect_section.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from typing import Tuple, Union, List, Optional
22

33
import numpy as np
4-
import shapely
4+
from shapely import LineString, GeometryCollection, Polygon
55

66

77
def create_line_segment(
@@ -23,19 +23,19 @@ def create_line_segment(
2323

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

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

3535

3636
def group_top_and_bottom_polys(
37-
polys: shapely.geometry.GeometryCollection,
38-
line: shapely.geometry.LineString,
37+
polys: GeometryCollection,
38+
line: LineString,
3939
) -> Tuple[list, list]:
4040
"""
4141
Returns tuple of two lists representing the list of Polygons in 'polys' on the "top" side of 'line' and the
@@ -67,7 +67,7 @@ def group_top_and_bottom_polys(
6767

6868

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

121121

122122
def sum_poly_areas(
123-
lop: List[shapely.geometry.Polygon],
123+
lop: List[Polygon],
124124
) -> float:
125125
"""
126126
Returns a float representing the total area of all polygons

sectionproperties/pre/geometry.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@
77
import pathlib
88
import more_itertools
99
import numpy as np
10-
from shapely.geometry import (
10+
from shapely import (
1111
Polygon,
1212
MultiPolygon,
1313
LineString,
1414
LinearRing,
1515
Point,
16-
box,
1716
GeometryCollection,
17+
box,
18+
affinity,
1819
)
1920
from shapely.ops import split, unary_union
20-
import shapely
2121
import matplotlib
2222
import matplotlib.pyplot as plt
2323
import sectionproperties.pre.pre as pre
@@ -51,7 +51,7 @@ class Geometry:
5151

5252
def __init__(
5353
self,
54-
geom: shapely.geometry.Polygon,
54+
geom: Polygon,
5555
material: pre.Material = pre.DEFAULT_MATERIAL,
5656
control_points: Optional[Union[Point, List[float, float]]] = None,
5757
tol=12,
@@ -544,11 +544,11 @@ def shift_section(
544544
# Move assigned control point
545545
new_ctrl_point = None
546546
if self.assigned_control_point:
547-
new_ctrl_point = shapely.affinity.translate(
547+
new_ctrl_point = affinity.translate(
548548
self.assigned_control_point, x_offset, y_offset
549549
).coords[0]
550550
new_geom = Geometry(
551-
shapely.affinity.translate(self.geom, x_offset, y_offset),
551+
affinity.translate(self.geom, x_offset, y_offset),
552552
self.material,
553553
new_ctrl_point,
554554
)
@@ -585,11 +585,11 @@ def rotate_section(
585585
rotate_point = rot_point
586586
if rot_point == "center":
587587
rotate_point = box(*self.geom.bounds).centroid
588-
new_ctrl_point = shapely.affinity.rotate(
588+
new_ctrl_point = affinity.rotate(
589589
self.assigned_control_point, angle, rotate_point, use_radians
590590
).coords[0]
591591
new_geom = Geometry(
592-
shapely.affinity.rotate(self.geom, angle, rot_point, use_radians),
592+
affinity.rotate(self.geom, angle, rot_point, use_radians),
593593
self.material,
594594
new_ctrl_point,
595595
)
@@ -625,13 +625,13 @@ def mirror_section(
625625
x_mirror = -x_mirror
626626
elif axis == "y":
627627
y_mirror = -y_mirror
628-
mirrored_geom = shapely.affinity.scale(
628+
mirrored_geom = affinity.scale(
629629
self.geom, xfact=y_mirror, yfact=x_mirror, zfact=1.0, origin=mirror_point
630630
)
631631

632632
new_ctrl_point = None
633633
if self.assigned_control_point:
634-
new_ctrl_point = shapely.affinity.scale(
634+
new_ctrl_point = affinity.scale(
635635
self.assigned_control_point,
636636
xfact=y_mirror,
637637
yfact=x_mirror,
@@ -677,7 +677,7 @@ def split_section(
677677
The following example splits a 200PFC section about the y-axis::
678678
679679
import sectionproperties.pre.library.steel_sections as steel_sections
680-
from shapely.geometry import LineString
680+
from shapely import LineString
681681
682682
geometry = steel_sections.channel_section(d=200, b=75, t_f=12, t_w=6, r=12, n_r=8)
683683
right_geom, left_geom = geometry.split_section((0, 0), (0, 1))
@@ -1672,7 +1672,7 @@ def split_section(
16721672
The following example splits a 200PFC section about the y-axis::
16731673
16741674
import sectionproperties.pre.library.steel_sections as steel_sections
1675-
from shapely.geometry import LineString
1675+
from shapely import LineString
16761676
16771677
geometry = steel_sections.channel_section(d=200, b=75, t_f=12, t_w=6, r=12, n_r=8)
16781678
right_geom, left_geom = geometry.split_section((0, 0), (0, 1))

sectionproperties/pre/library/bridge_sections.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import numpy as np
2-
from shapely.geometry import Polygon
2+
from shapely import Polygon
33
import sectionproperties.pre.geometry as geometry
44
import sectionproperties.pre.pre as pre
55

sectionproperties/pre/library/nastran_sections.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import numpy as np
2-
from shapely.geometry import Polygon
2+
from shapely import Polygon
33
import sectionproperties.pre.geometry as geometry
44
import sectionproperties.pre.pre as pre
55
from sectionproperties.pre.library.utils import draw_radius

sectionproperties/pre/library/primitive_sections.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import numpy as np
2-
from shapely.geometry import Polygon
2+
from shapely import Polygon
33
import sectionproperties.pre.geometry as geometry
44
import sectionproperties.pre.pre as pre
55
from sectionproperties.pre.library.utils import draw_radius

sectionproperties/pre/library/steel_sections.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import numpy as np
2-
from shapely.geometry import Polygon
2+
from shapely import Polygon
33
import sectionproperties.pre.geometry as geometry
44
import sectionproperties.pre.pre as pre
55
from sectionproperties.pre.library.utils import draw_radius, rotate

0 commit comments

Comments
 (0)