Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.79 KB | None | 0 0
  1. (function ($hx_exports) { "use strict";
  2. function $extend(from, fields) {
  3. function Inherit() {} Inherit.prototype = from; var proto = new Inherit();
  4. for (var name in fields) proto[name] = fields[name];
  5. if( fields.toString !== Object.prototype.toString ) proto.toString = fields.toString;
  6. return proto;
  7. }
  8. var EventDispatcher = function() {
  9. };
  10. EventDispatcher.prototype = {
  11. dispatchEvent: function(event) {
  12. if(this._listeners == null) {
  13. return;
  14. }
  15. var listeners = this._listeners;
  16. var key = event.type;
  17. var listenerArray = __map_reserved[key] != null ? listeners.getReserved(key) : listeners.h[key];
  18. if(listenerArray != null) {
  19. event.target = this;
  20. var array = listenerArray.slice(0);
  21. var len = array.length;
  22. var _g = 0;
  23. while(_g < array.length) {
  24. var el = array[_g];
  25. ++_g;
  26. el.call(this,event);
  27. }
  28. }
  29. }
  30. };
  31. var Global = function() { };
  32. var HxOverrides = function() { };
  33. HxOverrides.remove = function(a,obj) {
  34. var i = a.indexOf(obj);
  35. if(i == -1) {
  36. return false;
  37. }
  38. a.splice(i,1);
  39. return true;
  40. };
  41. var Main = $hx_exports["Main"] = function() {
  42. };
  43. Main.init = function() {
  44. [1,2,3].map(function(e) {
  45. return e > 2;
  46. });
  47. MNKLJLOIYOIYOIUOIUOI.init();
  48. var t = new Test();
  49. t.test();
  50. };
  51. Main.main = function() {
  52. console.log("init haxe ");
  53. };
  54. var MNKLJLOIYOIYOIUOIUOI = $hx_exports["MNKLJLOIYOIYOIUOIUOI"] = function() { };
  55. MNKLJLOIYOIYOIUOIUOI.init = function() {
  56. };
  57. var Reflect = function() { };
  58. Reflect.field = function(o,field) {
  59. try {
  60. return o[field];
  61. } catch( e ) {
  62. return null;
  63. }
  64. };
  65. var Test = function() {
  66. };
  67. Test.prototype = {
  68. test: function() {
  69. var op = MNKLJLOIYOIYOIUOIUOI.board;
  70. op.axis = true;
  71. op.grid = true;
  72. op.showCopyright = false;
  73. op.pan.enabled = true;
  74. op.pan.needTwoFingers = true;
  75. op.pan.needShift = true;
  76. op.zoom.factorX = 1.25;
  77. op.zoom.factorY = 1.25;
  78. op.zoom.min = 0.8;
  79. op.zoom.max = 2;
  80. op.zoom.pinchHorizontal = true;
  81. op.zoom.pinchVertical = true;
  82. op.zoom.pinchSensitivity = 7;
  83. op.zoom.needShift = false;
  84. op.boundingBox = [-20,10,20,-10];
  85. this.board = JXG.JSXGraph.initBoard("box",op);
  86. Global.board = this.board;
  87. var a = "a";
  88. var b = "b";
  89. var c = "c";
  90. var d = "d";
  91. var e = "e";
  92. var f = "f";
  93. var g = "g";
  94. var h = "h";
  95. var points = [a,b,c,d,e,f,g,h];
  96. 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]];
  97. 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}};
  98. var cs = new haxe_ds_StringMap();
  99. var ps = [];
  100. var _g = 0;
  101. while(_g < points.length) {
  102. var p = points[_g];
  103. ++_g;
  104. var xy = Reflect.field(pointsPs,p);
  105. var c1 = new bp3d_model_Corner(xy.x,xy.y,{ fixed : false, snapToGrid : true});
  106. if(__map_reserved[p] != null) {
  107. cs.setReserved(p,c1);
  108. } else {
  109. cs.h[p] = c1;
  110. }
  111. ps.push(c1);
  112. }
  113. var _g1 = 0;
  114. while(_g1 < graph.length) {
  115. var line = graph[_g1];
  116. ++_g1;
  117. var key = line[0];
  118. var tmp = __map_reserved[key] != null ? cs.getReserved(key) : cs.h[key];
  119. var key1 = line[1];
  120. new bp3d_model_Wall(tmp,__map_reserved[key1] != null ? cs.getReserved(key1) : cs.h[key1]);
  121. }
  122. var fs = this.findRooms(ps);
  123. if(fs != null) {
  124. console.log(fs.length);
  125. }
  126. this.draw(fs);
  127. }
  128. ,_calculateTheta: function(previousCorner,currentCorner,nextCorner) {
  129. 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());
  130. return theta;
  131. }
  132. ,_removeDuplicateRooms: function(roomArray) {
  133. var results = [];
  134. var lookup = new haxe_ds_StringMap();
  135. var hashFunc = function(corner) {
  136. return corner.id;
  137. };
  138. var sep = "-";
  139. var str = "";
  140. var _g1 = 0;
  141. var _g = roomArray.length;
  142. while(_g1 < _g) {
  143. var i = _g1++;
  144. var add = true;
  145. var room = roomArray[i];
  146. var _g3 = 0;
  147. var _g2 = room.length;
  148. while(_g3 < _g2) {
  149. var j = _g3++;
  150. var roomShift = bp3d_core_Utils.cycle(room,j);
  151. str = bp3d_core_Utils.map(roomShift,hashFunc).join(sep);
  152. if(__map_reserved[str] != null ? lookup.existsReserved(str) : lookup.h.hasOwnProperty(str)) {
  153. add = false;
  154. }
  155. }
  156. if(add) {
  157. results.push(roomArray[i]);
  158. if(__map_reserved[str] != null) {
  159. lookup.setReserved(str,true);
  160. } else {
  161. lookup.h[str] = true;
  162. }
  163. }
  164. }
  165. return results;
  166. }
  167. ,_findTightestCycle: function(firstCorner,secondCorner) {
  168. var _gthis = this;
  169. var stack = [];
  170. var next = { corner : secondCorner, previousCorners : [firstCorner]};
  171. var visited = new haxe_ds_StringMap();
  172. var k = firstCorner.id;
  173. if(__map_reserved[k] != null) {
  174. visited.setReserved(k,true);
  175. } else {
  176. visited.h[k] = true;
  177. }
  178. while(next != null) {
  179. var currentCorner = [next.corner];
  180. var k1 = currentCorner[0].id;
  181. if(__map_reserved[k1] != null) {
  182. visited.setReserved(k1,true);
  183. } else {
  184. visited.h[k1] = true;
  185. }
  186. if(next.corner == firstCorner && currentCorner[0] != secondCorner) {
  187. return next.previousCorners;
  188. }
  189. var addToStack = [];
  190. var adjacentCorners = next.corner.adjacentCorners();
  191. var _g1 = 0;
  192. var _g = adjacentCorners.length;
  193. while(_g1 < _g) {
  194. var i = _g1++;
  195. var nextCorner = adjacentCorners[i];
  196. var tmp;
  197. var key = nextCorner.id;
  198. if(__map_reserved[key] != null ? visited.existsReserved(key) : visited.h.hasOwnProperty(key)) {
  199. tmp = !(nextCorner == firstCorner && currentCorner[0] != secondCorner);
  200. } else {
  201. tmp = false;
  202. }
  203. if(tmp) {
  204. continue;
  205. }
  206. addToStack.push(nextCorner);
  207. }
  208. var previousCorners = next.previousCorners.slice(0);
  209. previousCorners.push(currentCorner[0]);
  210. if(addToStack.length > 1) {
  211. var previousCorner = [next.previousCorners[next.previousCorners.length - 1]];
  212. addToStack.sort((function(previousCorner1,currentCorner1) {
  213. return function(a,b) {
  214. return (_gthis._calculateTheta(previousCorner1[0],currentCorner1[0],b) | 0) - (_gthis._calculateTheta(previousCorner1[0],currentCorner1[0],a) | 0);
  215. };
  216. })(previousCorner,currentCorner));
  217. }
  218. if(addToStack.length > 0) {
  219. var _g2 = 0;
  220. while(_g2 < addToStack.length) {
  221. var corner = addToStack[_g2];
  222. ++_g2;
  223. stack.push({ corner : corner, previousCorners : previousCorners});
  224. }
  225. }
  226. next = stack.pop();
  227. }
  228. return [];
  229. }
  230. ,getCentroid: function(polygon) {
  231. var center = [0.0,0.0];
  232. var len = polygon.vertices.length - 1;
  233. var _g1 = 0;
  234. var _g = len;
  235. while(_g1 < _g) {
  236. var i = _g1++;
  237. center[0] += polygon.vertices[i].coords.usrCoords[1];
  238. center[1] += polygon.vertices[i].coords.usrCoords[2];
  239. }
  240. if(len > 0) {
  241. center[0] /= len;
  242. center[1] /= len;
  243. } else {
  244. center = [NaN,NaN];
  245. }
  246. return center;
  247. }
  248. ,findRooms: function(corners) {
  249. var loops = [];
  250. var _g = 0;
  251. while(_g < corners.length) {
  252. var firstCorner = corners[_g];
  253. ++_g;
  254. var cs = firstCorner.adjacentCorners();
  255. var _g1 = 0;
  256. while(_g1 < cs.length) {
  257. var secondCorner = cs[_g1];
  258. ++_g1;
  259. loops.push(this._findTightestCycle(firstCorner,secondCorner));
  260. }
  261. }
  262. var uniqueLoops = this._removeDuplicateRooms(loops);
  263. var _result = uniqueLoops;
  264. var result = this.removeContain(_result);
  265. return result;
  266. }
  267. ,removeContain: function(array) {
  268. var polys = [];
  269. var _g = 0;
  270. while(_g < array.length) {
  271. var corners = array[_g];
  272. ++_g;
  273. var _g1 = [];
  274. var _g3 = 0;
  275. var _g2 = corners.length;
  276. while(_g3 < _g2) {
  277. var i = _g3++;
  278. _g1.push(corners[i].point2d);
  279. }
  280. var ps = _g1;
  281. var this1 = ps == null ? [] : ps;
  282. polys.push(this1);
  283. }
  284. var remove = [];
  285. var _g4 = 0;
  286. while(_g4 < polys.length) {
  287. var start = polys[_g4];
  288. ++_g4;
  289. var _g11 = 0;
  290. while(_g11 < polys.length) {
  291. var end = polys[_g11];
  292. ++_g11;
  293. if(start != end && start.length != end.length) {
  294. var tempArray = [start,end];
  295. tempArray.sort(function(a,b) {
  296. return a.length - b.length;
  297. });
  298. var len = 0;
  299. var _g2_l;
  300. var _g2_i;
  301. var _g2_a;
  302. _g2_i = 0;
  303. _g2_a = tempArray[0];
  304. _g2_l = _g2_a.length;
  305. while(_g2_i < _g2_l) {
  306. var detectpoint = _g2_a[_g2_i++];
  307. if(h2d_col__$Polygon_Polygon_$Impl_$.contains(tempArray[1],detectpoint)) {
  308. ++len;
  309. }
  310. if(len == tempArray[0].length) {
  311. remove.push(array[polys.indexOf(tempArray[1])]);
  312. }
  313. }
  314. }
  315. }
  316. }
  317. var _g5 = 0;
  318. while(_g5 < remove.length) {
  319. var el = remove[_g5];
  320. ++_g5;
  321. HxOverrides.remove(array,el);
  322. }
  323. polys = null;
  324. return array;
  325. }
  326. ,draw: function(array) {
  327. var _gthis = this;
  328. var polys = [];
  329. var _g = 0;
  330. while(_g < array.length) {
  331. var corners = array[_g];
  332. ++_g;
  333. var _g1 = [];
  334. var _g3 = 0;
  335. var _g2 = corners.length;
  336. while(_g3 < _g2) {
  337. var i = _g3++;
  338. _g1.push(corners[i].point2d);
  339. }
  340. var ps = _g1;
  341. var this1 = ps == null ? [] : ps;
  342. polys.push(this1);
  343. }
  344. var remove = [];
  345. var _g4 = 0;
  346. while(_g4 < polys.length) {
  347. var start = polys[_g4];
  348. ++_g4;
  349. var _g11 = 0;
  350. while(_g11 < polys.length) {
  351. var end = polys[_g11];
  352. ++_g11;
  353. if(start != end && start.length != end.length) {
  354. var tempArray = [start,end];
  355. tempArray.sort(function(a,b) {
  356. return a.length - b.length;
  357. });
  358. var len = 0;
  359. var _g2_l;
  360. var _g2_i;
  361. var _g2_a;
  362. _g2_i = 0;
  363. _g2_a = tempArray[0];
  364. _g2_l = _g2_a.length;
  365. while(_g2_i < _g2_l) {
  366. var detectpoint = _g2_a[_g2_i++];
  367. if(h2d_col__$Polygon_Polygon_$Impl_$.contains(tempArray[1],detectpoint)) {
  368. ++len;
  369. }
  370. if(len == tempArray[0].length) {
  371. remove.push(array[polys.indexOf(tempArray[1])]);
  372. }
  373. }
  374. }
  375. }
  376. }
  377. var _g5 = 0;
  378. while(_g5 < remove.length) {
  379. var el = remove[_g5];
  380. ++_g5;
  381. HxOverrides.remove(array,el);
  382. }
  383. var _g6 = 0;
  384. while(_g6 < array.length) {
  385. var corners1 = array[_g6];
  386. ++_g6;
  387. var _g12 = [];
  388. var _g31 = 0;
  389. var _g21 = corners1.length;
  390. while(_g31 < _g21) {
  391. var i1 = _g31++;
  392. _g12.push(corners1[i1].point);
  393. }
  394. var ps1 = _g12;
  395. var pol = [Global.board.create("polygon",ps1,{ hasInnerPoints : true, fillColor : "gray"})];
  396. Global.board.create("text",[(function(pol1) {
  397. return function(x) {
  398. return _gthis.getCentroid(pol1[0])[0];
  399. };
  400. })(pol),(function(pol2) {
  401. return function(x1) {
  402. return _gthis.getCentroid(pol2[0])[1];
  403. };
  404. })(pol),(function(pol3) {
  405. return function() {
  406. return "面积" + Math.ceil(pol3[0].Area());
  407. };
  408. })(pol)],{ });
  409. }
  410. }
  411. };
  412. var bp3d_Event = function() { };
  413. var bp3d_core_Utils = function() { };
  414. bp3d_core_Utils.angle = function(x1,y1,x2,y2) {
  415. var tDot = x1 * x2 + y1 * y2;
  416. var tDet = x1 * y2 - y1 * x2;
  417. var tAngle = -Math.atan2(tDet,tDot);
  418. return tAngle;
  419. };
  420. bp3d_core_Utils.angle2pi = function(x1,y1,x2,y2) {
  421. var tTheta = bp3d_core_Utils.angle(x1,y1,x2,y2);
  422. if(tTheta < 0) {
  423. tTheta += 2 * Math.PI;
  424. }
  425. return tTheta;
  426. };
  427. bp3d_core_Utils.map = function(array,func) {
  428. var tResult = [];
  429. var _g = 0;
  430. while(_g < array.length) {
  431. var element = array[_g];
  432. ++_g;
  433. tResult.push(func(element));
  434. }
  435. return tResult;
  436. };
  437. bp3d_core_Utils.cycle = function(arr,shift) {
  438. var tReturn = arr.slice(0);
  439. var tI = 0;
  440. while(tI < shift) {
  441. var tmp = tReturn.shift();
  442. tReturn.push(tmp);
  443. ++tI;
  444. }
  445. return tReturn;
  446. };
  447. var bp3d_model_Corner = function(xx,yy,propery) {
  448. this.wallEnds = [];
  449. this.wallStarts = [];
  450. EventDispatcher.call(this);
  451. this.set_x(xx);
  452. this.set_y(yy);
  453. this.set_point(Global.board.create("point",[xx,yy],propery));
  454. this.point2d = new h2d_col_Point(this.get_x(),this.get_y());
  455. this.id = this.point.id;
  456. this.name = this.point.name;
  457. this.point.on("move",$bind(this,this.onMove));
  458. };
  459. bp3d_model_Corner.__super__ = EventDispatcher;
  460. bp3d_model_Corner.prototype = $extend(EventDispatcher.prototype,{
  461. get_x: function() {
  462. return this.x;
  463. }
  464. ,set_x: function(x) {
  465. return this.x = x;
  466. }
  467. ,get_y: function() {
  468. return this.y;
  469. }
  470. ,set_y: function(y) {
  471. return this.y = y;
  472. }
  473. ,set_point: function(p) {
  474. return this.point = p;
  475. }
  476. ,onMove: function(e) {
  477. }
  478. ,detachWall: function(wall) {
  479. HxOverrides.remove(this.wallStarts,wall);
  480. HxOverrides.remove(this.wallEnds,wall);
  481. if(this.wallStarts.length == 0 && this.wallEnds.length == 0) {
  482. this.remove();
  483. }
  484. }
  485. ,remove: function() {
  486. this.dispatchEvent({ event : bp3d_Event.EVENT_ITEM_REMOVED, target : this});
  487. }
  488. ,adjacentCorners: function() {
  489. var retArray = [];
  490. var _g = 0;
  491. var _g1 = this.wallStarts;
  492. while(_g < _g1.length) {
  493. var _wall = _g1[_g];
  494. ++_g;
  495. retArray.push(_wall.getEnd());
  496. }
  497. var _g2 = 0;
  498. var _g11 = this.wallEnds;
  499. while(_g2 < _g11.length) {
  500. var _wall1 = _g11[_g2];
  501. ++_g2;
  502. retArray.push(_wall1.getStart());
  503. }
  504. return retArray;
  505. }
  506. ,attachStart: function(wall) {
  507. this.wallStarts.push(wall);
  508. }
  509. ,attachEnd: function(wall) {
  510. this.wallEnds.push(wall);
  511. }
  512. });
  513. var bp3d_model_Wall = function(c1,c2) {
  514. EventDispatcher.call(this);
  515. Global.board.create("segment",[c1.point,c2.point],{ strokeWidth : 5, strokeColor : "#666666", lineCap : "square", hightlight : false});
  516. this.start = c1;
  517. this.end = c2;
  518. this.start.attachStart(this);
  519. this.end.attachEnd(this);
  520. };
  521. bp3d_model_Wall.__super__ = EventDispatcher;
  522. bp3d_model_Wall.prototype = $extend(EventDispatcher.prototype,{
  523. setStart: function(corner) {
  524. this.start.detachWall(this);
  525. corner.attachStart(this);
  526. this.start = corner;
  527. }
  528. ,setEnd: function(corner) {
  529. this.end.detachWall(this);
  530. corner.attachEnd(this);
  531. this.end = corner;
  532. }
  533. ,getEnd: function() {
  534. return this.end;
  535. }
  536. ,getStart: function() {
  537. return this.start;
  538. }
  539. ,distanceFromWall: function(point) {
  540. return JXG.Math.Geometry.distPointLine(this.line,point);
  541. }
  542. ,remove: function() {
  543. }
  544. });
  545. var h2d_col_IPoint = function() { };
  546. var h2d_col_Point = function(x,y) {
  547. if(y == null) {
  548. y = 0.;
  549. }
  550. if(x == null) {
  551. x = 0.;
  552. }
  553. this.x = x;
  554. this.y = y;
  555. };
  556. var h2d_col__$Polygon_Polygon_$Impl_$ = {};
  557. h2d_col__$Polygon_Polygon_$Impl_$.contains = function(this1,p,isConvex) {
  558. if(isConvex == null) {
  559. isConvex = false;
  560. }
  561. if(isConvex) {
  562. var p1 = this1[this1.length - 1];
  563. var _g = 0;
  564. var _g1 = this1;
  565. while(_g < _g1.length) {
  566. var p2 = _g1[_g];
  567. ++_g;
  568. if((p2.x - p1.x) * (p.y - p1.y) - (p2.y - p1.y) * (p.x - p1.x) < 0) {
  569. return false;
  570. }
  571. p1 = p2;
  572. }
  573. return true;
  574. } else {
  575. var w = 0;
  576. var p11 = this1[this1.length - 1];
  577. var _g2 = 0;
  578. var _g11 = this1;
  579. while(_g2 < _g11.length) {
  580. var p21 = _g11[_g2];
  581. ++_g2;
  582. if(p21.y <= p.y) {
  583. if(p11.y > p.y && (p11.x - p21.x) * (p.y - p21.y) - (p11.y - p21.y) * (p.x - p21.x) > 0) {
  584. ++w;
  585. }
  586. } else if(p11.y <= p.y && (p11.x - p21.x) * (p.y - p21.y) - (p11.y - p21.y) * (p.x - p21.x) < 0) {
  587. --w;
  588. }
  589. p11 = p21;
  590. }
  591. return w != 0;
  592. }
  593. };
  594. var h2d_col_Segment = function() { };
  595. var haxe_IMap = function() { };
  596. var haxe_ds_StringMap = function() {
  597. this.h = { };
  598. };
  599. haxe_ds_StringMap.__interfaces__ = [haxe_IMap];
  600. haxe_ds_StringMap.prototype = {
  601. setReserved: function(key,value) {
  602. if(this.rh == null) {
  603. this.rh = { };
  604. }
  605. this.rh["$" + key] = value;
  606. }
  607. ,getReserved: function(key) {
  608. if(this.rh == null) {
  609. return null;
  610. } else {
  611. return this.rh["$" + key];
  612. }
  613. }
  614. ,existsReserved: function(key) {
  615. if(this.rh == null) {
  616. return false;
  617. }
  618. return this.rh.hasOwnProperty("$" + key);
  619. }
  620. };
  621. var $_, $fid = 0;
  622. 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; }
  623. var __map_reserved = {};
  624. MNKLJLOIYOIYOIUOIUOI.board = { pan : { }, zoom : { }};
  625. MNKLJLOIYOIYOIUOIUOI.point = { };
  626. bp3d_Event.EVENT_ITEM_REMOVED = "ITEM_REMOVED_EVENT";
  627. Main.main();
  628. })(typeof exports != "undefined" ? exports : typeof window != "undefined" ? window : typeof self != "undefined" ? self : this);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement