/* Copyright (C) 2001-2007 Peter Selinger and nitoyon. Original code(Potrace v1.8) by Peter Selinger. Ported to ActionScript 3.0 by nitoyon. This file is part of PotrAs. It is free software and it is covered by the GNU General Public License. See the file COPYING for details. */ package com.nitoyon.potras { import flash.geom.Point; import flash.display.Graphics; public class ClosedPath { /** * */ public var $a:Array; /** * Constructor. * * initialize the members of the given curve structure to size m. * Return 0 on success, 1 on error with errno set. */ public function ClosedPath(array:Array = null):void { $a = array || []; } /** * draw */ public function draw(g:Graphics):void { var pt:Point = $a[$a.length - 1].c[2]; g.moveTo(pt.x, pt.y); for(var i:int = 0; i < $a.length; i++) { var c:Curve = $a[i]; if(c.tag == ProcessPath.POTRACE_CORNER) { g.lineTo(c.c[1].x, c.c[1].y); g.lineTo(c.c[2].x, c.c[2].y); } else { for(var t:Number = 0; t < 1.0; t += 0.02) { var p:Point = getBezierPoint(pt, c.c[0], c.c[1], c.c[2], t); g.lineTo(p.x, p.y); } g.lineTo(c.c[2].x, c.c[2].y); } pt = c.c[2]; } } /** * Get quad bezier curve point. */ private function getBezierPoint(p0:Point, p1:Point, p2:Point, p3:Point, t:Number):Point { return new Point(Math.pow(1 - t, 3) * p0.x + 3 * t * Math.pow(1 - t, 2) * p1.x + 3 * t * t * (1 - t) * p2.x + t * t * t * p3.x, Math.pow(1 - t, 3) * p0.y + 3 * t * Math.pow(1 - t, 2) * p1.y + 3 * t * t * (1 - t) * p2.y + t * t * t * p3.y); } } }