package { import flash.display.Sprite; public class DelaunayTriangulation extends Sprite { public var diagram : VoronoiDiagram; public function DelaunayTriangulation() { } public function setDiagram(voronoi:VoronoiDiagram):void { diagram = voronoi; } /** * Calculates and draws the DelaunayTriangulation based on the sites (and their edges) in * the Voronoi Diagram. */ public function calculate():void { } public function draw():void { graphics.clear(); graphics.lineStyle(2, 0x6666DD, 0.3); for each(var s : VoronoiSite in diagram.sites) { for each(var e : VoronoiEdge in s.edges) { // Draw a line from the two sites that make up this edge graphics.moveTo(e.siteA.x, stage.stageHeight - e.siteA.y); graphics.lineTo(e.siteB.x, stage.stageHeight - e.siteB.y); } } } /** * Returns the DCEL of the Delaunay Triangulation. * Note: calculate() must be called first for the complete triangulation to be in the output. * @return a string representation of the DCEL */ public function outputDCEL():String { var o : String = "****** Delaunay Triangulation ******\n\n"; // Vertices for each (var v:VoronoiNode in diagram.nodes) o += v.toString(); o += "\n"; // Faces for each (var f:VoronoiNode in diagram.nodes) o += f.toStringFace(); o += "\n"; // Half-edges for each (var e:VoronoiEdge in diagram.edges) o += e.toString(); o += "\n"; return o; } } }