From a2265c8e1bb35c649f2606f82caefdbf8cd86272 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Tue, 17 Sep 2002 14:21:36 +0000 Subject: [PATCH] Added comments describing polygon tessellation algorithm --- src/xrtraps.c | 25 +++++++++++++++++++++++++ xrtraps.c | 25 +++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/src/xrtraps.c b/src/xrtraps.c index 8345d021c..e457bc652 100644 --- a/src/xrtraps.c +++ b/src/xrtraps.c @@ -321,6 +321,31 @@ _SortEdgeList(XrEdge **active) } } +/* The algorithm here is pretty simple: + + inactive = [edges] + y = min_p1_y(inactive) + + while (num_active || num_inactive) { + active = all edges containing y + + next_y = min( min_p2_y(active), min_p1_y(inactive), min_intersection(active) ) + + fill_traps(active, y, next_y, winding) + + y = next_y + } + + The invariants that hold during fill_traps are: + + All edges in active contain both y and next_y + No edges in active intersect within y and next_y + + These invariants mean that fill_traps is as simple as sorting the + active edges, forming a trapezoid between each adjacent pair. Then, + either the even-odd or winding rule is used to determine whether to + emit each of these trapezoids. +*/ XrError XrTrapsTessellatePolygon (XrTraps *traps, XrPolygon *poly, diff --git a/xrtraps.c b/xrtraps.c index 8345d021c..e457bc652 100644 --- a/xrtraps.c +++ b/xrtraps.c @@ -321,6 +321,31 @@ _SortEdgeList(XrEdge **active) } } +/* The algorithm here is pretty simple: + + inactive = [edges] + y = min_p1_y(inactive) + + while (num_active || num_inactive) { + active = all edges containing y + + next_y = min( min_p2_y(active), min_p1_y(inactive), min_intersection(active) ) + + fill_traps(active, y, next_y, winding) + + y = next_y + } + + The invariants that hold during fill_traps are: + + All edges in active contain both y and next_y + No edges in active intersect within y and next_y + + These invariants mean that fill_traps is as simple as sorting the + active edges, forming a trapezoid between each adjacent pair. Then, + either the even-odd or winding rule is used to determine whether to + emit each of these trapezoids. +*/ XrError XrTrapsTessellatePolygon (XrTraps *traps, XrPolygon *poly,