~/bend-docscommunity

src/penetrable.bend checks

raw source on the hub · import bend-visgraph@1.0.1.0/src/penetrable.bend as Penetrable

Limited penetrable visibility graphs, as ts2vg 1.2.4's _natural_penetrable and _horizontal_penetrable build them, in F32: every point sweeps the points right of it, and an edge may cross up to limit points. The sweeps are independent, so the points split into parallel ranges of equal work.

2 imports
import Base
import ./graph.bend as G

Types

type Pts source · line 9 · raw

Data

The points, in a list the parallel ranges share.

type Tops source · line 30 · raw

Data

The limit + 1 largest slopes (or heights) a sweep has accepted, as ts2vg's max_slopes; the sweep accepts a point above the smallest of them.

type Low source · line 35 · raw

Data

The position and value of the first smallest top.

Definitions

def points source · line 16 · raw

@count:Nat -> @+i:U32 -> @yr:Pair(Array<F32>, F32) -> @xr:Pair(Array<F32>, F32) -> @+index:Bool -> @acc:Pts -> Pts

The points of ys and xs from index i down to 0, onto acc; yr and xr hold y and x at i, and x is the index if index says so. The last read, at index -1, wraps around.

def tops_new source · line 38 · raw

@n:Nat -> Tops

def pick_low source · line 45 · raw

@c:Bool -> @a:Low -> @b:Low -> Low

def low_from source · line 52 · raw

@ts:Tops -> @+k:Nat -> @+best:Low -> Low

def lowest source · line 60 · raw

@ts:Tops -> Low

def Low.v source · line 63 · raw

@+l:Low -> F32

def set_at source · line 67 · raw

@k:Nat -> @ts:Tops -> @v:F32 -> Tops

def blocked_natural source · line 78 · raw

@ts:Tops -> @+s:F32 -> @+t:F32 -> @+n:F32 -> F32

How many tops a natural edge with slope s does not clear, as ts2vg's num_penetrations weight.

def blocked_horizontal source · line 85 · raw

@ts:Tops -> @+ya:F32 -> @+yb:F32 -> @+n:F32 -> F32

def add_known source · line 94 · raw

@+k:0xa7606adc225be7b0e88389ca594e0d14/src/graph.Weight -> @+lo:F32 -> @+hi:F32 -> @i1:U32 -> @i2:U32 -> @+x1:F32 -> @+x2:F32 -> @+y1:F32 -> @+y2:F32 -> @+s:F32 -> @+known:F32 -> @es:0xa7606adc225be7b0e88389ca594e0d14/src/graph.Edges -> 0xa7606adc225be7b0e88389ca594e0d14/src/graph.Edges

ts2vg's add_edge with a known weight: NaN means the weight function computes it.

def add_oriented source · line 99 · raw

@down:Bool -> @+k:0xa7606adc225be7b0e88389ca594e0d14/src/graph.Weight -> @+lo:F32 -> @+hi:F32 -> @ia:U32 -> @ib:U32 -> @xa:F32 -> @xb:F32 -> @ya:F32 -> @yb:F32 -> @s:F32 -> @known:F32 -> @es:0xa7606adc225be7b0e88389ca594e0d14/src/graph.Edges -> 0xa7606adc225be7b0e88389ca594e0d14/src/graph.Edges

The edge from a to b, or from b to a for top_to_bottom when b is higher.

def is_down source · line 106 · raw

@dir:0xa7606adc225be7b0e88389ca594e0d14/src/graph.Direction -> @+ya:F32 -> @+yb:F32 -> Bool

def is_count source · line 113 · raw

@k:0xa7606adc225be7b0e88389ca594e0d14/src/graph.Weight -> Bool

def natural_edge source · line 120 · raw

@+dir:0xa7606adc225be7b0e88389ca594e0d14/src/graph.Direction -> @+k:0xa7606adc225be7b0e88389ca594e0d14/src/graph.Weight -> @+lo:F32 -> @+hi:F32 -> @ia:U32 -> @ib:U32 -> @+xa:F32 -> @+xb:F32 -> @+ya:F32 -> @+yb:F32 -> @+s:F32 -> @+scale_a:F32 -> @ts:Tops -> @es:0xa7606adc225be7b0e88389ca594e0d14/src/graph.Edges -> 0xa7606adc225be7b0e88389ca594e0d14/src/graph.Edges

def horizontal_edge source · line 124 · raw

@+dir:0xa7606adc225be7b0e88389ca594e0d14/src/graph.Direction -> @+k:0xa7606adc225be7b0e88389ca594e0d14/src/graph.Weight -> @+lo:F32 -> @+hi:F32 -> @ia:U32 -> @ib:U32 -> @+xa:F32 -> @xb:F32 -> @+ya:F32 -> @+yb:F32 -> @ts:Tops -> @es:0xa7606adc225be7b0e88389ca594e0d14/src/graph.Edges -> 0xa7606adc225be7b0e88389ca594e0d14/src/graph.Edges

def natural_sweep source · line 132 · raw

@pts:Pts -> @up:Bool -> @+dir:0xa7606adc225be7b0e88389ca594e0d14/src/graph.Direction -> @+k:0xa7606adc225be7b0e88389ca594e0d14/src/graph.Weight -> @+lo:F32 -> @+hi:F32 -> @+ia:U32 -> @+xa:F32 -> @+ya:F32 -> @+scale_a:F32 -> @+ts:Tops -> @low:Low -> @+ib:U32 -> @+xb:F32 -> @+yb:F32 -> @+sb:F32 -> @es:0xa7606adc225be7b0e88389ca594e0d14/src/graph.Edges -> 0xa7606adc225be7b0e88389ca594e0d14/src/graph.Edges

The sweep of point a over the points right of it: ts2vg's inner loop. A point b the sweep sees replaces the smallest top and adds its edge at the next step, when up says so, so a step after an unseen point calls no def that recurses.

def horizontal_sweep source · line 151 · raw

@pts:Pts -> @up:Bool -> @stop:Bool -> @+dir:0xa7606adc225be7b0e88389ca594e0d14/src/graph.Direction -> @+k:0xa7606adc225be7b0e88389ca594e0d14/src/graph.Weight -> @+lo:F32 -> @+hi:F32 -> @+ia:U32 -> @+xa:F32 -> @+ya:F32 -> @+ts:Tops -> @low:Low -> @+ib:U32 -> @+xb:F32 -> @+yb:F32 -> @es:0xa7606adc225be7b0e88389ca594e0d14/src/graph.Edges -> 0xa7606adc225be7b0e88389ca594e0d14/src/graph.Edges

The same for the horizontal sweep, which stops once the smallest top is above a: no later point can be seen.

def sweep source · line 168 · raw

@g:0xa7606adc225be7b0e88389ca594e0d14/src/graph.Graph -> @+dir:0xa7606adc225be7b0e88389ca594e0d14/src/graph.Direction -> @+k:0xa7606adc225be7b0e88389ca594e0d14/src/graph.Weight -> @+lo:F32 -> @+hi:F32 -> @+limit:Nat -> @ia:U32 -> @+xa:F32 -> @+ya:F32 -> @pts:Pts -> @es:0xa7606adc225be7b0e88389ca594e0d14/src/graph.Edges -> 0xa7606adc225be7b0e88389ca594e0d14/src/graph.Edges

def sweeps source · line 177 · raw

@pts:Pts -> @count:Nat -> @+g:0xa7606adc225be7b0e88389ca594e0d14/src/graph.Graph -> @+dir:0xa7606adc225be7b0e88389ca594e0d14/src/graph.Direction -> @+k:0xa7606adc225be7b0e88389ca594e0d14/src/graph.Weight -> @+lo:F32 -> @+hi:F32 -> @+limit:Nat -> 0xa7606adc225be7b0e88389ca594e0d14/src/graph.Edges

The sweeps of the first count points of pts, one rope each: ts2vg's outer loop.

def drop source · line 184 · raw

@n:Nat -> @pts:Pts -> Pts

def first_half source · line 195 · raw

@g:0xa7606adc225be7b0e88389ca594e0d14/src/graph.Graph -> @+len:U32 -> @+count:U32 -> U32

How many of the first count of len points do half the sweeps' work. A natural sweep walks every point right of its start, so the first c starts walk c (2 len - 1 - c) / 2 points; a horizontal sweep stops early, so halving the starts is close enough.

def split source · line 207 · raw

@depth:Nat -> @+g:0xa7606adc225be7b0e88389ca594e0d14/src/graph.Graph -> @+dir:0xa7606adc225be7b0e88389ca594e0d14/src/graph.Direction -> @+k:0xa7606adc225be7b0e88389ca594e0d14/src/graph.Weight -> @+lo:F32 -> @+hi:F32 -> @+limit:Nat -> @+pts:Pts -> @+len:U32 -> @+cu:U32 -> @+count:Nat -> 0xa7606adc225be7b0e88389ca594e0d14/src/graph.Edges

The sweeps of the first count points of pts, as two halves of equal work in parallel, depth times over. len and cu are pts's length and count as U32; they only place the cut.

def built source · line 217 · raw

@+index:Bool -> @+g:0xa7606adc225be7b0e88389ca594e0d14/src/graph.Graph -> @+dir:0xa7606adc225be7b0e88389ca594e0d14/src/graph.Direction -> @+k:0xa7606adc225be7b0e88389ca594e0d14/src/graph.Weight -> @+lo:F32 -> @+hi:F32 -> @+limit:U32 -> @ys:Array<F32> -> @xs:Array<F32> -> @+n:U32 -> 0xa7606adc225be7b0e88389ca594e0d14/src/graph.Edges

def build source · line 223 · raw

@+g:0xa7606adc225be7b0e88389ca594e0d14/src/graph.Graph -> @+dir:0xa7606adc225be7b0e88389ca594e0d14/src/graph.Direction -> @+k:0xa7606adc225be7b0e88389ca594e0d14/src/graph.Weight -> @+lo:F32 -> @+hi:F32 -> @+limit:U32 -> @ys:Array<F32> -> @xs:0xa7606adc225be7b0e88389ca594e0d14/src/graph.Xs -> @+n:U32 -> 0xa7606adc225be7b0e88389ca594e0d14/src/graph.Edges

The limited penetrable graph of the n values ys at xs, crossing at most limit points. The x of G.Index{} is the index as an F32, exact for up to 2^24 values; the x of G.At{xs} must increase.