Skip to content

Commit

Permalink
Added initShape, initSubShape, exitShape, exitSubShape in IBackend. S…
Browse files Browse the repository at this point in the history
…mall fix to prevent array overflow.
  • Loading branch information
Claus Wahlers committed May 21, 2011
1 parent 892f082 commit 098f74a
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 39 deletions.
Binary file modified bin/as3potrace.swc
Binary file not shown.
68 changes: 36 additions & 32 deletions src/com/powerflasher/as3potrace/POTrace.as
Expand Up @@ -91,12 +91,6 @@
this.bmWidth = bitmapDataCopy.width; this.bmWidth = bitmapDataCopy.width;
this.bmHeight = bitmapDataCopy.height; this.bmHeight = bitmapDataCopy.height;


if(backend == null) {
backend = new NullBackend();
}

backend.init(bmWidth, bmHeight);

var i:int; var i:int;
var j:int; var j:int;
var k:int; var k:int;
Expand All @@ -120,36 +114,46 @@


var shapes:Array = pathlist_to_curvearrayslist(plist); var shapes:Array = pathlist_to_curvearrayslist(plist);


for (i = 0; i < shapes.length; i++) { if(backend != null)
var shape:Array = shapes[i] as Array; {
for (j = 0; j < shape.length; j++) { backend.init(bmWidth, bmHeight);
var curves:Array = shape[j] as Array;
if(curves.length > 0) { for (i = 0; i < shapes.length; i++) {
var curve:Curve = curves[0] as Curve; backend.initShape();
backend.moveTo(curve.a.clone()); var shape:Array = shapes[i] as Array;
for (k = 0; k < curves.length; k++) { for (j = 0; j < shape.length; j++) {
curve = curves[k] as Curve; backend.initSubShape((j % 2) == 0);
switch(curve.kind) { var curves:Array = shape[j] as Array;
case CurveKind.BEZIER: if(curves.length > 0) {
backend.addBezier( var curve:Curve = curves[0] as Curve;
curve.a.clone(), backend.moveTo(curve.a.clone());
curve.cpa.clone(), for (k = 0; k < curves.length; k++) {
curve.cpb.clone(), curve = curves[k] as Curve;
curve.b.clone() switch(curve.kind) {
); case CurveKind.BEZIER:
break; backend.addBezier(
case CurveKind.LINE: curve.a.clone(),
backend.addLine( curve.cpa.clone(),
curve.a.clone(), curve.cpb.clone(),
curve.b.clone() curve.b.clone()
); );
break; break;
case CurveKind.LINE:
backend.addLine(
curve.a.clone(),
curve.b.clone()
);
break;
}
} }
} }
backend.exitSubShape();
} }
backend.exitShape();
} }

backend.exit();
} }
backend.exit();


return shapes; return shapes;
} }
Expand Down Expand Up @@ -673,7 +677,7 @@


// Keep track of "directions" that have occurred // Keep track of "directions" that have occurred
dir = (3 + 3 * (pt[mod(i + 1, n)].x - pt[i].x) + (pt[mod(i + 1, n)].y - pt[i].y)) / 2; dir = (3 + 3 * (pt[mod(i + 1, n)].x - pt[i].x) + (pt[mod(i + 1, n)].y - pt[i].y)) / 2;
ct[dir]++; ct[dir % 4]++;


constraint[0].x = 0; constraint[0].x = 0;
constraint[0].y = 0; constraint[0].y = 0;
Expand Down
Expand Up @@ -17,9 +17,9 @@ package com.powerflasher.as3potrace.backend
this.gp = new GraphicsPath(); this.gp = new GraphicsPath();
} }


public function init(width:int, height:int):void public function init(width:int, height:int):void {}
{ public function initShape():void {}
} public function initSubShape(positive:Boolean):void {}


public function moveTo(a:Point):void public function moveTo(a:Point):void
{ {
Expand All @@ -41,6 +41,9 @@ package com.powerflasher.as3potrace.backend
gp.lineTo(b.x, b.y); gp.lineTo(b.x, b.y);
} }


public function exitSubShape():void {}
public function exitShape():void {}

public function exit():void public function exit():void
{ {
gd.push(gp); gd.push(gp);
Expand Down
4 changes: 4 additions & 0 deletions src/com/powerflasher/as3potrace/backend/IBackend.as
Expand Up @@ -5,9 +5,13 @@ package com.powerflasher.as3potrace.backend
public interface IBackend public interface IBackend
{ {
function init(width:int, height:int):void; function init(width:int, height:int):void;
function initShape():void;
function initSubShape(positive:Boolean):void;
function moveTo(a:Point):void; function moveTo(a:Point):void;
function addBezier(a:Point, cpa:Point, cpb:Point, b:Point):void; function addBezier(a:Point, cpa:Point, cpb:Point, b:Point):void;
function addLine(a:Point, b:Point):void; function addLine(a:Point, b:Point):void;
function exitSubShape():void;
function exitShape():void;
function exit():void; function exit():void;
} }
} }
16 changes: 16 additions & 0 deletions src/com/powerflasher/as3potrace/backend/NullBackend.as
Expand Up @@ -8,6 +8,14 @@ package com.powerflasher.as3potrace.backend
{ {
} }


public function initShape():void
{
}

public function initSubShape(positive:Boolean):void
{
}

public function moveTo(a:Point):void public function moveTo(a:Point):void
{ {
} }
Expand All @@ -20,6 +28,14 @@ package com.powerflasher.as3potrace.backend
{ {
} }


public function exitSubShape():void
{
}

public function exitShape():void
{
}

public function exit():void public function exit():void
{ {
} }
Expand Down
26 changes: 22 additions & 4 deletions src/com/powerflasher/as3potrace/backend/TraceBackend.as
Expand Up @@ -8,24 +8,42 @@ package com.powerflasher.as3potrace.backend
{ {
public function init(width:int, height:int):void public function init(width:int, height:int):void
{ {
trace("Segment w:" + width + ", h:" + height); trace("Canvas width:" + width + ", height:" + height);
} }


public function initShape():void
{
trace(" Shape");
}

public function initSubShape(positive:Boolean):void
{
trace(" SubShape positive:" + positive);
}

public function moveTo(a:Point):void public function moveTo(a:Point):void
{ {
trace(" MoveTo a:" + a); trace(" MoveTo a:" + a);
} }


public function addBezier(a:Point, cpa:Point, cpb:Point, b:Point):void public function addBezier(a:Point, cpa:Point, cpb:Point, b:Point):void
{ {
trace(" Bezier a:" + a + ", cpa:" + cpa + ", cpb:" + cpb + ", b:" + b); trace(" Bezier a:" + a + ", cpa:" + cpa + ", cpb:" + cpb + ", b:" + b);
} }


public function addLine(a:Point, b:Point):void public function addLine(a:Point, b:Point):void
{ {
trace(" Line a:" + a + ", b:" + b); trace(" Line a:" + a + ", b:" + b);
} }


public function exitSubShape():void
{
}

public function exitShape():void
{
}

public function exit():void public function exit():void
{ {
} }
Expand Down

0 comments on commit 098f74a

Please sign in to comment.