diff --git a/bin/as3/Partitioning.swf b/bin/as3/Partitioning.swf index 050ab48..e757fe4 100644 Binary files a/bin/as3/Partitioning.swf and b/bin/as3/Partitioning.swf differ diff --git a/bin/as3/src/IPartitionCalculator.as b/bin/as3/src/IPartitionCalculator.as new file mode 100644 index 0000000..5dbb086 --- /dev/null +++ b/bin/as3/src/IPartitionCalculator.as @@ -0,0 +1,5 @@ +package { + public interface IPartitionCalculator { + function calculate(input : Array) : Array ; + } +} diff --git a/bin/as3/src/IPartitionDebugger.as b/bin/as3/src/IPartitionDebugger.as new file mode 100644 index 0000000..50fb7d6 --- /dev/null +++ b/bin/as3/src/IPartitionDebugger.as @@ -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 ; + } +} diff --git a/bin/as3/src/IPolygonConverter.as b/bin/as3/src/IPolygonConverter.as new file mode 100644 index 0000000..23d3987 --- /dev/null +++ b/bin/as3/src/IPolygonConverter.as @@ -0,0 +1,5 @@ +package { + public interface IPolygonConverter { + function convert(input : *) : Array ; + } +} diff --git a/bin/as3/src/IntIterator.as b/bin/as3/src/IntIterator.as new file mode 100644 index 0000000..9816829 --- /dev/null +++ b/bin/as3/src/IntIterator.as @@ -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++; + } + + } +} diff --git a/bin/as3/src/Main.as b/bin/as3/src/Main.as new file mode 100644 index 0000000..1864c81 --- /dev/null +++ b/bin/as3/src/Main.as @@ -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(); + } + + } +} diff --git a/bin/as3/src/Reflect.as b/bin/as3/src/Reflect.as new file mode 100644 index 0000000..cfb5268 --- /dev/null +++ b/bin/as3/src/Reflect.as @@ -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__); + } + } + + } +} diff --git a/bin/as3/src/Std.as b/bin/as3/src/Std.as new file mode 100644 index 0000000..6948a70 --- /dev/null +++ b/bin/as3/src/Std.as @@ -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; + } + + } +} diff --git a/bin/as3/src/StringBuf.as b/bin/as3/src/StringBuf.as new file mode 100644 index 0000000..7ced598 --- /dev/null +++ b/bin/as3/src/StringBuf.as @@ -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; + } + + } +} diff --git a/bin/as3/src/Type.as b/bin/as3/src/Type.as new file mode 100644 index 0000000..a934b80 --- /dev/null +++ b/bin/as3/src/Type.as @@ -0,0 +1,332 @@ +package { + import flash.utils.getDefinitionByName; + import flash.utils.getQualifiedClassName; + import flash.utils.describeType; + import flash.Boot; + import flash.utils.getQualifiedSuperclassName; + public class Type { + static public function getClass(o : *) : Class { + var cname : String = flash.utils.getQualifiedClassName(o); + if(cname == "null" || cname == "Object" || cname == "int" || cname == "Number" || cname == "Boolean") return null; + if(o.hasOwnProperty("prototype")) return null; + var c : * = flash.utils.getDefinitionByName(cname) as Class; + if(c.__isenum) return null; + return c; + } + + static public function getEnum(o : enum) : Class { + var cname : String = flash.utils.getQualifiedClassName(o); + if(cname == "null" || cname.substr(0,8) == "builtin.") return null; + if(o.hasOwnProperty("prototype")) return null; + var c : * = flash.utils.getDefinitionByName(cname) as Class; + if(!c.__isenum) return null; + return c; + } + + static public function getSuperClass(c : Class) : Class { + var cname : String = flash.utils.getQualifiedSuperclassName(c); + if(cname == null || cname == "Object") return null; + return flash.utils.getDefinitionByName(cname) as Class; + } + + static public function getClassName(c : Class) : String { + if(c == null) return null; + var str : String = flash.utils.getQualifiedClassName(c); + switch(str) { + case "int": + return "Int"; + break; + case "Number": + return "Float"; + break; + case "Boolean": + return "Bool"; + break; + case "Object": + return "Dynamic"; + break; + default: + break; + }; + return str.split("::").join("."); + } + + static public function getEnumName(e : Class) : String { + return Type.getClassName(Class(e)); + } + + static public function resolveClass(name : String) : Class { + var cl : Class; + try { + cl = flash.utils.getDefinitionByName(name) as Class; + if(cl.__isenum) return null; + return cl; + } + catch( e : * ){ + switch(name) { + case "Int": + return int; + break; + case "Float": + return Number; + break; + case "Dynamic": + return Object; + break; + }; + return null; + }; + if(cl == null || cl.__name__ == null) return null; + return cl; + } + + static public function resolveEnum(name : String) : Class { + var e : *; + try { + e = flash.utils.getDefinitionByName(name); + if(!e.__isenum) return null; + return e; + } + catch( e1 : * ){ + if(name == "Bool") return Boolean; + return null; + }; + if(e == null || e.__ename__ == null) return null; + return e; + } + + static public function createInstance(cl : Class,args : Array) : * { + var _g : int = args.length; + switch(_g) { + case 0: + return new cl(); + break; + case 1: + return new cl(args[0]); + break; + case 2: + return new cl(args[0],args[1]); + break; + case 3: + return new cl(args[0],args[1],args[2]); + break; + case 4: + return new cl(args[0],args[1],args[2],args[3]); + break; + case 5: + return new cl(args[0],args[1],args[2],args[3],args[4]); + break; + case 6: + return new cl(args[0],args[1],args[2],args[3],args[4],args[5]); + break; + case 7: + return new cl(args[0],args[1],args[2],args[3],args[4],args[5],args[6]); + break; + case 8: + return new cl(args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7]); + break; + case 9: + return new cl(args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7],args[8]); + break; + case 10: + return new cl(args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7],args[8],args[9]); + break; + case 11: + return new cl(args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7],args[8],args[9],args[10]); + break; + case 12: + return new cl(args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7],args[8],args[9],args[10],args[11]); + break; + case 13: + return new cl(args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7],args[8],args[9],args[10],args[11],args[12]); + break; + case 14: + return new cl(args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7],args[8],args[9],args[10],args[11],args[12],args[13]); + break; + default: + throw "Too many arguments"; + break; + }; + return null; + } + + static public function createEmptyInstance(cl : Class) : * { + try { + flash.Boot.skip_constructor = true; + var i : * = new cl(); + flash.Boot.skip_constructor = false; + return i; + } + catch( e : * ){ + flash.Boot.skip_constructor = false; + throw e; + }; + return null; + } + + static public function createEnum(e : Class,constr : String,params : Array = null) : * { + var f : * = e[constr]; + if(f == null) throw "No such constructor " + constr; + if(Reflect.isFunction(f)) { + if(params == null) throw "Constructor " + constr + " need parameters"; + return Reflect.callMethod(e,f,params); + }; + if(params != null && params.length != 0) throw "Constructor " + constr + " does not need parameters"; + return f; + } + + static public function createEnumIndex(e : Class,index : int,params : Array = null) : * { + var c : String = e.__constructs__[index]; + if(c == null) throw index + " is not a valid enum constructor index"; + return Type.createEnum(e,c,params); + } + + static protected function describe(t : *,fact : Boolean) : Array { + var fields : Array = new Array(); + var xml : XML = flash.utils.describeType(t); + if(fact) xml = xml.factory[0]; + var methods : XMLList = xml.child("method"); + { + var _g1 : int = 0; + var _g : int = methods.length(); + while(_g1 < _g) { + var i : int = _g1++; + fields.push(Std.string(methods[i].attribute("name"))); + } + }; + var vars : XMLList = xml.child("variable"); + { + var _g11 : int = 0; + var _g2 : int = vars.length(); + while(_g11 < _g2) { + var i1 : int = _g11++; + fields.push(Std.string(vars[i1].attribute("name"))); + } + }; + var accs : XMLList = xml.child("accessor"); + { + var _g12 : int = 0; + var _g3 : int = accs.length(); + while(_g12 < _g3) { + var i2 : int = _g12++; + fields.push(Std.string(accs[i2].attribute("name"))); + } + }; + return fields; + } + + static public function getInstanceFields(c : Class) : Array { + return Type.describe(c,true); + } + + static public function getClassFields(c : Class) : Array { + var a : Array = Type.describe(c,false); + a.remove("__construct__"); + a.remove("prototype"); + return a; + } + + static public function getEnumConstructs(e : Class) : Array { + var a : Array = e.__constructs__; + return a.copy(); + } + + static public function _typeof(v : *) : ValueType { + var cname : String = flash.utils.getQualifiedClassName(v); + switch(cname) { + case "null": + return ValueType.TNull; + break; + case "void": + return ValueType.TNull; + break; + case "int": + return ValueType.TInt; + break; + case "Number": + { + if((v < -268435456 || v >= 268435456) && Std._int(v) == v) return ValueType.TInt; + return ValueType.TFloat; + } + break; + case "Boolean": + return ValueType.TBool; + break; + case "Object": + return ValueType.TObject; + break; + case "Function": + return ValueType.TFunction; + break; + default: + { + var c : * = null; + try { + c = flash.utils.getDefinitionByName(cname); + if(v.hasOwnProperty("prototype")) return ValueType.TObject; + if(c.__isenum) return ValueType.TEnum(c); + return ValueType.TClass(c); + } + catch( e : * ){ + if(cname == "builtin.as$0::MethodClosure" || cname.indexOf("-") != -1) return ValueType.TFunction; + if(c == null) return ValueType.TFunction; + else return ValueType.TClass(c); + } + } + break; + }; + return null; + } + + static public function enumEq(a : *,b : *) : Boolean { + if(a == b) return true; + try { + if(a.index != b.index) return false; + var ap : Array = a.params; + var bp : Array = b.params; + { + var _g1 : int = 0; + var _g : int = ap.length; + while(_g1 < _g) { + var i : int = _g1++; + if(!Type.enumEq(ap[i],bp[i])) return false; + } + } + } + catch( e : * ){ + return false; + }; + return true; + } + + static public function enumConstructor(e : enum) : String { + return e.tag; + } + + static public function enumParameters(e : enum) : Array { + if(e.params == null) return []; + else return e.params; + return null; + } + + static public function enumIndex(e : enum) : int { + return e.index; + } + + static public function allEnums(e : Class) : Array { + var all : Array = []; + var cst : Array = e.__constructs__; + { + var _g : int = 0; + while(_g < cst.length) { + var c : String = cst[_g]; + ++_g; + var v : * = Reflect.field(e,c); + if(!Reflect.isFunction(v)) all.push(v); + } + }; + return all; + } + + } +} diff --git a/bin/as3/src/ValueType.as b/bin/as3/src/ValueType.as new file mode 100644 index 0000000..d9c6b51 --- /dev/null +++ b/bin/as3/src/ValueType.as @@ -0,0 +1,16 @@ +package { + public final class ValueType extends enum { + public static const __isenum : Boolean = true; + public function ValueType( t : String, index : int, p : Array = null ) : void { this.tag = t; this.index = index; this.params = p; } + public static var TBool : ValueType = new ValueType("TBool",3); + public static function TClass(c : Class) : ValueType { return new ValueType("TClass",6,[c]); } + public static function TEnum(e : Class) : ValueType { return new ValueType("TEnum",7,[e]); } + public static var TFloat : ValueType = new ValueType("TFloat",2); + public static var TFunction : ValueType = new ValueType("TFunction",5); + public static var TInt : ValueType = new ValueType("TInt",1); + public static var TNull : ValueType = new ValueType("TNull",0); + public static var TObject : ValueType = new ValueType("TObject",4); + public static var TUnknown : ValueType = new ValueType("TUnknown",8); + public static var __constructs__ : Array = ["TNull","TInt","TFloat","TBool","TObject","TFunction","TClass","TEnum","TUnknown"]; + } +} diff --git a/bin/as3/src/_Map/Map_Impl_.as b/bin/as3/src/_Map/Map_Impl_.as new file mode 100644 index 0000000..604efe8 --- /dev/null +++ b/bin/as3/src/_Map/Map_Impl_.as @@ -0,0 +1,71 @@ +package _Map { + import haxe.IMap; + import haxe.ds.IntMap; + import haxe.ds.EnumValueMap; + import haxe.ds.ObjectMap; + import haxe.ds.StringMap; + public class Map_Impl_ { + static public var _new : Function; + static public function set(this1 : haxe.IMap,key : *,value : *) : void { + this1.set(key,value); + } + + static public function get(this1 : haxe.IMap,key : *) : * { + return this1.get(key); + } + + static public function exists(this1 : haxe.IMap,key : *) : Boolean { + return this1.exists(key); + } + + static public function remove(this1 : haxe.IMap,key : *) : Boolean { + return this1.remove(key); + } + + static public function keys(this1 : haxe.IMap) : * { + return this1.keys(); + } + + static public function iterator(this1 : haxe.IMap) : * { + return this1.iterator(); + } + + static public function toString(this1 : haxe.IMap) : String { + return this1.toString(); + } + + static public function arrayWrite(this1 : haxe.IMap,k : *,v : *) : * { + this1.set(k,v); + return v; + } + + static public function toStringMap(t : haxe.IMap) : haxe.ds.StringMap { + return new haxe.ds.StringMap(); + } + + static public function toIntMap(t : haxe.IMap) : haxe.ds.IntMap { + return new haxe.ds.IntMap(); + } + + static public function toEnumValueMapMap(t : haxe.IMap) : haxe.ds.EnumValueMap { + return new haxe.ds.EnumValueMap(); + } + + static public function toObjectMap(t : haxe.IMap) : haxe.ds.ObjectMap { + return new haxe.ds.ObjectMap(); + } + + static public function fromStringMap(map : haxe.ds.StringMap) : haxe.ds.StringMap { + return haxe.ds.StringMap(map); + } + + static public function fromIntMap(map : haxe.ds.IntMap) : haxe.ds.IntMap { + return haxe.ds.IntMap(map); + } + + static public function fromObjectMap(map : haxe.ds.ObjectMap) : haxe.ds.ObjectMap { + return haxe.ds.ObjectMap(map); + } + + } +} diff --git a/bin/as3/src/__main__.as b/bin/as3/src/__main__.as new file mode 100644 index 0000000..b2553c2 --- /dev/null +++ b/bin/as3/src/__main__.as @@ -0,0 +1,78 @@ +package { + import flash.Boot; + import flash.Lib; + public class __main__ extends flash.Boot { + public function __main__() { + super(); + flash.Lib.current = this; + { + Math["NaN"] = Number.NaN; + Math["NEGATIVE_INFINITY"] = Number.NEGATIVE_INFINITY; + Math["POSITIVE_INFINITY"] = Number.POSITIVE_INFINITY; + Math["isFinite"] = function(i : Number) : Boolean { + return isFinite(i); + }; + Math["isNaN"] = function(i1 : Number) : Boolean { + return isNaN(i1); + } + } + { + var aproto : * = Array.prototype; + aproto.copy = function() : * { + return this.slice(); + }; + aproto.insert = function(i : *,x : *) : void { + this.splice(i,0,x); + }; + aproto.remove = function(obj : *) : Boolean { + var idx : int = this.indexOf(obj); + if(idx == -1) return false; + this.splice(idx,1); + return true; + }; + aproto.iterator = function() : * { + var cur : int = 0; + var arr : Array = this; + return { hasNext : function() : Boolean { + return cur < arr.length; + }, next : function() : * { + return arr[cur++]; + }} + }; + aproto.setPropertyIsEnumerable("copy",false); + aproto.setPropertyIsEnumerable("insert",false); + aproto.setPropertyIsEnumerable("remove",false); + aproto.setPropertyIsEnumerable("iterator",false); + aproto.filterHX = function(f : Function) : Array { + var ret : Array = []; + var i1 : int = 0; + var l : int = this.length; + while(i1 < l) { + if(f(this[i1])) ret.push(this[i1]); + i1++; + }; + return ret; + }; + aproto.mapHX = function(f1 : Function) : Array { + var ret1 : Array = []; + var i2 : int = 0; + var l1 : int = this.length; + while(i2 < l1) { + ret1.push(f1(this[i2])); + i2++; + }; + return ret1; + }; + aproto.setPropertyIsEnumerable("mapHX",false); + aproto.setPropertyIsEnumerable("filterHX",false); + String.prototype.charCodeAtHX = function(i3 : *) : * { + var s : String = this; + var x1 : Number = s.charCodeAt(i3); + if(isNaN(x1)) return null; + return Std._int(x1); + } + } + Main.main(); + } + } +} diff --git a/bin/as3/src/at/dotpoint/core/ICloneable.as b/bin/as3/src/at/dotpoint/core/ICloneable.as new file mode 100644 index 0000000..2c4b247 --- /dev/null +++ b/bin/as3/src/at/dotpoint/core/ICloneable.as @@ -0,0 +1,5 @@ +package at.dotpoint.core { + public interface ICloneable { + function clone(instance : * = null) : * ; + } +} diff --git a/bin/as3/src/at/dotpoint/math/MathUtil.as b/bin/as3/src/at/dotpoint/math/MathUtil.as new file mode 100644 index 0000000..b5ff343 --- /dev/null +++ b/bin/as3/src/at/dotpoint/math/MathUtil.as @@ -0,0 +1,21 @@ +package at.dotpoint.math { + public class MathUtil { + static public var ZERO_TOLERANCE : Number = 1e-08; + static public var RAD_DEG : Number = 57.29577951308232; + static public var DEG_RAD : Number = 0.017453292519943295; + static public var FLOAT_MAX : Number = 3.4028234663852886e+37; + static public var FLOAT_MIN : Number = -3.4028234663852886e+37; + static public function isEqual(a : Number,b : Number) : Boolean { + if(a > b) return a - b < 1e-08; + else return b - a < 1e-08; + return false; + } + + static public function getAngle(x1 : Number,y1 : Number,x2 : Number,y2 : Number) : Number { + var dx : Number = x2 - x1; + var dy : Number = y2 - y1; + return Math.atan2(dy,dx); + } + + } +} diff --git a/bin/as3/src/at/dotpoint/math/geom/Rectangle.as b/bin/as3/src/at/dotpoint/math/geom/Rectangle.as new file mode 100644 index 0000000..fe46527 --- /dev/null +++ b/bin/as3/src/at/dotpoint/math/geom/Rectangle.as @@ -0,0 +1,176 @@ +package at.dotpoint.math.geom { + import at.dotpoint.math.vector.Vector2; + import flash.Boot; + public class Rectangle { + public function Rectangle(x : Number = 0,y : Number = 0,w : Number = 0,h : Number = 0) : void { if( !flash.Boot.skip_constructor ) { + this.position = new at.dotpoint.math.vector.Vector2(x,y); + this.size = new at.dotpoint.math.vector.Vector2(w,h); + }} + + public var position : at.dotpoint.math.vector.Vector2; + public var size : at.dotpoint.math.vector.Vector2; + public function get x() : Number { return get_x(); } + public function set x( __v : Number ) : void { set_x(__v); } + protected var $x : Number; + public function get y() : Number { return get_y(); } + public function set y( __v : Number ) : void { set_y(__v); } + protected var $y : Number; + public function get width() : Number { return get_width(); } + public function set width( __v : Number ) : void { set_width(__v); } + protected var $width : Number; + public function get height() : Number { return get_height(); } + public function set height( __v : Number ) : void { set_height(__v); } + protected var $height : Number; + public function get top() : Number { return get_top(); } + public function set top( __v : Number ) : void { set_top(__v); } + protected var $top : Number; + public function get bottom() : Number { return get_bottom(); } + public function set bottom( __v : Number ) : void { set_bottom(__v); } + protected var $bottom : Number; + public function get left() : Number { return get_left(); } + public function set left( __v : Number ) : void { set_left(__v); } + protected var $left : Number; + public function get right() : Number { return get_right(); } + public function set right( __v : Number ) : void { set_right(__v); } + protected var $right : Number; + public function get topLeft() : at.dotpoint.math.vector.Vector2 { return get_topLeft(); } + public function set topLeft( __v : at.dotpoint.math.vector.Vector2 ) : void { set_topLeft(__v); } + protected var $topLeft : at.dotpoint.math.vector.Vector2; + public function get bottomRight() : at.dotpoint.math.vector.Vector2 { return get_bottomRight(); } + public function set bottomRight( __v : at.dotpoint.math.vector.Vector2 ) : void { set_bottomRight(__v); } + protected var $bottomRight : at.dotpoint.math.vector.Vector2; + public function get dimension() : at.dotpoint.math.vector.Vector2 { return get_dimension(); } + public function set dimension( __v : at.dotpoint.math.vector.Vector2 ) : void { set_dimension(__v); } + protected var $dimension : at.dotpoint.math.vector.Vector2; + public function clone() : at.dotpoint.math.geom.Rectangle { + return new at.dotpoint.math.geom.Rectangle(this.get_x(),this.get_y(),this.get_width(),this.get_height()); + } + + public function setZero() : void { + this.position.set_x(0); + this.position.set_y(0); + this.size.set_x(0); + this.size.set_y(0); + } + + public function get_x() : Number { + return this.position.get_x(); + } + + public function set_x(value : Number) : Number { + return this.position.set_x(value); + } + + public function get_y() : Number { + return this.position.get_y(); + } + + public function set_y(value : Number) : Number { + return this.position.set_y(value); + } + + public function get_width() : Number { + return this.size.get_x(); + } + + public function set_width(value : Number) : Number { + if(value < 0) throw "dimension below zero"; + return this.size.set_x(value); + } + + public function get_height() : Number { + return this.size.get_y(); + } + + public function set_height(value : Number) : Number { + if(value < 0) throw "dimension below zero"; + return this.size.set_y(value); + } + + public function get_top() : Number { + return this.get_y(); + } + + public function set_top(value : Number) : Number { + { + var _g : at.dotpoint.math.geom.Rectangle = this; + _g.set_height(_g.get_height() - (value - this.get_y())); + }; + this.set_y(value); + return value; + } + + public function get_bottom() : Number { + return this.get_y() + this.get_height(); + } + + public function set_bottom(value : Number) : Number { + this.set_height(value - this.get_y()); + return value; + } + + public function get_left() : Number { + return this.get_x(); + } + + public function set_left(value : Number) : Number { + { + var _g : at.dotpoint.math.geom.Rectangle = this; + _g.set_width(_g.get_width() - (value - this.get_x())); + }; + this.set_x(value); + return value; + } + + public function get_right() : Number { + return this.get_x() + this.get_width(); + } + + public function set_right(value : Number) : Number { + this.set_width(value - this.get_x()); + return value; + } + + public function get_topLeft() : at.dotpoint.math.vector.Vector2 { + return this.position.clone(); + } + + public function set_topLeft(value : at.dotpoint.math.vector.Vector2) : at.dotpoint.math.vector.Vector2 { + this.set_top(value.get_y()); + this.set_left(value.get_x()); + return value; + } + + public function get_bottomRight() : at.dotpoint.math.vector.Vector2 { + return at.dotpoint.math.vector.Vector2.add(this.position,this.size); + } + + public function set_bottomRight(value : at.dotpoint.math.vector.Vector2) : at.dotpoint.math.vector.Vector2 { + this.set_bottom(value.get_y()); + this.set_right(value.get_x()); + return value; + } + + public function get_dimension() : at.dotpoint.math.vector.Vector2 { + return this.size.clone(); + } + + public function set_dimension(value : at.dotpoint.math.vector.Vector2) : at.dotpoint.math.vector.Vector2 { + this.size.set(value.get_x(),value.get_y()); + return value; + } + + public function isInside(x : int,y : int) : Boolean { + if(x < this.get_left()) return false; + if(y < this.get_top()) return false; + if(x > this.get_right()) return false; + if(y > this.get_bottom()) return false; + return true; + } + + public function toString() : String { + return "x:" + this.get_x() + " y:" + this.get_y() + " w:" + this.get_width() + " h:" + this.get_height(); + } + + } +} diff --git a/bin/as3/src/at/dotpoint/math/vector/IMatrix33.as b/bin/as3/src/at/dotpoint/math/vector/IMatrix33.as new file mode 100644 index 0000000..53933b4 --- /dev/null +++ b/bin/as3/src/at/dotpoint/math/vector/IMatrix33.as @@ -0,0 +1,17 @@ +package at.dotpoint.math.vector { + public interface IMatrix33 { + + + + + + + + + + function toIdentity() : void ; + function transpose() : void ; + function determinant() : Number ; + function set33(m : at.dotpoint.math.vector.IMatrix33) : void ; + } +} diff --git a/bin/as3/src/at/dotpoint/math/vector/IMatrix44.as b/bin/as3/src/at/dotpoint/math/vector/IMatrix44.as new file mode 100644 index 0000000..760028a --- /dev/null +++ b/bin/as3/src/at/dotpoint/math/vector/IMatrix44.as @@ -0,0 +1,13 @@ +package at.dotpoint.math.vector { + import at.dotpoint.math.vector.IMatrix33; + public interface IMatrix44 extends at.dotpoint.math.vector.IMatrix33{ + + + + + + + + function set44(m : at.dotpoint.math.vector.IMatrix44) : void ; + } +} diff --git a/bin/as3/src/at/dotpoint/math/vector/IVector2.as b/bin/as3/src/at/dotpoint/math/vector/IVector2.as new file mode 100644 index 0000000..b4ca341 --- /dev/null +++ b/bin/as3/src/at/dotpoint/math/vector/IVector2.as @@ -0,0 +1,12 @@ +package at.dotpoint.math.vector { + public interface IVector2 { + function get_x() : Number ; + function set_x(value : Number) : Number ; + function get_y() : Number ; + function set_y(value : Number) : Number ; + + + function normalize() : void ; + function length() : Number ; + } +} diff --git a/bin/as3/src/at/dotpoint/math/vector/IVector3.as b/bin/as3/src/at/dotpoint/math/vector/IVector3.as new file mode 100644 index 0000000..0f433f7 --- /dev/null +++ b/bin/as3/src/at/dotpoint/math/vector/IVector3.as @@ -0,0 +1,11 @@ +package at.dotpoint.math.vector { + import at.dotpoint.math.vector.IVector2; + public interface IVector3 extends at.dotpoint.math.vector.IVector2{ + function get_z() : Number ; + function set_z(value : Number) : Number ; + function get_w() : Number ; + function set_w(value : Number) : Number ; + + + } +} diff --git a/bin/as3/src/at/dotpoint/math/vector/Vector2.as b/bin/as3/src/at/dotpoint/math/vector/Vector2.as new file mode 100644 index 0000000..29bd9b6 --- /dev/null +++ b/bin/as3/src/at/dotpoint/math/vector/Vector2.as @@ -0,0 +1,136 @@ +package at.dotpoint.math.vector { + import at.dotpoint.math.vector.IVector2; + import at.dotpoint.core.ICloneable; + import at.dotpoint.math.MathUtil; + import flash.Boot; + public class Vector2 implements at.dotpoint.core.ICloneable, at.dotpoint.math.vector.IVector2{ + public function Vector2(x : Number = 0,y : Number = 0) : void { if( !flash.Boot.skip_constructor ) { + this.set_x(x); + this.set_y(y); + }} + + public function get x() : Number { return get_x(); } + public function set x( __v : Number ) : void { set_x(__v); } + protected var $x : Number; + public function get y() : Number { return get_y(); } + public function set y( __v : Number ) : void { set_y(__v); } + protected var $y : Number; + public function clone(_tmp_output : * = null) : * { + var output : at.dotpoint.math.vector.Vector2 = at.dotpoint.math.vector.Vector2(_tmp_output); + if(output != null) output = output; + else output = new at.dotpoint.math.vector.Vector2(); + output.set_x(this.get_x()); + output.set_y(this.get_y()); + return output; + } + + public function get_x() : Number { + return this.$x; + } + + public function set_x(value : Number) : Number { + return this.$x = value; + } + + public function get_y() : Number { + return this.$y; + } + + public function set_y(value : Number) : Number { + return this.$y = value; + } + + public function set(x : Number,y : Number) : void { + this.set_x(x); + this.set_y(y); + } + + public function normalize() : void { + var k : Number = 1. / this.length(); + { + var _g : at.dotpoint.math.vector.Vector2 = this; + _g.set_x(_g.get_x() * k); + }; + { + var _g1 : at.dotpoint.math.vector.Vector2 = this; + _g1.set_y(_g1.get_y() * k); + } + } + + public function length() : Number { + return Math.sqrt(this.get_x() * this.get_x() + this.get_y() * this.get_y()); + } + + public function lengthSq() : Number { + return this.get_x() * this.get_x() + this.get_y() * this.get_y(); + } + + public function toArray(output : Array = null) : Array { + if(output != null) output = new Array(); + output[0] = this.get_x(); + output[1] = this.get_y(); + return output; + } + + public function getIndex(index : int) : Number { + switch(index) { + case 0: + return this.get_x(); + break; + case 1: + return this.get_y(); + break; + default: + throw "out of bounds"; + break; + }; + return 0.; + } + + public function setIndex(index : int,value : Number) : void { + switch(index) { + case 0: + this.set_x(value); + break; + case 1: + this.set_y(value); + break; + default: + throw "out of bounds"; + break; + } + } + + public function toString() : String { + return "[Vector2;" + this.get_x() + ", " + this.get_y() + "]"; + } + + static public function add(a : at.dotpoint.math.vector.IVector2,b : at.dotpoint.math.vector.IVector2,output : * = null) : * { + if(output == null) output = new at.dotpoint.math.vector.Vector2(); + output.set_x(a.get_x() + b.get_x()); + output.set_y(a.get_y() + b.get_y()); + return output; + } + + static public function subtract(a : at.dotpoint.math.vector.IVector2,b : at.dotpoint.math.vector.IVector2,output : * = null) : * { + if(output == null) output = new at.dotpoint.math.vector.Vector2(); + output.set_x(a.get_x() - b.get_x()); + output.set_y(a.get_y() - b.get_y()); + return output; + } + + static public function scale(a : at.dotpoint.math.vector.IVector2,scalar : Number,output : * = null) : * { + if(output == null) output = new at.dotpoint.math.vector.Vector2(); + output.set_x(a.get_x() * scalar); + output.set_y(a.get_y() * scalar); + return output; + } + + static public function isEqual(a : at.dotpoint.math.vector.IVector2,b : at.dotpoint.math.vector.IVector2) : Boolean { + if(!at.dotpoint.math.MathUtil.isEqual(a.get_x(),b.get_x())) return false; + if(!at.dotpoint.math.MathUtil.isEqual(a.get_y(),b.get_y())) return false; + return true; + } + + } +} diff --git a/bin/as3/src/at/dotpoint/math/vector/Vector3.as b/bin/as3/src/at/dotpoint/math/vector/Vector3.as new file mode 100644 index 0000000..5d10009 --- /dev/null +++ b/bin/as3/src/at/dotpoint/math/vector/Vector3.as @@ -0,0 +1,241 @@ +package at.dotpoint.math.vector { + import at.dotpoint.math.vector.IVector3; + import at.dotpoint.core.ICloneable; + import at.dotpoint.math.vector.IMatrix44; + import at.dotpoint.math.MathUtil; + import flash.Boot; + public class Vector3 implements at.dotpoint.core.ICloneable, at.dotpoint.math.vector.IVector3{ + public function Vector3(x : Number = 0,y : Number = 0,z : Number = 0,w : Number = 1) : void { if( !flash.Boot.skip_constructor ) { + this.set_x(x); + this.set_y(y); + this.set_z(z); + this.set_w(w); + }} + + public function get x() : Number { return get_x(); } + public function set x( __v : Number ) : void { set_x(__v); } + protected var $x : Number; + public function get y() : Number { return get_y(); } + public function set y( __v : Number ) : void { set_y(__v); } + protected var $y : Number; + public function get z() : Number { return get_z(); } + public function set z( __v : Number ) : void { set_z(__v); } + protected var $z : Number; + public function get w() : Number { return get_w(); } + public function set w( __v : Number ) : void { set_w(__v); } + protected var $w : Number; + public function clone(_tmp_output : * = null) : * { + var output : at.dotpoint.math.vector.Vector3 = at.dotpoint.math.vector.Vector3(_tmp_output); + if(output == null) output = new at.dotpoint.math.vector.Vector3(); + output.set_x(this.get_x()); + output.set_y(this.get_y()); + output.set_z(this.get_z()); + output.set_w(this.get_w()); + return output; + } + + public function get_x() : Number { + return this.$x; + } + + public function set_x(value : Number) : Number { + return this.$x = value; + } + + public function get_y() : Number { + return this.$y; + } + + public function set_y(value : Number) : Number { + return this.$y = value; + } + + public function get_z() : Number { + return this.$z; + } + + public function set_z(value : Number) : Number { + return this.$z = value; + } + + public function get_w() : Number { + return this.$w; + } + + public function set_w(value : Number) : Number { + return this.$w = value; + } + + public function set(x : Number,y : Number,z : Number,w : * = null) : void { + this.set_x(x); + this.set_y(y); + this.set_z(z); + if(w != null) this.set_w(w); + } + + public function normalize() : void { + var l : Number = this.length(); + if(l == 0) return; + var k : Number = 1. / l; + { + var _g : at.dotpoint.math.vector.Vector3 = this; + _g.set_x(_g.get_x() * k); + }; + { + var _g1 : at.dotpoint.math.vector.Vector3 = this; + _g1.set_y(_g1.get_y() * k); + }; + { + var _g2 : at.dotpoint.math.vector.Vector3 = this; + _g2.set_z(_g2.get_z() * k); + } + } + + public function length() : Number { + return Math.sqrt(this.get_x() * this.get_x() + this.get_y() * this.get_y() + this.get_z() * this.get_z()); + } + + public function lengthSq() : Number { + return this.get_x() * this.get_x() + this.get_y() * this.get_y() + this.get_z() * this.get_z(); + } + + public function toArray(w : * = false,output : Array = null) : Array { + if(w==null) w=false; + if(output != null) output = new Array(); + output[0] = this.get_x(); + output[1] = this.get_y(); + output[2] = this.get_z(); + if(w) output[3] = this.get_w(); + return output; + } + + public function getIndex(index : int) : Number { + switch(index) { + case 0: + return this.get_x(); + break; + case 1: + return this.get_y(); + break; + case 2: + return this.get_z(); + break; + case 3: + return this.get_w(); + break; + default: + throw "out of bounds"; + break; + }; + return 0.; + } + + public function setIndex(index : int,value : Number) : void { + switch(index) { + case 0: + this.set_x(value); + break; + case 1: + this.set_y(value); + break; + case 2: + this.set_z(value); + break; + case 3: + this.set_w(value); + break; + default: + throw "out of bounds"; + break; + } + } + + public function toString() : String { + return "[Vector3;" + this.get_x() + ", " + this.get_y() + ", " + this.get_z() + ", " + this.get_w() + "]"; + } + + static public function add(a : at.dotpoint.math.vector.IVector3,b : at.dotpoint.math.vector.IVector3,output : * = null) : * { + if(output == null) output = new at.dotpoint.math.vector.Vector3(); + output.set_x(a.get_x() + b.get_x()); + output.set_y(a.get_y() + b.get_y()); + output.set_z(a.get_z() + b.get_z()); + return output; + } + + static public function subtract(a : at.dotpoint.math.vector.IVector3,b : at.dotpoint.math.vector.IVector3,output : * = null) : * { + if(output == null) output = new at.dotpoint.math.vector.Vector3(); + output.set_x(a.get_x() - b.get_x()); + output.set_y(a.get_y() - b.get_y()); + output.set_z(a.get_z() - b.get_z()); + return output; + } + + static public function scale(a : at.dotpoint.math.vector.IVector3,scalar : Number,output : * = null) : * { + if(output == null) output = new at.dotpoint.math.vector.Vector3(); + output.set_x(a.get_x() * scalar); + output.set_y(a.get_y() * scalar); + output.set_z(a.get_z() * scalar); + return output; + } + + static public function cross(a : at.dotpoint.math.vector.IVector3,b : at.dotpoint.math.vector.IVector3,output : * = null) : * { + if(output == null) output = new at.dotpoint.math.vector.Vector3(); + output.set_x(a.get_y() * b.get_z() - a.get_z() * b.get_y()); + output.set_y(a.get_z() * b.get_x() - a.get_x() * b.get_z()); + output.set_z(a.get_x() * b.get_y() - a.get_y() * b.get_x()); + return output; + } + + static public function dot(a : at.dotpoint.math.vector.IVector3,b : at.dotpoint.math.vector.IVector3) : Number { + return a.get_x() * b.get_x() + a.get_y() * b.get_y() + a.get_z() * b.get_z(); + } + + static public function multiplyMatrix(a : at.dotpoint.math.vector.IVector3,b : at.dotpoint.math.vector.IMatrix44,output : * = null) : * { + if(output == null) output = new at.dotpoint.math.vector.Vector3(); + var x : Number = a.get_x(); + var y : Number = a.get_y(); + var z : Number = a.get_z(); + var w : Number = a.get_w(); + output.set_x(b["m11"] * x + b["m12"] * y + b["m13"] * z + b["m14"] * w); + output.set_y(b["m21"] * x + b["m22"] * y + b["m23"] * z + b["m24"] * w); + output.set_z(b["m31"] * x + b["m32"] * y + b["m33"] * z + b["m34"] * w); + output.set_w(b["m41"] * x + b["m42"] * y + b["m43"] * z + b["m44"] * w); + return output; + } + + static public function project(a : at.dotpoint.math.vector.IVector3,b : at.dotpoint.math.vector.IVector3,output : * = null) : * { + if(output == null) output = new at.dotpoint.math.vector.Vector3(); + var l : Number = a.get_x() * a.get_x() + a.get_y() * a.get_y() + a.get_z() * a.get_z(); + if(l == 0) throw "undefined result"; + var d : Number = at.dotpoint.math.vector.Vector3.dot(a,b); + var div : Number = d / l; + return at.dotpoint.math.vector.Vector3.scale(a,div,output); + } + + static public function orthoNormalize(vectors : Array) : void { + var _g1 : int = 0; + var _g : int = vectors.length; + while(_g1 < _g) { + var i : int = _g1++; + var sum : at.dotpoint.math.vector.Vector3 = new at.dotpoint.math.vector.Vector3(); + { + var _g2 : int = 0; + while(_g2 < i) { + var j : int = _g2++; + var projected : at.dotpoint.math.vector.Vector3 = at.dotpoint.math.vector.Vector3.project(vectors[i],vectors[j]); + at.dotpoint.math.vector.Vector3.add(sum,projected,sum); + } + }; + at.dotpoint.math.vector.Vector3.subtract(vectors[i],sum,vectors[i]).normalize(); + } + } + + static public function isEqual(a : at.dotpoint.math.vector.IVector3,b : at.dotpoint.math.vector.IVector3) : Boolean { + if(!at.dotpoint.math.MathUtil.isEqual(a.get_x(),b.get_x())) return false; + if(!at.dotpoint.math.MathUtil.isEqual(a.get_y(),b.get_y())) return false; + if(!at.dotpoint.math.MathUtil.isEqual(a.get_z(),b.get_z())) return false; + return true; + } + + } +} diff --git a/bin/as3/src/calculator/EdgeContainer.as b/bin/as3/src/calculator/EdgeContainer.as new file mode 100644 index 0000000..14fb51f --- /dev/null +++ b/bin/as3/src/calculator/EdgeContainer.as @@ -0,0 +1,128 @@ +package calculator { + import calculator.Vertex; + import at.dotpoint.math.vector.Vector2; + import at.dotpoint.math.MathUtil; + import flash.Boot; + public class EdgeContainer { + public function EdgeContainer() : void { if( !flash.Boot.skip_constructor ) { + this.vertical = new Array(); + this.horizontal = new Array(); + }} + + public var horizontal : Array; + public var vertical : Array; + public function insert(a : calculator.Vertex,b : calculator.Vertex) : void { + if(this.isVertical(a,b)) { + var index : int = this.getIndex(a.get_x(),true); + this.vertical.insert(index * 2,a); + this.vertical.insert(index * 2,b); + } + else { + var index1 : int = this.getIndex(a.get_y(),false); + this.horizontal.insert(index1 * 2,a); + this.horizontal.insert(index1 * 2,b); + } + } + + public function remove(a : calculator.Vertex,b : calculator.Vertex) : void { + if(this.isVertical(a,b)) { + this.vertical.remove(a); + this.vertical.remove(b); + } + else { + this.horizontal.remove(a); + this.horizontal.remove(b); + } + } + + public function split(start : calculator.Vertex,dir : at.dotpoint.math.vector.Vector2) : calculator.Vertex { + var isVertical : Boolean = Math.abs(dir.get_x()) < Math.abs(dir.get_y()); + if(isVertical) { + var ystep : int; + if(dir.get_y() < 0) ystep = -1; + else ystep = 1; + var hstart : int = this.getIndex(start.get_y(),false) - 1; + var hlength : int = this.horizontal.length >> 1; + while((hstart += ystep) >= 0 && hstart <= hlength) { + var hindex : int = hstart * 2; + var a : calculator.Vertex = this.horizontal[hindex]; + var b : calculator.Vertex = this.horizontal[hindex + 1]; + if(a == start || b == start) continue; + if(start.get_x() >= a.get_x() && start.get_x() <= b.get_x() || start.get_x() >= b.get_x() && start.get_x() <= a.get_x()) return this.insertSplit(start,a,b); + } + } + else { + var xstep : int; + if(dir.get_x() < 0) xstep = -1; + else xstep = 1; + var vstart : int = this.getIndex(start.get_x(),true) - 1; + var vlength : int = this.vertical.length >> 1; + while((vstart += xstep) >= 0 && vstart <= vlength) { + var vindex : int = vstart * 2; + var a1 : calculator.Vertex = this.vertical[vindex]; + var b1 : calculator.Vertex = this.vertical[vindex + 1]; + if(a1 == start || b1 == start) continue; + if(start.get_y() >= a1.get_y() && start.get_y() <= b1.get_y() || start.get_y() >= b1.get_y() && start.get_y() <= a1.get_y()) return this.insertSplit(start,a1,b1); + } + }; + return null; + } + + public function insertSplit(start : calculator.Vertex,a : calculator.Vertex,b : calculator.Vertex) : calculator.Vertex { + var split : calculator.Vertex = new calculator.Vertex(null); + split.index = Math.min(a.index,b.index) + Math.min(1,Math.abs(b.index - a.index)) * 0.5; + if(this.isVertical(a,b)) { + split.set_x(a.get_x()); + split.set_y(start.get_y()); + } + else { + split.set_x(start.get_x()); + split.set_y(a.get_y()); + }; + this.remove(a,b); + this.insert(split,start); + this.insert(split,a); + this.insert(split,b); + a.removeNeighbor(b); + b.removeNeighbor(a); + a.insertNeighbor(split); + b.insertNeighbor(split); + split.insertNeighbor(start); + split.insertNeighbor(a); + split.insertNeighbor(b); + start.insertNeighbor(split); + return split; + } + + public function getIndex(value : Number,isVertical : Boolean) : int { + if(isVertical) { + var vlength : int = this.vertical.length >> 1; + { + var _g : int = 0; + while(_g < vlength) { + var v : int = _g++; + if(this.vertical[v * 2].get_x() > value) return v; + } + }; + return vlength; + } + else { + var hlength : int = this.horizontal.length >> 1; + { + var _g1 : int = 0; + while(_g1 < hlength) { + var h : int = _g1++; + if(this.horizontal[h * 2].get_y() > value) return h; + } + }; + return hlength; + }; + return -1; + } + + public function isVertical(a : calculator.Vertex,b : calculator.Vertex) : Boolean { + return at.dotpoint.math.MathUtil.isEqual(a.get_x(),b.get_x()); + } + + } +} diff --git a/bin/as3/src/calculator/TraversalSplitter.as b/bin/as3/src/calculator/TraversalSplitter.as new file mode 100644 index 0000000..c3baa4d --- /dev/null +++ b/bin/as3/src/calculator/TraversalSplitter.as @@ -0,0 +1,216 @@ +package calculator { + import calculator.EdgeContainer; + import calculator.VertexTriangle; + import at.dotpoint.math.geom.Rectangle; + import calculator.Vertex; + import haxe.Log; + import at.dotpoint.math.vector.Vector2; + import at.dotpoint.math.vector.Vector3; + public class TraversalSplitter implements IPartitionCalculator{ + public function TraversalSplitter() : void { + } + + public var coordinates : Array; + public var splitters : Array; + public var edges : calculator.EdgeContainer; + public var partitions : Array; + public function calculate(input : Array) : Array { + this.coordinates = new Array(); + this.edges = new calculator.EdgeContainer(); + this.partitions = new Array(); + this.prepareInput(input); + this.split(); + this.partitionate(); + return this.partitions; + } + + public function prepareInput(input : Array) : void { + this.toVertices(input); + this.sortClockwise(); + this.buildGraph(); + } + + public function toVertices(input : Array) : void { + { + var _g : int = 0; + while(_g < input.length) { + var point : at.dotpoint.math.vector.Vector2 = input[_g]; + ++_g; + this.coordinates.push(new calculator.Vertex(point)); + } + }; + var first : calculator.Vertex = this.coordinates[0]; + var last : calculator.Vertex = this.coordinates[this.coordinates.length - 1]; + if(at.dotpoint.math.vector.Vector2.isEqual(first.coordinate,last.coordinate)) this.coordinates.pop(); + } + + public function sortClockwise() : void { + var clockwise : Array = new Array(); + var counterwise : Array = new Array(); + { + var _g1 : int = 0; + var _g : int = this.coordinates.length; + while(_g1 < _g) { + var v : int = _g1++; + var triangle : calculator.VertexTriangle = this.getTriangle(v,true); + if(triangle.isClockwise()) clockwise.push(triangle.p2); + else counterwise.push(triangle.p2); + } + }; + if(clockwise.length < counterwise.length) { + (haxe.Log._trace)("reverse coordinates to conform to clockwise direction",{ fileName : "TraversalSplitter.hx", lineNumber : 168, className : "calculator.TraversalSplitter", methodName : "sortClockwise"}); + this.coordinates.reverse(); + this.splitters = clockwise; + this.splitters.reverse(); + } + else this.splitters = counterwise; + } + + public function buildGraph() : void { + { + var _g1 : int = 0; + var _g : int = this.coordinates.length; + while(_g1 < _g) { + var v : int = _g1++; + var triangle : calculator.VertexTriangle = this.getTriangle(v,true); + triangle.p2.insertNeighbor(triangle.p1); + triangle.p2.insertNeighbor(triangle.p3); + this.edges.insert(triangle.p1,triangle.p2); + } + }; + (haxe.Log._trace)("vertical: " + Std.string(this.edges.vertical),{ fileName : "TraversalSplitter.hx", lineNumber : 204, className : "calculator.TraversalSplitter", methodName : "buildGraph"}); + (haxe.Log._trace)("horizontal:" + Std.string(this.edges.horizontal),{ fileName : "TraversalSplitter.hx", lineNumber : 205, className : "calculator.TraversalSplitter", methodName : "buildGraph"}); + } + + public function split() : void { + var _g : int = 0; + var _g1 : Array = this.splitters; + while(_g < _g1.length) { + var vertex : calculator.Vertex = _g1[_g]; + ++_g; + var normal : at.dotpoint.math.vector.Vector2 = this.getNormal(vertex); + var split : calculator.Vertex = this.edges.split(vertex,normal); + if(split == null) throw "split could not be resolved, check the input"; + this.coordinates.push(split); + } + } + + public function partitionate() : void { + var _g : int = 0; + var _g1 : Array = this.coordinates; + while(_g < _g1.length) { + var start : calculator.Vertex = _g1[_g]; + ++_g; + var current : calculator.Vertex = start; + var previous : calculator.Vertex = null; + var next : calculator.Vertex = null; + var partition : at.dotpoint.math.geom.Rectangle = null; + do { + next = this.selectClockwiseVertex(current,previous); + if(next == null) { + (haxe.Log._trace)("skip",{ fileName : "TraversalSplitter.hx", lineNumber : 276, className : "calculator.TraversalSplitter", methodName : "partitionate", customParams : [current]}); + break; + } + else { + (haxe.Log._trace)("select",{ fileName : "TraversalSplitter.hx", lineNumber : 281, className : "calculator.TraversalSplitter", methodName : "partitionate", customParams : [previous,current,next,"\t neighbors:" + Std.string(next.neighbors)]}); + if(partition == null) partition = new at.dotpoint.math.geom.Rectangle(); + this.expandBounding(next,partition); + }; + previous = current; + current = next; + } while(current != start); + if(partition != null && this.isUniquePartiton(partition)) this.partitions.push(partition); + } + } + + public function selectClockwiseVertex(current : calculator.Vertex,previous : calculator.Vertex) : calculator.Vertex { + var iterator : * = null; + var possible : calculator.Vertex = null; + if(previous == null) { + iterator = current.neighbors.iterator(); + previous = current.neighbors[0]; + }; + while(previous != null) { + { var $it : * = current.neighbors.iterator(); + while( $it.hasNext() ) { var neighbor : calculator.Vertex = $it.next(); + { + if(neighbor == previous) continue; + var triangle : calculator.VertexTriangle = calculator.VertexTriangle.instance; + triangle.p1 = previous; + triangle.p2 = current; + triangle.p3 = neighbor; + if(triangle.isClockwise()) return neighbor; + else if(triangle.isClockwise(true)) possible = neighbor; + } + }}; + if(possible != null) return possible; + if(iterator == null || !iterator.hasNext()) break; + previous = iterator.next(); + }; + return null; + } + + public function isUniquePartiton(partition : at.dotpoint.math.geom.Rectangle) : Boolean { + { + var _g : int = 0; + var _g1 : Array = this.partitions; + while(_g < _g1.length) { + var area : at.dotpoint.math.geom.Rectangle = _g1[_g]; + ++_g; + if(area == partition) continue; + if(at.dotpoint.math.vector.Vector2.isEqual(partition.get_topLeft(),area.get_topLeft()) && at.dotpoint.math.vector.Vector2.isEqual(partition.get_bottomRight(),area.get_bottomRight())) return false; + } + }; + return true; + } + + public function getTriangle(index : int,pool : * = false) : calculator.VertexTriangle { + if(pool==null) pool=false; + var p1 : calculator.Vertex = this.coordinates[index % this.coordinates.length]; + var p2 : calculator.Vertex = this.coordinates[(index + 1) % this.coordinates.length]; + var p3 : calculator.Vertex = this.coordinates[(index + 2) % this.coordinates.length]; + var triangle : calculator.VertexTriangle; + if(pool) triangle = calculator.VertexTriangle.instance; + else triangle = new calculator.VertexTriangle(); + triangle.p1 = p1; + triangle.p2 = p2; + triangle.p3 = p3; + return triangle; + } + + public function getNormal(current : calculator.Vertex) : at.dotpoint.math.vector.Vector2 { + var previous : calculator.Vertex = current.neighbors[0]; + var delta : at.dotpoint.math.vector.Vector3 = new at.dotpoint.math.vector.Vector3(); + delta.set_x(current.get_x() - previous.get_x()); + delta.set_y(current.get_y() - previous.get_y()); + var normal : at.dotpoint.math.vector.Vector3 = at.dotpoint.math.vector.Vector3.cross(delta,new at.dotpoint.math.vector.Vector3(0,0,-1)); + normal.normalize(); + return new at.dotpoint.math.vector.Vector2(normal.get_x(),normal.get_y()); + } + + public function expandBounding(vertex : calculator.Vertex,bounding : at.dotpoint.math.geom.Rectangle) : void { + var v : Boolean = bounding.get_width() == 0 && bounding.get_height() == 0 && bounding.get_x() == 0 && bounding.get_y() == 0; + var x : Number = vertex.get_x(); + var y : Number = vertex.get_y(); + var nl : Number; + if(v) nl = x; + else nl = Math.min(bounding.get_left(),x); + var nr : Number; + if(v) nr = x; + else nr = Math.max(bounding.get_right(),x); + var nt : Number; + if(v) nt = y; + else nt = Math.min(bounding.get_top(),y); + var nb : Number; + if(v) nb = y; + else nb = Math.max(bounding.get_bottom(),y); + if(nl != bounding.get_left() || nr != bounding.get_right() || nt != bounding.get_top() || nb != bounding.get_bottom()) { + bounding.set_right(nr); + bounding.set_left(nl); + bounding.set_bottom(nb); + bounding.set_top(nt); + } + } + + } +} diff --git a/bin/as3/src/calculator/Vertex.as b/bin/as3/src/calculator/Vertex.as new file mode 100644 index 0000000..fa87bfd --- /dev/null +++ b/bin/as3/src/calculator/Vertex.as @@ -0,0 +1,63 @@ +package calculator { + import at.dotpoint.math.vector.IVector2; + import at.dotpoint.math.vector.Vector2; + import flash.Boot; + public class Vertex implements at.dotpoint.math.vector.IVector2{ + public function Vertex(coordinate : at.dotpoint.math.vector.Vector2 = null) : void { if( !flash.Boot.skip_constructor ) { + if(coordinate == null) coordinate = new at.dotpoint.math.vector.Vector2(); + this.coordinate = coordinate; + this.neighbors = new Array(); + }} + + public var coordinate : at.dotpoint.math.vector.Vector2; + public var index : Number; + public var neighbors : Array; + public function get x() : Number { return get_x(); } + public function set x( __v : Number ) : void { set_x(__v); } + protected var $x : Number; + public function get y() : Number { return get_y(); } + public function set y( __v : Number ) : void { set_y(__v); } + protected var $y : Number; + public function get_x() : Number { + return this.coordinate.get_x(); + } + + public function set_x(value : Number) : Number { + return this.coordinate.set_x(value); + } + + public function get_y() : Number { + return this.coordinate.get_y(); + } + + public function set_y(value : Number) : Number { + return this.coordinate.set_y(value); + } + + public function normalize() : void { + this.coordinate.normalize(); + } + + public function length() : Number { + return this.coordinate.length(); + } + + public function insertNeighbor(vertex : calculator.Vertex) : void { + this.neighbors.push(vertex); + this.neighbors.sort(this.sortNeighbors); + } + + public function removeNeighbor(vertex : calculator.Vertex) : Boolean { + return this.neighbors.remove(vertex); + } + + public function sortNeighbors(a : calculator.Vertex,b : calculator.Vertex) : int { + return Math.round(a.index - b.index); + } + + public function toString() : String { + return "[" + this.index + "]"; + } + + } +} diff --git a/bin/as3/src/calculator/VertexTriangle.as b/bin/as3/src/calculator/VertexTriangle.as new file mode 100644 index 0000000..4199e07 --- /dev/null +++ b/bin/as3/src/calculator/VertexTriangle.as @@ -0,0 +1,26 @@ +package calculator { + import calculator.Vertex; + import at.dotpoint.math.vector.Vector3; + public class VertexTriangle { + public function VertexTriangle() : void { + } + + public var p1 : calculator.Vertex; + public var p2 : calculator.Vertex; + public var p3 : calculator.Vertex; + public function isClockwise(includeZero : Boolean = false) : Boolean { + if(this.p1 == null || this.p2 == null || this.p3 == null) throw "must set 3 vertex coordinates"; + var v1 : at.dotpoint.math.vector.Vector3 = new at.dotpoint.math.vector.Vector3(this.p1.coordinate.get_x(),this.p1.coordinate.get_y(),0); + var v2 : at.dotpoint.math.vector.Vector3 = new at.dotpoint.math.vector.Vector3(this.p2.coordinate.get_x(),this.p2.coordinate.get_y(),0); + var v3 : at.dotpoint.math.vector.Vector3 = new at.dotpoint.math.vector.Vector3(this.p3.coordinate.get_x(),this.p3.coordinate.get_y(),0); + var sub1 : at.dotpoint.math.vector.Vector3 = at.dotpoint.math.vector.Vector3.subtract(v2,v1,new at.dotpoint.math.vector.Vector3()); + var sub2 : at.dotpoint.math.vector.Vector3 = at.dotpoint.math.vector.Vector3.subtract(v3,v1,new at.dotpoint.math.vector.Vector3()); + var cross : at.dotpoint.math.vector.Vector3 = at.dotpoint.math.vector.Vector3.cross(sub1,sub2); + if(includeZero) return cross.get_z() >= 0; + else return cross.get_z() > 0; + return false; + } + + static public var instance : calculator.VertexTriangle = new calculator.VertexTriangle(); + } +} diff --git a/bin/as3/src/converter/StringConverter.as b/bin/as3/src/converter/StringConverter.as new file mode 100644 index 0000000..3a4bd9a --- /dev/null +++ b/bin/as3/src/converter/StringConverter.as @@ -0,0 +1,32 @@ +package converter { + import at.dotpoint.math.vector.Vector2; + import flash.Boot; + public class StringConverter implements IPolygonConverter{ + public function StringConverter(seperator : String = null) : void { if( !flash.Boot.skip_constructor ) { + if(seperator == null) seperator = " "; + this.seperator = seperator; + }} + + public var seperator : String; + public function convert(_tmp_input : *) : Array { + var input : String = String(_tmp_input); + var coordinates : Array = new Array(); + var splitted : Array = input.split(this.seperator); + var length : int = Std._int(splitted.length * 0.5); + { + var _g : int = 0; + while(_g < length) { + var j : int = _g++; + var index : int = j * 2; + var point : at.dotpoint.math.vector.Vector2 = new at.dotpoint.math.vector.Vector2(); + point.set_x(Std._parseInt(splitted[index])); + point.set_y(Std._parseInt(splitted[index + 1])); + coordinates.push(point); + } + }; + if(coordinates.length == 0) throw "input string does not contain parsable float or integer coordinates or does not use " + this.seperator + " as seperator"; + return coordinates; + } + + } +} diff --git a/bin/as3/src/enum.as b/bin/as3/src/enum.as new file mode 100644 index 0000000..5f411f7 --- /dev/null +++ b/bin/as3/src/enum.as @@ -0,0 +1,9 @@ +package { + import flash.Boot; + public class enum { + public var tag : String; + public var index : int; + public var params : Array; + public function toString() : String { return flash.Boot.enum_to_string(this); } + } +} diff --git a/bin/as3/src/flash/Boot.as b/bin/as3/src/flash/Boot.as new file mode 100644 index 0000000..1f9c665 --- /dev/null +++ b/bin/as3/src/flash/Boot.as @@ -0,0 +1,211 @@ +package flash { + import flash.events.Event; + import flash.Lib; + import flash.text.TextFormat; + import flash.display.Stage; + import flash.text.TextFieldAutoSize; + import flash.utils.getQualifiedClassName; + import flash.utils.setTimeout; + import flash.display.MovieClip; + import flash.text.TextField; + public class Boot extends flash.display.MovieClip { + public function Boot() : void { if( !flash.Boot.skip_constructor ) { + super(); + }} + + protected function start() : void { + var c : flash.display.MovieClip = flash.Lib.current; + try { + if(c == this && c.stage != null && c.stage.align == "") c.stage.align = "TOP_LEFT"; + } + catch( e : * ){ + }; + if(c.stage == null) c.addEventListener(flash.events.Event.ADDED_TO_STAGE,this.doInitDelay); + else if(c.stage.stageWidth == 0 || c.stage.stageHeight == 0) flash.utils.setTimeout(this.start,1); + else this.init(); + } + + protected function doInitDelay(_ : *) : void { + flash.Lib.current.removeEventListener(flash.events.Event.ADDED_TO_STAGE,this.doInitDelay); + this.start(); + } + + protected function init() : void { + throw "assert"; + } + + static protected var tf : flash.text.TextField; + static protected var lines : Array; + static protected var lastError : Error; + static public var skip_constructor : Boolean = false; + static public function enum_to_string(e : *) : String { + if(e.params == null) return e.tag; + var pstr : Array = []; + { + var _g : int = 0; + var _g1 : Array = e.params; + while(_g < _g1.length) { + var p : * = _g1[_g]; + ++_g; + pstr.push(flash.Boot.__string_rec(p,"")); + } + }; + return e.tag + "(" + pstr.join(",") + ")"; + } + + static public function __instanceof(v : *,t : *) : Boolean { + try { + if(t == Object) return true; + return v is t; + } + catch( e : * ){ + }; + return false; + } + + static public function __clear_trace() : void { + if(flash.Boot.tf == null) return; + flash.Boot.tf.parent.removeChild(flash.Boot.tf); + flash.Boot.tf = null; + flash.Boot.lines = null; + } + + static public function __set_trace_color(rgb : uint) : void { + var tf : flash.text.TextField = flash.Boot.getTrace(); + tf.textColor = rgb; + tf.filters = []; + } + + static public function getTrace() : flash.text.TextField { + var mc : flash.display.MovieClip = flash.Lib.current; + if(flash.Boot.tf == null) { + flash.Boot.tf = new flash.text.TextField(); + var format : flash.text.TextFormat = flash.Boot.tf.getTextFormat(); + format.font = "_sans"; + flash.Boot.tf.defaultTextFormat = format; + flash.Boot.tf.selectable = false; + if(mc.stage == null) flash.Boot.tf.width = 800; + else flash.Boot.tf.width = mc.stage.stageWidth; + flash.Boot.tf.autoSize = flash.text.TextFieldAutoSize.LEFT; + flash.Boot.tf.mouseEnabled = false; + }; + if(mc.stage == null) mc.addChild(flash.Boot.tf); + else mc.stage.addChild(flash.Boot.tf); + return flash.Boot.tf; + } + + static public function __trace(v : *,pos : *) : void { + var tf : flash.text.TextField = flash.Boot.getTrace(); + var pstr : String; + if(pos == null) pstr = "(null)"; + else pstr = pos.fileName + ":" + pos.lineNumber; + if(flash.Boot.lines == null) flash.Boot.lines = []; + var str : String = pstr + ": " + flash.Boot.__string_rec(v,""); + if(pos != null && pos.customParams != null) { + var _g : int = 0; + var _g1 : Array = pos.customParams; + while(_g < _g1.length) { + var v1 : * = _g1[_g]; + ++_g; + str += "," + flash.Boot.__string_rec(v1,""); + } + }; + flash.Boot.lines = flash.Boot.lines.concat(str.split("\n")); + tf.text = flash.Boot.lines.join("\n"); + var stage : flash.display.Stage = flash.Lib.current.stage; + if(stage == null) return; + while(flash.Boot.lines.length > 1 && tf.height > stage.stageHeight) { + flash.Boot.lines.shift(); + tf.text = flash.Boot.lines.join("\n"); + } + } + + static public function __string_rec(v : *,str : String) : String { + var cname : String = flash.utils.getQualifiedClassName(v); + switch(cname) { + case "Object": + { + var k : Array = function() : Array { + var $r : Array; + $r = new Array(); + for(var $k2 : String in v) $r.push($k2); + return $r; + }(); + var s : String = "{"; + var first : Boolean = true; + { + var _g1 : int = 0; + var _g : int = k.length; + while(_g1 < _g) { + var i : int = _g1++; + var key : String = k[i]; + if(key == "toString") try { + return v.toString(); + } + catch( e : * ){ + }; + if(first) first = false; + else s += ","; + s += " " + key + " : " + flash.Boot.__string_rec(v[key],str); + } + }; + if(!first) s += " "; + s += "}"; + return s; + } + break; + case "Array": + { + if(v == Array) return "#Array"; + var s1 : String = "["; + var i1 : *; + var first1 : Boolean = true; + var a : Array = v; + { + var _g11 : int = 0; + var _g2 : int = a.length; + while(_g11 < _g2) { + var i2 : int = _g11++; + if(first1) first1 = false; + else s1 += ","; + s1 += flash.Boot.__string_rec(a[i2],str); + } + }; + return s1 + "]"; + } + break; + default: + { + var _g3 : String = typeof v; + switch(_g3) { + case "function": + return ""; + break; + case "undefined": + return "null"; + break; + } + } + break; + }; + return new String(v); + } + + static protected function __unprotect__(s : String) : String { + return s; + } + + static public function mapDynamic(d : *,f : *) : * { + if(Std._is(d,Array)) return d["mapHX"](f); + else return d["map"](f); + return null; + } + + static public function filterDynamic(d : *,f : *) : * { + if(Std._is(d,Array)) return d["filterHX"](f); + else return d["filter"](f); + return null; + } + + } +} diff --git a/bin/as3/src/flash/Lib.as b/bin/as3/src/flash/Lib.as new file mode 100644 index 0000000..ed357c4 --- /dev/null +++ b/bin/as3/src/flash/Lib.as @@ -0,0 +1,88 @@ +package flash { + import flash.net.URLRequest; + import flash.utils.getDefinitionByName; + import flash.display.MovieClip; + import flash.external.ExternalInterface; + import haxe.Log; + import flash.system.fscommand; + import flash.net.navigateToURL; + import flash.utils.getTimer; + public class Lib { + static public var current : flash.display.MovieClip; + static public function _getTimer() : int { + return flash.utils.getTimer(); + } + + static public function eval(path : String) : * { + var p : Array = path.split("."); + var fields : Array = new Array(); + var o : * = null; + while(p.length > 0) { + try { + o = flash.utils.getDefinitionByName(p.join(".")); + } + catch( e : * ){ + fields.unshift(p.pop()); + }; + if(o != null) break; + }; + { + var _g : int = 0; + while(_g < fields.length) { + var f : String = fields[_g]; + ++_g; + if(o == null) return null; + o = o[f]; + } + }; + return o; + } + + static public function getURL(url : flash.net.URLRequest,target : String = null) : void { + var f : Function = flash.net.navigateToURL; + if(target == null) f(url); + else ((f) as Function)(url,target); + } + + static public function fscommand(cmd : String,param : String = null) : void { + flash.system.fscommand(cmd,((param == null)?"":param)); + } + + static public function _trace(arg : *) : void { + trace(arg); + } + + static public function attach(name : String) : flash.display.MovieClip { + var cl : * = flash.utils.getDefinitionByName(name) as Class; + return new cl(); + } + + static public function _as(v : *,c : Class) : * { + return v as c; + } + + static public function redirectTraces() : void { + if(flash.external.ExternalInterface.available) haxe.Log._trace = flash.Lib.traceToConsole; + } + + static protected function traceToConsole(v : *,inf : * = null) : void { + var type : String; + if(inf != null && inf.customParams != null) type = inf.customParams[0]; + else type = null; + if(type != "warn" && type != "info" && type != "debug" && type != "error") if(inf == null) type = "error"; + else type = "log"; + var str : String; + if(inf == null) str = ""; + else str = inf.fileName + ":" + inf.lineNumber + " : "; + try { + str += Std.string(v); + } + catch( e : * ){ + str += "????"; + }; + str = str.split("\\").join("\\\\"); + flash.external.ExternalInterface.call("console." + type,str); + } + + } +} diff --git a/bin/as3/src/haxe/IMap.as b/bin/as3/src/haxe/IMap.as new file mode 100644 index 0000000..12f48c3 --- /dev/null +++ b/bin/as3/src/haxe/IMap.as @@ -0,0 +1,11 @@ +package haxe { + public interface IMap { + function get(k : *) : * ; + function set(k : *,v : *) : void ; + function exists(k : *) : Boolean ; + function remove(k : *) : Boolean ; + function keys() : * ; + function iterator() : * ; + function toString() : String ; + } +} diff --git a/bin/as3/src/haxe/Log.as b/bin/as3/src/haxe/Log.as new file mode 100644 index 0000000..5ec1ce9 --- /dev/null +++ b/bin/as3/src/haxe/Log.as @@ -0,0 +1,14 @@ +package haxe { + import flash.Boot; + public class Log { + static public var _trace : Function = function(v : *,infos : * = null) : void { + flash.Boot.__trace(v,infos); + } + static public var clear : Function = function() : void { + flash.Boot.__clear_trace(); + } + static public var setColor : Function = function(rgb : int) : void { + flash.Boot.__set_trace_color(rgb); + } + } +} diff --git a/bin/as3/src/haxe/ds/BalancedTree.as b/bin/as3/src/haxe/ds/BalancedTree.as new file mode 100644 index 0000000..7061618 --- /dev/null +++ b/bin/as3/src/haxe/ds/BalancedTree.as @@ -0,0 +1,167 @@ +package haxe.ds { + import haxe.ds.TreeNode; + public class BalancedTree { + public function BalancedTree() : void { + } + + protected var root : haxe.ds.TreeNode; + public function set(key : *,value : *) : void { + this.root = this.setLoop(key,value,this.root); + } + + public function get(key : *) : * { + var node : haxe.ds.TreeNode = this.root; + while(node != null) { + var c : int = this.compare(key,node.key); + if(c == 0) return node.value; + if(c < 0) node = node.left; + else node = node.right; + }; + return null; + } + + public function remove(key : *) : Boolean { + try { + this.root = this.removeLoop(key,this.root); + return true; + } + catch( e : String ){ + return false; + }; + return false; + } + + public function exists(key : *) : Boolean { + var node : haxe.ds.TreeNode = this.root; + while(node != null) { + var c : int = this.compare(key,node.key); + if(c == 0) return true; + else if(c < 0) node = node.left; + else node = node.right; + }; + return false; + } + + public function iterator() : * { + var ret : Array = []; + this.iteratorLoop(this.root,ret); + return ret.iterator(); + } + + public function keys() : * { + var ret : Array = []; + this.keysLoop(this.root,ret); + return ret.iterator(); + } + + protected function setLoop(k : *,v : *,node : haxe.ds.TreeNode) : haxe.ds.TreeNode { + if(node == null) return new haxe.ds.TreeNode(null,k,v,null); + var c : int = this.compare(k,node.key); + if(c == 0) return new haxe.ds.TreeNode(node.left,k,v,node.right,((node == null)?0:node._height)); + else if(c < 0) { + var nl : haxe.ds.TreeNode = this.setLoop(k,v,node.left); + return this.balance(nl,node.key,node.value,node.right); + } + else { + var nr : haxe.ds.TreeNode = this.setLoop(k,v,node.right); + return this.balance(node.left,node.key,node.value,nr); + }; + return null; + } + + protected function removeLoop(k : *,node : haxe.ds.TreeNode) : haxe.ds.TreeNode { + if(node == null) throw "Not_found"; + var c : int = this.compare(k,node.key); + if(c == 0) return this.merge(node.left,node.right); + else if(c < 0) return this.balance(this.removeLoop(k,node.left),node.key,node.value,node.right); + else return this.balance(node.left,node.key,node.value,this.removeLoop(k,node.right)); + return null; + } + + protected function iteratorLoop(node : haxe.ds.TreeNode,acc : Array) : void { + if(node != null) { + this.iteratorLoop(node.left,acc); + acc.push(node.value); + this.iteratorLoop(node.right,acc); + } + } + + protected function keysLoop(node : haxe.ds.TreeNode,acc : Array) : void { + if(node != null) { + this.keysLoop(node.left,acc); + acc.push(node.key); + this.keysLoop(node.right,acc); + } + } + + protected function merge(t1 : haxe.ds.TreeNode,t2 : haxe.ds.TreeNode) : haxe.ds.TreeNode { + if(t1 == null) return t2; + if(t2 == null) return t1; + var t : haxe.ds.TreeNode = this.minBinding(t2); + return this.balance(t1,t.key,t.value,this.removeMinBinding(t2)); + } + + protected function minBinding(t : haxe.ds.TreeNode) : haxe.ds.TreeNode { + if(t == null) throw "Not_found"; + else if(t.left == null) return t; + else return this.minBinding(t.left); + return null; + } + + protected function removeMinBinding(t : haxe.ds.TreeNode) : haxe.ds.TreeNode { + if(t.left == null) return t.right; + else return this.balance(this.removeMinBinding(t.left),t.key,t.value,t.right); + return null; + } + + protected function balance(l : haxe.ds.TreeNode,k : *,v : *,r : haxe.ds.TreeNode) : haxe.ds.TreeNode { + var hl : int; + if(l == null) hl = 0; + else hl = l._height; + var hr : int; + if(r == null) hr = 0; + else hr = r._height; + if(hl > hr + 2) { + if((function($this:BalancedTree) : int { + var $r : int; + var _this : haxe.ds.TreeNode = l.left; + $r = ((_this == null)?0:_this._height); + return $r; + }(this)) >= (function($this:BalancedTree) : int { + var $r2 : int; + var _this1 : haxe.ds.TreeNode = l.right; + $r2 = ((_this1 == null)?0:_this1._height); + return $r2; + }(this))) return new haxe.ds.TreeNode(l.left,l.key,l.value,new haxe.ds.TreeNode(l.right,k,v,r)); + else return new haxe.ds.TreeNode(new haxe.ds.TreeNode(l.left,l.key,l.value,l.right.left),l.right.key,l.right.value,new haxe.ds.TreeNode(l.right.right,k,v,r)); + } + else if(hr > hl + 2) { + if((function($this:BalancedTree) : int { + var $r3 : int; + var _this2 : haxe.ds.TreeNode = r.right; + $r3 = ((_this2 == null)?0:_this2._height); + return $r3; + }(this)) > (function($this:BalancedTree) : int { + var $r4 : int; + var _this3 : haxe.ds.TreeNode = r.left; + $r4 = ((_this3 == null)?0:_this3._height); + return $r4; + }(this))) return new haxe.ds.TreeNode(new haxe.ds.TreeNode(l,k,v,r.left),r.key,r.value,r.right); + else return new haxe.ds.TreeNode(new haxe.ds.TreeNode(l,k,v,r.left.left),r.left.key,r.left.value,new haxe.ds.TreeNode(r.left.right,r.key,r.value,r.right)); + } + else return new haxe.ds.TreeNode(l,k,v,r,(((hl > hr)?hl:hr)) + 1); + return null; + } + + protected function compare(k1 : *,k2 : *) : int { + return Reflect.compare(k1,k2); + } + + public function toString() : String { + if(this.root == null) return "{}"; + else return "{" + this.root.toString() + "}"; + return null; + } + + } +} diff --git a/bin/as3/src/haxe/ds/EnumValueMap.as b/bin/as3/src/haxe/ds/EnumValueMap.as new file mode 100644 index 0000000..629ad0a --- /dev/null +++ b/bin/as3/src/haxe/ds/EnumValueMap.as @@ -0,0 +1,44 @@ +package haxe.ds { + import haxe.IMap; + import haxe.ds.BalancedTree; + import flash.Boot; + public class EnumValueMap extends haxe.ds.BalancedTree implements haxe.IMap{ + public function EnumValueMap() : void { if( !flash.Boot.skip_constructor ) { + super(); + }} + + protected override function compare(_tmp_k1 : *,_tmp_k2 : *) : int { + var k1 : enum = enum(_tmp_k1); + var k2 : enum = enum(_tmp_k2); + var d : int = Type.enumIndex(k1) - Type.enumIndex(k2); + if(d != 0) return d; + var p1 : Array = Type.enumParameters(k1); + var p2 : Array = Type.enumParameters(k2); + if(p1.length == 0 && p2.length == 0) return 0; + return this.compareArgs(p1,p2); + } + + protected function compareArgs(a1 : Array,a2 : Array) : int { + var ld : int = a1.length - a2.length; + if(ld != 0) return ld; + { + var _g1 : int = 0; + var _g : int = a1.length; + while(_g1 < _g) { + var i : int = _g1++; + var d : int = this.compareArg(a1[i],a2[i]); + if(d != 0) return d; + } + }; + return 0; + } + + protected function compareArg(v1 : *,v2 : *) : int { + if(Reflect.isEnumValue(v1) && Reflect.isEnumValue(v2)) return this.compare(v1,v2); + else if(Std._is(v1,Array) && Std._is(v2,Array)) return this.compareArgs(v1,v2); + else return Reflect.compare(v1,v2); + return 0; + } + + } +} diff --git a/bin/as3/src/haxe/ds/IntMap.as b/bin/as3/src/haxe/ds/IntMap.as new file mode 100644 index 0000000..c934694 --- /dev/null +++ b/bin/as3/src/haxe/ds/IntMap.as @@ -0,0 +1,69 @@ +package haxe.ds { + import haxe.IMap; + import flash.utils.Dictionary; + import flash.Boot; + public class IntMap implements haxe.IMap{ + public function IntMap() : void { if( !flash.Boot.skip_constructor ) { + this.h = new flash.utils.Dictionary(); + }} + + protected var h : flash.utils.Dictionary; + public function set(_tmp_key : *,value : *) : void { + var key : int = int(_tmp_key); + this.h[key] = value; + } + + public function get(_tmp_key : *) : * { + var key : int = int(_tmp_key); + return this.h[key]; + } + + public function exists(_tmp_key : *) : Boolean { + var key : int = int(_tmp_key); + return (key in this.h); + } + + public function remove(_tmp_key : *) : Boolean { + var key : int = int(_tmp_key); + if(!this.exists(key)) return false; + delete(this.h[key]); + return true; + } + + public function keys() : * { + return (function($this:IntMap) : * { + var $r : *; + $r = new Array(); + for(var $k2 : String in $this.h) $r.push($k2); + return $r; + }(this)).iterator(); + } + + public function iterator() : * { + return { ref : this.h, it : this.keys(), hasNext : function() : Boolean { + return this.it.hasNext(); + }, next : function() : * { + var i : int = this.it.next(); + return this.ref[i]; + }} + } + + public function toString() : String { + var s : StringBuf = new StringBuf(); + s.add("{"); + var it : * = this.keys(); + { var $it : * = it; + while( $it.hasNext() ) { var i : int = $it.next(); + { + s.add(i); + s.add(" => "); + s.add(Std.string(this.get(i))); + if(it.hasNext()) s.add(", "); + } + }}; + s.add("}"); + return s.toString(); + } + + } +} diff --git a/bin/as3/src/haxe/ds/ObjectMap.as b/bin/as3/src/haxe/ds/ObjectMap.as new file mode 100644 index 0000000..77a9395 --- /dev/null +++ b/bin/as3/src/haxe/ds/ObjectMap.as @@ -0,0 +1,65 @@ +package haxe.ds { + import haxe.IMap; + import flash.Boot; + import flash.utils.Dictionary; + public class ObjectMap extends flash.utils.Dictionary implements haxe.IMap{ + public function ObjectMap() : void { if( !flash.Boot.skip_constructor ) { + super(false); + }} + + public function get(_tmp_key : *) : * { + var key : * = _tmp_key; + return this[key]; + } + + public function set(_tmp_key : *,value : *) : void { + var key : * = _tmp_key; + this[key] = value; + } + + public function exists(_tmp_key : *) : Boolean { + var key : * = _tmp_key; + return this[key] != null; + } + + public function remove(_tmp_key : *) : Boolean { + var key : * = _tmp_key; + var has : Boolean = this.exists(key); + delete(this[key]); + return has; + } + + public function keys() : * { + return (function($this:ObjectMap) : * { + var $r : *; + $r = new Array(); + for(var $k2 : String in $this) $r.push($k2); + return $r; + }(this)).iterator(); + } + + public function iterator() : * { + var ret : Array = []; + { var $it : * = this.keys(); + while( $it.hasNext() ) { var i : * = $it.next(); + ret.push(this.get(i)); + }}; + return ret.iterator(); + } + + public function toString() : String { + var s : String = ""; + var it : * = this.keys(); + { var $it : * = it; + while( $it.hasNext() ) { var i : * = $it.next(); + { + s += (((s == "")?"":",")) + Std.string(i); + s += " => "; + s += Std.string(this.get(i)); + } + }}; + return s + "}"; + } + + } +} diff --git a/bin/as3/src/haxe/ds/StringMap.as b/bin/as3/src/haxe/ds/StringMap.as new file mode 100644 index 0000000..13753e4 --- /dev/null +++ b/bin/as3/src/haxe/ds/StringMap.as @@ -0,0 +1,75 @@ +package haxe.ds { + import haxe.IMap; + import flash.utils.Dictionary; + import flash.Boot; + public class StringMap implements haxe.IMap{ + public function StringMap() : void { if( !flash.Boot.skip_constructor ) { + this.h = new flash.utils.Dictionary(); + }} + + protected var h : flash.utils.Dictionary; + public function set(_tmp_key : *,value : *) : void { + var key : String = String(_tmp_key); + this.h["$" + key] = value; + } + + public function get(_tmp_key : *) : * { + var key : String = String(_tmp_key); + return this.h["$" + key]; + } + + public function exists(_tmp_key : *) : Boolean { + var key : String = String(_tmp_key); + return ("$" + key in this.h); + } + + public function remove(_tmp_key : *) : Boolean { + var key : String = String(_tmp_key); + key = "$" + key; + if(!(key in this.h)) return false; + delete(this.h[key]); + return true; + } + + public function keys() : * { + return (function($this:StringMap) : * { + var $r : *; + $r = new Array(); + for(var $k2 : String in $this.h) $r.push($k2.substr(1)); + return $r; + }(this)).iterator(); + } + + public function iterator() : * { + return { ref : this.h, it : (function($this:StringMap) : * { + var $r : *; + $r = new Array(); + for(var $k2 : String in $this.h) $r.push($k2); + return $r; + }(this)).iterator(), hasNext : function() : Boolean { + return this.it.hasNext(); + }, next : function() : * { + var i : * = this.it.next(); + return this.ref[i]; + }} + } + + public function toString() : String { + var s : StringBuf = new StringBuf(); + s.add("{"); + var it : * = this.keys(); + { var $it : * = it; + while( $it.hasNext() ) { var i : String = $it.next(); + { + s.add(i); + s.add(" => "); + s.add(Std.string(this.get(i))); + if(it.hasNext()) s.add(", "); + } + }}; + s.add("}"); + return s.toString(); + } + + } +} diff --git a/bin/as3/src/haxe/ds/TreeNode.as b/bin/as3/src/haxe/ds/TreeNode.as new file mode 100644 index 0000000..1ecc7dc --- /dev/null +++ b/bin/as3/src/haxe/ds/TreeNode.as @@ -0,0 +1,43 @@ +package haxe.ds { + import flash.Boot; + public class TreeNode { + public function TreeNode(l : haxe.ds.TreeNode = null,k : * = null,v : * = null,r : haxe.ds.TreeNode = null,h : int = -1) : void { if( !flash.Boot.skip_constructor ) { + this.left = l; + this.key = k; + this.value = v; + this.right = r; + if(h == -1) this._height = ((((function($this:TreeNode) : int { + var $r : int; + var _this : haxe.ds.TreeNode = $this.left; + $r = ((_this == null)?0:_this._height); + return $r; + }(this)) > (function($this:TreeNode) : int { + var $r2 : int; + var _this1 : haxe.ds.TreeNode = $this.right; + $r2 = ((_this1 == null)?0:_this1._height); + return $r2; + }(this)))?(function($this:TreeNode) : int { + var $r3 : int; + var _this2 : haxe.ds.TreeNode = $this.left; + $r3 = ((_this2 == null)?0:_this2._height); + return $r3; + }(this)):(function($this:TreeNode) : int { + var $r4 : int; + var _this3 : haxe.ds.TreeNode = $this.right; + $r4 = ((_this3 == null)?0:_this3._height); + return $r4; + }(this)))) + 1; + else this._height = h; + }} + + public var left : haxe.ds.TreeNode; + public var right : haxe.ds.TreeNode; + public var key : *; + public var value : *; + public var _height : int; + public function toString() : String { + return (((this.left == null)?"":this.left.toString() + ", ")) + ("" + Std.string(this.key) + "=" + Std.string(this.value)) + (((this.right == null)?"":", " + this.right.toString())); + } + + } +} diff --git a/bin/as3/src/haxe/ds/WeakMap.as b/bin/as3/src/haxe/ds/WeakMap.as new file mode 100644 index 0000000..5fbc60f --- /dev/null +++ b/bin/as3/src/haxe/ds/WeakMap.as @@ -0,0 +1,65 @@ +package haxe.ds { + import haxe.IMap; + import flash.Boot; + import flash.utils.Dictionary; + public class WeakMap extends flash.utils.Dictionary implements haxe.IMap{ + public function WeakMap() : void { if( !flash.Boot.skip_constructor ) { + super(true); + }} + + public function get(_tmp_key : *) : * { + var key : * = _tmp_key; + return this[key]; + } + + public function set(_tmp_key : *,value : *) : void { + var key : * = _tmp_key; + this[key] = value; + } + + public function exists(_tmp_key : *) : Boolean { + var key : * = _tmp_key; + return this[key] != null; + } + + public function remove(_tmp_key : *) : Boolean { + var key : * = _tmp_key; + var has : Boolean = this.exists(key); + delete(this[key]); + return has; + } + + public function keys() : * { + return (function($this:WeakMap) : * { + var $r : *; + $r = new Array(); + for(var $k2 : String in $this) $r.push($k2); + return $r; + }(this)).iterator(); + } + + public function iterator() : * { + var ret : Array = []; + { var $it : * = this.keys(); + while( $it.hasNext() ) { var i : * = $it.next(); + ret.push(this.get(i)); + }}; + return ret.iterator(); + } + + public function toString() : String { + var s : String = ""; + var it : * = this.keys(); + { var $it : * = it; + while( $it.hasNext() ) { var i : * = $it.next(); + { + s += (((s == "")?"":",")) + Std.string(i); + s += " => "; + s += Std.string(this.get(i)); + } + }}; + return s + "}"; + } + + } +} diff --git a/bin/as3/src/haxe/ds/_HashMap/HashMapData.as b/bin/as3/src/haxe/ds/_HashMap/HashMapData.as new file mode 100644 index 0000000..db291f1 --- /dev/null +++ b/bin/as3/src/haxe/ds/_HashMap/HashMapData.as @@ -0,0 +1,13 @@ +package haxe.ds._HashMap { + import haxe.ds.IntMap; + import flash.Boot; + public class HashMapData { + public function HashMapData() : void { if( !flash.Boot.skip_constructor ) { + this.keys = new haxe.ds.IntMap(); + this.values = new haxe.ds.IntMap(); + }} + + public var keys : haxe.ds.IntMap; + public var values : haxe.ds.IntMap; + } +} diff --git a/bin/as3/src/haxe/ds/_HashMap/HashMap_Impl_.as b/bin/as3/src/haxe/ds/_HashMap/HashMap_Impl_.as new file mode 100644 index 0000000..9164d28 --- /dev/null +++ b/bin/as3/src/haxe/ds/_HashMap/HashMap_Impl_.as @@ -0,0 +1,35 @@ +package haxe.ds._HashMap { + import haxe.ds._HashMap.HashMapData; + public class HashMap_Impl_ { + static public function _new() : haxe.ds._HashMap.HashMapData { + return new haxe.ds._HashMap.HashMapData(); + } + + static public function set(this1 : haxe.ds._HashMap.HashMapData,k : *,v : *) : void { + this1.keys.set(k.hashCode(),k); + this1.values.set(k.hashCode(),v); + } + + static public function get(this1 : haxe.ds._HashMap.HashMapData,k : *) : * { + return this1.values.get(k.hashCode()); + } + + static public function exists(this1 : haxe.ds._HashMap.HashMapData,k : *) : Boolean { + return this1.values.exists(k.hashCode()); + } + + static public function remove(this1 : haxe.ds._HashMap.HashMapData,k : *) : Boolean { + this1.values.remove(k.hashCode()); + return this1.keys.remove(k.hashCode()); + } + + static public function keys(this1 : haxe.ds._HashMap.HashMapData) : * { + return this1.keys.iterator(); + } + + static public function iterator(this1 : haxe.ds._HashMap.HashMapData) : * { + return this1.values.iterator(); + } + + } +} diff --git a/bin/as3/src/haxe/ds/_ObjectMap/NativePropertyIterator.as b/bin/as3/src/haxe/ds/_ObjectMap/NativePropertyIterator.as new file mode 100644 index 0000000..39af857 --- /dev/null +++ b/bin/as3/src/haxe/ds/_ObjectMap/NativePropertyIterator.as @@ -0,0 +1,31 @@ +package haxe.ds._ObjectMap { + public class NativePropertyIterator { + public function NativePropertyIterator() : void { + } + + public var collection : *; + protected var index : int = 0; + public function hasNext() : Boolean { + var c : * = this.collection; + var i : int = this.index; + var result : Boolean = __has_next__(c,i); + this.collection = c; + this.index = i; + return result; + } + + public function next() : * { + var i : int = this.index; + var result : * = __forin__(this.collection,i); + this.index = i; + return result; + } + + static public function iterator(collection : *) : haxe.ds._ObjectMap.NativePropertyIterator { + var result : haxe.ds._ObjectMap.NativePropertyIterator = new haxe.ds._ObjectMap.NativePropertyIterator(); + result.collection = collection; + return result; + } + + } +} diff --git a/bin/as3/src/haxe/ds/_ObjectMap/NativeValueIterator.as b/bin/as3/src/haxe/ds/_ObjectMap/NativeValueIterator.as new file mode 100644 index 0000000..59985a8 --- /dev/null +++ b/bin/as3/src/haxe/ds/_ObjectMap/NativeValueIterator.as @@ -0,0 +1,31 @@ +package haxe.ds._ObjectMap { + public class NativeValueIterator { + public function NativeValueIterator() : void { + } + + public var collection : *; + protected var index : int = 0; + public function hasNext() : Boolean { + var c : * = this.collection; + var i : int = this.index; + var result : Boolean = __has_next__(c,i); + this.collection = c; + this.index = i; + return result; + } + + public function next() : * { + var i : int = this.index; + var result : * = __foreach__(this.collection,i); + this.index = i; + return result; + } + + static public function iterator(collection : *) : haxe.ds._ObjectMap.NativeValueIterator { + var result : haxe.ds._ObjectMap.NativeValueIterator = new haxe.ds._ObjectMap.NativeValueIterator(); + result.collection = collection; + return result; + } + + } +} diff --git a/bin/as3/src/haxe/ds/_WeakMap/NativePropertyIterator.as b/bin/as3/src/haxe/ds/_WeakMap/NativePropertyIterator.as new file mode 100644 index 0000000..3098c8b --- /dev/null +++ b/bin/as3/src/haxe/ds/_WeakMap/NativePropertyIterator.as @@ -0,0 +1,31 @@ +package haxe.ds._WeakMap { + public class NativePropertyIterator { + public function NativePropertyIterator() : void { + } + + public var collection : *; + protected var index : int = 0; + public function hasNext() : Boolean { + var c : * = this.collection; + var i : int = this.index; + var result : Boolean = __has_next__(c,i); + this.collection = c; + this.index = i; + return result; + } + + public function next() : * { + var i : int = this.index; + var result : * = __forin__(this.collection,i); + this.index = i; + return result; + } + + static public function iterator(collection : *) : haxe.ds._WeakMap.NativePropertyIterator { + var result : haxe.ds._WeakMap.NativePropertyIterator = new haxe.ds._WeakMap.NativePropertyIterator(); + result.collection = collection; + return result; + } + + } +} diff --git a/bin/as3/src/haxe/ds/_WeakMap/NativeValueIterator.as b/bin/as3/src/haxe/ds/_WeakMap/NativeValueIterator.as new file mode 100644 index 0000000..f6865df --- /dev/null +++ b/bin/as3/src/haxe/ds/_WeakMap/NativeValueIterator.as @@ -0,0 +1,31 @@ +package haxe.ds._WeakMap { + public class NativeValueIterator { + public function NativeValueIterator() : void { + } + + public var collection : *; + protected var index : int = 0; + public function hasNext() : Boolean { + var c : * = this.collection; + var i : int = this.index; + var result : Boolean = __has_next__(c,i); + this.collection = c; + this.index = i; + return result; + } + + public function next() : * { + var i : int = this.index; + var result : * = __foreach__(this.collection,i); + this.index = i; + return result; + } + + static public function iterator(collection : *) : haxe.ds._WeakMap.NativeValueIterator { + var result : haxe.ds._WeakMap.NativeValueIterator = new haxe.ds._WeakMap.NativeValueIterator(); + result.collection = collection; + return result; + } + + } +} diff --git a/bin/as3/src/view/CanvasView.as b/bin/as3/src/view/CanvasView.as new file mode 100644 index 0000000..5b4a222 --- /dev/null +++ b/bin/as3/src/view/CanvasView.as @@ -0,0 +1,147 @@ +package view { + import flash.display.Sprite; + import at.dotpoint.math.vector.IVector2; + import at.dotpoint.math.geom.Rectangle; + import flash.display.Shape; + import flash.text.TextField; + import haxe.ds.ObjectMap; + import flash.Boot; + public class CanvasView extends flash.display.Sprite implements IPartitionDebugger{ + public function CanvasView() : void { if( !flash.Boot.skip_constructor ) { + super(); + this.countRectangle = 0; + this.countVertex = 0; + this.debugRectangle = new haxe.ds.ObjectMap(); + this.debugVertex = new haxe.ds.ObjectMap(); + this.canvas = new flash.display.Sprite(); + this.addChild(this.canvas); + }} + + public var debugVertex : haxe.ds.ObjectMap; + public var countVertex : int; + public var debugRectangle : haxe.ds.ObjectMap; + public var countRectangle : int; + public var canvas : flash.display.Sprite; + public function drawOutline(list : Array) : void { + var shape : flash.display.Shape = new flash.display.Shape(); + shape.graphics.lineStyle(8,Std._int(16777215 * Math.random()),0.35); + { + var _g1 : int = 0; + var _g : int = list.length + 1; + while(_g1 < _g) { + var v : int = _g1++; + var vertex : at.dotpoint.math.vector.IVector2 = list[v % list.length]; + if(v == 0) shape.graphics.moveTo(vertex.get_x(),vertex.get_y()); + else shape.graphics.lineTo(vertex.get_x(),vertex.get_y()); + var debug : flash.text.TextField = new flash.text.TextField(); + debug.text = this.getDebugVertex(vertex); + debug.x = vertex.get_x(); + debug.y = vertex.get_y(); + this.canvas.addChild(debug); + } + }; + this.canvas.addChild(shape); + var bounds : at.dotpoint.math.geom.Rectangle = this.calculateBoundings(list); + this.canvas.x -= bounds.get_x() - 15; + this.canvas.y -= bounds.get_y() - 25; + } + + public function drawPartition(area : at.dotpoint.math.geom.Rectangle) : void { + var color : int = Std._int(16777215 * Math.random()); + var shape : flash.display.Shape = new flash.display.Shape(); + shape.graphics.lineStyle(1,color); + shape.graphics.beginFill(color,0.1); + shape.graphics.drawRect(area.get_x(),area.get_y(),area.get_width(),area.get_height()); + shape.graphics.endFill(); + this.canvas.addChild(shape); + var debug : flash.text.TextField = new flash.text.TextField(); + debug.text = this.getDebugRectangle(area); + debug.x = area.get_x() + area.get_width() * 0.5; + debug.y = area.get_y() + area.get_height() * 0.5; + this.canvas.addChild(debug); + } + + public function drawSplitLine(a : at.dotpoint.math.vector.IVector2,b : at.dotpoint.math.vector.IVector2) : void { + var shape : flash.display.Shape = new flash.display.Shape(); + shape.graphics.lineStyle(4,0,0.65); + shape.graphics.moveTo(a.get_x(),a.get_y()); + shape.graphics.lineTo(b.get_x(),b.get_y()); + this.canvas.addChild(shape); + } + + public function drawSplitStart(a : at.dotpoint.math.vector.IVector2) : void { + var shape : flash.display.Shape = new flash.display.Shape(); + shape.graphics.lineStyle(2,16711680,0.85); + shape.graphics.drawCircle(a.get_x(),a.get_y(),4); + this.canvas.addChild(shape); + } + + public function drawSplitEnd(a : at.dotpoint.math.vector.IVector2) : void { + var shape : flash.display.Shape = new flash.display.Shape(); + shape.graphics.lineStyle(2,0,0.85); + shape.graphics.drawCircle(a.get_x(),a.get_y(),4); + this.canvas.addChild(shape); + var debug : flash.text.TextField = new flash.text.TextField(); + debug.text = this.getDebugVertex(a); + debug.x = a.get_x(); + debug.y = a.get_y(); + this.canvas.addChild(debug); + } + + public function getDebugVertex(vertex : at.dotpoint.math.vector.IVector2) : String { + if(!this.debugVertex.exists(vertex)) this.setDebugVertex(vertex); + return this.debugVertex.get(vertex); + } + + public function setDebugVertex(vertex : at.dotpoint.math.vector.IVector2) : void { + var index : int = this.countVertex++; + var value : String = "[" + index + "]"; + this.debugVertex.set(vertex,value); + } + + public function getDebugRectangle(rectangle : at.dotpoint.math.geom.Rectangle) : String { + if(!this.debugRectangle.exists(rectangle)) this.setDebugRectangle(rectangle); + return this.debugRectangle.get(rectangle); + } + + public function setDebugRectangle(rectangle : at.dotpoint.math.geom.Rectangle) : void { + var letters : Array = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q"]; + var index : int = this.countRectangle++; + var value : String = "[" + letters[index % letters.length] + "]"; + this.debugRectangle.set(rectangle,value); + } + + public function calculateBoundings(coordinates : Array) : at.dotpoint.math.geom.Rectangle { + var bounding : at.dotpoint.math.geom.Rectangle = new at.dotpoint.math.geom.Rectangle(); + { + var _g1 : int = 0; + var _g : int = coordinates.length; + while(_g1 < _g) { + var v : int = _g1++; + var x : Number = coordinates[v].get_x(); + var y : Number = coordinates[v].get_y(); + var nl : Number; + if(v == 0) nl = x; + else nl = Math.min(bounding.get_left(),x); + var nr : Number; + if(v == 0) nr = x; + else nr = Math.max(bounding.get_right(),x); + var nt : Number; + if(v == 0) nt = y; + else nt = Math.min(bounding.get_top(),y); + var nb : Number; + if(v == 0) nb = y; + else nb = Math.max(bounding.get_bottom(),y); + if(nl != bounding.get_left() || nr != bounding.get_right() || nt != bounding.get_top() || nb != bounding.get_bottom()) { + bounding.set_right(nr); + bounding.set_left(nl); + bounding.set_bottom(nb); + bounding.set_top(nt); + } + } + }; + return bounding; + } + + } +} diff --git a/bin/as3/src/view/ControllerView.as b/bin/as3/src/view/ControllerView.as new file mode 100644 index 0000000..f1cc430 --- /dev/null +++ b/bin/as3/src/view/ControllerView.as @@ -0,0 +1,131 @@ +package view { + import flash.events.Event; + import flash.text.TextFieldType; + import flash.display.Sprite; + import flash.text.TextFieldAutoSize; + import flash.display.DisplayObject; + import flash.text.TextField; + import flash.events.MouseEvent; + import flash.Boot; + public class ControllerView extends flash.display.Sprite { + public function ControllerView() : void { if( !flash.Boot.skip_constructor ) { + super(); + this.presets = new Array(); + this.presets.push("740 917 740 747 540 747 540 637 390 637 390 527 260 527 260 427 130 427 130 177 710 177 710 87 950 87 950 257 1090 257 1090 387 1220 387 1220 567 1340 567 1340 767 1080 767 1080 917"); + this.presets.push("68 139 223 139 223 216 382 216 382 45 791 45 791 329 923 329 923 564 858 564 858 505 665 505 665 410 562 410 562 670 730 670 730 740 296 740 296 450 68 450 68 139"); + this.presets.push("164 156 164 280 230 280 230 373 299 373 299 218 361 218 361 156 164 156"); + this.presets.push("132 112 468 112 468 429 352 429 352 287 249 287 249 529 132 529 132 112"); + this.presets.push("133 63 500 63 500 339 458 339 458 416 564 416 564 623 133 623 133 63"); + this.presets.push("584 143 584 592 756 592 756 379 860 379 860 143"); + this.createUI(); + }} + + public var presets : Array; + public var inputField : flash.text.TextField; + public var resultField : flash.text.TextField; + public function get input() : String { return get_input(); } + public function set input( __v : String ) : void { set_input(__v); } + protected var $input : String; + public function get output() : String { return get_output(); } + public function set output( __v : String ) : void { set_output(__v); } + protected var $output : String; + public function get_input() : String { + return this.inputField.text; + } + + public function set_input(value : String) : String { + return this.inputField.text = value; + } + + public function get_output() : String { + return this.resultField.text; + } + + public function set_output(value : String) : String { + return this.resultField.text = value; + } + + public function createUI() : void { + var input : flash.display.DisplayObject = this.createInputBox(); + var output : flash.display.DisplayObject = this.createOutputBox(); + output.y = input.y + input.height + 10; + this.addChild(input); + this.addChild(output); + this.selectInput(0); + } + + public function onCalculate(value : flash.events.Event) : void { + this.set_output("processing ... "); + this.dispatchEvent(new flash.events.Event("calculate")); + } + + public function onInputSelected(value : flash.events.Event) : void { + var item : flash.text.TextField = flash.text.TextField(value.target); + var index : int = this.presets.indexOf(item.text); + if(index < 0) this.set_output("error: preset not found"); + this.selectInput(index); + } + + public function selectInput(index : int) : void { + this.set_input(this.presets[index]); + this.set_output("press 'calculate' to process"); + } + + public function createInputBox() : flash.display.DisplayObject { + var presetList : flash.display.Sprite = this.createPresetList(); + var inputField : flash.display.Sprite = this.createInputField(); + inputField.y = presetList.height + 15; + var vbox : flash.display.Sprite = new flash.display.Sprite(); + vbox.addChild(presetList); + vbox.addChild(inputField); + return vbox; + } + + public function createPresetList() : flash.display.Sprite { + var presetList : flash.display.Sprite = new flash.display.Sprite(); + var y : Number = 0; + { + var _g : int = 0; + var _g1 : Array = this.presets; + while(_g < _g1.length) { + var preset : String = _g1[_g]; + ++_g; + var item : flash.text.TextField = new flash.text.TextField(); + item.autoSize = flash.text.TextFieldAutoSize.LEFT; + item.text = preset; + item.selectable = false; + item.addEventListener(flash.events.MouseEvent.CLICK,this.onInputSelected); + item.y = y; + presetList.addChild(item); + y += item.height; + } + }; + return presetList; + } + + public function createInputField() : flash.display.Sprite { + this.inputField = new flash.text.TextField(); + this.inputField.type = flash.text.TextFieldType.INPUT; + this.inputField.autoSize = flash.text.TextFieldAutoSize.LEFT; + this.inputField.border = true; + var calculate : flash.text.TextField = new flash.text.TextField(); + calculate.text = ">> calculate <<"; + calculate.border = true; + calculate.addEventListener(flash.events.MouseEvent.CLICK,this.onCalculate); + calculate.y = this.inputField.height + 5; + calculate.autoSize = flash.text.TextFieldAutoSize.LEFT; + calculate.selectable = false; + var hbox : flash.display.Sprite = new flash.display.Sprite(); + hbox.addChild(this.inputField); + hbox.addChild(calculate); + return hbox; + } + + public function createOutputBox() : flash.display.DisplayObject { + this.resultField = new flash.text.TextField(); + this.resultField.autoSize = flash.text.TextFieldAutoSize.LEFT; + return this.resultField; + } + + } +} diff --git a/bin/js/Partitioning.js b/bin/js/Partitioning.js index bbeb738..3070377 100644 --- a/bin/js/Partitioning.js +++ b/bin/js/Partitioning.js @@ -25,56 +25,17 @@ HxOverrides.remove = function(a,obj) { a.splice(i,1); return true; }; +HxOverrides.iter = function(a) { + return { cur : 0, arr : a, hasNext : function() { + return this.cur < this.arr.length; + }, next : function() { + return this.arr[this.cur++]; + }}; +}; var IPartitionCalculator = function() { }; IPartitionCalculator.__name__ = true; var IPolygonConverter = function() { }; IPolygonConverter.__name__ = true; -var List = function() { - this.length = 0; -}; -List.__name__ = true; -List.prototype = { - add: function(item) { - var x = [item]; - if(this.h == null) this.h = x; else this.q[1] = x; - this.q = x; - this.length++; - } - ,first: function() { - if(this.h == null) return null; else return this.h[0]; - } - ,remove: function(v) { - var prev = null; - var l = this.h; - while(l != null) { - if(l[0] == v) { - if(prev == null) this.h = l[1]; else prev[1] = l[1]; - if(this.q == l) this.q = prev; - this.length--; - return true; - } - prev = l; - l = l[1]; - } - return false; - } -}; -var _List = {}; -_List.ListIterator = function(head) { - this.head = head; - this.val = null; -}; -_List.ListIterator.__name__ = true; -_List.ListIterator.prototype = { - hasNext: function() { - return this.head != null; - } - ,next: function() { - this.val = this.head[0]; - this.head = this.head[1]; - return this.val; - } -}; var Main = function() { this.initialize(); }; @@ -112,6 +73,9 @@ Std.parseInt = function(x) { }; var at = {}; at.dotpoint = {}; +at.dotpoint.core = {}; +at.dotpoint.core.ICloneable = function() { }; +at.dotpoint.core.ICloneable.__name__ = true; at.dotpoint.math = {}; at.dotpoint.math.MathUtil = function() { }; at.dotpoint.math.MathUtil.__name__ = true; @@ -221,7 +185,7 @@ at.dotpoint.math.geom.Rectangle.prototype = { return this.size.clone(); } ,set_dimension: function(value) { - this.size.copyFrom(value); + this.size.set(value.get_x(),value.get_y()); return value; } ,isInside: function(x,y) { @@ -246,248 +210,6 @@ at.dotpoint.math.vector.IVector2.__name__ = true; at.dotpoint.math.vector.IVector3 = function() { }; at.dotpoint.math.vector.IVector3.__name__ = true; at.dotpoint.math.vector.IVector3.__interfaces__ = [at.dotpoint.math.vector.IVector2]; -at.dotpoint.math.vector.Matrix44 = function(m) { - if(m != null) this.set44(m); else this.toIdentity(); -}; -at.dotpoint.math.vector.Matrix44.__name__ = true; -at.dotpoint.math.vector.Matrix44.__interfaces__ = [at.dotpoint.math.vector.IMatrix44]; -at.dotpoint.math.vector.Matrix44.add = function(a,b,output) { - output.m11 = a.m11 + b.m11; - output.m12 = a.m12 + b.m12; - output.m13 = a.m13 + b.m13; - output.m14 = a.m14 + b.m14; - output.m21 = a.m21 + b.m21; - output.m22 = a.m22 + b.m22; - output.m23 = a.m23 + b.m23; - output.m24 = a.m24 + b.m24; - output.m31 = a.m31 + b.m31; - output.m32 = a.m32 + b.m32; - output.m33 = a.m33 + b.m33; - output.m34 = a.m34 + b.m34; - output.m41 = a.m41 + b.m41; - output.m42 = a.m42 + b.m42; - output.m43 = a.m43 + b.m43; - output.m44 = a.m44 + b.m44; - return output; -}; -at.dotpoint.math.vector.Matrix44.subtract = function(a,b,output) { - output.m11 = a.m11 - b.m11; - output.m12 = a.m12 - b.m12; - output.m13 = a.m13 - b.m13; - output.m14 = a.m14 - b.m14; - output.m21 = a.m21 - b.m21; - output.m22 = a.m22 - b.m22; - output.m23 = a.m23 - b.m23; - output.m24 = a.m24 - b.m24; - output.m31 = a.m31 - b.m31; - output.m32 = a.m32 - b.m32; - output.m33 = a.m33 - b.m33; - output.m34 = a.m34 - b.m34; - output.m41 = a.m41 - b.m41; - output.m42 = a.m42 - b.m42; - output.m43 = a.m43 - b.m43; - output.m44 = a.m44 - b.m44; - return output; -}; -at.dotpoint.math.vector.Matrix44.scale = function(a,scalar,output) { - output.m11 = a.m11 * scalar; - output.m12 = a.m12 * scalar; - output.m13 = a.m13 * scalar; - output.m14 = a.m14 * scalar; - output.m21 = a.m21 * scalar; - output.m22 = a.m22 * scalar; - output.m23 = a.m23 * scalar; - output.m24 = a.m24 * scalar; - output.m31 = a.m31 * scalar; - output.m32 = a.m32 * scalar; - output.m33 = a.m33 * scalar; - output.m34 = a.m34 * scalar; - output.m41 = a.m41 * scalar; - output.m42 = a.m42 * scalar; - output.m43 = a.m43 * scalar; - output.m44 = a.m44 * scalar; - return output; -}; -at.dotpoint.math.vector.Matrix44.multiply = function(a,b,output) { - var b11 = b.m11; - var b12 = b.m12; - var b13 = b.m13; - var b14 = b.m14; - var b21 = b.m21; - var b22 = b.m22; - var b23 = b.m23; - var b24 = b.m24; - var b31 = b.m31; - var b32 = b.m32; - var b33 = b.m33; - var b34 = b.m34; - var b41 = b.m41; - var b42 = b.m42; - var b43 = b.m43; - var b44 = b.m44; - var t1; - var t2; - var t3; - var t4; - t1 = a.m11; - t2 = a.m12; - t3 = a.m13; - t4 = a.m14; - output.m11 = t1 * b11 + t2 * b21 + t3 * b31 + t4 * b41; - output.m12 = t1 * b12 + t2 * b22 + t3 * b32 + t4 * b42; - output.m13 = t1 * b13 + t2 * b23 + t3 * b33 + t4 * b43; - output.m14 = t1 * b14 + t2 * b24 + t3 * b34 + t4 * b44; - t1 = a.m21; - t2 = a.m22; - t3 = a.m23; - t4 = a.m24; - output.m21 = t1 * b11 + t2 * b21 + t3 * b31 + t4 * b41; - output.m22 = t1 * b12 + t2 * b22 + t3 * b32 + t4 * b42; - output.m23 = t1 * b13 + t2 * b23 + t3 * b33 + t4 * b43; - output.m24 = t1 * b14 + t2 * b24 + t3 * b34 + t4 * b44; - t1 = a.m31; - t2 = a.m32; - t3 = a.m33; - t4 = a.m34; - output.m31 = t1 * b11 + t2 * b21 + t3 * b31 + t4 * b41; - output.m32 = t1 * b12 + t2 * b22 + t3 * b32 + t4 * b42; - output.m33 = t1 * b13 + t2 * b23 + t3 * b33 + t4 * b43; - output.m34 = t1 * b14 + t2 * b24 + t3 * b34 + t4 * b44; - t1 = a.m41; - t2 = a.m42; - t3 = a.m43; - t4 = a.m44; - output.m41 = t1 * b11 + t2 * b21 + t3 * b31 + t4 * b41; - output.m42 = t1 * b12 + t2 * b22 + t3 * b32 + t4 * b42; - output.m43 = t1 * b13 + t2 * b23 + t3 * b33 + t4 * b43; - output.m44 = t1 * b14 + t2 * b24 + t3 * b34 + t4 * b44; - return output; -}; -at.dotpoint.math.vector.Matrix44.isEqual = function(a,b) { - var success = true; - if(!at.dotpoint.math.MathUtil.isEqual(a.m11,b.m11) || !at.dotpoint.math.MathUtil.isEqual(a.m12,b.m12) || !at.dotpoint.math.MathUtil.isEqual(a.m13,b.m13) || !at.dotpoint.math.MathUtil.isEqual(a.m14,b.m14) || !at.dotpoint.math.MathUtil.isEqual(a.m21,b.m21) || !at.dotpoint.math.MathUtil.isEqual(a.m22,b.m22) || !at.dotpoint.math.MathUtil.isEqual(a.m23,b.m23) || !at.dotpoint.math.MathUtil.isEqual(a.m24,b.m24) || !at.dotpoint.math.MathUtil.isEqual(a.m31,b.m31) || !at.dotpoint.math.MathUtil.isEqual(a.m32,b.m32) || !at.dotpoint.math.MathUtil.isEqual(a.m33,b.m33) || !at.dotpoint.math.MathUtil.isEqual(a.m34,b.m34) || !at.dotpoint.math.MathUtil.isEqual(a.m41,b.m41) || !at.dotpoint.math.MathUtil.isEqual(a.m42,b.m42) || !at.dotpoint.math.MathUtil.isEqual(a.m43,b.m43) || !at.dotpoint.math.MathUtil.isEqual(a.m44,b.m44)) success = false; - return success; -}; -at.dotpoint.math.vector.Matrix44.prototype = { - clone: function() { - return new at.dotpoint.math.vector.Matrix44(this); - } - ,set44: function(m) { - this.m11 = m.m11; - this.m12 = m.m12; - this.m13 = m.m13; - this.m14 = m.m14; - this.m21 = m.m21; - this.m22 = m.m22; - this.m23 = m.m23; - this.m24 = m.m24; - this.m31 = m.m31; - this.m32 = m.m32; - this.m33 = m.m33; - this.m34 = m.m34; - this.m41 = m.m41; - this.m42 = m.m42; - this.m43 = m.m43; - this.m44 = m.m44; - } - ,set33: function(m) { - this.m11 = m.m11; - this.m12 = m.m12; - this.m13 = m.m13; - this.m14 = 0; - this.m21 = m.m21; - this.m22 = m.m22; - this.m23 = m.m23; - this.m24 = 0; - this.m31 = m.m31; - this.m32 = m.m32; - this.m33 = m.m33; - this.m34 = 0; - this.m41 = 0; - this.m42 = 0; - this.m43 = 0; - this.m44 = 1; - } - ,toIdentity: function() { - this.m11 = 1; - this.m12 = 0; - this.m13 = 0; - this.m14 = 0; - this.m21 = 0; - this.m22 = 1; - this.m23 = 0; - this.m24 = 0; - this.m31 = 0; - this.m32 = 0; - this.m33 = 1; - this.m34 = 0; - this.m41 = 0; - this.m42 = 0; - this.m43 = 0; - this.m44 = 1; - } - ,transpose: function() { - var t; - t = this.m21; - this.m21 = this.m12; - this.m12 = t; - t = this.m31; - this.m31 = this.m13; - this.m13 = t; - t = this.m32; - this.m32 = this.m23; - this.m23 = t; - t = this.m41; - this.m41 = this.m14; - this.m14 = t; - t = this.m42; - this.m42 = this.m24; - this.m24 = t; - t = this.m43; - this.m43 = this.m34; - this.m34 = t; - } - ,determinant: function() { - return (this.m11 * this.m22 - this.m21 * this.m12) * (this.m33 * this.m44 - this.m43 * this.m34) - (this.m11 * this.m32 - this.m31 * this.m12) * (this.m23 * this.m44 - this.m43 * this.m24) + (this.m11 * this.m42 - this.m41 * this.m12) * (this.m23 * this.m34 - this.m33 * this.m24) + (this.m21 * this.m32 - this.m31 * this.m22) * (this.m13 * this.m44 - this.m43 * this.m14) - (this.m21 * this.m42 - this.m41 * this.m22) * (this.m13 * this.m34 - this.m33 * this.m14) + (this.m31 * this.m42 - this.m41 * this.m32) * (this.m13 * this.m24 - this.m23 * this.m14); - } - ,inverse: function() { - var d = this.determinant(); - if(Math.abs(d) < 1e-08) return; - d = 1 / d; - var m11 = this.m11; - var m21 = this.m21; - var m31 = this.m31; - var m41 = this.m41; - var m12 = this.m12; - var m22 = this.m22; - var m32 = this.m32; - var m42 = this.m42; - var m13 = this.m13; - var m23 = this.m23; - var m33 = this.m33; - var m43 = this.m43; - var m14 = this.m14; - var m24 = this.m24; - var m34 = this.m34; - var m44 = this.m44; - this.m11 = d * (m22 * (m33 * m44 - m43 * m34) - m32 * (m23 * m44 - m43 * m24) + m42 * (m23 * m34 - m33 * m24)); - this.m12 = -d * (m12 * (m33 * m44 - m43 * m34) - m32 * (m13 * m44 - m43 * m14) + m42 * (m13 * m34 - m33 * m14)); - this.m13 = d * (m12 * (m23 * m44 - m43 * m24) - m22 * (m13 * m44 - m43 * m14) + m42 * (m13 * m24 - m23 * m14)); - this.m14 = -d * (m12 * (m23 * m34 - m33 * m24) - m22 * (m13 * m34 - m33 * m14) + m32 * (m13 * m24 - m23 * m14)); - this.m21 = -d * (m21 * (m33 * m44 - m43 * m34) - m31 * (m23 * m44 - m43 * m24) + m41 * (m23 * m34 - m33 * m24)); - this.m22 = d * (m11 * (m33 * m44 - m43 * m34) - m31 * (m13 * m44 - m43 * m14) + m41 * (m13 * m34 - m33 * m14)); - this.m23 = -d * (m11 * (m23 * m44 - m43 * m24) - m21 * (m13 * m44 - m43 * m14) + m41 * (m13 * m24 - m23 * m14)); - this.m24 = d * (m11 * (m23 * m34 - m33 * m24) - m21 * (m13 * m34 - m33 * m14) + m31 * (m13 * m24 - m23 * m14)); - this.m31 = d * (m21 * (m32 * m44 - m42 * m34) - m31 * (m22 * m44 - m42 * m24) + m41 * (m22 * m34 - m32 * m24)); - this.m32 = -d * (m11 * (m32 * m44 - m42 * m34) - m31 * (m12 * m44 - m42 * m14) + m41 * (m12 * m34 - m32 * m14)); - this.m33 = d * (m11 * (m22 * m44 - m42 * m24) - m21 * (m12 * m44 - m42 * m14) + m41 * (m12 * m24 - m22 * m14)); - this.m34 = -d * (m11 * (m22 * m34 - m32 * m24) - m21 * (m12 * m34 - m32 * m14) + m31 * (m12 * m24 - m22 * m14)); - this.m41 = -d * (m21 * (m32 * m43 - m42 * m33) - m31 * (m22 * m43 - m42 * m23) + m41 * (m22 * m33 - m32 * m23)); - this.m42 = d * (m11 * (m32 * m43 - m42 * m33) - m31 * (m12 * m43 - m42 * m13) + m41 * (m12 * m33 - m32 * m13)); - this.m43 = -d * (m11 * (m22 * m43 - m42 * m23) - m21 * (m12 * m43 - m42 * m13) + m41 * (m12 * m23 - m22 * m13)); - this.m44 = d * (m11 * (m22 * m33 - m32 * m23) - m21 * (m12 * m33 - m32 * m13) + m31 * (m12 * m23 - m22 * m13)); - } -}; at.dotpoint.math.vector.Vector2 = function(x,y) { if(y == null) y = 0; if(x == null) x = 0; @@ -495,7 +217,7 @@ at.dotpoint.math.vector.Vector2 = function(x,y) { this.set_y(y); }; at.dotpoint.math.vector.Vector2.__name__ = true; -at.dotpoint.math.vector.Vector2.__interfaces__ = [at.dotpoint.math.vector.IVector2]; +at.dotpoint.math.vector.Vector2.__interfaces__ = [at.dotpoint.core.ICloneable,at.dotpoint.math.vector.IVector2]; at.dotpoint.math.vector.Vector2.add = function(a,b,output) { if(output == null) output = new at.dotpoint.math.vector.Vector2(); output.set_x(a.get_x() + b.get_x()); @@ -520,8 +242,11 @@ at.dotpoint.math.vector.Vector2.isEqual = function(a,b) { return true; }; at.dotpoint.math.vector.Vector2.prototype = { - clone: function() { - return new at.dotpoint.math.vector.Vector2(this.get_x(),this.get_y()); + clone: function(output) { + if(output != null) output = output; else output = new at.dotpoint.math.vector.Vector2(); + output.set_x(this.get_x()); + output.set_y(this.get_y()); + return output; } ,get_x: function() { return this.x; @@ -539,10 +264,6 @@ at.dotpoint.math.vector.Vector2.prototype = { this.set_x(x); this.set_y(y); } - ,copyFrom: function(vector) { - this.set_x(vector.get_x()); - this.set_y(vector.get_y()); - } ,normalize: function() { var k = 1. / this.length(); var _g = this; @@ -551,11 +272,39 @@ at.dotpoint.math.vector.Vector2.prototype = { _g1.set_y(_g1.get_y() * k); } ,length: function() { - return Math.sqrt(this.lengthSq()); + return Math.sqrt(this.get_x() * this.get_x() + this.get_y() * this.get_y()); } ,lengthSq: function() { return this.get_x() * this.get_x() + this.get_y() * this.get_y(); } + ,toArray: function(output) { + if(output != null) output = []; + output[0] = this.get_x(); + output[1] = this.get_y(); + return output; + } + ,getIndex: function(index) { + switch(index) { + case 0: + return this.get_x(); + case 1: + return this.get_y(); + default: + throw "out of bounds"; + } + } + ,setIndex: function(index,value) { + switch(index) { + case 0: + this.set_x(value); + break; + case 1: + this.set_y(value); + break; + default: + throw "out of bounds"; + } + } ,toString: function() { return "[Vector2;" + this.get_x() + ", " + this.get_y() + "]"; } @@ -567,67 +316,61 @@ at.dotpoint.math.vector.Vector3 = function(x,y,z,w) { if(x == null) x = 0; this.set_x(x); this.set_y(y); - this.z = z; - this.w = w; + this.set_z(z); + this.set_w(w); }; at.dotpoint.math.vector.Vector3.__name__ = true; -at.dotpoint.math.vector.Vector3.__interfaces__ = [at.dotpoint.math.vector.IVector3]; +at.dotpoint.math.vector.Vector3.__interfaces__ = [at.dotpoint.core.ICloneable,at.dotpoint.math.vector.IVector3]; at.dotpoint.math.vector.Vector3.add = function(a,b,output) { if(output == null) output = new at.dotpoint.math.vector.Vector3(); output.set_x(a.get_x() + b.get_x()); output.set_y(a.get_y() + b.get_y()); - output.z = a.z + b.z; + output.set_z(a.get_z() + b.get_z()); return output; }; at.dotpoint.math.vector.Vector3.subtract = function(a,b,output) { if(output == null) output = new at.dotpoint.math.vector.Vector3(); output.set_x(a.get_x() - b.get_x()); output.set_y(a.get_y() - b.get_y()); - output.z = a.z - b.z; + output.set_z(a.get_z() - b.get_z()); return output; }; at.dotpoint.math.vector.Vector3.scale = function(a,scalar,output) { if(output == null) output = new at.dotpoint.math.vector.Vector3(); output.set_x(a.get_x() * scalar); output.set_y(a.get_y() * scalar); - output.z = a.z * scalar; + output.set_z(a.get_z() * scalar); return output; }; at.dotpoint.math.vector.Vector3.cross = function(a,b,output) { if(output == null) output = new at.dotpoint.math.vector.Vector3(); - output.set_x(a.get_y() * b.z - a.z * b.get_y()); - output.set_y(a.z * b.get_x() - a.get_x() * b.z); - output.z = a.get_x() * b.get_y() - a.get_y() * b.get_x(); + output.set_x(a.get_y() * b.get_z() - a.get_z() * b.get_y()); + output.set_y(a.get_z() * b.get_x() - a.get_x() * b.get_z()); + output.set_z(a.get_x() * b.get_y() - a.get_y() * b.get_x()); return output; }; at.dotpoint.math.vector.Vector3.dot = function(a,b) { - return a.get_x() * b.get_x() + a.get_y() * b.get_y() + a.z * b.z; + return a.get_x() * b.get_x() + a.get_y() * b.get_y() + a.get_z() * b.get_z(); }; at.dotpoint.math.vector.Vector3.multiplyMatrix = function(a,b,output) { if(output == null) output = new at.dotpoint.math.vector.Vector3(); var x = a.get_x(); var y = a.get_y(); - var z = a.z; - var w = a.w; + var z = a.get_z(); + var w = a.get_w(); output.set_x(b.m11 * x + b.m12 * y + b.m13 * z + b.m14 * w); output.set_y(b.m21 * x + b.m22 * y + b.m23 * z + b.m24 * w); - output.z = b.m31 * x + b.m32 * y + b.m33 * z + b.m34 * w; - output.w = b.m41 * x + b.m42 * y + b.m43 * z + b.m44 * w; + output.set_z(b.m31 * x + b.m32 * y + b.m33 * z + b.m34 * w); + output.set_w(b.m41 * x + b.m42 * y + b.m43 * z + b.m44 * w); return output; }; -at.dotpoint.math.vector.Vector3.isEqual = function(a,b) { - if(!at.dotpoint.math.MathUtil.isEqual(a.get_x(),b.get_x())) return false; - if(!at.dotpoint.math.MathUtil.isEqual(a.get_y(),b.get_y())) return false; - if(!at.dotpoint.math.MathUtil.isEqual(a.z,b.z)) return false; - return true; -}; at.dotpoint.math.vector.Vector3.project = function(a,b,output) { if(output == null) output = new at.dotpoint.math.vector.Vector3(); - var l = a.lengthSq(); + var l = a.get_x() * a.get_x() + a.get_y() * a.get_y() + a.get_z() * a.get_z(); if(l == 0) throw "undefined result"; var d = at.dotpoint.math.vector.Vector3.dot(a,b); - var d_div = d / l; - return at.dotpoint.math.vector.Vector3.scale(a,d_div,output); + var div = d / l; + return at.dotpoint.math.vector.Vector3.scale(a,div,output); }; at.dotpoint.math.vector.Vector3.orthoNormalize = function(vectors) { var _g1 = 0; @@ -644,9 +387,20 @@ at.dotpoint.math.vector.Vector3.orthoNormalize = function(vectors) { at.dotpoint.math.vector.Vector3.subtract(vectors[i],sum,vectors[i]).normalize(); } }; +at.dotpoint.math.vector.Vector3.isEqual = function(a,b) { + if(!at.dotpoint.math.MathUtil.isEqual(a.get_x(),b.get_x())) return false; + if(!at.dotpoint.math.MathUtil.isEqual(a.get_y(),b.get_y())) return false; + if(!at.dotpoint.math.MathUtil.isEqual(a.get_z(),b.get_z())) return false; + return true; +}; at.dotpoint.math.vector.Vector3.prototype = { - clone: function() { - return new at.dotpoint.math.vector.Vector3(this.get_x(),this.get_y(),this.z,this.w); + clone: function(output) { + if(output == null) output = new at.dotpoint.math.vector.Vector3(); + output.set_x(this.get_x()); + output.set_y(this.get_y()); + output.set_z(this.get_z()); + output.set_w(this.get_w()); + return output; } ,get_x: function() { return this.x; @@ -660,6 +414,24 @@ at.dotpoint.math.vector.Vector3.prototype = { ,set_y: function(value) { return this.y = value; } + ,get_z: function() { + return this.z; + } + ,set_z: function(value) { + return this.z = value; + } + ,get_w: function() { + return this.w; + } + ,set_w: function(value) { + return this.w = value; + } + ,set: function(x,y,z,w) { + this.set_x(x); + this.set_y(y); + this.set_z(z); + if(w != null) this.set_w(w); + } ,normalize: function() { var l = this.length(); if(l == 0) return; @@ -668,21 +440,22 @@ at.dotpoint.math.vector.Vector3.prototype = { _g.set_x(_g.get_x() * k); var _g1 = this; _g1.set_y(_g1.get_y() * k); - this.z *= k; + var _g2 = this; + _g2.set_z(_g2.get_z() * k); } ,length: function() { - return Math.sqrt(this.lengthSq()); + return Math.sqrt(this.get_x() * this.get_x() + this.get_y() * this.get_y() + this.get_z() * this.get_z()); } ,lengthSq: function() { - return this.get_x() * this.get_x() + this.get_y() * this.get_y() + this.z * this.z; + return this.get_x() * this.get_x() + this.get_y() * this.get_y() + this.get_z() * this.get_z(); } - ,toArray: function(w) { + ,toArray: function(w,output) { if(w == null) w = false; - var output = []; + if(output != null) output = []; output[0] = this.get_x(); output[1] = this.get_y(); - output[2] = this.z; - if(w) output[3] = this.w; + output[2] = this.get_z(); + if(w) output[3] = this.get_w(); return output; } ,getIndex: function(index) { @@ -692,9 +465,9 @@ at.dotpoint.math.vector.Vector3.prototype = { case 1: return this.get_y(); case 2: - return this.z; + return this.get_z(); case 3: - return this.w; + return this.get_w(); default: throw "out of bounds"; } @@ -708,23 +481,17 @@ at.dotpoint.math.vector.Vector3.prototype = { this.set_y(value); break; case 2: - this.z = value; + this.set_z(value); break; case 3: - this.w = value; + this.set_w(value); break; default: throw "out of bounds"; } } - ,set: function(x,y,z,w) { - this.set_x(x); - this.set_y(y); - this.z = z; - if(w != null) this.w = w; - } ,toString: function() { - return "[Vector3;" + this.get_x() + ", " + this.get_y() + ", " + this.z + ", " + this.w + "]"; + return "[Vector3;" + this.get_x() + ", " + this.get_y() + ", " + this.get_z() + ", " + this.get_w() + "]"; } }; var calculator = {}; @@ -785,6 +552,7 @@ calculator.EdgeContainer.prototype = { } ,insertSplit: function(start,a,b) { var split = new calculator.Vertex(null); + split.index = Math.min(a.index,b.index) + Math.min(1,Math.abs(b.index - a.index)) * 0.5; if(this.isVertical(a,b)) { split.set_x(a.get_x()); split.set_y(start.get_y()); @@ -796,14 +564,14 @@ calculator.EdgeContainer.prototype = { this.insert(split,start); this.insert(split,a); this.insert(split,b); - a.neighbors.remove(b); - b.neighbors.remove(a); - a.neighbors.add(split); - b.neighbors.add(split); - split.neighbors.add(start); - split.neighbors.add(a); - split.neighbors.add(b); - start.neighbors.add(split); + a.removeNeighbor(b); + b.removeNeighbor(a); + a.insertNeighbor(split); + b.insertNeighbor(split); + split.insertNeighbor(start); + split.insertNeighbor(a); + split.insertNeighbor(b); + start.insertNeighbor(split); return split; } ,getIndex: function(value,isVertical) { @@ -882,8 +650,8 @@ calculator.TraversalSplitter.prototype = { while(_g1 < _g) { var v = _g1++; var triangle = this.getTriangle(v,true); - triangle.p2.neighbors.add(triangle.p1); - triangle.p2.neighbors.add(triangle.p3); + triangle.p2.insertNeighbor(triangle.p1); + triangle.p2.insertNeighbor(triangle.p3); this.edges.insert(triangle.p1,triangle.p2); } null; @@ -926,17 +694,13 @@ calculator.TraversalSplitter.prototype = { var iterator = null; var possible = null; if(previous == null) { - iterator = new _List.ListIterator(current.neighbors.h); - previous = current.neighbors.first(); + iterator = HxOverrides.iter(current.neighbors); + previous = current.neighbors[0]; } while(previous != null) { - var _g_head = current.neighbors.h; - var _g_val = null; - while(_g_head != null) { - var neighbor; - _g_val = _g_head[0]; - _g_head = _g_head[1]; - neighbor = _g_val; + var $it0 = HxOverrides.iter(current.neighbors); + while( $it0.hasNext() ) { + var neighbor = $it0.next(); if(neighbor == previous) continue; var triangle = calculator.VertexTriangle.instance; triangle.p1 = previous; @@ -974,7 +738,7 @@ calculator.TraversalSplitter.prototype = { return triangle; } ,getNormal: function(current) { - var previous = current.neighbors.first(); + var previous = current.neighbors[0]; var delta = new at.dotpoint.math.vector.Vector3(); delta.set_x(current.get_x() - previous.get_x()); delta.set_y(current.get_y() - previous.get_y()); @@ -1007,7 +771,7 @@ calculator.TraversalSplitter.prototype = { calculator.Vertex = function(coordinate) { if(coordinate == null) coordinate = new at.dotpoint.math.vector.Vector2(); this.coordinate = coordinate; - this.neighbors = new List(); + this.neighbors = []; }; calculator.Vertex.__name__ = true; calculator.Vertex.__interfaces__ = [at.dotpoint.math.vector.IVector2]; @@ -1024,6 +788,25 @@ calculator.Vertex.prototype = { ,set_y: function(value) { return this.coordinate.set_y(value); } + ,normalize: function() { + this.coordinate.normalize(); + } + ,length: function() { + return this.coordinate.length(); + } + ,insertNeighbor: function(vertex) { + this.neighbors.push(vertex); + this.neighbors.sort($bind(this,this.sortNeighbors)); + } + ,removeNeighbor: function(vertex) { + return HxOverrides.remove(this.neighbors,vertex); + } + ,sortNeighbors: function(a,b) { + return Math.round(a.index - b.index); + } + ,toString: function() { + return "[" + this.index + "]"; + } }; calculator.VertexTriangle = function() { }; @@ -1037,7 +820,8 @@ calculator.VertexTriangle.prototype = { var v3 = new at.dotpoint.math.vector.Vector3(this.p3.coordinate.get_x(),this.p3.coordinate.get_y(),0); var sub1 = at.dotpoint.math.vector.Vector3.subtract(v2,v1,new at.dotpoint.math.vector.Vector3()); var sub2 = at.dotpoint.math.vector.Vector3.subtract(v3,v1,new at.dotpoint.math.vector.Vector3()); - if(includeZero) return at.dotpoint.math.vector.Vector3.cross(sub1,sub2).z >= 0; else return at.dotpoint.math.vector.Vector3.cross(sub1,sub2).z > 0; + var cross = at.dotpoint.math.vector.Vector3.cross(sub1,sub2); + if(includeZero) return cross.get_z() >= 0; else return cross.get_z() > 0; } }; var converter = {}; @@ -1135,6 +919,8 @@ js.Boot.__string_rec = function(o,s) { return String(o); } }; +var $_, $fid = 0; +function $bind(o,m) { if( m == null ) return null; if( m.__id__ == null ) m.__id__ = $fid++; var f; if( o.hx__closures__ == null ) o.hx__closures__ = {}; else f = o.hx__closures__[m.__id__]; if( f == null ) { f = function(){ return f.method.apply(f.scope, arguments); }; f.scope = o; f.method = m; o.hx__closures__[m.__id__] = f; } return f; } if(Array.prototype.indexOf) HxOverrides.indexOf = function(a,o,i) { return Array.prototype.indexOf.call(a,o,i); }; diff --git a/bin/php/lib/Math.class.php b/bin/php/lib/Math.class.php index bcf5eec..9209c12 100644 --- a/bin/php/lib/Math.class.php +++ b/bin/php/lib/Math.class.php @@ -29,6 +29,9 @@ static function atan2($y, $x) { static function sqrt($v) { return sqrt($v); } + static function round($v) { + return (int) floor($v + 0.5); + } static function isNaN($f) { return is_nan($f); } diff --git a/bin/php/lib/at/dotpoint/core/ICloneable.interface.php b/bin/php/lib/at/dotpoint/core/ICloneable.interface.php new file mode 100644 index 0000000..0dcf3ea --- /dev/null +++ b/bin/php/lib/at/dotpoint/core/ICloneable.interface.php @@ -0,0 +1,5 @@ +position->hclone(); + return $this->position->hclone(null); } public function set_topLeft($value) { { @@ -184,10 +184,10 @@ public function set_bottomRight($value) { return $value; } public function get_dimension() { - return $this->size->hclone(); + return $this->size->hclone(null); } public function set_dimension($value) { - $this->size->copyFrom($value); + $this->size->set($value->get_x(), $value->get_y()); return $value; } public function isInside($x, $y) { diff --git a/bin/php/lib/at/dotpoint/math/vector/IVector2.interface.php b/bin/php/lib/at/dotpoint/math/vector/IVector2.interface.php index 2dcabdf..7bc178c 100644 --- a/bin/php/lib/at/dotpoint/math/vector/IVector2.interface.php +++ b/bin/php/lib/at/dotpoint/math/vector/IVector2.interface.php @@ -5,4 +5,6 @@ function get_x(); function set_x($value); function get_y(); function set_y($value); + function normalize(); + function length(); } diff --git a/bin/php/lib/at/dotpoint/math/vector/IVector3.interface.php b/bin/php/lib/at/dotpoint/math/vector/IVector3.interface.php index 9c7404d..907c3f4 100644 --- a/bin/php/lib/at/dotpoint/math/vector/IVector3.interface.php +++ b/bin/php/lib/at/dotpoint/math/vector/IVector3.interface.php @@ -1,6 +1,8 @@ get_x(), $this->get_y()); + public function hclone($output = null) { + if($output !== null) { + $output = $output; + } else { + $output = new at_dotpoint_math_vector_Vector2(null, null); + } + $output->set_x($this->get_x()); + $output->set_y($this->get_y()); + return $output; } public function get_x() { return $this->x; @@ -33,10 +40,6 @@ public function set($x, $y) { $this->set_x($x); $this->set_y($y); } - public function copyFrom($vector) { - $this->set_x($vector->get_x()); - $this->set_y($vector->get_y()); - } public function normalize() { $k = 1. / $this->length(); { @@ -49,11 +52,45 @@ public function normalize() { } } public function length() { - return Math::sqrt($this->lengthSq()); + return Math::sqrt($this->get_x() * $this->get_x() + $this->get_y() * $this->get_y()); } public function lengthSq() { return $this->get_x() * $this->get_x() + $this->get_y() * $this->get_y(); } + public function toArray($output = null) { + if($output !== null) { + $output = new _hx_array(array()); + } + $output[0] = $this->get_x(); + $output[1] = $this->get_y(); + return $output; + } + public function getIndex($index) { + switch($index) { + case 0:{ + return $this->get_x(); + }break; + case 1:{ + return $this->get_y(); + }break; + default:{ + throw new HException("out of bounds"); + }break; + } + } + public function setIndex($index, $value) { + switch($index) { + case 0:{ + $this->set_x($value); + }break; + case 1:{ + $this->set_y($value); + }break; + default:{ + throw new HException("out of bounds"); + }break; + } + } public function toString() { return "[Vector2;" . _hx_string_rec($this->get_x(), "") . ", " . _hx_string_rec($this->get_y(), "") . "]"; } diff --git a/bin/php/lib/at/dotpoint/math/vector/Vector3.class.php b/bin/php/lib/at/dotpoint/math/vector/Vector3.class.php index 9b9079f..b559f7b 100644 --- a/bin/php/lib/at/dotpoint/math/vector/Vector3.class.php +++ b/bin/php/lib/at/dotpoint/math/vector/Vector3.class.php @@ -1,6 +1,6 @@ set_x($x); $this->set_y($y); - $this->z = $z; - $this->w = $w; + $this->set_z($z); + $this->set_w($w); }} public $x; public $y; public $z; public $w; - public function hclone() { - return new at_dotpoint_math_vector_Vector3($this->get_x(), $this->get_y(), $this->z, $this->w); + public function hclone($output = null) { + if($output === null) { + $output = new at_dotpoint_math_vector_Vector3(null, null, null, null); + } + $output->set_x($this->get_x()); + $output->set_y($this->get_y()); + $output->set_z($this->get_z()); + $output->set_w($this->get_w()); + return $output; } public function get_x() { return $this->x; @@ -39,6 +46,26 @@ public function get_y() { public function set_y($value) { return $this->y = $value; } + public function get_z() { + return $this->z; + } + public function set_z($value) { + return $this->z = $value; + } + public function get_w() { + return $this->w; + } + public function set_w($value) { + return $this->w = $value; + } + public function set($x, $y, $z, $w = null) { + $this->set_x($x); + $this->set_y($y); + $this->set_z($z); + if($w !== null) { + $this->set_w($w); + } + } public function normalize() { $l = $this->length(); if(_hx_equal($l, 0)) { @@ -53,24 +80,29 @@ public function normalize() { $_g1 = $this; $_g1->set_y($_g1->get_y() * $k); } - $this->z *= $k; + { + $_g2 = $this; + $_g2->set_z($_g2->get_z() * $k); + } } public function length() { - return Math::sqrt($this->lengthSq()); + return Math::sqrt($this->get_x() * $this->get_x() + $this->get_y() * $this->get_y() + $this->get_z() * $this->get_z()); } public function lengthSq() { - return $this->get_x() * $this->get_x() + $this->get_y() * $this->get_y() + $this->z * $this->z; + return $this->get_x() * $this->get_x() + $this->get_y() * $this->get_y() + $this->get_z() * $this->get_z(); } - public function toArray($w = null) { + public function toArray($w = null, $output = null) { if($w === null) { $w = false; } - $output = new _hx_array(array()); + if($output !== null) { + $output = new _hx_array(array()); + } $output[0] = $this->get_x(); $output[1] = $this->get_y(); - $output[2] = $this->z; + $output[2] = $this->get_z(); if($w) { - $output[3] = $this->w; + $output[3] = $this->get_w(); } return $output; } @@ -83,10 +115,10 @@ public function getIndex($index) { return $this->get_y(); }break; case 2:{ - return $this->z; + return $this->get_z(); }break; case 3:{ - return $this->w; + return $this->get_w(); }break; default:{ throw new HException("out of bounds"); @@ -102,26 +134,18 @@ public function setIndex($index, $value) { $this->set_y($value); }break; case 2:{ - $this->z = $value; + $this->set_z($value); }break; case 3:{ - $this->w = $value; + $this->set_w($value); }break; default:{ throw new HException("out of bounds"); }break; } } - public function set($x, $y, $z, $w = null) { - $this->set_x($x); - $this->set_y($y); - $this->z = $z; - if($w !== null) { - $this->w = $w; - } - } public function toString() { - return "[Vector3;" . _hx_string_rec($this->get_x(), "") . ", " . _hx_string_rec($this->get_y(), "") . ", " . _hx_string_rec($this->z, "") . ", " . _hx_string_rec($this->w, "") . "]"; + return "[Vector3;" . _hx_string_rec($this->get_x(), "") . ", " . _hx_string_rec($this->get_y(), "") . ", " . _hx_string_rec($this->get_z(), "") . ", " . _hx_string_rec($this->get_w(), "") . "]"; } public function __call($m, $a) { if(isset($this->$m) && is_callable($this->$m)) @@ -139,7 +163,7 @@ static function add($a, $b, $output = null) { } $output->set_x($a->get_x() + $b->get_x()); $output->set_y($a->get_y() + $b->get_y()); - $output->z = $a->z + $b->z; + $output->set_z($a->get_z() + $b->get_z()); return $output; } static function subtract($a, $b, $output = null) { @@ -148,7 +172,7 @@ static function subtract($a, $b, $output = null) { } $output->set_x($a->get_x() - $b->get_x()); $output->set_y($a->get_y() - $b->get_y()); - $output->z = $a->z - $b->z; + $output->set_z($a->get_z() - $b->get_z()); return $output; } static function scale($a, $scalar, $output = null) { @@ -157,20 +181,20 @@ static function scale($a, $scalar, $output = null) { } $output->set_x($a->get_x() * $scalar); $output->set_y($a->get_y() * $scalar); - $output->z = $a->z * $scalar; + $output->set_z($a->get_z() * $scalar); return $output; } static function cross($a, $b, $output = null) { if($output === null) { $output = new at_dotpoint_math_vector_Vector3(null, null, null, null); } - $output->set_x($a->get_y() * $b->z - $a->z * $b->get_y()); - $output->set_y($a->z * $b->get_x() - $a->get_x() * $b->z); - $output->z = $a->get_x() * $b->get_y() - $a->get_y() * $b->get_x(); + $output->set_x($a->get_y() * $b->get_z() - $a->get_z() * $b->get_y()); + $output->set_y($a->get_z() * $b->get_x() - $a->get_x() * $b->get_z()); + $output->set_z($a->get_x() * $b->get_y() - $a->get_y() * $b->get_x()); return $output; } static function dot($a, $b) { - return $a->get_x() * $b->get_x() + $a->get_y() * $b->get_y() + $a->z * $b->z; + return $a->get_x() * $b->get_x() + $a->get_y() * $b->get_y() + $a->get_z() * $b->get_z(); } static function multiplyMatrix($a, $b, $output = null) { if($output === null) { @@ -178,37 +202,25 @@ static function multiplyMatrix($a, $b, $output = null) { } $x = $a->get_x(); $y = $a->get_y(); - $z = $a->z; - $w = $a->w; + $z = $a->get_z(); + $w = $a->get_w(); $output->set_x($b->m11 * $x + $b->m12 * $y + $b->m13 * $z + $b->m14 * $w); $output->set_y($b->m21 * $x + $b->m22 * $y + $b->m23 * $z + $b->m24 * $w); - $output->z = $b->m31 * $x + $b->m32 * $y + $b->m33 * $z + $b->m34 * $w; - $output->w = $b->m41 * $x + $b->m42 * $y + $b->m43 * $z + $b->m44 * $w; + $output->set_z($b->m31 * $x + $b->m32 * $y + $b->m33 * $z + $b->m34 * $w); + $output->set_w($b->m41 * $x + $b->m42 * $y + $b->m43 * $z + $b->m44 * $w); return $output; } - static function isEqual($a, $b) { - if(!at_dotpoint_math_vector_Vector3_0($a, $b)) { - return false; - } - if(!at_dotpoint_math_vector_Vector3_1($a, $b)) { - return false; - } - if(!at_dotpoint_math_vector_Vector3_2($a, $b)) { - return false; - } - return true; - } static function project($a, $b, $output = null) { if($output === null) { $output = new at_dotpoint_math_vector_Vector3(null, null, null, null); } - $l = $a->lengthSq(); + $l = $a->get_x() * $a->get_x() + $a->get_y() * $a->get_y() + $a->get_z() * $a->get_z(); if(_hx_equal($l, 0)) { throw new HException("undefined result"); } $d = at_dotpoint_math_vector_Vector3::dot($a, $b); - $d_div = $d / $l; - return at_dotpoint_math_vector_Vector3::scale($a, $d_div, $output); + $div = $d / $l; + return at_dotpoint_math_vector_Vector3::scale($a, $div, $output); } static function orthoNormalize($vectors) { $_g1 = 0; @@ -230,7 +242,19 @@ static function orthoNormalize($vectors) { unset($sum,$i); } } - static $__properties__ = array("set_y" => "set_y","get_y" => "get_y","set_x" => "set_x","get_x" => "get_x"); + static function isEqual($a, $b) { + if(!at_dotpoint_math_vector_Vector3_0($a, $b)) { + return false; + } + if(!at_dotpoint_math_vector_Vector3_1($a, $b)) { + return false; + } + if(!at_dotpoint_math_vector_Vector3_2($a, $b)) { + return false; + } + return true; + } + static $__properties__ = array("set_w" => "set_w","get_w" => "get_w","set_z" => "set_z","get_z" => "get_z","set_y" => "set_y","get_y" => "get_y","set_x" => "set_x","get_x" => "get_x"); function __toString() { return $this->toString(); } } function at_dotpoint_math_vector_Vector3_0(&$a, &$b) { @@ -259,8 +283,8 @@ function at_dotpoint_math_vector_Vector3_1(&$a, &$b) { } function at_dotpoint_math_vector_Vector3_2(&$a, &$b) { { - $a3 = $a->z; - $b3 = $b->z; + $a3 = $a->get_z(); + $b3 = $b->get_z(); if($a3 > $b3) { return $a3 - $b3 < 1e-08; } else { diff --git a/bin/php/lib/calculator/EdgeContainer.class.php b/bin/php/lib/calculator/EdgeContainer.class.php index 18fada7..611231f 100644 --- a/bin/php/lib/calculator/EdgeContainer.class.php +++ b/bin/php/lib/calculator/EdgeContainer.class.php @@ -77,6 +77,7 @@ public function split($start, $dir) { } public function insertSplit($start, $a, $b) { $split = new calculator_Vertex(null); + $split->index = Math::min($a->index, $b->index) + Math::min(1, Math::abs($b->index - $a->index)) * 0.5; if($this->isVertical($a, $b)) { $split->set_x($a->get_x()); $split->set_y($start->get_y()); @@ -88,14 +89,14 @@ public function insertSplit($start, $a, $b) { $this->insert($split, $start); $this->insert($split, $a); $this->insert($split, $b); - $a->neighbors->remove($b); - $b->neighbors->remove($a); - $a->neighbors->add($split); - $b->neighbors->add($split); - $split->neighbors->add($start); - $split->neighbors->add($a); - $split->neighbors->add($b); - $start->neighbors->add($split); + $a->removeNeighbor($b); + $b->removeNeighbor($a); + $a->insertNeighbor($split); + $b->insertNeighbor($split); + $split->insertNeighbor($start); + $split->insertNeighbor($a); + $split->insertNeighbor($b); + $start->insertNeighbor($split); return $split; } public function getIndex($value, $isVertical) { diff --git a/bin/php/lib/calculator/TraversalSplitter.class.php b/bin/php/lib/calculator/TraversalSplitter.class.php index fd7f1fe..e08d6e2 100644 --- a/bin/php/lib/calculator/TraversalSplitter.class.php +++ b/bin/php/lib/calculator/TraversalSplitter.class.php @@ -69,8 +69,8 @@ public function buildGraph() { while($_g1 < $_g) { $v = $_g1++; $triangle = $this->getTriangle($v, true); - $triangle->p2->neighbors->add($triangle->p1); - $triangle->p2->neighbors->add($triangle->p3); + $triangle->p2->insertNeighbor($triangle->p1); + $triangle->p2->insertNeighbor($triangle->p3); $this->edges->insert($triangle->p1, $triangle->p2); unset($v,$triangle); } @@ -126,7 +126,7 @@ public function selectClockwiseVertex($current, $previous) { $possible = null; if($previous === null) { $iterator = $current->neighbors->iterator(); - $previous = $current->neighbors->first(); + $previous = $current->neighbors[0]; } while($previous !== null) { if(null == $current->neighbors) throw new HException('null iterable'); @@ -170,7 +170,7 @@ public function isUniquePartiton($partition) { if($area === $partition) { continue; } - if(at_dotpoint_math_vector_Vector2::isEqual($partition->position->hclone(), $area->position->hclone()) && at_dotpoint_math_vector_Vector2::isEqual(at_dotpoint_math_vector_Vector2::add($partition->position, $partition->size, null), at_dotpoint_math_vector_Vector2::add($area->position, $area->size, null))) { + if(at_dotpoint_math_vector_Vector2::isEqual($partition->position->hclone(null), $area->position->hclone(null)) && at_dotpoint_math_vector_Vector2::isEqual(at_dotpoint_math_vector_Vector2::add($partition->position, $partition->size, null), at_dotpoint_math_vector_Vector2::add($area->position, $area->size, null))) { return false; } unset($area); @@ -197,7 +197,7 @@ public function getTriangle($index, $pool = null) { return $triangle; } public function getNormal($current) { - $previous = $current->neighbors->first(); + $previous = $current->neighbors[0]; $delta = new at_dotpoint_math_vector_Vector3(null, null, null, null); $delta->set_x($current->get_x() - $previous->get_x()); $delta->set_y($current->get_y() - $previous->get_y()); diff --git a/bin/php/lib/calculator/Vertex.class.php b/bin/php/lib/calculator/Vertex.class.php index 539eeb4..cdde520 100644 --- a/bin/php/lib/calculator/Vertex.class.php +++ b/bin/php/lib/calculator/Vertex.class.php @@ -7,9 +7,10 @@ public function __construct($coordinate) { $coordinate = new at_dotpoint_math_vector_Vector2(null, null); } $this->coordinate = $coordinate; - $this->neighbors = new HList(); + $this->neighbors = new _hx_array(array()); }} public $coordinate; + public $index; public $neighbors; public function get_x() { return $this->coordinate->get_x(); @@ -23,6 +24,25 @@ public function get_y() { public function set_y($value) { return $this->coordinate->set_y($value); } + public function normalize() { + $this->coordinate->normalize(); + } + public function length() { + return $this->coordinate->length(); + } + public function insertNeighbor($vertex) { + $this->neighbors->push($vertex); + $this->neighbors->sort((isset($this->sortNeighbors) ? $this->sortNeighbors: array($this, "sortNeighbors"))); + } + public function removeNeighbor($vertex) { + return $this->neighbors->remove($vertex); + } + public function sortNeighbors($a, $b) { + return Math::round($a->index - $b->index); + } + public function toString() { + return "[" . _hx_string_rec($this->index, "") . "]"; + } public function __call($m, $a) { if(isset($this->$m) && is_callable($this->$m)) return call_user_func_array($this->$m, $a); @@ -34,5 +54,5 @@ public function __call($m, $a) { throw new HException('Unable to call <'.$m.'>'); } static $__properties__ = array("set_y" => "set_y","get_y" => "get_y","set_x" => "set_x","get_x" => "get_x"); - function __toString() { return 'calculator.Vertex'; } + function __toString() { return $this->toString(); } } diff --git a/bin/php/lib/calculator/VertexTriangle.class.php b/bin/php/lib/calculator/VertexTriangle.class.php index 22cbaa1..264d78a 100644 --- a/bin/php/lib/calculator/VertexTriangle.class.php +++ b/bin/php/lib/calculator/VertexTriangle.class.php @@ -18,10 +18,11 @@ public function isClockwise($includeZero = null) { $v3 = new at_dotpoint_math_vector_Vector3($this->p3->coordinate->get_x(), $this->p3->coordinate->get_y(), 0, null); $sub1 = at_dotpoint_math_vector_Vector3::subtract($v2, $v1, new at_dotpoint_math_vector_Vector3(null, null, null, null)); $sub2 = at_dotpoint_math_vector_Vector3::subtract($v3, $v1, new at_dotpoint_math_vector_Vector3(null, null, null, null)); + $cross = at_dotpoint_math_vector_Vector3::cross($sub1, $sub2, null); if($includeZero) { - return at_dotpoint_math_vector_Vector3::cross($sub1, $sub2, null)->z >= 0; + return $cross->get_z() >= 0; } else { - return at_dotpoint_math_vector_Vector3::cross($sub1, $sub2, null)->z > 0; + return $cross->get_z() > 0; } }} public function __call($m, $a) { diff --git a/build.hxml b/build.hxml index d6456f7..97942f6 100644 --- a/build.hxml +++ b/build.hxml @@ -26,7 +26,7 @@ -js bin/js/Partitioning.js ## ################################ -## AS3 +## AS3 SWF --next @@ -40,5 +40,20 @@ -D display +-swf-header 1024:768:40 -swf-version 11 --swf bin/as3/Partitioning.swf \ No newline at end of file +-swf bin/as3/Partitioning.swf + +## ################################ +## AS3 Source-Code with Display + +--next + +-main Main + +-cp src +-cp lib/dotCore/src + +-D display + +-as3 bin/as3/src \ No newline at end of file diff --git a/lib/dotCore b/lib/dotCore index 3f4cefc..1b8180b 160000 --- a/lib/dotCore +++ b/lib/dotCore @@ -1 +1 @@ -Subproject commit 3f4cefc9e51e6dd915642cccd7525295481bc1de +Subproject commit 1b8180b64541cc6a5deb5ee85b120235f6e65f1e diff --git a/src/Main.hx b/src/Main.hx index 7b86b14..cc8e7d1 100644 --- a/src/Main.hx +++ b/src/Main.hx @@ -5,14 +5,11 @@ import at.dotpoint.math.vector.Vector2; import calculator.TraversalSplitter; import converter.StringConverter; + #if display import view.CanvasView; - import view.ControllerView; - - import at.dotpoint.core.bootstrapper.task.StageTask; - import at.dotpoint.core.event.Event; - import at.dotpoint.display.event.MouseEvent; - import at.dotpoint.display.Stage; + import view.ControllerView; + import flash.events.Event; #end /** @@ -133,45 +130,20 @@ class Main #if display - /** - * - * @param value - */ - private function onCalculate( value:Event ):Void - { - this.setupCanvas(); - - // ------------------------ // - - #if debug - this.controller.output = this.calculate( this.controller.input ).toString(); - #else - try - { - this.controller.output = this.calculate( this.controller.input ).toString(); - } - catch( error:Dynamic ) - { - this.controller.output = "error: " + error; - } - #end - } - - /** * */ public function setupController():Void { - var task:StageTask = new StageTask(null); - task.execute(); + flash.Lib.current.stage.scaleMode = flash.display.StageScaleMode.NO_SCALE; + flash.Lib.current.stage.align = flash.display.StageAlign.TOP_LEFT; // ------------ // this.controller = new ControllerView(); - this.controller.addEventListener( MouseEvent.CLICK, this.onCalculate ); + this.controller.addEventListener( "calculate", this.onCalculate ); - Stage.instance.addChild( this.controller ); + flash.Lib.current.stage.addChild( this.controller ); } /** @@ -181,7 +153,7 @@ class Main { if( this.canvas != null ) { - Stage.instance.removeChild( this.canvas ); + flash.Lib.current.stage.removeChild( this.canvas ); this.canvas = null; } @@ -189,14 +161,38 @@ class Main this.canvas = new CanvasView(); this.canvas.x = 15; - this.canvas.y = 150; + this.canvas.y = this.controller.y + this.controller.height; - Stage.instance.addChild( this.canvas ); + flash.Lib.current.stage.addChild( this.canvas ); #if debug this.calculator.debugger = this.canvas; #end } + /** + * + * @param value + */ + private function onCalculate( value:Event ):Void + { + this.setupCanvas(); + + // ------------------------ // + + #if debug + this.controller.output = this.calculate( this.controller.input ).toString(); + #else + try + { + this.controller.output = this.calculate( this.controller.input ).toString(); + } + catch( error:Dynamic ) + { + this.controller.output = "error: " + error; + } + #end + } + #end } \ No newline at end of file diff --git a/src/calculator/EdgeContainer.hx b/src/calculator/EdgeContainer.hx index 5b5aef0..2d7d5a7 100644 --- a/src/calculator/EdgeContainer.hx +++ b/src/calculator/EdgeContainer.hx @@ -171,7 +171,8 @@ class EdgeContainer private function insertSplit( start:Vertex, a:Vertex, b:Vertex ):Vertex { var split:Vertex = new Vertex( null ); - + split.index = Math.min( a.index, b.index ) + Math.min( 1, Math.abs(b.index - a.index) ) * 0.5; + if( this.isVertical( a, b ) ) // vertical edge, horizontal ray that splits the edge { split.x = a.x; @@ -181,11 +182,10 @@ class EdgeContainer { split.x = start.x; split.y = a.y; - } + } #if debug - var index:Float = Math.min( a.index, b.index ) + Math.min( 1, Math.abs(b.index - a.index) ) * 0.5; - trace( "split", start, "--X--", a, b + ": [" + index + "]" ); + trace( "split", start, "--X--", a, b + ": [" + split.index + "]" ); #end // ------------------- // @@ -200,17 +200,17 @@ class EdgeContainer // ------------------- // // adjust graph: - a.neighbors.remove( b ); - b.neighbors.remove( a ); + a.removeNeighbor( b ); + b.removeNeighbor( a ); - a.neighbors.add( split ); - b.neighbors.add( split ); + a.insertNeighbor( split ); + b.insertNeighbor( split ); - split.neighbors.add( start ); - split.neighbors.add( a ); - split.neighbors.add( b ); + split.insertNeighbor( start ); + split.insertNeighbor( a ); + split.insertNeighbor( b ); - start.neighbors.add( split ); + start.insertNeighbor( split ); // ------------------- // diff --git a/src/calculator/TraversalSplitter.hx b/src/calculator/TraversalSplitter.hx index 399b0d3..6a0d4b9 100644 --- a/src/calculator/TraversalSplitter.hx +++ b/src/calculator/TraversalSplitter.hx @@ -195,8 +195,8 @@ class TraversalSplitter implements IPartitionCalculator { var triangle:VertexTriangle = this.getTriangle( v, true ); - triangle.p2.neighbors.add( triangle.p1 ); // clockwise previous neighbor - triangle.p2.neighbors.add( triangle.p3 ); // clockwise next neighbor + triangle.p2.insertNeighbor( triangle.p1 ); // clockwise previous neighbor + triangle.p2.insertNeighbor( triangle.p3 ); // clockwise next neighbor this.edges.insert( triangle.p1, triangle.p2 ); // line between previous and current vertex } @@ -312,7 +312,7 @@ class TraversalSplitter implements IPartitionCalculator if( previous == null ) { iterator = current.neighbors.iterator(); - previous = current.neighbors.first(); + previous = current.neighbors[0]; } while( previous != null ) @@ -418,7 +418,7 @@ class TraversalSplitter implements IPartitionCalculator */ private function getNormal( current:Vertex ):Vector2 { - var previous:Vertex = current.neighbors.first(); + var previous:Vertex = current.neighbors[0]; var delta:Vector3 = new Vector3(); delta.x = current.x - previous.x; diff --git a/src/calculator/Vertex.hx b/src/calculator/Vertex.hx index cfd067f..689ae4f 100644 --- a/src/calculator/Vertex.hx +++ b/src/calculator/Vertex.hx @@ -15,6 +15,13 @@ class Vertex implements IVector2 */ public var coordinate:Vector2; + /** + * unique ID of the vertex - calculated by counting through the whole + * polygon graph clockwise/counterclockwise. new vertices are assigned + * a value between its left and right neighbor. e.g.: 8 --- 8.5 --- 9 + */ + public var index:Float; + /** * X------o------X * | @@ -24,9 +31,10 @@ class Vertex implements IVector2 * up to 3 neighbors vertices: left, right and when a split-vertex a normal vertex * linked list to save memory and random access performance is not an issue */ - public var neighbors:List; + public var neighbors:Array; // ----------------- // + // IVector2 /** * getter / setter for coordinate @@ -44,11 +52,11 @@ class Vertex implements IVector2 coordinate = new Vector2(); this.coordinate = coordinate; - this.neighbors = new List(); + this.neighbors = new Array(); } // ************************************************************************ // - // getter / setter + // IVector2 // ************************************************************************ // /** @@ -71,13 +79,60 @@ class Vertex implements IVector2 return this.coordinate.y = value; } + /** + * this.coordinate.normalize() + */ + public function normalize():Void + { + this.coordinate.normalize(); + } + + /** + * + * @return + */ + public function length():Float + { + return this.coordinate.length(); + } + // ************************************************************************ // - // Debug / toString + // Neighbors // ************************************************************************ // - #if debug + /** + * + * @param vertex + */ + public function insertNeighbor( vertex:Vertex ):Void + { + this.neighbors.push( vertex ); + this.neighbors.sort( this.sortNeighbors ); + } + + /** + * + * @param vertex + */ + public function removeNeighbor( vertex:Vertex ):Bool + { + return this.neighbors.remove( vertex ); + } - public var index:Int; + /** + * + * @param a + * @param b + * @return + */ + private function sortNeighbors( a:Vertex, b:Vertex ):Int + { + return Math.round( a.index - b.index ); + } + + // ************************************************************************ // + // Debug / toString + // ************************************************************************ // /** * @@ -87,6 +142,4 @@ class Vertex implements IVector2 { return "[" + this.index + "]"; } - - #end } \ No newline at end of file diff --git a/src/calculator/VertexTriangle.hx b/src/calculator/VertexTriangle.hx index 3a5d1b2..d8fb1ab 100644 --- a/src/calculator/VertexTriangle.hx +++ b/src/calculator/VertexTriangle.hx @@ -55,6 +55,8 @@ class VertexTriangle var sub1:Vector3 = Vector3.subtract( v2, v1, new Vector3() ); var sub2:Vector3 = Vector3.subtract( v3, v1, new Vector3() ); - return includeZero ? Vector3.cross( sub1, sub2 ).z >= 0 : Vector3.cross( sub1, sub2 ).z > 0; + var cross:Vector3 = Vector3.cross( sub1, sub2 ); + + return includeZero ? cross.z >= 0 : cross.z > 0; } } \ No newline at end of file diff --git a/src/view/CanvasView.hx b/src/view/CanvasView.hx index 46d25de..f65c361 100644 --- a/src/view/CanvasView.hx +++ b/src/view/CanvasView.hx @@ -1,11 +1,10 @@ package view; -import at.dotpoint.display.components.renderable.FillStyle; -import at.dotpoint.display.Shape; -import at.dotpoint.display.Sprite; -import at.dotpoint.display.TextField; import at.dotpoint.math.geom.Rectangle; import at.dotpoint.math.vector.IVector2; +import flash.display.Shape; +import flash.display.Sprite; +import flash.text.TextField; /** * ... @@ -39,7 +38,7 @@ class CanvasView extends Sprite implements IPartitionDebugger // ------------------- // /** - * + * polygon canvas (where debug gets drawn onto) */ private var canvas:Sprite; @@ -72,15 +71,16 @@ class CanvasView extends Sprite implements IPartitionDebugger public function drawOutline( list:Array ):Void { var shape:Shape = new Shape(); - + shape.graphics.lineStyle( 8, Std.int( 0xFFFFFF * Math.random() ), 0.35 ); + for( v in 0...list.length + 1 ) { var vertex:IVector2 = list[v % list.length]; if( v == 0 ) - shape.graphic.moveTo( vertex.x, vertex.y ); + shape.graphics.moveTo( vertex.x, vertex.y ); else - shape.graphic.lineTo( vertex.x, vertex.y ); + shape.graphics.lineTo( vertex.x, vertex.y ); // ---------- // @@ -92,8 +92,6 @@ class CanvasView extends Sprite implements IPartitionDebugger this.canvas.addChild( debug ); } - shape.graphic.drawStrokes( 8, Std.int( 0xFFFFFF * Math.random() ), 0.35 ); - this.canvas.addChild( shape ); // ----------------- // @@ -115,9 +113,10 @@ class CanvasView extends Sprite implements IPartitionDebugger var color:Int = Std.int( 0xFFFFFF * Math.random() ); var shape:Shape = new Shape(); - shape.graphic.createRectangle( area.x, area.y, area.width, area.height ); - shape.graphic.drawStrokes( 1, color ); - shape.graphic.drawFill( FillStyle.createSolid( color, 0.1 ) ); + shape.graphics.lineStyle( 1, color ); + shape.graphics.beginFill( color, 0.1 ); + shape.graphics.drawRect( area.x, area.y, area.width, area.height ); + shape.graphics.endFill(); this.canvas.addChild( shape ); @@ -139,10 +138,9 @@ class CanvasView extends Sprite implements IPartitionDebugger public function drawSplitLine( a:IVector2, b:IVector2 ):Void { var shape:Shape = new Shape(); - shape.graphic.moveTo( a.x, a.y ); - shape.graphic.lineTo( b.x, b.y ); - - shape.graphic.drawStrokes( 4, 0x000000, 0.65 ); + shape.graphics.lineStyle( 4, 0x000000, 0.65 ); + shape.graphics.moveTo( a.x, a.y ); + shape.graphics.lineTo( b.x, b.y ); this.canvas.addChild( shape ); } @@ -154,9 +152,8 @@ class CanvasView extends Sprite implements IPartitionDebugger public function drawSplitStart( a:IVector2 ):Void { var shape:Shape = new Shape(); - shape.graphic.createCircle( a.x, a.y, 4 ); - - shape.graphic.drawStrokes( 2, 0xFF0000, 0.85 ); + shape.graphics.lineStyle( 2, 0xFF0000, 0.85 ); + shape.graphics.drawCircle( a.x, a.y, 4 ); this.canvas.addChild( shape ); } @@ -168,9 +165,8 @@ class CanvasView extends Sprite implements IPartitionDebugger public function drawSplitEnd( a:IVector2 ):Void { var shape:Shape = new Shape(); - shape.graphic.createCircle( a.x, a.y, 4 ); - - shape.graphic.drawStrokes( 2, 0x000000, 0.85 ); + shape.graphics.lineStyle( 2, 0x000000, 0.85 ); + shape.graphics.drawCircle( a.x, a.y, 4 ); this.canvas.addChild( shape ); diff --git a/src/view/ControllerView.hx b/src/view/ControllerView.hx index 77918d7..08539ce 100644 --- a/src/view/ControllerView.hx +++ b/src/view/ControllerView.hx @@ -1,23 +1,12 @@ -package view ; +package view; -import at.dotpoint.core.event.Event; -import at.dotpoint.display.event.MouseEvent; -import at.dotpoint.display.Sprite; -import at.dotpoint.display.Stage; -import at.dotpoint.display.TextField; -import at.dotpoint.gui.Constraints; -import at.dotpoint.gui.dataprovider.ArrayCollection; -import at.dotpoint.gui.dataprovider.IDataProvider; -import at.dotpoint.gui.event.SelectionEvent; -import at.dotpoint.gui.layout.VerticalLayout; -import at.dotpoint.gui.UIDisplayObjectContainer; -import at.dotpoint.gui.viewport.List; -import at.dotpoint.gui.viewport.Viewport; - -#if flash - import at.dotpoint.display.components.renderable.flash.TextFieldEC; - import flash.text.TextFieldType; -#end +import flash.display.DisplayObject; +import flash.display.Sprite; +import flash.events.Event; +import flash.events.MouseEvent; +import flash.text.TextField; +import flash.text.TextFieldAutoSize; +import flash.text.TextFieldType; /** * ... @@ -29,7 +18,7 @@ class ControllerView extends Sprite /** * */ - private var presets:IDataProvider; + private var presets:Array; // ----------------- // @@ -62,7 +51,16 @@ class ControllerView extends Sprite public function new() { super(); - this.create(); + + this.presets = new Array(); + this.presets.push( "740 917 740 747 540 747 540 637 390 637 390 527 260 527 260 427 130 427 130 177 710 177 710 87 950 87 950 257 1090 257 1090 387 1220 387 1220 567 1340 567 1340 767 1080 767 1080 917" ); + this.presets.push( "68 139 223 139 223 216 382 216 382 45 791 45 791 329 923 329 923 564 858 564 858 505 665 505 665 410 562 410 562 670 730 670 730 740 296 740 296 450 68 450 68 139" ); + this.presets.push( "164 156 164 280 230 280 230 373 299 373 299 218 361 218 361 156 164 156" ); + this.presets.push( "132 112 468 112 468 429 352 429 352 287 249 287 249 529 132 529 132 112" ); + this.presets.push( "133 63 500 63 500 339 458 339 458 416 564 416 564 623 133 623 133 63" ); + this.presets.push( "584 143 584 592 756 592 756 379 860 379 860 143" ); + + this.createUI(); } // ************************************************************************ // @@ -98,10 +96,14 @@ class ControllerView extends Sprite /** * */ - private function create():Void + private function createUI():Void { - this.createInputBox(); - this.createOutputBox(); + var input:DisplayObject = this.createInputBox(); + var output:DisplayObject = this.createOutputBox(); + output.y = input.y + input.height + 10; + + this.addChild( input ); + this.addChild( output ); this.selectInput( 0 ); } @@ -113,7 +115,7 @@ class ControllerView extends Sprite private function onCalculate( value:Event ):Void { this.output = "processing ... "; - this.dispatchEvent( value ); + this.dispatchEvent( new Event("calculate") ); } /** @@ -122,8 +124,13 @@ class ControllerView extends Sprite */ private function onInputSelected( value:Event ):Void { - var event:SelectionEvent = cast value; - this.selectInput( event.dataIndex ); + var item:TextField = cast value.target; + var index:Int = this.presets.indexOf( item.text ); + + if( index < 0 ) + this.output = "error: preset not found"; + + this.selectInput( index ); } /** @@ -132,7 +139,7 @@ class ControllerView extends Sprite */ private function selectInput( index:Int ):Void { - this.input = this.presets.toArray()[index]; + this.input = this.presets[index]; this.output = "press 'calculate' to process"; } @@ -143,36 +150,48 @@ class ControllerView extends Sprite /** * */ - private function createInputBox():Void + private function createInputBox():DisplayObject { - var vbox:UIDisplayObjectContainer = new UIDisplayObjectContainer(); - vbox.addComponent( new VerticalLayout() ); + var presetList:Sprite = this.createPresetList(); + + var inputField:Sprite = this.createInputField(); + inputField.y = presetList.height + 15; + + // -------------- // - vbox.addChild( this.createPresetList() ); - vbox.addChild( this.createInputField() ); + var vbox:Sprite = new Sprite(); + vbox.addChild( presetList ); + vbox.addChild( inputField ); - this.addChild( vbox ); + return vbox; } /** * * @return */ - private function createPresetList():UIDisplayObjectContainer - { - var presetList:List = new List(); - presetList.boundings.bb.width = 450; - presetList.boundings.bb.height = 100; - presetList.addEventListener( SelectionEvent.ITEM_SELECTED, this.onInputSelected ); - - // --------------------------- // + private function createPresetList():Sprite + { + var presetList:Sprite = new Sprite(); + + // ---------- // - this.presets = presetList.dataProvider; - this.presets.add( "68 139 223 139 223 216 382 216 382 45 791 45 791 329 923 329 923 564 858 564 858 505 665 505 665 410 562 410 562 670 730 670 730 740 296 740 296 450 68 450 68 139" ); - this.presets.add( "164 156 164 280 230 280 230 373 299 373 299 218 361 218 361 156 164 156" ); - this.presets.add( "132 112 468 112 468 429 352 429 352 287 249 287 249 529 132 529 132 112" ); - this.presets.add( "133 63 500 63 500 339 458 339 458 416 564 416 564 623 133 623 133 63" ); - this.presets.add( "584 143 584 592 756 592 756 379 860 379 860 143" ); + var y:Float = 0; + + for( preset in this.presets ) + { + var item:TextField = new TextField(); + item.autoSize = TextFieldAutoSize.LEFT; + item.text = preset; + item.selectable = false; + + item.addEventListener( MouseEvent.CLICK, this.onInputSelected ); + item.y = y; + + presetList.addChild( item ); + + y += item.height; + } return presetList; } @@ -181,27 +200,26 @@ class ControllerView extends Sprite * * @return */ - private function createInputField():UIDisplayObjectContainer + private function createInputField():Sprite { this.inputField = new TextField(); - - #if flash - var renderable:TextFieldEC = cast this.inputField.renderable; - var internal:flash.text.TextField = cast renderable.internal; - internal.type = TextFieldType.INPUT; - internal.border = true; - #end + this.inputField.type = TextFieldType.INPUT; + this.inputField.autoSize = TextFieldAutoSize.LEFT; + this.inputField.border = true; // ---------- // var calculate:TextField = new TextField(); calculate.text = ">> calculate <<"; - calculate.userInput.addEventListener( MouseEvent.CLICK, this.onCalculate ); - calculate.y = 40; - + calculate.border = true; + calculate.addEventListener( MouseEvent.CLICK, this.onCalculate ); + calculate.y = this.inputField.height + 5; + calculate.autoSize = TextFieldAutoSize.LEFT; + calculate.selectable = false; + // ---------- // - var hbox:UIDisplayObjectContainer = new UIDisplayObjectContainer(); + var hbox:Sprite = new Sprite(); hbox.addChild( this.inputField ); hbox.addChild( calculate ); @@ -215,11 +233,11 @@ class ControllerView extends Sprite /** * */ - private function createOutputBox():Void + private function createOutputBox():DisplayObject { - this.resultField = new TextField(); - this.resultField.y = 120; + this.resultField = new TextField(); + this.resultField.autoSize = TextFieldAutoSize.LEFT; - this.addChild( this.resultField ); + return this.resultField; } } \ No newline at end of file