Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function ($hx_exports) { "use strict";
- function $extend(from, fields) {
- function Inherit() {} Inherit.prototype = from; var proto = new Inherit();
- for (var name in fields) proto[name] = fields[name];
- if( fields.toString !== Object.prototype.toString ) proto.toString = fields.toString;
- return proto;
- }
- var EventDispatcher = function() {
- };
- EventDispatcher.prototype = {
- dispatchEvent: function(event) {
- if(this._listeners == null) {
- return;
- }
- var listeners = this._listeners;
- var key = event.type;
- var listenerArray = __map_reserved[key] != null ? listeners.getReserved(key) : listeners.h[key];
- if(listenerArray != null) {
- event.target = this;
- var array = listenerArray.slice(0);
- var len = array.length;
- var _g = 0;
- while(_g < array.length) {
- var el = array[_g];
- ++_g;
- el.call(this,event);
- }
- }
- }
- };
- var Global = function() { };
- var HxOverrides = function() { };
- HxOverrides.remove = function(a,obj) {
- var i = a.indexOf(obj);
- if(i == -1) {
- return false;
- }
- a.splice(i,1);
- return true;
- };
- var Main = $hx_exports["Main"] = function() {
- };
- Main.init = function() {
- [1,2,3].map(function(e) {
- return e > 2;
- });
- MNKLJLOIYOIYOIUOIUOI.init();
- var t = new Test();
- t.test();
- };
- Main.main = function() {
- console.log("init haxe ");
- };
- var MNKLJLOIYOIYOIUOIUOI = $hx_exports["MNKLJLOIYOIYOIUOIUOI"] = function() { };
- MNKLJLOIYOIYOIUOIUOI.init = function() {
- };
- var Reflect = function() { };
- Reflect.field = function(o,field) {
- try {
- return o[field];
- } catch( e ) {
- return null;
- }
- };
- var Test = function() {
- };
- Test.prototype = {
- test: function() {
- var op = MNKLJLOIYOIYOIUOIUOI.board;
- op.axis = true;
- op.grid = true;
- op.showCopyright = false;
- op.pan.enabled = true;
- op.pan.needTwoFingers = true;
- op.pan.needShift = true;
- op.zoom.factorX = 1.25;
- op.zoom.factorY = 1.25;
- op.zoom.min = 0.8;
- op.zoom.max = 2;
- op.zoom.pinchHorizontal = true;
- op.zoom.pinchVertical = true;
- op.zoom.pinchSensitivity = 7;
- op.zoom.needShift = false;
- op.boundingBox = [-20,10,20,-10];
- this.board = JXG.JSXGraph.initBoard("box",op);
- Global.board = this.board;
- var a = "a";
- var b = "b";
- var c = "c";
- var d = "d";
- var e = "e";
- var f = "f";
- var g = "g";
- var h = "h";
- var points = [a,b,c,d,e,f,g,h];
- var graph = [[a,e],[e,b],[b,c],[d,f],[f,c],[a,g],[b,g],[e,g],[d,a],[d,g],[f,g],[c,g],[a,h],[e,h],[b,h]];
- var pointsPs = { "a" : { x : 0, y : 2}, "b" : { x : 2, y : 2}, "c" : { x : 2, y : 0}, "d" : { x : 0, y : 0}, "e" : { x : 1, y : 2}, "f" : { x : 1, y : 0}, "g" : { x : 1, y : 1}, "h" : { x : 1, y : 3}};
- var cs = new haxe_ds_StringMap();
- var ps = [];
- var _g = 0;
- while(_g < points.length) {
- var p = points[_g];
- ++_g;
- var xy = Reflect.field(pointsPs,p);
- var c1 = new bp3d_model_Corner(xy.x,xy.y,{ fixed : false, snapToGrid : true});
- if(__map_reserved[p] != null) {
- cs.setReserved(p,c1);
- } else {
- cs.h[p] = c1;
- }
- ps.push(c1);
- }
- var _g1 = 0;
- while(_g1 < graph.length) {
- var line = graph[_g1];
- ++_g1;
- var key = line[0];
- var tmp = __map_reserved[key] != null ? cs.getReserved(key) : cs.h[key];
- var key1 = line[1];
- new bp3d_model_Wall(tmp,__map_reserved[key1] != null ? cs.getReserved(key1) : cs.h[key1]);
- }
- var fs = this.findRooms(ps);
- if(fs != null) {
- console.log(fs.length);
- }
- this.draw(fs);
- }
- ,_calculateTheta: function(previousCorner,currentCorner,nextCorner) {
- var theta = bp3d_core_Utils.angle2pi(previousCorner.get_x() - currentCorner.get_x(),previousCorner.get_y() - currentCorner.get_y(),nextCorner.get_x() - currentCorner.get_x(),nextCorner.get_y() - currentCorner.get_y());
- return theta;
- }
- ,_removeDuplicateRooms: function(roomArray) {
- var results = [];
- var lookup = new haxe_ds_StringMap();
- var hashFunc = function(corner) {
- return corner.id;
- };
- var sep = "-";
- var str = "";
- var _g1 = 0;
- var _g = roomArray.length;
- while(_g1 < _g) {
- var i = _g1++;
- var add = true;
- var room = roomArray[i];
- var _g3 = 0;
- var _g2 = room.length;
- while(_g3 < _g2) {
- var j = _g3++;
- var roomShift = bp3d_core_Utils.cycle(room,j);
- str = bp3d_core_Utils.map(roomShift,hashFunc).join(sep);
- if(__map_reserved[str] != null ? lookup.existsReserved(str) : lookup.h.hasOwnProperty(str)) {
- add = false;
- }
- }
- if(add) {
- results.push(roomArray[i]);
- if(__map_reserved[str] != null) {
- lookup.setReserved(str,true);
- } else {
- lookup.h[str] = true;
- }
- }
- }
- return results;
- }
- ,_findTightestCycle: function(firstCorner,secondCorner) {
- var _gthis = this;
- var stack = [];
- var next = { corner : secondCorner, previousCorners : [firstCorner]};
- var visited = new haxe_ds_StringMap();
- var k = firstCorner.id;
- if(__map_reserved[k] != null) {
- visited.setReserved(k,true);
- } else {
- visited.h[k] = true;
- }
- while(next != null) {
- var currentCorner = [next.corner];
- var k1 = currentCorner[0].id;
- if(__map_reserved[k1] != null) {
- visited.setReserved(k1,true);
- } else {
- visited.h[k1] = true;
- }
- if(next.corner == firstCorner && currentCorner[0] != secondCorner) {
- return next.previousCorners;
- }
- var addToStack = [];
- var adjacentCorners = next.corner.adjacentCorners();
- var _g1 = 0;
- var _g = adjacentCorners.length;
- while(_g1 < _g) {
- var i = _g1++;
- var nextCorner = adjacentCorners[i];
- var tmp;
- var key = nextCorner.id;
- if(__map_reserved[key] != null ? visited.existsReserved(key) : visited.h.hasOwnProperty(key)) {
- tmp = !(nextCorner == firstCorner && currentCorner[0] != secondCorner);
- } else {
- tmp = false;
- }
- if(tmp) {
- continue;
- }
- addToStack.push(nextCorner);
- }
- var previousCorners = next.previousCorners.slice(0);
- previousCorners.push(currentCorner[0]);
- if(addToStack.length > 1) {
- var previousCorner = [next.previousCorners[next.previousCorners.length - 1]];
- addToStack.sort((function(previousCorner1,currentCorner1) {
- return function(a,b) {
- return (_gthis._calculateTheta(previousCorner1[0],currentCorner1[0],b) | 0) - (_gthis._calculateTheta(previousCorner1[0],currentCorner1[0],a) | 0);
- };
- })(previousCorner,currentCorner));
- }
- if(addToStack.length > 0) {
- var _g2 = 0;
- while(_g2 < addToStack.length) {
- var corner = addToStack[_g2];
- ++_g2;
- stack.push({ corner : corner, previousCorners : previousCorners});
- }
- }
- next = stack.pop();
- }
- return [];
- }
- ,getCentroid: function(polygon) {
- var center = [0.0,0.0];
- var len = polygon.vertices.length - 1;
- var _g1 = 0;
- var _g = len;
- while(_g1 < _g) {
- var i = _g1++;
- center[0] += polygon.vertices[i].coords.usrCoords[1];
- center[1] += polygon.vertices[i].coords.usrCoords[2];
- }
- if(len > 0) {
- center[0] /= len;
- center[1] /= len;
- } else {
- center = [NaN,NaN];
- }
- return center;
- }
- ,findRooms: function(corners) {
- var loops = [];
- var _g = 0;
- while(_g < corners.length) {
- var firstCorner = corners[_g];
- ++_g;
- var cs = firstCorner.adjacentCorners();
- var _g1 = 0;
- while(_g1 < cs.length) {
- var secondCorner = cs[_g1];
- ++_g1;
- loops.push(this._findTightestCycle(firstCorner,secondCorner));
- }
- }
- var uniqueLoops = this._removeDuplicateRooms(loops);
- var _result = uniqueLoops;
- var result = this.removeContain(_result);
- return result;
- }
- ,removeContain: function(array) {
- var polys = [];
- var _g = 0;
- while(_g < array.length) {
- var corners = array[_g];
- ++_g;
- var _g1 = [];
- var _g3 = 0;
- var _g2 = corners.length;
- while(_g3 < _g2) {
- var i = _g3++;
- _g1.push(corners[i].point2d);
- }
- var ps = _g1;
- var this1 = ps == null ? [] : ps;
- polys.push(this1);
- }
- var remove = [];
- var _g4 = 0;
- while(_g4 < polys.length) {
- var start = polys[_g4];
- ++_g4;
- var _g11 = 0;
- while(_g11 < polys.length) {
- var end = polys[_g11];
- ++_g11;
- if(start != end && start.length != end.length) {
- var tempArray = [start,end];
- tempArray.sort(function(a,b) {
- return a.length - b.length;
- });
- var len = 0;
- var _g2_l;
- var _g2_i;
- var _g2_a;
- _g2_i = 0;
- _g2_a = tempArray[0];
- _g2_l = _g2_a.length;
- while(_g2_i < _g2_l) {
- var detectpoint = _g2_a[_g2_i++];
- if(h2d_col__$Polygon_Polygon_$Impl_$.contains(tempArray[1],detectpoint)) {
- ++len;
- }
- if(len == tempArray[0].length) {
- remove.push(array[polys.indexOf(tempArray[1])]);
- }
- }
- }
- }
- }
- var _g5 = 0;
- while(_g5 < remove.length) {
- var el = remove[_g5];
- ++_g5;
- HxOverrides.remove(array,el);
- }
- polys = null;
- return array;
- }
- ,draw: function(array) {
- var _gthis = this;
- var polys = [];
- var _g = 0;
- while(_g < array.length) {
- var corners = array[_g];
- ++_g;
- var _g1 = [];
- var _g3 = 0;
- var _g2 = corners.length;
- while(_g3 < _g2) {
- var i = _g3++;
- _g1.push(corners[i].point2d);
- }
- var ps = _g1;
- var this1 = ps == null ? [] : ps;
- polys.push(this1);
- }
- var remove = [];
- var _g4 = 0;
- while(_g4 < polys.length) {
- var start = polys[_g4];
- ++_g4;
- var _g11 = 0;
- while(_g11 < polys.length) {
- var end = polys[_g11];
- ++_g11;
- if(start != end && start.length != end.length) {
- var tempArray = [start,end];
- tempArray.sort(function(a,b) {
- return a.length - b.length;
- });
- var len = 0;
- var _g2_l;
- var _g2_i;
- var _g2_a;
- _g2_i = 0;
- _g2_a = tempArray[0];
- _g2_l = _g2_a.length;
- while(_g2_i < _g2_l) {
- var detectpoint = _g2_a[_g2_i++];
- if(h2d_col__$Polygon_Polygon_$Impl_$.contains(tempArray[1],detectpoint)) {
- ++len;
- }
- if(len == tempArray[0].length) {
- remove.push(array[polys.indexOf(tempArray[1])]);
- }
- }
- }
- }
- }
- var _g5 = 0;
- while(_g5 < remove.length) {
- var el = remove[_g5];
- ++_g5;
- HxOverrides.remove(array,el);
- }
- var _g6 = 0;
- while(_g6 < array.length) {
- var corners1 = array[_g6];
- ++_g6;
- var _g12 = [];
- var _g31 = 0;
- var _g21 = corners1.length;
- while(_g31 < _g21) {
- var i1 = _g31++;
- _g12.push(corners1[i1].point);
- }
- var ps1 = _g12;
- var pol = [Global.board.create("polygon",ps1,{ hasInnerPoints : true, fillColor : "gray"})];
- Global.board.create("text",[(function(pol1) {
- return function(x) {
- return _gthis.getCentroid(pol1[0])[0];
- };
- })(pol),(function(pol2) {
- return function(x1) {
- return _gthis.getCentroid(pol2[0])[1];
- };
- })(pol),(function(pol3) {
- return function() {
- return "面积" + Math.ceil(pol3[0].Area());
- };
- })(pol)],{ });
- }
- }
- };
- var bp3d_Event = function() { };
- var bp3d_core_Utils = function() { };
- bp3d_core_Utils.angle = function(x1,y1,x2,y2) {
- var tDot = x1 * x2 + y1 * y2;
- var tDet = x1 * y2 - y1 * x2;
- var tAngle = -Math.atan2(tDet,tDot);
- return tAngle;
- };
- bp3d_core_Utils.angle2pi = function(x1,y1,x2,y2) {
- var tTheta = bp3d_core_Utils.angle(x1,y1,x2,y2);
- if(tTheta < 0) {
- tTheta += 2 * Math.PI;
- }
- return tTheta;
- };
- bp3d_core_Utils.map = function(array,func) {
- var tResult = [];
- var _g = 0;
- while(_g < array.length) {
- var element = array[_g];
- ++_g;
- tResult.push(func(element));
- }
- return tResult;
- };
- bp3d_core_Utils.cycle = function(arr,shift) {
- var tReturn = arr.slice(0);
- var tI = 0;
- while(tI < shift) {
- var tmp = tReturn.shift();
- tReturn.push(tmp);
- ++tI;
- }
- return tReturn;
- };
- var bp3d_model_Corner = function(xx,yy,propery) {
- this.wallEnds = [];
- this.wallStarts = [];
- EventDispatcher.call(this);
- this.set_x(xx);
- this.set_y(yy);
- this.set_point(Global.board.create("point",[xx,yy],propery));
- this.point2d = new h2d_col_Point(this.get_x(),this.get_y());
- this.id = this.point.id;
- this.name = this.point.name;
- this.point.on("move",$bind(this,this.onMove));
- };
- bp3d_model_Corner.__super__ = EventDispatcher;
- bp3d_model_Corner.prototype = $extend(EventDispatcher.prototype,{
- get_x: function() {
- return this.x;
- }
- ,set_x: function(x) {
- return this.x = x;
- }
- ,get_y: function() {
- return this.y;
- }
- ,set_y: function(y) {
- return this.y = y;
- }
- ,set_point: function(p) {
- return this.point = p;
- }
- ,onMove: function(e) {
- }
- ,detachWall: function(wall) {
- HxOverrides.remove(this.wallStarts,wall);
- HxOverrides.remove(this.wallEnds,wall);
- if(this.wallStarts.length == 0 && this.wallEnds.length == 0) {
- this.remove();
- }
- }
- ,remove: function() {
- this.dispatchEvent({ event : bp3d_Event.EVENT_ITEM_REMOVED, target : this});
- }
- ,adjacentCorners: function() {
- var retArray = [];
- var _g = 0;
- var _g1 = this.wallStarts;
- while(_g < _g1.length) {
- var _wall = _g1[_g];
- ++_g;
- retArray.push(_wall.getEnd());
- }
- var _g2 = 0;
- var _g11 = this.wallEnds;
- while(_g2 < _g11.length) {
- var _wall1 = _g11[_g2];
- ++_g2;
- retArray.push(_wall1.getStart());
- }
- return retArray;
- }
- ,attachStart: function(wall) {
- this.wallStarts.push(wall);
- }
- ,attachEnd: function(wall) {
- this.wallEnds.push(wall);
- }
- });
- var bp3d_model_Wall = function(c1,c2) {
- EventDispatcher.call(this);
- Global.board.create("segment",[c1.point,c2.point],{ strokeWidth : 5, strokeColor : "#666666", lineCap : "square", hightlight : false});
- this.start = c1;
- this.end = c2;
- this.start.attachStart(this);
- this.end.attachEnd(this);
- };
- bp3d_model_Wall.__super__ = EventDispatcher;
- bp3d_model_Wall.prototype = $extend(EventDispatcher.prototype,{
- setStart: function(corner) {
- this.start.detachWall(this);
- corner.attachStart(this);
- this.start = corner;
- }
- ,setEnd: function(corner) {
- this.end.detachWall(this);
- corner.attachEnd(this);
- this.end = corner;
- }
- ,getEnd: function() {
- return this.end;
- }
- ,getStart: function() {
- return this.start;
- }
- ,distanceFromWall: function(point) {
- return JXG.Math.Geometry.distPointLine(this.line,point);
- }
- ,remove: function() {
- }
- });
- var h2d_col_IPoint = function() { };
- var h2d_col_Point = function(x,y) {
- if(y == null) {
- y = 0.;
- }
- if(x == null) {
- x = 0.;
- }
- this.x = x;
- this.y = y;
- };
- var h2d_col__$Polygon_Polygon_$Impl_$ = {};
- h2d_col__$Polygon_Polygon_$Impl_$.contains = function(this1,p,isConvex) {
- if(isConvex == null) {
- isConvex = false;
- }
- if(isConvex) {
- var p1 = this1[this1.length - 1];
- var _g = 0;
- var _g1 = this1;
- while(_g < _g1.length) {
- var p2 = _g1[_g];
- ++_g;
- if((p2.x - p1.x) * (p.y - p1.y) - (p2.y - p1.y) * (p.x - p1.x) < 0) {
- return false;
- }
- p1 = p2;
- }
- return true;
- } else {
- var w = 0;
- var p11 = this1[this1.length - 1];
- var _g2 = 0;
- var _g11 = this1;
- while(_g2 < _g11.length) {
- var p21 = _g11[_g2];
- ++_g2;
- if(p21.y <= p.y) {
- if(p11.y > p.y && (p11.x - p21.x) * (p.y - p21.y) - (p11.y - p21.y) * (p.x - p21.x) > 0) {
- ++w;
- }
- } else if(p11.y <= p.y && (p11.x - p21.x) * (p.y - p21.y) - (p11.y - p21.y) * (p.x - p21.x) < 0) {
- --w;
- }
- p11 = p21;
- }
- return w != 0;
- }
- };
- var h2d_col_Segment = function() { };
- var haxe_IMap = function() { };
- var haxe_ds_StringMap = function() {
- this.h = { };
- };
- haxe_ds_StringMap.__interfaces__ = [haxe_IMap];
- haxe_ds_StringMap.prototype = {
- setReserved: function(key,value) {
- if(this.rh == null) {
- this.rh = { };
- }
- this.rh["$" + key] = value;
- }
- ,getReserved: function(key) {
- if(this.rh == null) {
- return null;
- } else {
- return this.rh["$" + key];
- }
- }
- ,existsReserved: function(key) {
- if(this.rh == null) {
- return false;
- }
- return this.rh.hasOwnProperty("$" + key);
- }
- };
- 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; }
- var __map_reserved = {};
- MNKLJLOIYOIYOIUOIUOI.board = { pan : { }, zoom : { }};
- MNKLJLOIYOIYOIUOIUOI.point = { };
- bp3d_Event.EVENT_ITEM_REMOVED = "ITEM_REMOVED_EVENT";
- Main.main();
- })(typeof exports != "undefined" ? exports : typeof window != "undefined" ? window : typeof self != "undefined" ? self : this);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement