Skip to content

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 undocumented delaunay).

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 ​

Variables ​

NameTypeAttributesDescription
GOODinteger(kind=I4P)parameterHead of the list of the triangles of the triangulation.
BADinteger(kind=I4P)parameterHead of the list of the triangles removed.
FROZENinteger(kind=I4P)parameterHead 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

NameTypeAttributesDescription
vinteger(kind=I4P)allocatableVertices (3, slot), ascending.
creal(kind=R8P)allocatableCircumcentre (2, slot).
rreal(kind=R8P)allocatableCircumradius.
nextinteger(kind=I4P)allocatableNext triangle of the list, 0 for none.
ninteger(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

fortran
subroutine sort_xy(x, y, order)

Arguments

NameTypeIntentAttributesDescription
xreal(kind=R8P)inAbscissae.
yreal(kind=R8P)inOrdinates.
orderinteger(kind=I4P)outallocatableSorted 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

fortran
subroutine convex_hull(x, y, idx)

Arguments

NameTypeIntentAttributesDescription
xreal(kind=R8P)inAbscissae.
yreal(kind=R8P)inOrdinates.
idxinteger(kind=I4P)outallocatableHull 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

fortran
subroutine expand_hull(x, y, d, ex, ey, src)

Arguments

NameTypeIntentAttributesDescription
xreal(kind=R8P)inHull abscissae, closed.
yreal(kind=R8P)inHull ordinates, closed.
dreal(kind=R8P)inDisplacement (its magnitude).
exreal(kind=R8P)outallocatableExpanded abscissae.
eyreal(kind=R8P)outallocatableExpanded ordinates.
srcinteger(kind=I4P)outallocatableHull 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

fortran
subroutine displacement(ux, uy, dd, winding, dx, dy)

Arguments

NameTypeIntentAttributesDescription
uxreal(kind=R8P)inEdge x extent.
uyreal(kind=R8P)inEdge y extent.
ddreal(kind=R8P)inDisplacement length.
windingreal(kind=R8P)in+1 clockwise hull, -1 anticlockwise.
dxreal(kind=R8P)outDisplacement x.
dyreal(kind=R8P)outDisplacement 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

fortran
subroutine concave_hull(x, y, chi_length, fraction, idx, chi_used)

Arguments

NameTypeIntentAttributesDescription
xreal(kind=R8P)inAbscissae.
yreal(kind=R8P)inOrdinates.
chi_lengthreal(kind=R8P)inCharacteristic length, 0 or less for the default.
fractionreal(kind=R8P)inDefault length, fraction of the longest hull edge.
idxinteger(kind=I4P)outallocatableHull rows.
chi_usedreal(kind=R8P)outCharacteristic 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

fortran
subroutine delaunay_triangles(x, y, idx)

Arguments

NameTypeIntentAttributesDescription
xreal(kind=R8P)inAbscissae.
yreal(kind=R8P)inOrdinates.
idxinteger(kind=I4P)outallocatableTriangle 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

fortran
subroutine dig_one_hole(tri, px, py, chi, on_hull, edges, lengths, nedges, dug)

Arguments

NameTypeIntentAttributesDescription
tritype(triangles_object)inoutTriangles.
pxreal(kind=R8P)inAbscissae.
pyreal(kind=R8P)inOrdinates.
chireal(kind=R8P)inCharacteristic length.
on_hulllogicalinoutPoints on the perimeter.
edgesinteger(kind=I4P)inoutallocatablePerimeter edges (2, edge).
lengthsreal(kind=R8P)inoutallocatableTheir lengths.
nedgesinteger(kind=I4P)inoutPerimeter edges.
duglogicaloutAn 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

fortran
subroutine delaunay(px, py, n, tri, edges, lengths, nedges, on_hull)

Arguments

NameTypeIntentAttributesDescription
pxreal(kind=R8P)inoutAbscissae, n + 4.
pyreal(kind=R8P)inoutOrdinates, n + 4.
ninteger(kind=I4P)inPoints.
tritype(triangles_object)outTriangles.
edgesinteger(kind=I4P)outallocatablePerimeter edges (2, edge).
lengthsreal(kind=R8P)outallocatableTheir lengths.
nedgesinteger(kind=I4P)outPerimeter edges.
on_hulllogicaloutallocatablePoints 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

fortran
subroutine insert_triangle(tri, px, py, a, b, c)

Arguments

NameTypeIntentAttributesDescription
tritype(triangles_object)inoutTriangles.
pxreal(kind=R8P)inAbscissae.
pyreal(kind=R8P)inOrdinates.
ainteger(kind=I4P)inVertex.
binteger(kind=I4P)inVertex.
cinteger(kind=I4P)inVertex.

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

fortran
subroutine move_triangle(tri, pt, t, head)

Arguments

NameTypeIntentAttributesDescription
tritype(triangles_object)inoutTriangles.
ptinteger(kind=I4P)inTriangle before it.
tinteger(kind=I4P)inTriangle.
headinteger(kind=I4P)inDestination list.

Call graph

sort_pairs ​

The first n pairs sorted by their first then second element (insertion sort; equal pairs are equal).

Attributes: pure

fortran
subroutine sort_pairs(pairs, n)

Arguments

NameTypeIntentAttributesDescription
pairsinteger(kind=I4P)inoutPairs (2, pair).
ninteger(kind=I4P)inPairs 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

fortran
subroutine sort_lengths(edges, lengths, n)

Arguments

NameTypeIntentAttributesDescription
edgesinteger(kind=I4P)inoutEdges (2, edge).
lengthsreal(kind=R8P)inoutLengths.
ninteger(kind=I4P)inEdges in use.

Call graph

grow_edges ​

Twice the room for perimeter edges.

Attributes: pure

fortran
subroutine grow_edges(edges, lengths)

Arguments

NameTypeIntentAttributesDescription
edgesinteger(kind=I4P)inoutallocatableEdges (2, edge).
lengthsreal(kind=R8P)inoutallocatableLengths.

Call graph

Functions ​

cross ​

gnuplot's CROSS(p1, p2, p3): positive for a left turn p1 -> p2 -> p3.

Attributes: pure

Returns: real(kind=R8P)

fortran
function cross(x1, y1, x2, y2, x3, y3) result(c)

Arguments

NameTypeIntentAttributesDescription
x1real(kind=R8P)inFirst point.
y1real(kind=R8P)inFirst point.
x2real(kind=R8P)inSecond point.
y2real(kind=R8P)inSecond point.
x3real(kind=R8P)inThird point.
y3real(kind=R8P)inThird point.

Call graph

Released under the GPL v3, BSD 2-Clause, BSD 3-Clause or MIT License.