Algorithm Search⌘K

Data structurecore

Winged-edge data structure

Also called winged edge, Baumgart winged edge.

Baumgart's B-rep in which each edge stores its two vertices, two faces and four neighbour edges, so edge queries take O(1) time and walks around a face or vertex O(1) per step.

Time
O(n) expected
Space
Θ(n) extra
Where
n = the number of edges

The winged-edge data structure stores the boundary of a polyhedral solid with one record per edge. Each edge record holds the two vertices of the edge, the two faces on its two sides and four more edges, the wings: the edges before and after it on each of its two faces. Each vertex and each face stores one edge. Bruce Baumgart made it for computer vision in the early 1970s, and it was the first edge-based boundary representation. From one edge, the program can reach every adjacent vertex, face and edge in O(1)O(1) time, and it can walk around a face or around a vertex in O(1)O(1) time per step. The price is that an edge does not know in which direction a face uses it, so every step of a walk must test which side of the edge it is on.

In plain words

Think of each fold of a cardboard box as a small card. The card names the two corners at the ends of the fold and the two sides of the box that meet at it. It also names four more folds. On each of the two sides, it names the fold just before it and the fold just after it, when you go around that side.

To go around one side of the box, start at any fold of that side, look on its card for the fold after it on this side, and move to that fold. To go around a corner, look on the card for the fold just before it on the side that leaves the corner. The four wings around each card give the structure its name.

The abstract type

The structure stores a closed oriented polyhedral surface whose faces are disks, and it answers adjacency queries about it.

  • BUILD(n,F)\mathrm{BUILD}(n, \mathcal{F}): make the structure for the vertices 0,…,n−10, \ldots, n - 1 and the faces F\mathcal{F}, each a cyclic list of vertices, counterclockwise seen from outside.
  • EDGE-VERTICES(e)\mathrm{EDGE\text{-}VERTICES}(e) and EDGE-FACES(e)\mathrm{EDGE\text{-}FACES}(e): the two ends and the two faces of ee.
  • FACE-EDGES(f)\mathrm{FACE\text{-}EDGES}(f): the edges of ff in counterclockwise order, so also its vertices.
  • VERTEX-EDGES(v)\mathrm{VERTEX\text{-}EDGES}(v): the edges at vv in counterclockwise order, so also the neighbours and the faces of vv.
  • SPLIT-EDGE(e)\mathrm{SPLIT\text{-}EDGE}(e): put a new vertex inside ee.
  • SPLIT-FACE(f,u,w)\mathrm{SPLIT\text{-}FACE}(f, u, w) and JOIN-FACES(e)\mathrm{JOIN\text{-}FACES}(e): cut ff into two faces by a new edge from uu to ww, and remove an edge that has two different faces.

The updates are three of the Euler operators, in the forms that keep one loop per face: SPLIT-EDGE is MEV, SPLIT-FACE is MEF and JOIN-FACES is KEF. Each one keeps V−E+FV - E + F, so the shell keeps its genus.

Representation

Each edge ee has a direction, from vstart[e]v_{start}[e] to vend[e]v_{end}[e]. Seen from outside and walking from vstartv_{start} to vendv_{end}, the face fleft[e]f_{left}[e] is on the left and fright[e]f_{right}[e] on the right. The faces run counterclockwise seen from outside, so fleft[e]f_{left}[e] uses ee from start to end, and fright[e]f_{right}[e] uses it from end to start.

record fields
edge ee vstart[e]v_{start}[e], vend[e]v_{end}[e], fleft[e]f_{left}[e], fright[e]f_{right}[e] and the four wings leftprev[e]left_{prev}[e], leftnext[e]left_{next}[e], rightprev[e]right_{prev}[e], rightnext[e]right_{next}[e]
vertex vv its point and one edge vertex_edge[v]vertex\_edge[v] at vv
face ff one edge face_edge[f]face\_edge[f] of ff; in a curved B-rep also the surface

The wings leftprev[e]left_{prev}[e] and leftnext[e]left_{next}[e] are the edges before and after ee in the counterclockwise loop of fleft[e]f_{left}[e], and rightprev[e]right_{prev}[e] and rightnext[e]right_{next}[e] are the same for fright[e]f_{right}[e]. So the topology takes 8 references per edge and one per vertex and per face, 8E+V+F8E + V + F in total. The half-edge form of the same surface stores 4 or 5 references per half-edge, 8 or 10 per edge, and it adds a loop record when faces have rings.

Baumgart's own edge nodes also hold list links and more fields than these eight; the table gives only the eight that carry the topology, as Weiler and Mäntylä describe them. Some texts call the four wings the clockwise and counterclockwise successors and predecessors, with different conventions for which is which, so read the convention of a source before you copy its code.

The edge record does not say in which direction a face uses the edge. To step to the next edge of face ff from edge ee, the program must test whether ff is fleft[e]f_{left}[e] or fright[e]f_{right}[e]. This test needs the two faces of each edge to be different. In the same way, to step around vertex vv, it must test whether vv is vstart[e]v_{start}[e] or vend[e]v_{end}[e].

Operations

  1. FACE-EDGES(f) ▷ the edges of f, counterclockwise from outside
  2. 1e₀ ← face_edge[f]; e ← e₀
  3. 2repeat output e
  4. 3if f_left[e] = f then e ← left_next[e] else e ← right_next[e]
  5. 4until e = e₀
  6. VERTEX-EDGES(v) ▷ the edges at v, counterclockwise from outside
  7. 5e₀ ← vertex_edge[v]; e ← e₀
  8. 6repeat output e
  9. 7if v_start[e] = v then e ← left_prev[e] else e ← right_prev[e]
  10. 8until e = e₀
  11. SPLIT-FACE(f, u, w) ▷ u, w on f and not joined by an edge
  12. 9walk f; find the edges a_in, a_out before and after u, and b_in, b_out before and after w
  13. 10make a face g and an edge n from u to w with f_left[n] ← f, f_right[n] ← g
  14. 11left_prev[n] ← a_in; left_next[n] ← b_out; right_prev[n] ← b_in; right_next[n] ← a_out
  15. 12for each edge of f from a_out to b_in: replace f by g on the side of f
  16. 13set the next wing of a_in on f, the prev wing of b_out on f, the next wing of b_in on g and the prev wing of a_out on g to n
  17. 14face_edge[f] ← n; face_edge[g] ← n

Around a face. Line L3 is the orientation test. If ff is the left face of ee, then ff uses ee from start to end, and the next edge of ff is leftnext[e]left_{next}[e]. If not, ff uses ee from end to start, and the next edge is rightnext[e]right_{next}[e]. The vertex at the start of ee on ff is vstart[e]v_{start}[e] in the first case and vend[e]v_{end}[e] in the second.

Around a vertex. Let ee be an edge at vv, and let ff be the face that uses ee as it leaves vv: this is fleft[e]f_{left}[e] if v=vstart[e]v = v_{start}[e] and fright[e]f_{right}[e] if not. The edge before ee in ff comes into vv. Seen from outside, ff lies counterclockwise from ee at vv, so this edge is the next edge counterclockwise around vv. Line L7 takes it from the wing on the side of ff.

Updates. In SPLIT-FACE, the new edge nn has ff on its left, so ff keeps the part of its loop from ww around to uu, and the new face gg gets the part from uu to ww. Line L12 moves the edges of that part to gg, one side field each. Line L13 sets the four wings that pointed across the cut. JOIN-FACES does the opposite steps: it moves the edges of the right face of nn to the left face and joins the wings around the two ends of nn. SPLIT-EDGE puts a new vertex mm inside ee: it makes a new edge from mm to vend[e]v_{end}[e], changes vend[e]v_{end}[e] to mm, and sets six wings. It needs no walk, so it takes O(1)O(1) time.

Build. BUILD makes one edge for each unordered pair {u,v}\{u, v\} that is a side of a face, with a hash map on the pair. The first face that uses the pair is the left face, and the direction of the edge is the direction in which that face uses it. The second face must use it in the other direction, and it becomes the right face. Then BUILD walks each face list once and sets the prev and next wings on the side of that face. It fails if a pair is used by one face only, by more than two faces, twice in one direction, or twice by one face, and if the walk around a vertex misses an edge at that vertex.

Example

Take the cube with the vertices 0=(0,0,0)0 = (0, 0, 0), 1=(1,0,0)1 = (1, 0, 0), 2=(1,1,0)2 = (1, 1, 0), 3=(0,1,0)3 = (0, 1, 0) and 44 to 77 the same points with z=1z = 1, and the faces 0=(0,3,2,1)0 = (0, 3, 2, 1) at the bottom, 1=(4,5,6,7)1 = (4, 5, 6, 7) at the top, 2=(0,1,5,4)2 = (0, 1, 5, 4), 3=(1,2,6,5)3 = (1, 2, 6, 5), 4=(2,3,7,6)4 = (2, 3, 7, 6) and 5=(3,0,4,7)5 = (3, 0, 4, 7). BUILD gives these 12 edges:

ee vstartv_{start} vendv_{end} fleftf_{left} frightf_{right} leftprevleft_{prev} leftnextleft_{next} rightprevright_{prev} rightnextright_{next}
0 0 3 0 5 3 1 11 9
1 3 2 0 4 0 2 10 11
2 2 1 0 3 1 3 8 10
3 1 0 0 2 2 0 9 8
4 4 5 1 2 7 5 8 9
5 5 6 1 3 4 6 10 8
6 6 7 1 4 5 7 11 10
7 7 4 1 5 6 4 9 11
8 1 5 2 3 3 4 5 2
9 4 0 2 5 4 3 0 7
10 2 6 3 4 2 5 6 1
11 3 7 4 5 1 6 7 0

The face edges are face_edge=(0,4,3,2,1,0)face\_edge = (0, 4, 3, 2, 1, 0), and the vertex edges are vertex_edge=(0,2,1,0,4,4,5,6)vertex\_edge = (0, 2, 1, 0, 4, 4, 5, 6).

FACE-EDGES(2) starts at edge 3. Face 2 is on the right of edge 3, so the next edge is rightnext[3]=8right_{next}[3] = 8. Face 2 is on the left of edge 8, so the next edge is leftnext[8]=4left_{next}[8] = 4. Then rightnext[4]=9right_{next}[4] = 9 and leftnext[9]=3left_{next}[9] = 3, the start. The walk uses the edges in both directions: the left and right sides alternate. The start vertices on face 2 are vend[3]=0v_{end}[3] = 0, vstart[8]=1v_{start}[8] = 1, vend[4]=5v_{end}[4] = 5 and vstart[9]=4v_{start}[9] = 4, which is the face list (0,1,5,4)(0, 1, 5, 4).

VERTEX-EDGES(0) starts at edge 0, which leaves 0, so the next edge is leftprev[0]=3left_{prev}[0] = 3. Edge 3 ends at 0, so the next is rightprev[3]=9right_{prev}[3] = 9, and edge 9 also ends at 0, so the next is rightprev[9]=0right_{prev}[9] = 0, the start. The neighbours of 0 are 3,1,43, 1, 4 and the faces on the left of the edges out of 0 are 0,2,50, 2, 5, counterclockwise seen from outside the corner.

SPLIT-FACE(1, 4, 6) cuts the top face along its diagonal. It makes edge 12 from 4 to 6 with fleft=1f_{left} = 1, fright=6f_{right} = 6 and the wings leftprev=7left_{prev} = 7, leftnext=6left_{next} = 6, rightprev=5right_{prev} = 5, rightnext=4right_{next} = 4. Face 1 becomes (4,6,7)(4, 6, 7) and the new face 6 is (6,4,5)(6, 4, 5). Now V−E+F=8−13+7=2V - E + F = 8 - 13 + 7 = 2, as before.

Correctness

Assume BUILD returns. Then every edge has two different faces that use it in opposite directions, and on the side of each face, its two wings are its neighbours in the face list of that face. So line L3 moves from each edge of ff to the next edge of ff, and FACE-EDGES lists the face list of ff once and stops. The vertex step of line L7 is a permutation of the edges at vv, because its inverse is the next wing on the face that comes into vv, and each of its steps crosses one face at vv. A cycle of this permutation is one fan of faces at vv. BUILD checks that the cycle of vertex_edge[v]vertex\_edge[v] has every edge at vv, so VERTEX-EDGES lists them all. Each update changes only the fields of the edges on the cut and keeps these two facts, so the queries stay correct after any sequence of updates. The full proof is in the proof file.

The orientation test of line L3 is correct only if fleft[e]≠fright[e]f_{left}[e] \ne f_{right}[e]. If both sides of ee are the same face, for example for a bridge edge that joins a hole to the outer boundary of a face, the test always takes the left wing, and the walk can go around the face in a loop that does not contain all its edges. BUILD rejects such input.

Proof: The winged-edge walks list each face and each vertex star exactly once, and the updates keep the wings correctfull

We use the pseudocode and the fields of the page. The input of BUILD is a list of faces, each a cyclic list (w0,…,wk−1)(w_0, \ldots, w_{k-1}) of k≥3k \ge 3 distinct vertices. A face ff uses the directed pair (wi,wi+1)(w_i, w_{i+1}), indices mod kk. For an edge ee and a face f∈{fleft[e],fright[e]}f \in \{f_{left}[e], f_{right}[e]\} with fleft[e]≠fright[e]f_{left}[e] \ne f_{right}[e], write side(e,f)\mathrm{side}(e, f) for left or right, next(e,f)\mathrm{next}(e, f) and prev(e,f)\mathrm{prev}(e, f) for the wings on that side, and tail(e,f)\mathrm{tail}(e, f) for vstart[e]v_{start}[e] if the side is left and vend[e]v_{end}[e] if it is right. Write head(e,f)\mathrm{head}(e, f) for the other end.

Invariant W. (a) For each edge ee, fleft[e]≠fright[e]f_{left}[e] \ne f_{right}[e]. (b) For each face ff, the edges ee with f∈{fleft[e],fright[e]}f \in \{f_{left}[e], f_{right}[e]\} can be listed as e0,…,ek−1e_0, \ldots, e_{k-1} so that next(ei,f)=ei+1\mathrm{next}(e_i, f) = e_{i+1} and prev(ei,f)=ei−1\mathrm{prev}(e_i, f) = e_{i-1}, indices mod kk, and head(ei,f)=tail(ei+1,f)\mathrm{head}(e_i, f) = \mathrm{tail}(e_{i+1}, f). (c) face_edge[f]face\_edge[f] is an edge of ff, and vertex_edge[v]vertex\_edge[v] is an edge with vv as an end. (d) For each vertex vv, the walk of lines L5 to L8 meets every edge with vv as an end.

The cyclic list (tail(e0,f),…,tail(ek−1,f))(\mathrm{tail}(e_0, f), \ldots, \mathrm{tail}(e_{k-1}, f)) of (b) is the face list of ff.

Lemma 1 (BUILD). If BUILD returns, then W holds, and the face list of each face ff is the input list of ff, up to a cyclic shift.

Proof. BUILD makes one edge per unordered pair {u,v}\{u, v\} that some face uses. If the first face ff that uses the pair uses it as (u,v)(u, v), the edge gets vstart=uv_{start} = u, vend=vv_{end} = v and fleft=ff_{left} = f. A later use is accepted only if it is (v,u)(v, u) by a face whose slot frightf_{right} is still empty, and it sets frightf_{right}. Any other use fails. After the loop, BUILD fails if some frightf_{right} is empty or equal to fleftf_{left}. So if BUILD returns, each edge is used by exactly two different faces, the left face as (vstart,vend)(v_{start}, v_{end}) and the right face as (vend,vstart)(v_{end}, v_{start}), and (a) holds. In particular tail(e,f)\mathrm{tail}(e, f) is the first vertex of the pair that ff uses on ee, and head(e,f)\mathrm{head}(e, f) the second. A face with distinct vertices uses each pair at most once. Now take the input list (w0,…,wk−1)(w_0, \ldots, w_{k-1}) of ff and let eie_i be the edge of {wi,wi+1}\{w_i, w_{i+1}\}. These are kk different edges, they are all the edges of ff, and the second loop of BUILD sets prev(ei,f)=ei−1\mathrm{prev}(e_i, f) = e_{i-1} and next(ei,f)=ei+1\mathrm{next}(e_i, f) = e_{i+1} on the side of ff. Each side of each edge belongs to one face, so no other step writes these fields. Also tail(ei,f)=wi\mathrm{tail}(e_i, f) = w_i and head(ei,f)=wi+1=tail(ei+1,f)\mathrm{head}(e_i, f) = w_{i+1} = \mathrm{tail}(e_{i+1}, f), which gives (b) and the claim about the face list. BUILD sets face_edge[f]=e0face\_edge[f] = e_0 and vertex_edge[v]vertex\_edge[v] to the first edge with vv as an end, and it fails if a vertex has none, so (c) holds. The last check of BUILD compares the length of the walk at each vv with the number of edges at vv, which gives (d) once Lemma 3 shows that the walk lists distinct edges. □\square

Lemma 2 (FACE-EDGES). Under W, FACE-EDGES(ff) stops and outputs the edges of ff once each, in the order of (b), starting at face_edge[f]face\_edge[f].

Proof. By (a), the test of line L3 decides side(e,f)\mathrm{side}(e, f) correctly, so line L3 sets e←next(e,f)e \leftarrow \mathrm{next}(e, f). By (b), next(⋅,f)\mathrm{next}(\cdot, f) is the cyclic shift ei↦ei+1e_i \mapsto e_{i+1} on the kk edges of ff, and by (c) the walk starts on one of them. So the walk visits ei,ei+1,…e_i, e_{i+1}, \ldots and returns to eie_i after exactly kk steps, at which point line L4 stops it. □\square

Lemma 3 (VERTEX-EDGES). Under W, for a vertex vv let AvA_v be the set of edges with vv as an end, and for e∈Ave \in A_v let σv(e)\sigma_v(e) be the edge that line L7 picks. Then σv\sigma_v is a permutation of AvA_v, and VERTEX-EDGES(vv) stops and outputs the cycle of σv\sigma_v that contains vertex_edge[v]vertex\_edge[v], once each. With (d), this is all of AvA_v.

Proof. Let e∈Ave \in A_v and let φ(e)\varphi(e) be fleft[e]f_{left}[e] if vstart[e]=vv_{start}[e] = v and fright[e]f_{right}[e] if not. Then tail(e,φ(e))=v\mathrm{tail}(e, \varphi(e)) = v: the face φ(e)\varphi(e) uses ee as it leaves vv. Line L7 sets σv(e)=prev(e,φ(e))\sigma_v(e) = \mathrm{prev}(e, \varphi(e)), and by (b), head(σv(e),φ(e))=tail(e,φ(e))=v\mathrm{head}(\sigma_v(e), \varphi(e)) = \mathrm{tail}(e, \varphi(e)) = v. So σv(e)∈Av\sigma_v(e) \in A_v, and φ(e)\varphi(e) uses it as it comes into vv. The two ends of an edge are different, because the vertices of a face are, so exactly one of the two cases holds for each edge. Now let p∈Avp \in A_v, and let ψ(p)\psi(p) be the face that uses pp as it comes into vv: fleft[p]f_{left}[p] if vend[p]=vv_{end}[p] = v and fright[p]f_{right}[p] if not. If σv(e)=p\sigma_v(e) = p, then φ(e)=ψ(p)\varphi(e) = \psi(p), because φ(e)\varphi(e) uses pp into vv and only one face does so, and e=next(p,ψ(p))e = \mathrm{next}(p, \psi(p)) by (b). So ee is determined by pp, and σv\sigma_v is injective on the finite set AvA_v, hence a permutation. The walk of lines L5 to L8 applies σv\sigma_v from vertex_edge[v]∈Avvertex\_edge[v] \in A_v, which is in AvA_v by (c), until it returns, so it outputs one cycle of σv\sigma_v once each and stops. □\square

Geometrically, φ(e)\varphi(e) is the face just counterclockwise of ee at vv, seen from outside, and σv(e)\sigma_v(e) is the next edge counterclockwise. A cycle of σv\sigma_v is a fan of faces at vv, and (d) says that vv has one fan, which is the vertex condition of a 2-manifold.

Lemma 4 (SPLIT-EDGE). If W holds before SPLIT-EDGE(ee), it holds after it, every face list keeps its order with the new vertex mm put between vstart[e]v_{start}[e] and vend[e]v_{end}[e], and V−E+FV - E + F does not change.

Proof. Let a=vstart[e]a = v_{start}[e], b=vend[e]b = v_{end}[e], f=fleft[e]f = f_{left}[e] and g=fright[e]g = f_{right}[e]. On ff the edges are …,e,x,…\ldots, e, x, \ldots with x=leftnext[e]x = left_{next}[e], and on gg they are …,y,e,…\ldots, y, e, \ldots with y=rightprev[e]y = right_{prev}[e]. The update makes e2e_2 from mm to bb with the same two faces, sets vend[e]=mv_{end}[e] = m, and sets the wings so that the cycle of ff becomes …,e,e2,x,…\ldots, e, e_2, x, \ldots and the cycle of gg becomes …,y,e2,e,…\ldots, y, e_2, e, \ldots. The heads and tails match: on ff, ee now ends at mm where e2e_2 starts, and e2e_2 ends at bb where xx starts; on gg, yy ends at bb where e2e_2 starts on that side, and e2e_2 ends at mm where ee starts on that side. No other face or wing changes. So (a) and (b) hold, vertex_edge[m]=evertex\_edge[m] = e and the update of vertex_edge[b]vertex\_edge[b] keep (c), and the edges at mm are ee and e2e_2, which line L7 joins in one cycle, so (d) holds at mm; at bb the edge e2e_2 takes the place of ee in the cycle. One vertex and one edge are new, so V−E+FV - E + F is the same. □\square

Lemma 5 (SPLIT-FACE). If W holds before SPLIT-FACE(f,u,wf, u, w) and u,wu, w are vertices of ff that are not joined by an edge, then W holds after it, the face list of ff is the part of the old list from ww around to uu, the face list of the new face gg is the part from uu to ww, and V−E+FV - E + F does not change.

Proof. By Lemma 2, line L9 finds the cycle e0,…,ek−1e_0, \ldots, e_{k-1} of ff. Let eie_i be the edge with tail uu and eje_j the edge with tail ww, so aout=eia_{out} = e_i, ain=ei−1a_{in} = e_{i-1}, bout=ejb_{out} = e_j and bin=ej−1b_{in} = e_{j-1}. Since uu and ww are not joined, j≠i±1j \ne i \pm 1. The new edge nn runs from uu to ww, with ff on its left and gg on its right, so ff uses it as (u,w)(u, w) and gg as (w,u)(w, u), and (a) holds for it. Line L12 gives the edges ei,…,ej−1e_i, \ldots, e_{j-1} to gg, each on its side of ff. Lines L11 and L13 make the cycle of ff equal to ei−1,n,ej,…e_{i-1}, n, e_j, \ldots, that is ej,…,ei−1,ne_j, \ldots, e_{i-1}, n, and the cycle of gg equal to n,ei,…,ej−1n, e_i, \ldots, e_{j-1}. On ff, ei−1e_{i-1} ends at uu where nn starts, and nn ends at ww where eje_j starts. On gg, ej−1e_{j-1} ends at ww where nn starts on the side of gg, and nn ends at uu where eie_i starts. The other wings of these edges point inside one of the two parts and are not changed, and the edges of other faces are not touched. So (b) holds, and the face lists are as claimed. Line L14 gives (c). For (d), at uu the old step σu(ei)=ei−1\sigma_u(e_i) = e_{i-1} becomes the two steps σu(ei)=n\sigma_u(e_i) = n and σu(n)=ei−1\sigma_u(n) = e_{i-1}: the edge nn is put into the one cycle at uu, and the same holds at ww. Each new edge is not an edge between the same ends as an old one, because of the test, so the edges at uu stay distinct. One edge and one face are new, so V−E+FV - E + F is the same. □\square

Lemma 6 (JOIN-FACES). If W holds before JOIN-FACES(nn), and the two faces f=fleft[n]f = f_{left}[n] and g=fright[n]g = f_{right}[n] have only the two ends u,wu, w of nn in common and each of u,wu, w has at least 3 edges, then W holds after it, and the face list of ff is the face list of ff with the part of gg from uu to ww put in place of nn.

Proof. The steps are the inverse of those of Lemma 5 with ei−1=leftprev[n]e_{i-1} = left_{prev}[n], ej=leftnext[n]e_j = left_{next}[n], ej−1=rightprev[n]e_{j-1} = right_{prev}[n] and ei=rightnext[n]e_i = right_{next}[n]: the edges of gg other than nn get ff on their side of gg, and the four wings that pointed to nn are joined. Since ff and gg share no vertex other than uu and ww, they share no edge other than nn, so no edge gets ff on both sides, and (a) holds. The cycle of ff becomes ej,…,ei−1,ei,…,ej−1e_j, \ldots, e_{i-1}, e_i, \ldots, e_{j-1}, and the heads and tails match at uu and at ww, which gives (b). The fields that pointed to nn are moved to eie_i and eje_j, which gives (c). At uu, the steps σu(ei)=n\sigma_u(e_i) = n and σu(n)=ei−1\sigma_u(n) = e_{i-1} become σu(ei)=ei−1\sigma_u(e_i) = e_{i-1}, which removes nn from the cycle and keeps one cycle, and the same holds at ww. The degree condition keeps at least 2 edges at each end, so no vertex is left with a face loop of length 2. So (d) holds. □\square

Theorem. After BUILD and any sequence of SPLIT-EDGE, SPLIT-FACE and JOIN-FACES whose preconditions hold, FACE-EDGES(ff) outputs the face list of each face ff and VERTEX-EDGES(vv) outputs all edges at each vertex vv, each once and in counterclockwise order, and both stop. The edge queries return the fields of the edge record, which are correct by W.

Proof. W holds after BUILD by Lemma 1, and after each update by Lemmas 4 to 6, by induction on the number of updates. Lemmas 2 and 3 give the output and the termination of the walks under W. □\square

The tests check the same facts on the cube, the octahedron and a torus, and after each of 360 random steps, against a brute force that stores only the face lists and answers each query by a scan of all faces. They also check that BUILD rejects an open surface, a reversed face, an edge on three faces and two tetrahedra that share one vertex. ■\blacksquare

Complexity

Let nn be the number of edges.

  • BUILD takes O(n)O(n) expected time with a hash map on the vertex pairs, and Θ(n)\Theta(n) space: 8n8n edge fields, one field per vertex and one per face.
  • EDGE-VERTICES, EDGE-FACES and each wing take O(1)O(1) time. The test of line L3 or line L7 is one comparison.
  • FACE-EDGES(ff) takes O(k)O(k) time for a face with kk edges, and VERTEX-EDGES(vv) takes O(d)O(d) time for a vertex of degree dd. So the neighbours, the faces at a vertex and the vertices of a face take time linear in the size of the answer.
  • SPLIT-EDGE takes O(1)O(1) time. SPLIT-FACE walks ff to find uu and ww and to change the face of the moved edges, so it takes O(k)O(k) time, plus O(d)O(d) for the test that uu and ww are not neighbours. JOIN-FACES takes time linear in the sizes of the two faces.

The constant time of the summary is the time of one step. No structure of this kind lists the kk edges of a face in less than kk steps, because it must output them.

Variants

  • Half-edge. Split each edge record into two half-edges, one for each face. Each half-edge knows its own face and its own next edge, so the orientation test of line L3 goes away, and a face can have rings through a loop record. This is the doubly connected edge list of planar subdivisions, and the B-rep page builds a solid modeler form of it.
  • Quad-edge. The quad-edge data structure of Guibas and Stolfi stores one record per edge with four directed versions of it, two for the edge and two for its dual. It stores the surface and its dual together, and it allows non-orientable surfaces.
  • Signed edge references. Store each wing, each face_edgeface\_edge and each vertex_edgevertex\_edge as an edge with a direction bit. Then the walks need no test, and the structure is close to a half-edge structure that shares one record per edge.
  • Faces with rings. Weiler's modified winged edge puts a loop record between the edges and the faces, so that a face can have several boundaries. Without it, a face with a hole needs a bridge edge with the same face on both sides, and the orientation test fails on it.
  • Non-manifold. The radial edge data structure stores any number of faces around an edge, which the two face fields of a winged edge cannot do.

When to use it

Use the winged edge when the faces are disks, the surface is a closed 2-manifold, and memory per edge matters more than the cost of one comparison per step. It suits polyhedral modelers and mesh editors that make many local changes by Euler operators, because each edge has only one record to update. When faces can have holes, or when code must walk loops fast and without branches, use a half-edge form. For a triangle mesh that does not change its connectivity, a corner table or the face-vertex lists of a polygon mesh use less memory.

Pitfalls

  • The orientation test. Every step around a face must test whether the face is the left or the right face of the edge. Code that always takes leftnextleft_{next} walks on the wrong face as soon as an edge is used backwards, as edges 3 and 4 of face 2 are in the example.
  • Same face on both sides. The test is ambiguous if fleft[e]=fright[e]f_{left}[e] = f_{right}[e]. This happens with bridge edges in faces with holes and with dangling edges inside a face. Reject them, or store directions with the references.
  • Wing conventions. Sources disagree on the names of the four wings and on the direction of the face loops. Mixing two conventions gives walks that go backwards or jump between faces.
  • Double edges. SPLIT-FACE between two vertices that are already joined by an edge makes two edges with the same ends. A face list then no longer gives the surface, and many algorithms that look up an edge by its ends break. Test w∉w \notin VERTEX-EDGES(uu) first, as the implementation does.
  • One fan per vertex. Two solids that touch at one vertex pass the edge tests of BUILD, but the walk around that vertex sees only one of them. Count the edges at each vertex and compare with the walk.
  • Wings after an update. An update must set the wings of the neighbouring edges on the correct side. Use helper functions that choose the side by the face, as the implementation does, and check all wings after each update in the tests.

Implementations

Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.

winged_edge_data_structure.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/winged-edge-data-structure/. The authors are listed in prov/4Q9BTY.jsonl.

"""Baumgart's winged-edge structure for a closed polyhedral surface.

Each edge e runs from v_start[e] to v_end[e]. Seen from outside the solid and
walking from v_start to v_end, the face f_left[e] is on the left and f_right[e]
on the right. The faces run counterclockwise seen from outside (the right-hand
rule), so f_left[e] traverses e from start to end and f_right[e] from end to
start. The four wings are the edges before and after e in the counterclockwise
loop of each face: left_prev, left_next, right_prev and right_next.

Each vertex and each face stores one edge. The faces are disks without rings,
and the two faces of an edge are different.
"""

from __future__ import annotations

from typing import Optional, Sequence

FIELDS = ("v_start", "v_end", "f_left", "f_right", "left_prev", "left_next", "right_prev", "right_next")


class WingedEdgeError(ValueError):
    """The input or the arguments do not fit the structure."""


class WingedEdge:
    def __init__(self, n_vertices: int, faces: Sequence[Sequence[int]]) -> None:
        """Build from faces given as counterclockwise lists of vertex ids 0..n-1.

        Time O(n) expected for n = the sum of the face sizes, with one hash map.
        """
        self.v_start: list[int] = []
        self.v_end: list[int] = []
        self.f_left: list[int] = []
        self.f_right: list[int] = []
        self.left_prev: list[int] = []
        self.left_next: list[int] = []
        self.right_prev: list[int] = []
        self.right_next: list[int] = []
        self.vertex_edge: list[int] = [-1] * n_vertices
        self.face_edge: list[int] = []
        self.alive_e: list[bool] = []
        self.alive_f: list[bool] = []
        key: dict[tuple[int, int], int] = {}  # (u, v) with u < v -> edge
        for f, cyc in enumerate(faces):
            k = len(cyc)
            if k < 3 or len(set(cyc)) != k:
                raise WingedEdgeError("a face needs at least 3 distinct vertices")
            self.face_edge.append(-1)
            self.alive_f.append(True)
            for i in range(k):
                u, v = cyc[i], cyc[(i + 1) % k]
                e = key.get((min(u, v), max(u, v)))
                if e is None:
                    e = self._new_edge(u, v, f, -1)
                    key[(min(u, v), max(u, v))] = e
                elif self.v_start[e] == v and self.f_right[e] == -1:
                    self.f_right[e] = f
                else:
                    raise WingedEdgeError("an edge is used twice in one direction or by more than two faces")
            self.face_edge[f] = key[(min(cyc[0], cyc[1]), max(cyc[0], cyc[1]))]
        for e in range(len(self.v_start)):
            if self.f_right[e] == -1:
                raise WingedEdgeError("an edge has only one face")
            if self.f_left[e] == self.f_right[e]:
                raise WingedEdgeError("an edge has the same face on both sides")
        for f, cyc in enumerate(faces):
            k = len(cyc)
            es = [key[(min(cyc[i], cyc[(i + 1) % k]), max(cyc[i], cyc[(i + 1) % k]))] for i in range(k)]
            for i, e in enumerate(es):
                self._set_prev(e, f, es[i - 1])
                self._set_next(e, f, es[(i + 1) % k])
        for e in range(len(self.v_start)):
            for v in (self.v_start[e], self.v_end[e]):
                if self.vertex_edge[v] == -1:
                    self.vertex_edge[v] = e
        if -1 in self.vertex_edge:
            raise WingedEdgeError("a vertex is on no face")
        self._check_fans()

    def _check_fans(self) -> None:
        """Each vertex walk must meet every edge at the vertex: one fan of faces."""
        degree = [0] * len(self.vertex_edge)
        for e in self.edges():
            degree[self.v_start[e]] += 1
            degree[self.v_end[e]] += 1
        for v in range(len(self.vertex_edge)):
            if len(self.vertex_edges(v)) != degree[v]:
                raise WingedEdgeError(f"vertex {v} has more than one fan of faces")

    # ----- O(1) helpers: the wing of e on the side of face f -----

    def _new_edge(self, u: int, v: int, fl: int, fr: int) -> int:
        for name, val in zip(FIELDS, (u, v, fl, fr, -1, -1, -1, -1)):
            getattr(self, name).append(val)
        self.alive_e.append(True)
        return len(self.v_start) - 1

    def _side(self, e: int, f: int) -> bool:
        """True if f is the left face of e, False if it is the right face."""
        if self.f_left[e] == f:
            return True
        if self.f_right[e] == f:
            return False
        raise WingedEdgeError(f"face {f} is not on edge {e}")

    def _next(self, e: int, f: int) -> int:
        return self.left_next[e] if self._side(e, f) else self.right_next[e]

    def _prev(self, e: int, f: int) -> int:
        return self.left_prev[e] if self._side(e, f) else self.right_prev[e]

    def _set_next(self, e: int, f: int, x: int) -> None:
        if self._side(e, f):
            self.left_next[e] = x
        else:
            self.right_next[e] = x

    def _set_prev(self, e: int, f: int, x: int) -> None:
        if self._side(e, f):
            self.left_prev[e] = x
        else:
            self.right_prev[e] = x

    def _set_face(self, e: int, old: int, new: int) -> None:
        if self._side(e, old):
            self.f_left[e] = new
        else:
            self.f_right[e] = new

    def _tail(self, e: int, f: int) -> int:
        """The vertex where the loop of f enters e."""
        return self.v_start[e] if self._side(e, f) else self.v_end[e]

    # ----- queries -----

    def edge_vertices(self, e: int) -> tuple[int, int]:
        return self.v_start[e], self.v_end[e]

    def edge_faces(self, e: int) -> tuple[int, int]:
        """(left face, right face), O(1)."""
        return self.f_left[e], self.f_right[e]

    def face_edges(self, f: int) -> list[int]:
        """The edges of f in counterclockwise order seen from outside."""
        out = []
        e0 = self.face_edge[f]  # @line L1
        e = e0
        while True:
            out.append(e)  # @line L2
            e = self.left_next[e] if self.f_left[e] == f else self.right_next[e]  # @line L3
            if e == e0:  # @line L4
                break
        return out

    def face_vertices(self, f: int) -> list[int]:
        return [self._tail(e, f) for e in self.face_edges(f)]

    def vertex_edges(self, v: int) -> list[int]:
        """The edges at v in counterclockwise order seen from outside."""
        out = []
        e0 = self.vertex_edge[v]  # @line L5
        e = e0
        while True:
            out.append(e)  # @line L6
            e = self.left_prev[e] if self.v_start[e] == v else self.right_prev[e]  # @line L7
            if e == e0:  # @line L8
                break
        return out

    def neighbors(self, v: int) -> list[int]:
        return [self.v_end[e] if self.v_start[e] == v else self.v_start[e] for e in self.vertex_edges(v)]

    def vertex_faces(self, v: int) -> list[int]:
        """The faces at v, counterclockwise: the face on the left of each edge out of v."""
        return [self.f_left[e] if self.v_start[e] == v else self.f_right[e] for e in self.vertex_edges(v)]

    def edges(self) -> list[int]:
        return [e for e in range(len(self.v_start)) if self.alive_e[e]]

    def faces(self) -> list[int]:
        return [f for f in range(len(self.face_edge)) if self.alive_f[f]]

    # ----- updates -----

    def split_edge(self, e: int) -> int:
        """Put a new vertex m inside e. Afterwards e runs from v_start to m and a
        new edge runs from m to the old v_end. Returns m. O(1)."""
        a, b = self.v_start[e], self.v_end[e]
        fl, fr = self.f_left[e], self.f_right[e]
        x = self.left_next[e]  # after e in fl
        y = self.right_prev[e]  # before e in fr
        m = len(self.vertex_edge)
        self.vertex_edge.append(e)
        e2 = self._new_edge(m, b, fl, fr)
        self.v_end[e] = m
        self.left_next[e2], self.left_prev[e2] = x, e
        self.left_next[e] = e2
        self.right_next[e2], self.right_prev[e2] = e, y
        self.right_prev[e] = e2
        self._set_prev(x, fl, e2)
        self._set_next(y, fr, e2)
        if self.vertex_edge[b] == e:
            self.vertex_edge[b] = e2
        return m

    def split_face(self, f: int, u: int, w: int) -> tuple[int, int]:
        """Add an edge n from u to w across f, two vertices of f that are not
        joined by an edge. The part of f from w around to u stays f; the part
        from u to w becomes a new face g. Returns (n, g). O(size of f + degree of u)."""
        es = self.face_edges(f)  # @line L9
        tails = [self._tail(e, f) for e in es]
        if u not in tails or w not in tails:
            raise WingedEdgeError("u and w must be vertices of f")
        iu, iw = tails.index(u), tails.index(w)
        k = len(es)
        if u == w or (iu + 1) % k == iw or (iw + 1) % k == iu:
            raise WingedEdgeError("u and w must be different and not next to each other")
        if w in self.neighbors(u):
            raise WingedEdgeError("u and w are already joined by an edge")
        a_out, a_in = es[iu], es[iu - 1]
        b_out, b_in = es[iw], es[iw - 1]
        g = len(self.face_edge)
        self.face_edge.append(-1)
        self.alive_f.append(True)
        n = self._new_edge(u, w, f, g)  # @line L10
        self.left_prev[n], self.left_next[n] = a_in, b_out  # @line L11
        self.right_prev[n], self.right_next[n] = b_in, a_out
        i = iu
        while i != iw:  # @line L12
            self._set_face(es[i], f, g)
            i = (i + 1) % k
        self._set_next(a_in, f, n)  # @line L13
        self._set_prev(b_out, f, n)
        self._set_next(b_in, g, n)
        self._set_prev(a_out, g, n)
        self.face_edge[f] = n  # @line L14
        self.face_edge[g] = n
        return n, g

    def join_faces(self, n: int) -> int:
        """Remove the edge n and join its right face into its left face. The two
        faces must have only the two ends of n in common, and each end of n must
        have at least 3 edges. Returns the deleted face. O(size of the faces)."""
        f, g = self.f_left[n], self.f_right[n]
        u, w = self.v_start[n], self.v_end[n]
        vf, vg = set(self.face_vertices(f)), set(self.face_vertices(g))
        if vf & vg != {u, w}:
            raise WingedEdgeError("the two faces must meet only along the edge")
        if len(self.vertex_edges(u)) < 3 or len(self.vertex_edges(w)) < 3:
            raise WingedEdgeError("each end must keep at least 2 edges")
        a_in, b_out = self.left_prev[n], self.left_next[n]
        b_in, a_out = self.right_prev[n], self.right_next[n]
        for e in self.face_edges(g):
            if e != n:
                self._set_face(e, g, f)
        self._set_next(a_in, f, a_out)
        self._set_prev(a_out, f, a_in)
        self._set_next(b_in, f, b_out)
        self._set_prev(b_out, f, b_in)
        if self.vertex_edge[u] == n:
            self.vertex_edge[u] = a_out
        if self.vertex_edge[w] == n:
            self.vertex_edge[w] = b_out
        self.face_edge[f] = a_out
        self.alive_e[n] = False
        self.alive_f[g] = False
        self.face_edge[g] = -1
        return g

    def check(self) -> None:
        """Check that the wings agree with the faces and the vertices."""
        for e in self.edges():
            for f, nxt, prv in ((self.f_left[e], self.left_next[e], self.left_prev[e]), (self.f_right[e], self.right_next[e], self.right_prev[e])):
                if not self.alive_e[nxt] or not self.alive_e[prv]:
                    raise WingedEdgeError("a wing points to a deleted edge")
                if self._prev(nxt, f) != e or self._next(prv, f) != e:
                    raise WingedEdgeError("the wings of two edges do not agree")
                head = self.v_end[e] if f == self.f_left[e] else self.v_start[e]
                if self._tail(nxt, f) != head:
                    raise WingedEdgeError("the next edge does not start where e ends")
            if self.f_left[e] == self.f_right[e]:
                raise WingedEdgeError("an edge has the same face on both sides")
        for v, e in enumerate(self.vertex_edge):
            if v not in (self.v_start[e], self.v_end[e]):
                raise WingedEdgeError("a vertex edge does not touch the vertex")
        for f in self.faces():
            if f not in self.edge_faces(self.face_edge[f]):
                raise WingedEdgeError("a face edge does not touch the face")
        self._check_fans()
test_winged_edge_data_structure.py 187 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/winged-edge-data-structure/. The authors are listed in prov/4Q9BTY.jsonl.

import random
import unittest

from winged_edge_data_structure import WingedEdge, WingedEdgeError

CUBE = [[0, 3, 2, 1], [4, 5, 6, 7], [0, 1, 5, 4], [1, 2, 6, 5], [2, 3, 7, 6], [3, 0, 4, 7]]
# vertices 0..3 at z = 0: (0,0), (1,0), (1,1), (0,1); 4..7 above them at z = 1
OCTAHEDRON = [[0, 2, 4], [2, 1, 4], [1, 3, 4], [3, 0, 4], [2, 0, 5], [1, 2, 5], [3, 1, 5], [0, 3, 5]]
# 0 = +x, 1 = -x, 2 = +y, 3 = -y, 4 = +z, 5 = -z


def torus(p, q):
    """A p by q grid of quads on a torus, oriented one way."""
    vid = lambda i, j: (i % p) * q + (j % q)
    return p * q, [[vid(i, j), vid(i + 1, j), vid(i + 1, j + 1), vid(i, j + 1)] for i in range(p) for j in range(q)]


def rotation(cyc, start):
    i = cyc.index(start)
    return cyc[i:] + cyc[:i]


class FaceList:
    """The brute force: faces as lists of vertex ids, and every query a scan."""

    def __init__(self, n, faces):
        self.n = n
        self.faces = {f: list(c) for f, c in enumerate(faces)}

    def edge_faces(self, u, v):
        left = [f for f, c in self.faces.items() if any(c[i] == u and c[(i + 1) % len(c)] == v for i in range(len(c)))]
        right = [f for f, c in self.faces.items() if any(c[i] == v and c[(i + 1) % len(c)] == u for i in range(len(c)))]
        assert len(left) == 1 and len(right) == 1
        return left[0], right[0]

    def ring(self, v):
        """The neighbours of v in counterclockwise order: from the edge v -> n
        of a face (..., p, v, n, ...), the next edge counterclockwise is v -> p."""
        step = {}
        for c in self.faces.values():
            k = len(c)
            for i in range(k):
                if c[i] == v:
                    step[c[(i + 1) % k]] = c[i - 1]
        start = next(iter(step))
        out = [start]
        x = step[start]
        while x != start:
            out.append(x)
            x = step[x]
        assert len(out) == len(step)
        return out

    def split_edge(self, u, v, m):
        for f, c in self.faces.items():
            k = len(c)
            for i in range(k):
                if {c[i], c[(i + 1) % k]} == {u, v}:
                    c.insert(i + 1, m)
                    break
        self.n += 1

    def split_face(self, f, u, w, g):
        c = rotation(self.faces[f], u)
        j = c.index(w)
        self.faces[g] = c[: j + 1]
        self.faces[f] = [u] + c[j:]

    def join_faces(self, u, w):
        f, g = self.edge_faces(u, w)
        cf = rotation(self.faces[f], w)  # w, ..., u
        cg = rotation(self.faces[g], u)  # u, ..., w
        self.faces[f] = cf + cg[1:-1]
        del self.faces[g]
        return g


def compare(test, we, fl):
    we.check()
    test.assertEqual(sorted(we.faces()), sorted(fl.faces))
    for f, c in fl.faces.items():
        got = we.face_vertices(f)
        test.assertEqual(rotation(got, c[0]), c)
    for v in range(fl.n):
        want = fl.ring(v)
        got = we.neighbors(v)
        test.assertEqual(rotation(got, want[0]), want)
        faces = we.vertex_faces(v)
        test.assertEqual(len(faces), len(want))
        for x, f in zip(we.neighbors(v), faces):
            test.assertEqual(fl.edge_faces(v, x)[0], f)
    edges = we.edges()
    for e in edges:
        u, v = we.edge_vertices(e)
        test.assertEqual(we.edge_faces(e), fl.edge_faces(u, v))
    pairs = {frozenset((c[i], c[(i + 1) % len(c)])) for c in fl.faces.values() for i in range(len(c))}
    test.assertEqual(len(pairs), len(edges))
    return len(fl.n * [0]) - len(edges) + len(fl.faces)


class WingedEdgeTests(unittest.TestCase):
    def test_cube(self):
        we = WingedEdge(8, CUBE)
        chi = compare(self, we, FaceList(8, CUBE))
        self.assertEqual(chi, 2)
        e = next(e for e in we.edges() if we.edge_vertices(e) == (0, 3))
        self.assertEqual(we.edge_faces(e), (0, 5))
        # seen from outside, at the corner (0, 0, 0): +y, then +x, then +z, counterclockwise
        self.assertEqual(rotation(we.neighbors(0), 3), [3, 1, 4])
        self.assertEqual(rotation(we.face_vertices(0), 0), [0, 3, 2, 1])

    def test_octahedron_and_torus(self):
        compare(self, WingedEdge(6, OCTAHEDRON), FaceList(6, OCTAHEDRON))
        n, faces = torus(4, 5)
        chi = compare(self, WingedEdge(n, faces), FaceList(n, faces))
        self.assertEqual(chi, 0)

    def test_bad_input(self):
        with self.assertRaises(WingedEdgeError):
            WingedEdge(8, CUBE[:-1])  # open surface
        with self.assertRaises(WingedEdgeError):
            WingedEdge(8, [CUBE[0][::-1]] + CUBE[1:])  # one face reversed
        with self.assertRaises(WingedEdgeError):
            WingedEdge(8, CUBE + [[0, 1, 2]])  # an edge on three faces
        two_tetrahedra = [[0, 2, 1], [0, 1, 3], [0, 3, 2], [1, 2, 3], [0, 5, 4], [0, 4, 6], [0, 6, 5], [4, 5, 6]]
        WingedEdge(4, two_tetrahedra[:4]).check()
        with self.assertRaises(WingedEdgeError):
            WingedEdge(7, two_tetrahedra)  # vertex 0 has two fans

    def test_random_updates(self):
        rng = random.Random(4171975)
        ops = {"split_edge": 0, "split_face": 0, "join_faces": 0}
        for start in range(6):
            if start % 3 == 0:
                n, faces = 8, CUBE
            elif start % 3 == 1:
                n, faces = 6, OCTAHEDRON
            else:
                n, faces = torus(3, 4)
            we, fl = WingedEdge(n, faces), FaceList(n, faces)
            chi0 = compare(self, we, fl)
            for step in range(60):
                r = rng.random()
                if r < 0.35:
                    e = rng.choice(we.edges())
                    u, v = we.edge_vertices(e)
                    m = we.split_edge(e)
                    fl.split_edge(u, v, m)
                    ops["split_edge"] += 1
                elif r < 0.7:
                    f = rng.choice(we.faces())
                    c = fl.faces[f]
                    if len(c) < 4:
                        continue
                    i = rng.randrange(len(c))
                    j = (i + rng.randrange(2, len(c) - 1)) % len(c)
                    try:
                        n_edge, g = we.split_face(f, c[i], c[j])
                    except WingedEdgeError:
                        continue  # the two vertices already have an edge
                    fl.split_face(f, c[i], c[j], g)
                    ops["split_face"] += 1
                else:
                    e = rng.choice(we.edges())
                    u, w = we.edge_vertices(e)
                    try:
                        g = we.join_faces(e)
                    except WingedEdgeError:
                        continue
                    self.assertEqual(fl.join_faces(u, w), g)
                    ops["join_faces"] += 1
                self.assertEqual(compare(self, we, fl), chi0)
        self.assertTrue(all(c > 40 for c in ops.values()), ops)

    def test_split_face_errors(self):
        we = WingedEdge(8, CUBE)
        with self.assertRaises(WingedEdgeError):
            we.split_face(0, 0, 3)  # next to each other
        with self.assertRaises(WingedEdgeError):
            we.split_face(0, 0, 5)  # 5 is not on face 0


if __name__ == "__main__":
    unittest.main()

History

Baumgart described the winged-edge polyhedron in a Stanford report of 1972 and at the AFIPS National Computer Conference in 1975, as the representation of his geometric modeling system for computer vision. It was the first boundary structure built on edges, and his Euler primitives made and changed polyhedra one edge and one face at a time. In 1985 Weiler studied which edge-based structures can answer all adjacency queries, and he gave variants with loops for faces with holes and with edge uses. In the same year Guibas and Stolfi published the quad-edge structure, which removes the orientation test with an algebra of directed edges. Mäntylä's book of 1988 compares the winged edge with the half-edge structure that later solid modelers used.

References

  1. Bruce G. Baumgart, A polyhedron representation for computer vision, Proceedings of the AFIPS National Computer Conference 44, 589 to 596, 1975, the winged-edge polyhedron, its edge, face and vertex nodes, and the traversals around a face and around a vertex
  2. Kevin Weiler, Edge-based data structures for solid modeling in curved-surface environments, IEEE Computer Graphics and Applications 5(1), 21 to 40, 1985, the winged-edge structure, its sufficiency for the adjacency relations, and the variants with loops and with edge uses
  3. Martti Mäntylä, An Introduction to Solid Modeling, Computer Science Press, 1988, Chapter 6, Boundary models, Section 6.2, Boundary data structures (p. 102), the winged-edge structure and its comparison with the half-edge structure
  4. Leonidas Guibas and Jorge Stolfi, Primitives for the manipulation of general subdivisions and the computation of Voronoi diagrams, ACM Transactions on Graphics 4(2), 74 to 123, 1985, the edge algebra and the quad-edge structure, which store one edge record with its two orientations and its dual

Where this leads

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH1 sketch
  • a full proof of time.expected
  • a full proof of space.extra
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW4 complete
  • a review of the text: no review record reviews/4Q9BTY/text.yaml