bluemesh2d 0.1.1.dev0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- bluemesh2d/_version.py +24 -0
- bluemesh2d/aabb_tree/findball.py +121 -0
- bluemesh2d/aabb_tree/findtria.py +299 -0
- bluemesh2d/aabb_tree/maketree.py +147 -0
- bluemesh2d/aabb_tree/mapvert.py +72 -0
- bluemesh2d/aabb_tree/queryset.py +83 -0
- bluemesh2d/aabb_tree/scantree.py +124 -0
- bluemesh2d/dependencies.py +83 -0
- bluemesh2d/feedback.py +142 -0
- bluemesh2d/geom_util/boundary_util.py +216 -0
- bluemesh2d/geom_util/getiso.py +194 -0
- bluemesh2d/geom_util/poly_util.py +795 -0
- bluemesh2d/geom_util/proj_util.py +250 -0
- bluemesh2d/geomesh_util/border_util.py +283 -0
- bluemesh2d/geomesh_util/depth_field.py +333 -0
- bluemesh2d/geomesh_util/grd_util.py +1000 -0
- bluemesh2d/geomesh_util/interpolation_mesh.py +318 -0
- bluemesh2d/geomesh_util/merge_circumcenters.py +268 -0
- bluemesh2d/geomesh_util/water_polygon.py +406 -0
- bluemesh2d/hfun_util/build_hfun.py +589 -0
- bluemesh2d/hfun_util/hfun_dispersion.py +96 -0
- bluemesh2d/hfun_util/lfshfn.py +110 -0
- bluemesh2d/hfun_util/limhfn.py +65 -0
- bluemesh2d/hfun_util/make_constant_hfun.py +32 -0
- bluemesh2d/hfun_util/make_depth_hfun.py +51 -0
- bluemesh2d/hfun_util/smooth_and_precomput.py +188 -0
- bluemesh2d/hfun_util/trihfn.py +84 -0
- bluemesh2d/hjac_util/limgrad.py +105 -0
- bluemesh2d/mesh_ball/cdtbal1.py +38 -0
- bluemesh2d/mesh_ball/cdtbal2.py +104 -0
- bluemesh2d/mesh_ball/inv_2x2.py +61 -0
- bluemesh2d/mesh_ball/inv_3x3.py +72 -0
- bluemesh2d/mesh_ball/pwrbal2.py +134 -0
- bluemesh2d/mesh_ball/tribal2.py +27 -0
- bluemesh2d/mesh_cost/relhfn.py +62 -0
- bluemesh2d/mesh_cost/triang.py +59 -0
- bluemesh2d/mesh_cost/triarea.py +51 -0
- bluemesh2d/mesh_cost/trideg.py +44 -0
- bluemesh2d/mesh_cost/triscr.py +43 -0
- bluemesh2d/mesh_file/bnd_util.py +664 -0
- bluemesh2d/mesh_file/loadmsh.py +165 -0
- bluemesh2d/mesh_file/ugrid.py +308 -0
- bluemesh2d/mesh_util/cfmtri.py +118 -0
- bluemesh2d/mesh_util/deltri.py +131 -0
- bluemesh2d/mesh_util/idxtri.py +53 -0
- bluemesh2d/mesh_util/isfeat.py +90 -0
- bluemesh2d/mesh_util/minlen.py +46 -0
- bluemesh2d/mesh_util/setset.py +49 -0
- bluemesh2d/mesh_util/tricon.py +90 -0
- bluemesh2d/mesh_util/tridiv.py +187 -0
- bluemesh2d/meshgen.py +202 -0
- bluemesh2d/ortho_merge/constants.py +27 -0
- bluemesh2d/ortho_merge/geometry.py +64 -0
- bluemesh2d/ortho_merge/ortho_merge_iter.py +812 -0
- bluemesh2d/ortho_merge/orthogonalize.py +2989 -0
- bluemesh2d/pipeline.py +277 -0
- bluemesh2d/poly_data/airfoil.msh +958 -0
- bluemesh2d/poly_data/channel.msh +212 -0
- bluemesh2d/poly_data/islands.msh +13819 -0
- bluemesh2d/poly_data/lake.msh +612 -0
- bluemesh2d/poly_data/river.msh +690 -0
- bluemesh2d/poly_test/inpoly.py +105 -0
- bluemesh2d/poly_test/inpoly_mat.py +104 -0
- bluemesh2d/refine.py +972 -0
- bluemesh2d/smood.py +623 -0
- bluemesh2d/smooth.py +522 -0
- bluemesh2d/tricost.py +426 -0
- bluemesh2d/tridemo.py +723 -0
- bluemesh2d/triread.py +53 -0
- bluemesh2d-0.1.1.dev0.dist-info/METADATA +139 -0
- bluemesh2d-0.1.1.dev0.dist-info/RECORD +74 -0
- bluemesh2d-0.1.1.dev0.dist-info/WHEEL +5 -0
- bluemesh2d-0.1.1.dev0.dist-info/licenses/LICENSE +674 -0
- bluemesh2d-0.1.1.dev0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
|
|
3
|
+
from .inpoly_mat import inpoly_mat
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def inpoly(vert, node, edge=None, ftol=None):
|
|
7
|
+
"""Test whether points lie inside a 2D polygon.
|
|
8
|
+
|
|
9
|
+
Parameters
|
|
10
|
+
----------
|
|
11
|
+
vert : ndarray of shape (N, 2)
|
|
12
|
+
Query point coordinates.
|
|
13
|
+
node : ndarray of shape (M, 2)
|
|
14
|
+
Polygon vertex coordinates.
|
|
15
|
+
edge : ndarray of shape (P, 2), optional
|
|
16
|
+
Edge connectivity as vertex-index pairs. When omitted, vertices in
|
|
17
|
+
``node`` are connected in order.
|
|
18
|
+
ftol : float, optional
|
|
19
|
+
Floating-point tolerance for boundary tests; default is
|
|
20
|
+
``eps**0.85``.
|
|
21
|
+
|
|
22
|
+
Returns
|
|
23
|
+
-------
|
|
24
|
+
stat : ndarray of bool, shape (N,)
|
|
25
|
+
``True`` for points classified as inside the polygon.
|
|
26
|
+
bnds : ndarray of bool, shape (N,)
|
|
27
|
+
``True`` for points lying on a polygon edge.
|
|
28
|
+
|
|
29
|
+
Notes
|
|
30
|
+
-----
|
|
31
|
+
Uses a crossing-number algorithm with sorted query points and binary
|
|
32
|
+
search over edge y-ranges.
|
|
33
|
+
|
|
34
|
+
References
|
|
35
|
+
----------
|
|
36
|
+
Translation of the MESH2D function ``INPOLY2``.
|
|
37
|
+
Original MATLAB source: https://github.com/dengwirda/mesh2d
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
node = np.asarray(node, dtype=float)
|
|
41
|
+
vert = np.asarray(vert, dtype=float)
|
|
42
|
+
if edge is None:
|
|
43
|
+
nnod = node.shape[0]
|
|
44
|
+
edge = np.vstack(
|
|
45
|
+
[np.column_stack([np.arange(nnod - 1), np.arange(1, nnod)]), [nnod - 1, 0]]
|
|
46
|
+
)
|
|
47
|
+
else:
|
|
48
|
+
edge = np.asarray(edge, dtype=int)
|
|
49
|
+
|
|
50
|
+
if ftol is None:
|
|
51
|
+
ftol = np.finfo(float).eps ** 0.85
|
|
52
|
+
|
|
53
|
+
nnod = node.shape[0]
|
|
54
|
+
nvrt = vert.shape[0]
|
|
55
|
+
|
|
56
|
+
if edge.min() < 0 or edge.max() > nnod:
|
|
57
|
+
raise ValueError("inpoly: invalid EDGE input array.")
|
|
58
|
+
|
|
59
|
+
STAT = np.zeros(nvrt, dtype=bool)
|
|
60
|
+
BNDS = np.zeros(nvrt, dtype=bool)
|
|
61
|
+
|
|
62
|
+
nmin = node.min(axis=0)
|
|
63
|
+
nmax = node.max(axis=0)
|
|
64
|
+
ddxy = nmax - nmin
|
|
65
|
+
lbar = ddxy.sum() / 2.0
|
|
66
|
+
veps = ftol * lbar
|
|
67
|
+
|
|
68
|
+
mask = (
|
|
69
|
+
(vert[:, 0] >= nmin[0] - veps)
|
|
70
|
+
& (vert[:, 0] <= nmax[0] + veps)
|
|
71
|
+
& (vert[:, 1] >= nmin[1] - veps)
|
|
72
|
+
& (vert[:, 1] <= nmax[1] + veps)
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
if not np.any(mask):
|
|
76
|
+
return STAT, BNDS
|
|
77
|
+
|
|
78
|
+
vmask = np.where(mask)[0]
|
|
79
|
+
vsub = vert[mask, :].copy()
|
|
80
|
+
nsub = node.copy()
|
|
81
|
+
|
|
82
|
+
# Flip to ensure the y-axis is the "long" axis
|
|
83
|
+
vmin = vsub.min(axis=0)
|
|
84
|
+
vmax = vsub.max(axis=0)
|
|
85
|
+
ddxy = vmax - vmin
|
|
86
|
+
if ddxy[0] > ddxy[1]:
|
|
87
|
+
vsub = vsub[:, [1, 0]]
|
|
88
|
+
nsub = nsub[:, [1, 0]]
|
|
89
|
+
|
|
90
|
+
swap = nsub[edge[:, 1], 1] < nsub[edge[:, 0], 1]
|
|
91
|
+
edge[swap] = edge[swap][:, [1, 0]]
|
|
92
|
+
|
|
93
|
+
ivec = np.lexsort((vsub[:, 0], vsub[:, 1]))
|
|
94
|
+
vsub = vsub[ivec, :]
|
|
95
|
+
|
|
96
|
+
stat, bnds = inpoly_mat(vsub, nsub, edge, ftol, lbar)
|
|
97
|
+
|
|
98
|
+
inv = np.argsort(ivec)
|
|
99
|
+
stat = stat[inv]
|
|
100
|
+
bnds = bnds[inv]
|
|
101
|
+
|
|
102
|
+
STAT[vmask] = stat
|
|
103
|
+
BNDS[vmask] = bnds
|
|
104
|
+
|
|
105
|
+
return STAT, BNDS
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def inpoly_mat(vert, node, edge, fTOL, lbar):
|
|
5
|
+
"""Run the crossing-number point-in-polygon test on sorted points.
|
|
6
|
+
|
|
7
|
+
Parameters
|
|
8
|
+
----------
|
|
9
|
+
vert : ndarray of shape (N, 2)
|
|
10
|
+
Query points, sorted by y-coordinate.
|
|
11
|
+
node : ndarray of shape (M, 2)
|
|
12
|
+
Polygon vertex coordinates.
|
|
13
|
+
edge : ndarray of shape (P, 2)
|
|
14
|
+
Edge connectivity as vertex-index pairs.
|
|
15
|
+
fTOL : float
|
|
16
|
+
Relative floating-point tolerance scale.
|
|
17
|
+
lbar : float
|
|
18
|
+
Characteristic polygon length scale.
|
|
19
|
+
|
|
20
|
+
Returns
|
|
21
|
+
-------
|
|
22
|
+
stat : ndarray of bool, shape (N,)
|
|
23
|
+
``True`` for points classified as inside the polygon.
|
|
24
|
+
bnds : ndarray of bool, shape (N,)
|
|
25
|
+
``True`` for points lying on a polygon edge.
|
|
26
|
+
|
|
27
|
+
References
|
|
28
|
+
----------
|
|
29
|
+
Translation of the MESH2D function ``INPOLY2_MAT``.
|
|
30
|
+
Original MATLAB source: https://github.com/dengwirda/mesh2d
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
feps = fTOL * lbar**1
|
|
34
|
+
veps = fTOL * lbar**1
|
|
35
|
+
|
|
36
|
+
nvrt = vert.shape[0]
|
|
37
|
+
_nnod = node.shape[0]
|
|
38
|
+
nedg = edge.shape[0]
|
|
39
|
+
|
|
40
|
+
stat = np.zeros(nvrt, dtype=bool)
|
|
41
|
+
bnds = np.zeros(nvrt, dtype=bool)
|
|
42
|
+
for epos in range(nedg):
|
|
43
|
+
inod = edge[epos, 0]
|
|
44
|
+
jnod = edge[epos, 1]
|
|
45
|
+
yone = node[inod, 1]
|
|
46
|
+
ytwo = node[jnod, 1]
|
|
47
|
+
xone = node[inod, 0]
|
|
48
|
+
xtwo = node[jnod, 0]
|
|
49
|
+
|
|
50
|
+
xmin = min(xone, xtwo) - veps
|
|
51
|
+
xmax = max(xone, xtwo) + veps
|
|
52
|
+
|
|
53
|
+
ymin = yone - veps
|
|
54
|
+
ymax = ytwo + veps
|
|
55
|
+
|
|
56
|
+
ydel = ytwo - yone
|
|
57
|
+
xdel = xtwo - xone
|
|
58
|
+
|
|
59
|
+
edel = abs(xdel) + ydel
|
|
60
|
+
ilow = 0
|
|
61
|
+
iupp = nvrt - 1
|
|
62
|
+
|
|
63
|
+
while ilow < iupp - 1: # binary search
|
|
64
|
+
imid = ilow + (iupp - ilow) // 2
|
|
65
|
+
if vert[imid, 1] < ymin:
|
|
66
|
+
ilow = imid
|
|
67
|
+
else:
|
|
68
|
+
iupp = imid
|
|
69
|
+
|
|
70
|
+
if vert[ilow, 1] >= ymin:
|
|
71
|
+
ilow -= 1
|
|
72
|
+
for jpos in range(ilow + 1, nvrt):
|
|
73
|
+
if bnds[jpos]:
|
|
74
|
+
continue
|
|
75
|
+
|
|
76
|
+
xpos = vert[jpos, 0]
|
|
77
|
+
ypos = vert[jpos, 1]
|
|
78
|
+
|
|
79
|
+
if ypos <= ymax:
|
|
80
|
+
if xpos >= xmin:
|
|
81
|
+
if xpos <= xmax:
|
|
82
|
+
mul1 = ydel * (xpos - xone)
|
|
83
|
+
mul2 = xdel * (ypos - yone)
|
|
84
|
+
|
|
85
|
+
if (feps * edel) >= abs(mul2 - mul1):
|
|
86
|
+
bnds[jpos] = True
|
|
87
|
+
stat[jpos] = True
|
|
88
|
+
elif ypos == yone and xpos == xone:
|
|
89
|
+
bnds[jpos] = True
|
|
90
|
+
stat[jpos] = True
|
|
91
|
+
elif ypos == ytwo and xpos == xtwo:
|
|
92
|
+
bnds[jpos] = True
|
|
93
|
+
stat[jpos] = True
|
|
94
|
+
elif mul1 < mul2:
|
|
95
|
+
if ypos >= yone and ypos < ytwo:
|
|
96
|
+
stat[jpos] = ~stat[jpos]
|
|
97
|
+
|
|
98
|
+
else:
|
|
99
|
+
if ypos >= yone and ypos < ytwo:
|
|
100
|
+
stat[jpos] = ~stat[jpos]
|
|
101
|
+
else:
|
|
102
|
+
break # -- done -- due to the sort
|
|
103
|
+
|
|
104
|
+
return stat, bnds
|