foresight_hulls
foresight_hulls, gnuplot's hull filters of a set of points: convexhull, concavehull and expand.
Ports of gnuplot 6.0's filters (filters.c, Ethan A Merritt 2021-2022), step by step so that the points come out in gnuplot's order:
convex_hull: the bounding convex polygon (Graham's algorithm on the points sorted by x then y), clockwise from the point of smallest x, closed (its first point repeated at the end);concave_hull: a chi-shape (Duckham et al. 2008): the Delaunay triangulation (Bowyer-Watson), then the longest perimeter edge longer than the characteristic length removed with its triangle while that does not reduce the shape's connectivity to a single point; closed;expand_hull: each edge of a hull pushed outward by a distance, a convex vertex becoming two points (a bevel), a concave one moved toward the mouth of the concavity;delaunay_triangles: the triangles of the Delaunay triangulation, each closed (gnuplot's undocumenteddelaunay).
The hulls return the rows of the points they keep (idx), so that the other columns of the data follow them.
Source: src/lib/foresight_hulls.F90
Contents
- triangles_object
- sort_xy
- convex_hull
- expand_hull
- displacement
- concave_hull
- delaunay_triangles
- dig_one_hole
- delaunay
- insert_triangle
- move_triangle
- sort_pairs
- sort_lengths
- grow_edges
- cross
Variables
| Name | Type | Attributes | Description |
|---|---|---|---|
GOOD | integer(kind=I4P) | parameter | Head of the list of the triangles of the triangulation. |
BAD | integer(kind=I4P) | parameter | Head of the list of the triangles removed. |
FROZEN | integer(kind=I4P) | parameter | Head of the list of the triangles left of every point still to add. |
Derived Types
triangles_object
Triangles in linked lists (gnuplot's), the slots GOOD, BAD and FROZEN the list heads.
Components
| Name | Type | Attributes | Description |
|---|---|---|---|
v | integer(kind=I4P) | allocatable | Vertices (3, slot), ascending. |
c | real(kind=R8P) | allocatable | Circumcentre (2, slot). |
r | real(kind=R8P) | allocatable | Circumradius. |
next | integer(kind=I4P) | allocatable | Next triangle of the list, 0 for none. |
n | integer(kind=I4P) | Slots in use. |
Subroutines
sort_xy
The rows of (x, y) sorted by x then y, stably (gnuplot's compare_xyz through glibc's merge sort).
Attributes: pure
subroutine sort_xy(x, y, order)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
x | real(kind=R8P) | in | Abscissae. | |
y | real(kind=R8P) | in | Ordinates. | |
order | integer(kind=I4P) | out | allocatable | Sorted rows. |
Call graph
convex_hull
gnuplot's convexhull: the rows of the convex hull of (x, y), clockwise from the smallest x, the first repeated at the end; fewer than 3 points are kept as they are, 3 closed in their order.
Attributes: pure
subroutine convex_hull(x, y, idx)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
x | real(kind=R8P) | in | Abscissae. | |
y | real(kind=R8P) | in | Ordinates. | |
idx | integer(kind=I4P) | out | allocatable | Hull rows. |
Call graph
expand_hull
gnuplot's expand D of a closed hull (x, y): each edge pushed outward by |D|; a convex vertex replaced by the two ends of the displaced edges, a concave one moved toward the mouth of the concavity. src the hull point each new point comes from.
Attributes: pure
subroutine expand_hull(x, y, d, ex, ey, src)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
x | real(kind=R8P) | in | Hull abscissae, closed. | |
y | real(kind=R8P) | in | Hull ordinates, closed. | |
d | real(kind=R8P) | in | Displacement (its magnitude). | |
ex | real(kind=R8P) | out | allocatable | Expanded abscissae. |
ey | real(kind=R8P) | out | allocatable | Expanded ordinates. |
src | integer(kind=I4P) | out | allocatable | Hull point of each new point. |
Call graph
displacement
The outward displacement of a hull edge of direction (ux, uy): length dd along its normal (gnuplot's, through the slope, written without its divisions by zero).
Attributes: pure
subroutine displacement(ux, uy, dd, winding, dx, dy)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
ux | real(kind=R8P) | in | Edge x extent. | |
uy | real(kind=R8P) | in | Edge y extent. | |
dd | real(kind=R8P) | in | Displacement length. | |
winding | real(kind=R8P) | in | +1 clockwise hull, -1 anticlockwise. | |
dx | real(kind=R8P) | out | Displacement x. | |
dy | real(kind=R8P) | out | Displacement y. |
Call graph
concave_hull
gnuplot's concavehull: the rows of the chi-shape of (x, y), closed; chi_length its characteristic length, if positive, else fraction of the longest edge of the convex hull (gnuplot's set chi_shape fraction, 0.6), the one used returned (GPVAL_CHI_LENGTH).
Attributes: pure
subroutine concave_hull(x, y, chi_length, fraction, idx, chi_used)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
x | real(kind=R8P) | in | Abscissae. | |
y | real(kind=R8P) | in | Ordinates. | |
chi_length | real(kind=R8P) | in | Characteristic length, 0 or less for the default. | |
fraction | real(kind=R8P) | in | Default length, fraction of the longest hull edge. | |
idx | integer(kind=I4P) | out | allocatable | Hull rows. |
chi_used | real(kind=R8P) | out | Characteristic length used. |
Call graph
delaunay_triangles
gnuplot's delaunay filter: the rows of each triangle of the Delaunay triangulation of (x, y), closed (its first vertex again), then 0 for a blank line, in gnuplot's order.
Attributes: pure
subroutine delaunay_triangles(x, y, idx)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
x | real(kind=R8P) | in | Abscissae. | |
y | real(kind=R8P) | in | Ordinates. | |
idx | integer(kind=I4P) | out | allocatable | Triangle rows, 0 between triangles. |
Call graph
dig_one_hole
gnuplot's dig_one_hole: the longest perimeter edge (the first), if longer than chi, removed with its triangle (its two other edges on the perimeter), unless the triangle's third vertex is on the perimeter already (the edge then flagged not removable, length -1).
Attributes: pure
subroutine dig_one_hole(tri, px, py, chi, on_hull, edges, lengths, nedges, dug)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
tri | type(triangles_object) | inout | Triangles. | |
px | real(kind=R8P) | in | Abscissae. | |
py | real(kind=R8P) | in | Ordinates. | |
chi | real(kind=R8P) | in | Characteristic length. | |
on_hull | logical | inout | Points on the perimeter. | |
edges | integer(kind=I4P) | inout | allocatable | Perimeter edges (2, edge). |
lengths | real(kind=R8P) | inout | allocatable | Their lengths. |
nedges | integer(kind=I4P) | inout | Perimeter edges. | |
dug | logical | out | An edge removed or flagged. |
Call graph
delaunay
gnuplot's delaunay_triangulation (Bowyer-Watson) of the n points sorted by x in (px, py), whose 4 last slots take the vertices of the two bounding triangles: the triangles in the GOOD list, the perimeter edges (sorted point numbers, their lengths) and the points on it.
Attributes: pure
subroutine delaunay(px, py, n, tri, edges, lengths, nedges, on_hull)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
px | real(kind=R8P) | inout | Abscissae, n + 4. | |
py | real(kind=R8P) | inout | Ordinates, n + 4. | |
n | integer(kind=I4P) | in | Points. | |
tri | type(triangles_object) | out | Triangles. | |
edges | integer(kind=I4P) | out | allocatable | Perimeter edges (2, edge). |
lengths | real(kind=R8P) | out | allocatable | Their lengths. |
nedges | integer(kind=I4P) | out | Perimeter edges. | |
on_hull | logical | out | allocatable | Points on the perimeter. |
Call graph
insert_triangle
A new triangle (a, b, c), its vertices ascending, at the head of the GOOD list, with its circumcircle.
Attributes: pure
subroutine insert_triangle(tri, px, py, a, b, c)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
tri | type(triangles_object) | inout | Triangles. | |
px | real(kind=R8P) | in | Abscissae. | |
py | real(kind=R8P) | in | Ordinates. | |
a | integer(kind=I4P) | in | Vertex. | |
b | integer(kind=I4P) | in | Vertex. | |
c | integer(kind=I4P) | in | Vertex. |
Call graph
move_triangle
Triangle t, after pt in its list, moved to the head of the list head (gnuplot's invalidate or freeze).
Attributes: pure
subroutine move_triangle(tri, pt, t, head)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
tri | type(triangles_object) | inout | Triangles. | |
pt | integer(kind=I4P) | in | Triangle before it. | |
t | integer(kind=I4P) | in | Triangle. | |
head | integer(kind=I4P) | in | Destination list. |
Call graph
sort_pairs
The first n pairs sorted by their first then second element (insertion sort; equal pairs are equal).
Attributes: pure
subroutine sort_pairs(pairs, n)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
pairs | integer(kind=I4P) | inout | Pairs (2, pair). | |
n | integer(kind=I4P) | in | Pairs in use. |
Call graph
sort_lengths
The first n edges sorted by decreasing length, stably (gnuplot's compare_edgelength through glibc's merge sort).
Attributes: pure
subroutine sort_lengths(edges, lengths, n)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
edges | integer(kind=I4P) | inout | Edges (2, edge). | |
lengths | real(kind=R8P) | inout | Lengths. | |
n | integer(kind=I4P) | in | Edges in use. |
Call graph
grow_edges
Twice the room for perimeter edges.
Attributes: pure
subroutine grow_edges(edges, lengths)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
edges | integer(kind=I4P) | inout | allocatable | Edges (2, edge). |
lengths | real(kind=R8P) | inout | allocatable | Lengths. |
Call graph
Functions
cross
gnuplot's CROSS(p1, p2, p3): positive for a left turn p1 -> p2 -> p3.
Attributes: pure
Returns: real(kind=R8P)
function cross(x1, y1, x2, y2, x3, y3) result(c)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
x1 | real(kind=R8P) | in | First point. | |
y1 | real(kind=R8P) | in | First point. | |
x2 | real(kind=R8P) | in | Second point. | |
y2 | real(kind=R8P) | in | Second point. | |
x3 | real(kind=R8P) | in | Third point. | |
y3 | real(kind=R8P) | in | Third point. |
Call graph