Skip to content

Commit

Permalink
fixed normal calculation choosing wrong direction due to unsorted nei…
Browse files Browse the repository at this point in the history
…ghbors; added AS3 source generation; removed dotUI for display/views in AS3
  • Loading branch information
ScrambledRK committed Jan 18, 2015
1 parent d49d600 commit 71b0b68
Show file tree
Hide file tree
Showing 68 changed files with 3,775 additions and 599 deletions.
Binary file modified bin/as3/Partitioning.swf
Binary file not shown.
5 changes: 5 additions & 0 deletions bin/as3/src/IPartitionCalculator.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package {
public interface IPartitionCalculator {
function calculate(input : Array) : Array ;
}
}
11 changes: 11 additions & 0 deletions bin/as3/src/IPartitionDebugger.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package {
import at.dotpoint.math.vector.IVector2;
import at.dotpoint.math.geom.Rectangle;
public interface IPartitionDebugger {
function drawOutline(list : Array) : void ;
function drawPartition(area : at.dotpoint.math.geom.Rectangle) : void ;
function drawSplitLine(a : at.dotpoint.math.vector.IVector2,b : at.dotpoint.math.vector.IVector2) : void ;
function drawSplitStart(a : at.dotpoint.math.vector.IVector2) : void ;
function drawSplitEnd(a : at.dotpoint.math.vector.IVector2) : void ;
}
}
5 changes: 5 additions & 0 deletions bin/as3/src/IPolygonConverter.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package {
public interface IPolygonConverter {
function convert(input : *) : Array ;
}
}
20 changes: 20 additions & 0 deletions bin/as3/src/IntIterator.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package {
import flash.Boot;
public class IntIterator {
public function IntIterator(min : int = 0,max : int = 0) : void { if( !flash.Boot.skip_constructor ) {
this.min = min;
this.max = max;
}}

public var min : int;
public var max : int;
public function hasNext() : Boolean {
return this.min < this.max;
}

public function next() : int {
return this.min++;
}

}
}
74 changes: 74 additions & 0 deletions bin/as3/src/Main.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Compile __main__.as instead
package {
import flash.events.Event;
import flash.Lib;
import converter.StringConverter;
import calculator.TraversalSplitter;
import view.CanvasView;
import flash.display.StageScaleMode;
import view.ControllerView;
import flash.display.StageAlign;
import flash.Boot;
public class Main {
public function Main() : void { if( !flash.Boot.skip_constructor ) {
this.initialize();
}}

public var calculator : IPartitionCalculator;
public var controller : view.ControllerView;
public var canvas : view.CanvasView;
public function initialize() : void {
this.calculator = new calculator.TraversalSplitter();
this.setupController();
this.onCalculate(null);
}

public function calculate(input : *) : * {
var input1 : Array = this.parseInput(input);
var result : Array = this.calculator.calculate(input1);
return result;
}

public function parseInput(input : *) : Array {
var output : Array = null;
if(Std._is(input,String)) output = new converter.StringConverter().convert(String(input));
if(output == null) throw "unable to convert given input " + Std.string(input);
return output;
}

public function setupController() : void {
flash.Lib.current.stage.scaleMode = flash.display.StageScaleMode.NO_SCALE;
flash.Lib.current.stage.align = flash.display.StageAlign.TOP_LEFT;
this.controller = new view.ControllerView();
this.controller.addEventListener("calculate",this.onCalculate);
flash.Lib.current.stage.addChild(this.controller);
}

public function setupCanvas() : void {
if(this.canvas != null) {
flash.Lib.current.stage.removeChild(this.canvas);
this.canvas = null;
};
this.canvas = new view.CanvasView();
this.canvas.x = 15;
this.canvas.y = this.controller.y + this.controller.height;
flash.Lib.current.stage.addChild(this.canvas);
}

public function onCalculate(value : flash.events.Event) : void {
this.setupCanvas();
try {
this.controller.set_output(this.calculate(this.controller.get_input()).toString());
}
catch( error : * ){
this.controller.set_output("error: " + Std.string(error));
}
}

static public var instance : Main;
static public function main() : void {
Main.instance = new Main();
}

}
}
124 changes: 124 additions & 0 deletions bin/as3/src/Reflect.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
package {
public class Reflect {
static public function hasField(o : *,field : String) : Boolean {
return o.hasOwnProperty(field);
}

static public function field(o : *,field : String) : * {
try {
return o[field];
}
catch( e : * ){
return null;
};
return null;
}

static public function setField(o : *,field : String,value : *) : void {
o[field] = value;
}

static public function getProperty(o : *,field : String) : * {
try {
return o["get_" + field]();
}
catch( e : * ){
try {
return o[field];
}
catch( e1 : * ){
return null;
}
};
return null;
}

static public function setProperty(o : *,field : String,value : *) : void {
try {
o["set_" + field](value);
}
catch( e : * ){
o[field] = value;
}
}

static public function callMethod(o : *,func : *,args : Array) : * {
return func.apply(o,args);
}

static public function fields(o : *) : Array {
if(o == null) return new Array();
var a : Array = function() : Array {
var $r : Array;
$r = new Array();
for(var $k2 : String in o) $r.push($k2);
return $r;
}();
var i : int = 0;
while(i < a.length) if(!o.hasOwnProperty(a[i])) a.splice(i,1);
else ++i;
return a;
}

static public function isFunction(f : *) : Boolean {
return typeof f == "function";
}

static public function compare(a : *,b : *) : int {
var a1 : * = a;
var b1 : * = b;
if(a1 == b1) return 0;
else if(a1 > b1) return 1;
else return -1;
return 0;
}

static public function compareMethods(f1 : *,f2 : *) : Boolean {
return f1 == f2;
}

static public function isObject(v : *) : Boolean {
if(v == null) return false;
var t : String = typeof v;
if(t == "object") return !Reflect.isEnumValue(v);
return t == "string";
}

static public function isEnumValue(v : *) : Boolean {
try {
return Type.getEnum(v) != null;
}
catch( e : * ){
return false;
};
return false;
}

static public function deleteField(o : *,field : String) : Boolean {
if(o.hasOwnProperty(field) != true) return false;
delete(o[field]);
return true;
}

static public function copy(o : *) : * {
var o2 : * = { };
{
var _g : int = 0;
var _g1 : Array = Reflect.fields(o);
while(_g < _g1.length) {
var f : String = _g1[_g];
++_g;
Reflect.setField(o2,f,Reflect.field(o,f));
}
};
return o2;
}

static public function makeVarArgs(f : Function) : * {
return function(...__arguments__) : * {
return f(__arguments__);
}
}

}
}
37 changes: 37 additions & 0 deletions bin/as3/src/Std.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package {
import flash.Boot;
public class Std {
static public function _is(v : *,t : *) : Boolean {
return flash.Boot.__instanceof(v,t);
}

static public function instance(value : *,c : Class) : * {
return value as c;
}

static public function string(s : *) : String {
return flash.Boot.__string_rec(s,"");
}

static public function _int(x : Number) : int {
return int(x);
}

static public function _parseInt(x : String) : * {
var v : * = parseInt(x);
if(isNaN(v)) return null;
return v;
}

static public function _parseFloat(x : String) : Number {
return parseFloat(x);
}

static public function random(x : int) : int {
if(x <= 0) return 0;
else return Math.floor(Math.random() * x);
return 0;
}

}
}
34 changes: 34 additions & 0 deletions bin/as3/src/StringBuf.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package {
import flash.Boot;
public class StringBuf {
public function StringBuf() : void { if( !flash.Boot.skip_constructor ) {
this.b = "";
}}

protected var b : String;
public function get length() : int { return get_length(); }
public function set length( __v : int ) : void { $length = __v; }
protected var $length : int;
public function get_length() : int {
return this.b.length;
}

public function add(x : *) : void {
this.b += Std.string(x);
}

public function addChar(c : int) : void {
this.b += String.fromCharCode(c);
}

public function addSub(s : String,pos : int,len : * = null) : void {
if(len == null) this.b += s.substr(pos);
else this.b += s.substr(pos,len);
}

public function toString() : String {
return this.b;
}

}
}
Loading

0 comments on commit 71b0b68

Please sign in to comment.