geometry only.Expand description
Geometry for weighted sets and fixed placements.
This module draws the outline of a hyperedge from the numbers on its memberships, places nodes at a weighted mix of given positions, and spreads overlapping points apart. Everything is a pure function of its input.
§Determinism
Nothing here is random, reads a clock or iterates a hash map, and only + - * /, sqrt, abs, floor, min
and max touch a float, so results are bit for bit the same on every machine. A test over every file of this
module enforces the rule.
§Stability
Nothing is kept between calls: every result is a function of its input alone, a measurement and not a simulation. Stability from one call to the next comes from four rules, each pinned by a test:
- Results are keyed by id and listed in the input’s order (
Positionskeeps insertion order). - The push that separates two points on one spot is chosen from the two ids, never from their indices, so adding or removing a far-away node changes no other node’s bits.
- A membrane’s grid sits on a lattice of
cellfixed at the origin(0, 0), so the outline of a set does not shimmer when its extent changes. - The same input gives the same bits on every run.
Easing between one call’s result and the next belongs to the caller.
§The two layers
The lower layer works on plain points and numbers: barycentre, corner_mix, spread, iso_lines
and weighted_outline. The upper layer reads a Hypergraph through the reads the core
already serves (node_ids and members_with_data): anchored_placement and edge_outline. The number on
a membership is read through a closure the caller gives, so the membership value may be of any type.
§Example
Three edges: two anchors, top and bottom, and one set, club, of three weighted members, each of which is
also in top or bottom, so every member is placed. The nodes are placed at the weighted mix of the anchors,
spread apart, and the set is outlined.
use hypergraph_rs::geometry::{
anchored_placement, edge_outline, spread, OutlineParams, Positions, SpreadParams,
};
use hypergraph_rs::Hypergraph;
let mut h: Hypergraph<(), (), f64> = Hypergraph::new();
for (node, edge, weight) in [
("a", "top", 3.0),
("a", "bottom", 1.0),
("b", "top", 1.0),
("b", "bottom", 3.0),
("c", "top", 2.0),
("c", "bottom", 2.0),
("a", "club", 5.0),
("b", "club", 4.0),
("c", "club", 6.0),
] {
h.add_node_to_edge_with_data(edge, node, weight).unwrap();
}
let mut anchors = Positions::new();
anchors.insert("top", (0.0, 10.0));
anchors.insert("bottom", (0.0, 0.0));
let placement = anchored_placement(&h, &anchors, |w| *w).unwrap();
assert!(placement.unplaced.is_empty());
let mut positions = placement.positions;
spread(&mut positions, &[], &SpreadParams::new(1.0, 8)).unwrap();
let params = OutlineParams::new(4.0, 0.5, 0.9);
let outline = edge_outline(&h, "club", &positions, |w| *w, ¶ms)
.unwrap()
.expect("the set has weight");
let drawn = &outline.outline;
assert!(drawn.held_weight >= 0.9 * drawn.total_weight);Structs§
- Edge
Outline - The outline of one hyperedge, and the members it was drawn from.
- Outline
Params - The parameters of
weighted_outline. - Placement
- The result of placing items.
- Positions
- Positions keyed by id, in insertion order.
- Scalar
Grid - A regular grid of numbers.
- Spread
Params - The parameters of
spread. - Spread
Report - What a call of
spreaddid. - Weighted
Outline - An outline and what it holds.
Enums§
- Geometry
Error - What can go wrong in a geometry function.
- Outline
- The shape of an outline.
Constants§
- DEFAULT_
LEVEL_ FRACTION - The default fraction of a member’s level that the line of a membrane is drawn at.
- DEFAULT_
MAX_ GRID_ NODES - The default most nodes the outline’s grid may hold.
- DEFAULT_
MAX_ NEIGHBOURS - The default cap on the points one point examines in a step.
Functions§
- anchored_
placement - Places each node of
hat the weighted mean of the positions of the anchored hyperedges it belongs to. - barycentre
- The weighted mean of
anchors:(Σ wᵢ·xᵢ / Σ wᵢ, Σ wᵢ·yᵢ / Σ wᵢ), summed in index order. - contains
- Whether
atis inside the paths by the even-odd rule: a ray fromatcrosses an odd number of segments. - corner_
mix - Places each item at the mix of
cornersgiven by its row of shares. - edge_
outline - The outline of the hyperedge
edge_id, from the numbers on its memberships and the positions of its members. - iso_
lines - The closed paths along which the grid crosses
threshold. - signed_
area - The signed area of a closed path by the shoelace formula: positive when it runs counter-clockwise.
- spread
- Pushes points apart until none is closer than
min_distanceto another, within a fixed number of steps. - weighted_
outline - The outline of a set of weighted points.
Type Aliases§
- Closed
Path - A closed path: its first vertex is not repeated at the end.
- Point
- A point
(x, y). - Rect
- A rectangle
(min_x, min_y, max_x, max_y), aslayout::LayoutResultuses.