[prev in list] [next in list] [prev in thread] [next in thread] 

List:       osflash-sandy
Subject:    [Sandy] [sandy commit] r895 - trunk/sandy/haxe/trunk/tests/unit
From:       makc.the.great () gmail ! com (Makc)
Date:       2009-01-04 22:22:36
Message-ID: 7a2c69bf0901041422q21924b49o3a8dbe6172c3e932 () mail ! gmail ! com
[Download RAW message or body]

In case anyone is interested, here's haxe port of as3 code at forum:

import flash.Lib;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.events.MouseEvent;
import flash.geom.Point;
import sandy.extrusion.data.Polygon2D;

class Hull extends Sprite
{
	private var pointsHolder:Array<Point>;
	private var convexHull:Array<Point>;

	public function new() {

		super ();

		pointsHolder = [];
		convexHull = [];

		addEventListener (Event.ADDED_TO_STAGE, onStage);
	}

	private function onStage (e:Event):Void {
		removeEventListener (Event.ADDED_TO_STAGE, onStage);

		stage.addEventListener (MouseEvent.CLICK, onMouseClick, false, 0, true);
		stage.addEventListener (KeyboardEvent.KEY_DOWN, onKeyPressed, false, 0, true);
	}

	private function onMouseClick(evt:MouseEvent):Void {
		pointsHolder.push(new Point(evt.stageX, evt.stageY));
		runConvexHull();
	}

	private function onKeyPressed(evt:KeyboardEvent):Void {
		this.graphics.clear();
	
		untyped pointsHolder.length = 0;
		untyped convexHull.length = 0;
	}

	private function runConvexHull():Void {
		this.graphics.clear();

		var p1:Polygon2D = new Polygon2D (pointsHolder);
		var p2:Polygon2D = p1.convexHull ();

		convexHull = p2.vertices;

		drawConvexHull ();
	
	}
	
	private function drawConvexHull ():Void {
		this.graphics.lineStyle(1, 0, 1, true);

		drawPoints();

		this.graphics.moveTo(convexHull[0].x, convexHull[0].y);

		var i:Int;
		for (i in 1 ... convexHull.length) {
			this.graphics.lineTo(convexHull[i].x, convexHull[i].y);
		}

		this.graphics.lineTo(convexHull[0].x, convexHull[0].y);
	}
	
	private function drawPoints ():Void {
		var i:Int;
		for (i in 0 ... pointsHolder.length) {
				this.graphics.beginFill(0x000000);
				this.graphics.drawCircle(pointsHolder[i].x, pointsHolder[i].y, 2);
				this.graphics.endFill();
		}
	}

	static function main() {
		Lib.current.stage.addChild(new Hull());
	}

	
}


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic