Geometrize Worker

Turn your Image into Lines and Circles!

当前为 2024-12-19 提交的版本,查看 最新版本

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.cn-greasyfork.org/scripts/521159/1505877/Geometrize%20Worker.js

  1. // ==UserScript==
  2. // @name Geometrize Worker
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.0.5
  5. // @description Turn your Image into Lines and Circles!
  6. // @homepage https://drawaria.online/profile/?uid=63196790-c7da-11ec-8266-c399f90709b7
  7. // @author ≺ᴄᴜʙᴇ³≻
  8. // @match https://drawaria.online/
  9. // @match https://drawaria.online/test
  10. // @match https://drawaria.online/room/*
  11. // @icon https://www.google.com/s2/favicons?sz=64&domain=greasyfork.org
  12. // @grant none
  13. // @license GNU GPLv3
  14. // ==/UserScript==
  15.  
  16. (function ($hx_exports, $global, worker_code) {
  17. "use strict";
  18. $hx_exports["geometrize"] = $hx_exports["geometrize"] || {};
  19. $hx_exports["geometrize"]["bitmap"] = $hx_exports["geometrize"]["bitmap"] || {};
  20. $hx_exports["geometrize"]["exporter"] = $hx_exports["geometrize"]["exporter"] || {};
  21. $hx_exports["geometrize"]["runner"] = $hx_exports["geometrize"]["runner"] || {};
  22. $hx_exports["geometrize"]["shape"] = $hx_exports["geometrize"]["shape"] || {};
  23. function $extend(from, fields) {
  24. var proto = Object.create(from);
  25. for (var name in fields) proto[name] = fields[name];
  26. if (fields.toString !== Object.prototype.toString) proto.toString = fields.toString;
  27. return proto;
  28. }
  29. var CanvasTools = function () {};
  30. CanvasTools.__name__ = true;
  31. CanvasTools.downScaleCanvas = function (cv, scale) {
  32. if (scale <= 0.0 || scale >= 1.0) {
  33. throw haxe_Exception.thrown("Scale must be a positive number < 1");
  34. }
  35. var sqScale = scale * scale;
  36. var sw = cv.width;
  37. var sh = cv.height;
  38. var tw = (sw * scale) | 0;
  39. var th = (sh * scale) | 0;
  40. var sx = 0;
  41. var sy = 0;
  42. var sIndex = 0;
  43. var tx = 0;
  44. var ty = 0;
  45. var yIndex = 0;
  46. var tIndex = 0;
  47. var tX = 0;
  48. var tY = 0;
  49. var w = 0.0;
  50. var nw = 0.0;
  51. var wx = 0.0;
  52. var nwx = 0.0;
  53. var wy = 0.0;
  54. var nwy = 0.0;
  55. var crossX = false;
  56. var crossY = false;
  57. var sBuffer = cv.getContext("2d").getImageData(0, 0, sw, sh).data;
  58. var this1 = new Float32Array(3 * tw * th);
  59. var tBuffer = this1;
  60. var sR = 0.0;
  61. var sG = 0.0;
  62. var sB = 0.0;
  63. while (sy < sh) {
  64. ty = (sy * scale) | 0;
  65. tY = ty | 0;
  66. yIndex = (3 * tY * tw) | 0;
  67. crossY = tY != ((ty + scale) | 0);
  68. if (crossY) {
  69. wy = tY + 1 - ty;
  70. nwy = ty + scale - tY - 1;
  71. }
  72. sx = 0;
  73. while (sx < sw) {
  74. tx = (sx * scale) | 0;
  75. tX = tx | 0;
  76. tIndex = (yIndex + tX * 3) | 0;
  77. crossX = tX != Math.floor(tx + scale);
  78. if (crossX) {
  79. wx = tX + 1 - tx;
  80. nwx = (tx + scale - tX - 1) | 0;
  81. }
  82. sR = sBuffer[sIndex];
  83. sG = sBuffer[sIndex + 1];
  84. sB = sBuffer[sIndex + 2];
  85. if (!crossX && !crossY) {
  86. tBuffer[tIndex] += sR * sqScale;
  87. tBuffer[tIndex + 1] += sG * sqScale;
  88. tBuffer[tIndex + 2] += sB * sqScale;
  89. } else if (crossX && !crossY) {
  90. w = wx * scale;
  91. tBuffer[tIndex] += sR * w;
  92. tBuffer[tIndex + 1] += sG * w;
  93. tBuffer[tIndex + 2] += sB * w;
  94. nw = nwx * scale;
  95. tBuffer[tIndex + 3] += sR * nw;
  96. tBuffer[tIndex + 4] += sG * nw;
  97. tBuffer[tIndex + 5] += sB * nw;
  98. } else if (crossY && !crossX) {
  99. w = wy * scale;
  100. tBuffer[tIndex] += sR * w;
  101. tBuffer[tIndex + 1] += sG * w;
  102. tBuffer[tIndex + 2] += sB * w;
  103. nw = nwy * scale;
  104. tBuffer[tIndex + 3 * tw] += sR * nw;
  105. tBuffer[tIndex + 3 * tw + 1] += sG * nw;
  106. tBuffer[tIndex + 3 * tw + 2] += sB * nw;
  107. } else {
  108. w = wx * wy;
  109. tBuffer[tIndex] += sR * w;
  110. tBuffer[tIndex + 1] += sG * w;
  111. tBuffer[tIndex + 2] += sB * w;
  112. nw = nwx * wy;
  113. tBuffer[tIndex + 3] += sR * nw;
  114. tBuffer[tIndex + 4] += sG * nw;
  115. tBuffer[tIndex + 5] += sB * nw;
  116. nw = wx * nwy;
  117. tBuffer[tIndex + 3 * tw] += sR * nw;
  118. tBuffer[tIndex + 3 * tw + 1] += sG * nw;
  119. tBuffer[tIndex + 3 * tw + 2] += sB * nw;
  120. nw = nwx * nwy;
  121. tBuffer[tIndex + 3 * tw + 3] += sR * nw;
  122. tBuffer[tIndex + 3 * tw + 4] += sG * nw;
  123. tBuffer[tIndex + 3 * tw + 5] += sB * nw;
  124. }
  125. sIndex += 4;
  126. ++sx;
  127. }
  128. ++sy;
  129. }
  130. var result = window.document.createElement("canvas");
  131. result.width = tw;
  132. result.height = th;
  133. var resultContext = result.getContext("2d");
  134. var resultImage = resultContext.getImageData(0, 0, tw, th);
  135. var tByteBuffer = resultImage.data;
  136. var pxIndex = 0;
  137. sIndex = 0;
  138. tIndex = 0;
  139. while (pxIndex < tw * th) {
  140. tByteBuffer[tIndex] = Math.ceil(tBuffer[sIndex]);
  141. tByteBuffer[tIndex + 1] = Math.ceil(tBuffer[sIndex + 1]);
  142. tByteBuffer[tIndex + 2] = Math.ceil(tBuffer[sIndex + 2]);
  143. tByteBuffer[tIndex + 3] = 255;
  144. sIndex += 3;
  145. tIndex += 4;
  146. ++pxIndex;
  147. }
  148. resultContext.putImageData(resultImage, 0, 0);
  149. return result;
  150. };
  151. var GeometrizeWorkerInterface = function () {
  152. var _gthis = this;
  153. // this.worker = new Worker("js/geometrize_worker.js");
  154. // this.worker = new Worker("https://www.samcodes.co.uk/project/geometrize-haxe-web/js/geometrize_worker.js");
  155. // this.worker = new Worker("/userscripts/geometrize_worker.js");
  156. this.worker = new Worker(window.URL.createObjectURL(new Blob([worker_code], { type: "text/javascript" })));
  157. console.log(this.worker);
  158. this.worker.onmessage = function (message) {
  159. _gthis.onMessage(message.data);
  160. };
  161. };
  162. GeometrizeWorkerInterface.__name__ = true;
  163. GeometrizeWorkerInterface.prototype = {
  164. postMessage: function (message) {
  165. this.worker.postMessage(message);
  166. },
  167. terminate: function () {
  168. this.worker.terminate();
  169. },
  170. onMessage: function (message) {},
  171. };
  172. var HxOverrides = function () {};
  173. HxOverrides.__name__ = true;
  174. HxOverrides.remove = function (a, obj) {
  175. var i = a.indexOf(obj);
  176. if (i == -1) {
  177. return false;
  178. }
  179. a.splice(i, 1);
  180. return true;
  181. };
  182. HxOverrides.now = function () {
  183. return Date.now();
  184. };
  185. var Main = function () {
  186. this.targetImage = null;
  187. this.shapeJsonData = [];
  188. this.shapeSvgData = [];
  189. this.shapeMutationsPerStep = 100;
  190. this.candidateShapesPerStep = 50;
  191. this.initialBackgroundOpacity = 255;
  192. this.shapeOpacity = 128;
  193. this.shapeTypes = geometrize_ArraySet.create([5, 6]);
  194. this.maxInputImageSize = 768;
  195. window.addEventListener("GeometrizeInitialize", $bind(this, this.onWindowLoaded));
  196. // window.onload = $bind(this, this.onWindowLoaded);
  197. };
  198. Main.__name__ = true;
  199. Main.main = function () {
  200. var main = new Main();
  201. };
  202. Main.prototype = {
  203. get_shapeCount: function () {
  204. return this.shapeSvgData.length;
  205. },
  206. get_maxShapeCountLimit: function () {
  207. var text = Main.maxShapesCapTextEdit.value;
  208. var value = Std.parseInt(text);
  209. if (value != null) {
  210. return value;
  211. }
  212. return 3000;
  213. },
  214. set_maxShapeCountLimit: function (limit) {
  215. Main.maxShapesCapTextEdit.value = limit == null ? "null" : "" + limit;
  216. return limit;
  217. },
  218. onWindowLoaded: function () {
  219. var _gthis = this;
  220. Main.runPauseButton = window.document.getElementById("runpausebutton");
  221. Main.stepButton = window.document.getElementById("stepbutton");
  222. Main.openImageFileInput = window.document.getElementById("openimageinput");
  223. Main.randomImageButton = window.document.getElementById("randomimagebutton");
  224. Main.resetButton = window.document.getElementById("resetbutton");
  225. Main.saveImageButton = window.document.getElementById("saveimagebutton");
  226. Main.saveSvgButton = window.document.getElementById("savesvgbutton");
  227. Main.saveJsonButton = window.document.getElementById("savejsonbutton");
  228. Main.rectanglesCheckbox = window.document.getElementById("rectangles");
  229. Main.rotatedRectanglesCheckbox = window.document.getElementById("rotatedrectangles");
  230. Main.trianglesCheckbox = window.document.getElementById("triangles");
  231. Main.ellipsesCheckbox = window.document.getElementById("ellipses");
  232. Main.rotatedEllipsesCheckbox = window.document.getElementById("rotatedellipses");
  233. Main.circlesCheckbox = window.document.getElementById("circles");
  234. Main.linesCheckbox = window.document.getElementById("lines");
  235. Main.quadraticBeziersCheckbox = window.document.getElementById("quadraticbeziers");
  236. Main.shapeOpacitySlider = window.document.getElementById("shapeopacity");
  237. Main.initialBackgroundOpacitySlider = window.document.getElementById("initialbackgroundopacity");
  238. Main.randomShapesPerStepSlider = window.document.getElementById("randomshapesperstep");
  239. Main.shapeMutationsPerStepSlider = window.document.getElementById("shapemutationsperstep");
  240. Main.shapesAddedText = window.document.getElementById("shapesaddedtext");
  241. Main.maxShapesCapTextEdit = window.document.getElementById("maxshapescaptextedit");
  242. Main.currentSvgContainer = window.document.getElementById("currentsvgcontainer");
  243. Main.sampleImagesContainer = window.document.getElementById("sampleimages");
  244. Main.defaultImageElement = window.document.getElementById("defaultimage");
  245.  
  246. _gthis.shapeOpacity = 255;
  247. _gthis.initialBackgroundOpacity = 0;
  248.  
  249. // noUiSlider.create(Main.shapeOpacitySlider, {
  250. // start: [this.shapeOpacity],
  251. // connect: "lower",
  252. // range: { min: [1, 1], max: [255] },
  253. // pips: { mode: "range", density: 10 },
  254. // });
  255. // this.createTooltips(Main.shapeOpacitySlider);
  256. // Main.shapeOpacitySlider.noUiSlider.on("change", function (values, handle, rawValues) {
  257. // _gthis.shapeOpacity = values[handle] | 0;
  258. // });
  259. // Main.shapeOpacitySlider.noUiSlider.on("update", function (values, handle, rawValues) {
  260. // _gthis.updateTooltips(Main.shapeOpacitySlider, handle, values[handle] | 0);
  261. // });
  262. // noUiSlider.create(Main.initialBackgroundOpacitySlider, {
  263. // start: [this.initialBackgroundOpacity],
  264. // connect: "lower",
  265. // range: { min: [0, 1], max: [255] },
  266. // pips: { mode: "range", density: 10 },
  267. // });
  268. // this.createTooltips(Main.initialBackgroundOpacitySlider);
  269. // Main.initialBackgroundOpacitySlider.noUiSlider.on("change", function (values, handle, rawValues) {
  270. // _gthis.initialBackgroundOpacity = values[handle] | 0;
  271. // });
  272. // Main.initialBackgroundOpacitySlider.noUiSlider.on("update", function (values, handle, rawValues) {
  273. // _gthis.updateTooltips(Main.initialBackgroundOpacitySlider, handle, values[handle] | 0);
  274. // });
  275. // noUiSlider.create(Main.randomShapesPerStepSlider, {
  276. // start: [this.candidateShapesPerStep],
  277. // connect: "lower",
  278. // range: { min: [10, 1], max: [300] },
  279. // pips: { mode: "range", density: 10 },
  280. // });
  281. // this.createTooltips(Main.randomShapesPerStepSlider);
  282. // Main.randomShapesPerStepSlider.noUiSlider.on("change", function (values, handle, rawValues) {
  283. // _gthis.candidateShapesPerStep = values[handle] | 0;
  284. // });
  285. // Main.randomShapesPerStepSlider.noUiSlider.on("update", function (values, handle, rawValues) {
  286. // _gthis.updateTooltips(Main.randomShapesPerStepSlider, handle, values[handle] | 0);
  287. // });
  288. // noUiSlider.create(Main.shapeMutationsPerStepSlider, {
  289. // start: [this.shapeMutationsPerStep],
  290. // connect: "lower",
  291. // range: { min: [10, 1], max: [300] },
  292. // pips: { mode: "range", density: 10 },
  293. // });
  294. // this.createTooltips(Main.shapeMutationsPerStepSlider);
  295. // Main.shapeMutationsPerStepSlider.noUiSlider.on("change", function (values, handle, rawValues) {
  296. // _gthis.shapeMutationsPerStep = values[handle] | 0;
  297. // });
  298. // Main.shapeMutationsPerStepSlider.noUiSlider.on("update", function (values, handle, rawValues) {
  299. // _gthis.updateTooltips(Main.shapeMutationsPerStepSlider, handle, values[handle] | 0);
  300. // });
  301. var _gthis1 = this;
  302. Main.runPauseButton.addEventListener(
  303. "click",
  304. function () {
  305. _gthis1.set_running(!_gthis1.running);
  306. },
  307. false
  308. );
  309. Main.openImageFileInput.addEventListener(
  310. "change",
  311. function (e) {
  312. if (Main.openImageFileInput.files == null || Main.openImageFileInput.files.length == 0) {
  313. return;
  314. }
  315. var file = Main.openImageFileInput.files[0];
  316. var fileReader = new FileReader();
  317. fileReader.onload = function (e) {
  318. var image = new Image();
  319. image.onload = function (e) {
  320. var canvas = _gthis1.imageToCanvas(image);
  321. while (canvas.width > _gthis1.maxInputImageSize || canvas.height > _gthis1.maxInputImageSize) canvas = CanvasTools.downScaleCanvas(canvas, 0.5);
  322. _gthis1.targetImage = _gthis1.canvasToBitmap(canvas);
  323. _gthis1.onTargetImageChanged();
  324. };
  325. image.src = fileReader.result;
  326. };
  327. fileReader.readAsDataURL(file);
  328. Main.openImageFileInput.files = null;
  329. },
  330. false
  331. );
  332. Main.stepButton.addEventListener(
  333. "click",
  334. function () {
  335. _gthis1.stepRunner();
  336. },
  337. false
  338. );
  339. Main.randomImageButton.addEventListener(
  340. "click",
  341. function () {
  342. var image = new Image();
  343. image.onload = function () {
  344. Main.sampleImagesContainer.appendChild(image);
  345. var _gthis = _gthis1;
  346. var tmp = _gthis1.imageToCanvas(image);
  347. _gthis1.targetImage = _gthis.canvasToBitmap(tmp);
  348. _gthis1.onTargetImageChanged();
  349. };
  350. var tmp = Main.imagesToGeometrize;
  351. var tmp1 = Math.floor(Math.random() * Main.imagesToGeometrize.length);
  352. image.src = tmp[tmp1];
  353. },
  354. false
  355. );
  356. Main.resetButton.addEventListener(
  357. "click",
  358. function () {
  359. _gthis1.targetImage = _gthis1.targetImage;
  360. _gthis1.onTargetImageChanged();
  361. },
  362. false
  363. );
  364. Main.saveImageButton.addEventListener(
  365. "click",
  366. function (e) {
  367. var svgData = "data:image/svg+xml;base64," + window.btoa(_gthis1.makeSvgData());
  368. var svgImage = new Image();
  369. svgImage.onload = function () {
  370. var canvas = _gthis1.imageToCanvas(svgImage);
  371. if (canvas.msToBlob != null) {
  372. var blob = canvas.msToBlob();
  373. var navigator = window.navigator;
  374. navigator.msSaveBlob(blob, "geometrized_image.png");
  375. } else {
  376. var data = canvas.toDataURL("image/png").replace("image/png", "image/octet-stream");
  377. var tempLink = window.document.createElement("a");
  378. tempLink.href = data;
  379. tempLink.download = "geometrized_image.png";
  380. window.document.body.appendChild(tempLink);
  381. tempLink.click();
  382. window.document.body.removeChild(tempLink);
  383. }
  384. };
  385. svgImage.setAttribute("src", svgData);
  386. },
  387. false
  388. );
  389. var saveBlob = function (data, dataType, filename, anchor) {
  390. var blob = new Blob([data], { type: dataType });
  391. var navigator = window.navigator;
  392. if (navigator.msSaveBlob != null) {
  393. navigator.msSaveBlob(blob, filename);
  394. } else {
  395. var dataUrl = URL.createObjectURL(blob);
  396. anchor.download = filename;
  397. anchor.href = dataUrl;
  398. }
  399. };
  400. Main.saveSvgButton.addEventListener(
  401. "click",
  402. function (e) {
  403. saveBlob(Main.currentSvgContainer.innerHTML, "image/svg+xml;charset=utf-8", "geometrized_svg.svg", Main.saveSvgButton);
  404. },
  405. false
  406. );
  407. Main.saveJsonButton.addEventListener(
  408. "click",
  409. function (e) {
  410. saveBlob("[\r\n" + _gthis1.shapeJsonData.join(",\r\n") + "\r\n]", "data:text/json;charset=utf-8", "geometrized_json.json", Main.saveJsonButton);
  411. },
  412. false
  413. );
  414. var setShapeOption = function (option, enable) {
  415. if (enable) {
  416. geometrize_ArraySet.add(_gthis1.shapeTypes, option);
  417. } else {
  418. HxOverrides.remove(_gthis1.shapeTypes, option);
  419. }
  420. };
  421. Main.rectanglesCheckbox.addEventListener(
  422. "click",
  423. function () {
  424. setShapeOption(0, Main.rectanglesCheckbox.checked);
  425. },
  426. false
  427. );
  428. Main.rotatedRectanglesCheckbox.addEventListener(
  429. "click",
  430. function () {
  431. setShapeOption(1, Main.rotatedRectanglesCheckbox.checked);
  432. },
  433. false
  434. );
  435. Main.trianglesCheckbox.addEventListener(
  436. "click",
  437. function () {
  438. setShapeOption(2, Main.trianglesCheckbox.checked);
  439. },
  440. false
  441. );
  442. Main.ellipsesCheckbox.addEventListener(
  443. "click",
  444. function () {
  445. setShapeOption(3, Main.ellipsesCheckbox.checked);
  446. },
  447. false
  448. );
  449. Main.rotatedEllipsesCheckbox.addEventListener(
  450. "click",
  451. function () {
  452. setShapeOption(4, Main.rotatedEllipsesCheckbox.checked);
  453. },
  454. false
  455. );
  456. Main.circlesCheckbox.addEventListener(
  457. "click",
  458. function () {
  459. setShapeOption(5, Main.circlesCheckbox.checked);
  460. },
  461. false
  462. );
  463. Main.linesCheckbox.addEventListener(
  464. "click",
  465. function () {
  466. setShapeOption(6, Main.linesCheckbox.checked);
  467. },
  468. false
  469. );
  470. Main.quadraticBeziersCheckbox.addEventListener(
  471. "click",
  472. function () {
  473. setShapeOption(7, Main.quadraticBeziersCheckbox.checked);
  474. },
  475. false
  476. );
  477. this.set_maxShapeCountLimit(1000);
  478. if (this.worker != null) {
  479. this.worker.terminate();
  480. }
  481. this.worker = new GeometrizeWorkerInterface();
  482. this.worker.onMessage = $bind(this, this.onWorkerMessageReceived);
  483. // this.targetImage = this.createDefaultBitmap();
  484. // this.onTargetImageChanged();
  485. this.set_running(false);
  486.  
  487. globalThis["geometrize"] = this;
  488. },
  489. createTooltips: function (slider) {
  490. var tipHandles = slider.getElementsByClassName("noUi-handle");
  491. var _g = 0;
  492. var _g1 = tipHandles.length;
  493. while (_g < _g1) {
  494. var i = _g++;
  495. var div = window.document.createElement("div");
  496. div.className += "tooltip";
  497. tipHandles[i].appendChild(div);
  498. this.updateTooltips(slider, i, 0);
  499. }
  500. },
  501. updateTooltips: function (slider, handleIdx, value) {
  502. var tipHandles = slider.getElementsByClassName("noUi-handle");
  503. tipHandles[handleIdx].innerHTML = "<span class='tooltip'>" + (value == null ? "null" : "" + value) + "</span>";
  504. },
  505. checkStopConditions: function () {
  506. if (this.get_shapeCount() >= this.get_maxShapeCountLimit()) {
  507. this.set_running(false);
  508. }
  509. },
  510. stepRunner: function () {
  511. var options = {
  512. shapeTypes: this.shapeTypes.length == 0 ? [2] : geometrize_ArraySet.toArray(this.shapeTypes),
  513. alpha: this.shapeOpacity | 0,
  514. candidateShapesPerStep: this.candidateShapesPerStep,
  515. shapeMutationsPerStep: this.shapeMutationsPerStep,
  516. };
  517. this.worker.postMessage({ id: "should_step", data: options });
  518. },
  519. onWorkerMessageReceived: function (message) {
  520. switch (message.id) {
  521. case "did_set_target_image":
  522. break;
  523. case "did_step":
  524. this.shapeJsonData.push(message.jsonData);
  525. this.appendSvgShapeData(message.svgData);
  526. this.checkStopConditions();
  527. break;
  528. }
  529. if (this.running) {
  530. this.stepRunner();
  531. }
  532. },
  533. appendSvgShapeData: function (data) {
  534. this.shapeSvgData.push(data);
  535. var tmp = this.get_shapeCount();
  536. Main.shapesAddedText.innerHTML = Std.string(tmp);
  537. var data = this.makeSvgData();
  538. this.setSvgElement(data);
  539. },
  540. setSvgElement: function (svgCode) {
  541. Main.currentSvgContainer.innerHTML = svgCode;
  542. },
  543. canvasToBitmap: function (canvas) {
  544. var context = canvas.getContext("2d", null);
  545. var imageData = context.getImageData(0, 0, canvas.width, canvas.height);
  546. var bytesData = new haxe_io_Bytes(new ArrayBuffer(imageData.data.length));
  547. var _g = 0;
  548. var _g1 = bytesData.length;
  549. while (_g < _g1) {
  550. var i = _g++;
  551. bytesData.b[i] = imageData.data[i];
  552. }
  553. var w = canvas.width;
  554. var h = canvas.height;
  555. var bitmap = new geometrize_bitmap_Bitmap();
  556. if (bytesData == null) {
  557. throw haxe_Exception.thrown("FAIL: bytes != null");
  558. }
  559. var actual = bytesData.length;
  560. var expected = w * h * 4;
  561. if (actual != expected) {
  562. throw haxe_Exception.thrown("FAIL: values are not equal (expected: " + expected + ", actual: " + actual + ")");
  563. }
  564. bitmap.width = w;
  565. bitmap.height = h;
  566. var this1 = new Array((bytesData.length / 4) | 0);
  567. bitmap.data = this1;
  568. var i = 0;
  569. var x = 0;
  570. while (i < bytesData.length) {
  571. var red = bytesData.b[i];
  572. var green = bytesData.b[i + 1];
  573. var blue = bytesData.b[i + 2];
  574. var alpha = bytesData.b[i + 3];
  575. bitmap.data[x] =
  576. ((red < 0 ? 0 : red > 255 ? 255 : red) << 24) +
  577. ((green < 0 ? 0 : green > 255 ? 255 : green) << 16) +
  578. ((blue < 0 ? 0 : blue > 255 ? 255 : blue) << 8) +
  579. (alpha < 0 ? 0 : alpha > 255 ? 255 : alpha);
  580. i += 4;
  581. ++x;
  582. }
  583. var bitmap1 = bitmap;
  584. return bitmap1;
  585. },
  586. imageToCanvas: function (image) {
  587. var canvas = window.document.createElement("canvas");
  588. canvas.width = image.width;
  589. canvas.height = image.height;
  590. var context = canvas.getContext("2d", null);
  591. context.drawImage(image, 0, 0);
  592. return canvas;
  593. },
  594. createDefaultBitmap: function () {
  595. return this.canvasToBitmap(this.imageToCanvas(Main.defaultImageElement));
  596. },
  597. onTargetImageChanged: function () {
  598. var backgroundColor = geometrize_Util.getAverageImageColor(this.targetImage);
  599. var red = ((((backgroundColor >> 24) & 255) * this.initialBackgroundOpacity) / 255.0) | 0;
  600. var green = ((((backgroundColor >> 16) & 255) * this.initialBackgroundOpacity) / 255.0) | 0;
  601. var blue = ((((backgroundColor >> 8) & 255) * this.initialBackgroundOpacity) / 255.0) | 0;
  602. var alpha = this.initialBackgroundOpacity | 0;
  603. var premultipliedColor =
  604. ((red < 0 ? 0 : red > 255 ? 255 : red) << 24) +
  605. ((green < 0 ? 0 : green > 255 ? 255 : green) << 16) +
  606. ((blue < 0 ? 0 : blue > 255 ? 255 : blue) << 8) +
  607. (alpha < 0 ? 0 : alpha > 255 ? 255 : alpha);
  608. var backgroundRect = new geometrize_shape_Rectangle(this.targetImage.width, this.targetImage.height);
  609. backgroundRect.x1 = 0;
  610. backgroundRect.y1 = 0;
  611. backgroundRect.x2 = this.targetImage.width - 1;
  612. backgroundRect.y2 = this.targetImage.height - 1;
  613. this.shapeSvgData = [];
  614. this.shapeJsonData = [];
  615. this.appendSvgShapeData(geometrize_exporter_SvgExporter.exportShape({ score: 0.0, color: premultipliedColor, shape: backgroundRect }));
  616. this.shapeJsonData.push(
  617. geometrize_exporter_ShapeJsonExporter.exportShape({
  618. score: 0.0,
  619. color: premultipliedColor,
  620. shape: backgroundRect,
  621. })
  622. );
  623. if (this.worker != null) {
  624. this.worker.terminate();
  625. }
  626. this.worker = new GeometrizeWorkerInterface();
  627. this.worker.onMessage = $bind(this, this.onWorkerMessageReceived);
  628. this.worker.postMessage({ id: "should_set_target_image", data: this.targetImage });
  629. if (this.running) {
  630. this.stepRunner();
  631. }
  632. },
  633. makeSvgData: function () {
  634. return (
  635. geometrize_exporter_SvgExporter.getSvgPrelude() +
  636. geometrize_exporter_SvgExporter.getSvgNodeOpen(this.targetImage.width, this.targetImage.height) +
  637. Std.string(this.shapeSvgData) +
  638. geometrize_exporter_SvgExporter.getSvgNodeClose()
  639. );
  640. },
  641. set_running: function (running) {
  642. // Main.runPauseButton.innerHTML = running ? "<h2>Pause</h2>" : "<h2>Run</h2>";
  643. var wasRunning = this.running;
  644. this.running = running;
  645. if (!wasRunning && this.running) {
  646. this.stepRunner();
  647. }
  648. return this.running;
  649. },
  650. };
  651. Math.__name__ = true;
  652. var Std = function () {};
  653. Std.__name__ = true;
  654. Std.string = function (s) {
  655. return js_Boot.__string_rec(s, "");
  656. };
  657. Std.parseInt = function (x) {
  658. if (x != null) {
  659. var _g = 0;
  660. var _g1 = x.length;
  661. while (_g < _g1) {
  662. var i = _g++;
  663. var c = x.charCodeAt(i);
  664. if (c <= 8 || (c >= 14 && c != 32 && c != 45)) {
  665. var nc = x.charCodeAt(i + 1);
  666. var v = parseInt(x, nc == 120 || nc == 88 ? 16 : 10);
  667. if (isNaN(v)) {
  668. return null;
  669. } else {
  670. return v;
  671. }
  672. }
  673. }
  674. }
  675. return null;
  676. };
  677. Std.random = function (x) {
  678. if (x <= 0) {
  679. return 0;
  680. } else {
  681. return Math.floor(Math.random() * x);
  682. }
  683. };
  684. var StringTools = function () {};
  685. StringTools.__name__ = true;
  686. StringTools.replace = function (s, sub, by) {
  687. return s.split(sub).join(by);
  688. };
  689. var UInt = {};
  690. UInt.toFloat = function (this1) {
  691. var int = this1;
  692. if (int < 0) {
  693. return 4294967296.0 + int;
  694. } else {
  695. return int + 0.0;
  696. }
  697. };
  698. var geometrize_ArraySet = {};
  699. geometrize_ArraySet.create = function (array) {
  700. if (array == null) {
  701. var this1 = [];
  702. return this1;
  703. }
  704. return geometrize_ArraySet.toSet(array);
  705. };
  706. geometrize_ArraySet.add = function (this1, element) {
  707. if (element == null) {
  708. throw haxe_Exception.thrown("FAIL: element != null");
  709. }
  710. if (geometrize_ArraySet.contains(this1, element)) {
  711. return false;
  712. }
  713. this1.push(element);
  714. return true;
  715. };
  716. geometrize_ArraySet.contains = function (this1, element) {
  717. var _g = 0;
  718. while (_g < this1.length) {
  719. var i = this1[_g];
  720. ++_g;
  721. if (i == element) {
  722. return true;
  723. }
  724. }
  725. return false;
  726. };
  727. geometrize_ArraySet.toArray = function (this1) {
  728. return this1.slice();
  729. };
  730. geometrize_ArraySet.toSet = function (array) {
  731. var this1 = [];
  732. var set = this1;
  733. var _g = 0;
  734. while (_g < array.length) {
  735. var v = array[_g];
  736. ++_g;
  737. geometrize_ArraySet.add(set, v);
  738. }
  739. return set;
  740. };
  741. var geometrize_Core = function () {};
  742. geometrize_Core.__name__ = true;
  743. geometrize_Core.computeColor = function (target, current, lines, alpha) {
  744. if (target == null) {
  745. throw haxe_Exception.thrown("FAIL: target != null");
  746. }
  747. if (current == null) {
  748. throw haxe_Exception.thrown("FAIL: current != null");
  749. }
  750. if (lines == null) {
  751. throw haxe_Exception.thrown("FAIL: lines != null");
  752. }
  753. if (alpha < 0) {
  754. throw haxe_Exception.thrown("FAIL: alpha >= 0");
  755. }
  756. var totalRed = 0;
  757. var totalGreen = 0;
  758. var totalBlue = 0;
  759. var count = 0;
  760. var f = 65535 / alpha;
  761. var a = f | 0;
  762. var _g = 0;
  763. while (_g < lines.length) {
  764. var line = lines[_g];
  765. ++_g;
  766. var y = line.y;
  767. var _g1 = line.x1;
  768. var _g2 = line.x2 + 1;
  769. while (_g1 < _g2) {
  770. var x = _g1++;
  771. var t = target.data[target.width * y + x];
  772. var c = current.data[current.width * y + x];
  773. totalRed += (((t >> 24) & 255) - ((c >> 24) & 255)) * a + ((c >> 24) & 255) * 257;
  774. totalGreen += (((t >> 16) & 255) - ((c >> 16) & 255)) * a + ((c >> 16) & 255) * 257;
  775. totalBlue += (((t >> 8) & 255) - ((c >> 8) & 255)) * a + ((c >> 8) & 255) * 257;
  776. ++count;
  777. }
  778. }
  779. if (count == 0) {
  780. return 0;
  781. }
  782. var value = ((totalRed / count) | 0) >> 8;
  783. var r = value < 0 ? 0 : value > 255 ? 255 : value;
  784. var value = ((totalGreen / count) | 0) >> 8;
  785. var g = value < 0 ? 0 : value > 255 ? 255 : value;
  786. var value = ((totalBlue / count) | 0) >> 8;
  787. var b = value < 0 ? 0 : value > 255 ? 255 : value;
  788. return ((r < 0 ? 0 : r > 255 ? 255 : r) << 24) + ((g < 0 ? 0 : g > 255 ? 255 : g) << 16) + ((b < 0 ? 0 : b > 255 ? 255 : b) << 8) + (alpha < 0 ? 0 : alpha > 255 ? 255 : alpha);
  789. };
  790. geometrize_Core.differenceFull = function (first, second) {
  791. if (first == null) {
  792. throw haxe_Exception.thrown("FAIL: first != null");
  793. }
  794. if (second == null) {
  795. throw haxe_Exception.thrown("FAIL: second != null");
  796. }
  797. if (first.width == 0) {
  798. throw haxe_Exception.thrown("FAIL: first.width != 0");
  799. }
  800. if (first.height == 0) {
  801. throw haxe_Exception.thrown("FAIL: first.height != 0");
  802. }
  803. if (second.width == 0) {
  804. throw haxe_Exception.thrown("FAIL: second.width != 0");
  805. }
  806. if (second.height == 0) {
  807. throw haxe_Exception.thrown("FAIL: second.height != 0");
  808. }
  809. var actual = first.width;
  810. var expected = second.width;
  811. if (actual != expected) {
  812. throw haxe_Exception.thrown("FAIL: values are not equal (expected: " + expected + ", actual: " + actual + ")");
  813. }
  814. var actual = first.height;
  815. var expected = second.height;
  816. if (actual != expected) {
  817. throw haxe_Exception.thrown("FAIL: values are not equal (expected: " + expected + ", actual: " + actual + ")");
  818. }
  819. var total = 0;
  820. var width = first.width;
  821. var height = first.height;
  822. var _g = 0;
  823. var _g1 = height;
  824. while (_g < _g1) {
  825. var y = _g++;
  826. var _g2 = 0;
  827. var _g3 = width;
  828. while (_g2 < _g3) {
  829. var x = _g2++;
  830. var f = first.data[first.width * y + x];
  831. var s = second.data[second.width * y + x];
  832. var dr = ((f >> 24) & 255) - ((s >> 24) & 255);
  833. var dg = ((f >> 16) & 255) - ((s >> 16) & 255);
  834. var db = ((f >> 8) & 255) - ((s >> 8) & 255);
  835. var da = (f & 255) - (s & 255);
  836. total += dr * dr + dg * dg + db * db + da * da;
  837. }
  838. }
  839. var result = Math.sqrt(total / (width * height * 4.0)) / 255;
  840. if (!isFinite(result)) {
  841. throw haxe_Exception.thrown("FAIL: Math.isFinite(result)");
  842. }
  843. return result;
  844. };
  845. geometrize_Core.differencePartial = function (target, before, after, score, lines) {
  846. if (target == null) {
  847. throw haxe_Exception.thrown("FAIL: target != null");
  848. }
  849. if (before == null) {
  850. throw haxe_Exception.thrown("FAIL: before != null");
  851. }
  852. if (after == null) {
  853. throw haxe_Exception.thrown("FAIL: after != null");
  854. }
  855. if (lines == null) {
  856. throw haxe_Exception.thrown("FAIL: lines != null");
  857. }
  858. if (lines.length == 0) {
  859. throw haxe_Exception.thrown("FAIL: lines.length != 0");
  860. }
  861. var width = target.width;
  862. var height = target.height;
  863. var rgbaCount = width * height * 4;
  864. var total = Math.pow(score * 255, 2) * rgbaCount;
  865. var _g = 0;
  866. while (_g < lines.length) {
  867. var line = lines[_g];
  868. ++_g;
  869. var y = line.y;
  870. var _g1 = line.x1;
  871. var _g2 = line.x2 + 1;
  872. while (_g1 < _g2) {
  873. var x = _g1++;
  874. var t = target.data[target.width * y + x];
  875. var b = before.data[before.width * y + x];
  876. var a = after.data[after.width * y + x];
  877. var dtbr = ((t >> 24) & 255) - ((b >> 24) & 255);
  878. var dtbg = ((t >> 16) & 255) - ((b >> 16) & 255);
  879. var dtbb = ((t >> 8) & 255) - ((b >> 8) & 255);
  880. var dtba = (t & 255) - (b & 255);
  881. var dtar = ((t >> 24) & 255) - ((a >> 24) & 255);
  882. var dtag = ((t >> 16) & 255) - ((a >> 16) & 255);
  883. var dtab = ((t >> 8) & 255) - ((a >> 8) & 255);
  884. var dtaa = (t & 255) - (a & 255);
  885. total -= dtbr * dtbr + dtbg * dtbg + dtbb * dtbb + dtba * dtba;
  886. total += dtar * dtar + dtag * dtag + dtab * dtab + dtaa * dtaa;
  887. }
  888. }
  889. var result = Math.sqrt(total / rgbaCount) / 255;
  890. if (!isFinite(result)) {
  891. throw haxe_Exception.thrown("FAIL: Math.isFinite(result)");
  892. }
  893. return result;
  894. };
  895. geometrize_Core.bestRandomState = function (shapes, alpha, n, target, current, buffer, lastScore) {
  896. var bestEnergy = 0;
  897. var bestState = null;
  898. var _g = 0;
  899. var _g1 = n;
  900. while (_g < _g1) {
  901. var i = _g++;
  902. var state = new geometrize_State(geometrize_shape_ShapeFactory.randomShapeOf(shapes, current.width, current.height), alpha, target, current, buffer);
  903. var energy = state.energy(lastScore);
  904. if (i == 0 || energy < bestEnergy) {
  905. bestEnergy = energy;
  906. bestState = state;
  907. }
  908. }
  909. return bestState;
  910. };
  911. geometrize_Core.bestHillClimbState = function (shapes, alpha, n, age, target, current, buffer, lastScore) {
  912. var state = geometrize_Core.bestRandomState(shapes, alpha, n, target, current, buffer, lastScore);
  913. state = geometrize_Core.hillClimb(state, age, lastScore);
  914. return state;
  915. };
  916. geometrize_Core.hillClimb = function (state, maxAge, lastScore) {
  917. if (state == null) {
  918. throw haxe_Exception.thrown("FAIL: state != null");
  919. }
  920. if (maxAge < 0) {
  921. throw haxe_Exception.thrown("FAIL: maxAge >= 0");
  922. }
  923. var state1 = state.clone();
  924. var bestState = state1.clone();
  925. var bestEnergy = state1.energy(lastScore);
  926. var age = 0;
  927. while (age < maxAge) {
  928. var undo = state1.mutate();
  929. var energy = state1.energy(lastScore);
  930. if (energy >= bestEnergy) {
  931. state1 = undo;
  932. } else {
  933. bestEnergy = energy;
  934. bestState = state1.clone();
  935. age = -1;
  936. }
  937. ++age;
  938. }
  939. return bestState;
  940. };
  941. geometrize_Core.energy = function (shape, alpha, target, current, buffer, score) {
  942. if (shape == null) {
  943. throw haxe_Exception.thrown("FAIL: shape != null");
  944. }
  945. if (target == null) {
  946. throw haxe_Exception.thrown("FAIL: target != null");
  947. }
  948. if (current == null) {
  949. throw haxe_Exception.thrown("FAIL: current != null");
  950. }
  951. if (buffer == null) {
  952. throw haxe_Exception.thrown("FAIL: buffer != null");
  953. }
  954. var lines = shape.rasterize();
  955. if (lines == null) {
  956. throw haxe_Exception.thrown("FAIL: lines != null");
  957. }
  958. if (lines.length == 0) {
  959. throw haxe_Exception.thrown("FAIL: lines.length != 0");
  960. }
  961. var color = geometrize_Core.computeColor(target, current, lines, alpha);
  962. geometrize_rasterizer_Rasterizer.copyLines(buffer, current, lines);
  963. geometrize_rasterizer_Rasterizer.drawLines(buffer, color, lines);
  964. return geometrize_Core.differencePartial(target, current, buffer, score, lines);
  965. };
  966. var geometrize_Model = function (target, backgroundColor) {
  967. if (target == null) {
  968. throw haxe_Exception.thrown("FAIL: target != null");
  969. }
  970. this.width = target.width;
  971. this.height = target.height;
  972. this.target = target;
  973. var w = target.width;
  974. var h = target.height;
  975. var bitmap = new geometrize_bitmap_Bitmap();
  976. bitmap.width = w;
  977. bitmap.height = h;
  978. var this1 = new Array(w * h);
  979. bitmap.data = this1;
  980. var i = 0;
  981. while (i < bitmap.data.length) {
  982. bitmap.data[i] = backgroundColor;
  983. ++i;
  984. }
  985. this.current = bitmap;
  986. var w = target.width;
  987. var h = target.height;
  988. var bitmap = new geometrize_bitmap_Bitmap();
  989. bitmap.width = w;
  990. bitmap.height = h;
  991. var this1 = new Array(w * h);
  992. bitmap.data = this1;
  993. var i = 0;
  994. while (i < bitmap.data.length) {
  995. bitmap.data[i] = backgroundColor;
  996. ++i;
  997. }
  998. this.buffer = bitmap;
  999. this.score = geometrize_Core.differenceFull(target, this.current);
  1000. };
  1001. geometrize_Model.__name__ = true;
  1002. geometrize_Model.prototype = {
  1003. step: function (shapeTypes, alpha, n, age) {
  1004. var state = geometrize_Core.bestHillClimbState(shapeTypes, alpha, n, age, this.target, this.current, this.buffer, this.score);
  1005. var results = [this.addShape(state.shape, state.alpha)];
  1006. return results;
  1007. },
  1008. addShape: function (shape, alpha) {
  1009. if (shape == null) {
  1010. throw haxe_Exception.thrown("FAIL: shape != null");
  1011. }
  1012. var _this = this.current;
  1013. var bitmap = new geometrize_bitmap_Bitmap();
  1014. bitmap.width = _this.width;
  1015. bitmap.height = _this.height;
  1016. var this1 = new Array(_this.data.length);
  1017. bitmap.data = this1;
  1018. var _g = 0;
  1019. var _g1 = _this.data.length;
  1020. while (_g < _g1) {
  1021. var i = _g++;
  1022. bitmap.data[i] = _this.data[i];
  1023. }
  1024. var before = bitmap;
  1025. var lines = shape.rasterize();
  1026. var color = geometrize_Core.computeColor(this.target, this.current, lines, alpha);
  1027. geometrize_rasterizer_Rasterizer.drawLines(this.current, color, lines);
  1028. this.score = geometrize_Core.differencePartial(this.target, before, this.current, this.score, lines);
  1029. var result = { score: this.score, color: color, shape: shape };
  1030. return result;
  1031. },
  1032. };
  1033. var geometrize_State = function (shape, alpha, target, current, buffer) {
  1034. if (shape == null) {
  1035. throw haxe_Exception.thrown("FAIL: shape != null");
  1036. }
  1037. this.shape = shape;
  1038. this.alpha = alpha;
  1039. this.score = -1;
  1040. this.target = target;
  1041. this.current = current;
  1042. this.buffer = buffer;
  1043. };
  1044. geometrize_State.__name__ = true;
  1045. geometrize_State.prototype = {
  1046. energy: function (lastScore) {
  1047. if (this.score < 0) {
  1048. this.score = geometrize_Core.energy(this.shape, this.alpha, this.target, this.current, this.buffer, lastScore);
  1049. }
  1050. return this.score;
  1051. },
  1052. mutate: function () {
  1053. var oldState = this.clone();
  1054. this.shape.mutate();
  1055. return oldState;
  1056. },
  1057. clone: function () {
  1058. return new geometrize_State(this.shape.clone(), this.alpha, this.target, this.current, this.buffer);
  1059. },
  1060. };
  1061. var geometrize_Util = function () {};
  1062. geometrize_Util.__name__ = true;
  1063. geometrize_Util.getAverageImageColor = function (image, alpha) {
  1064. if (alpha == null) {
  1065. alpha = 255;
  1066. }
  1067. if (image == null) {
  1068. throw haxe_Exception.thrown("FAIL: image != null");
  1069. }
  1070. var totalRed = 0;
  1071. var totalGreen = 0;
  1072. var totalBlue = 0;
  1073. var _g = 0;
  1074. var _g1 = image.width;
  1075. while (_g < _g1) {
  1076. var x = _g++;
  1077. var _g2 = 0;
  1078. var _g3 = image.height;
  1079. while (_g2 < _g3) {
  1080. var y = _g2++;
  1081. var pixel = image.data[image.width * y + x];
  1082. totalRed += (pixel >> 24) & 255;
  1083. totalGreen += (pixel >> 16) & 255;
  1084. totalBlue += (pixel >> 8) & 255;
  1085. }
  1086. }
  1087. var size = image.width * image.height;
  1088. var red = (totalRed / size) | 0;
  1089. var green = (totalGreen / size) | 0;
  1090. var blue = (totalBlue / size) | 0;
  1091. return (
  1092. ((red < 0 ? 0 : red > 255 ? 255 : red) << 24) +
  1093. ((green < 0 ? 0 : green > 255 ? 255 : green) << 16) +
  1094. ((blue < 0 ? 0 : blue > 255 ? 255 : blue) << 8) +
  1095. (alpha < 0 ? 0 : alpha > 255 ? 255 : alpha)
  1096. );
  1097. };
  1098. var geometrize_bitmap_Bitmap = ($hx_exports["geometrize"]["bitmap"]["Bitmap"] = function () {});
  1099. geometrize_bitmap_Bitmap.__name__ = true;
  1100. geometrize_bitmap_Bitmap.create = function (w, h, color) {
  1101. var bitmap = new geometrize_bitmap_Bitmap();
  1102. bitmap.width = w;
  1103. bitmap.height = h;
  1104. var this1 = new Array(w * h);
  1105. bitmap.data = this1;
  1106. var i = 0;
  1107. while (i < bitmap.data.length) {
  1108. bitmap.data[i] = color;
  1109. ++i;
  1110. }
  1111. return bitmap;
  1112. };
  1113. geometrize_bitmap_Bitmap.createFromBytes = function (w, h, bytes) {
  1114. var bitmap = new geometrize_bitmap_Bitmap();
  1115. if (bytes == null) {
  1116. throw haxe_Exception.thrown("FAIL: bytes != null");
  1117. }
  1118. var actual = bytes.length;
  1119. var expected = w * h * 4;
  1120. if (actual != expected) {
  1121. throw haxe_Exception.thrown("FAIL: values are not equal (expected: " + expected + ", actual: " + actual + ")");
  1122. }
  1123. bitmap.width = w;
  1124. bitmap.height = h;
  1125. var this1 = new Array((bytes.length / 4) | 0);
  1126. bitmap.data = this1;
  1127. var i = 0;
  1128. var x = 0;
  1129. while (i < bytes.length) {
  1130. var red = bytes.b[i];
  1131. var green = bytes.b[i + 1];
  1132. var blue = bytes.b[i + 2];
  1133. var alpha = bytes.b[i + 3];
  1134. bitmap.data[x] =
  1135. ((red < 0 ? 0 : red > 255 ? 255 : red) << 24) +
  1136. ((green < 0 ? 0 : green > 255 ? 255 : green) << 16) +
  1137. ((blue < 0 ? 0 : blue > 255 ? 255 : blue) << 8) +
  1138. (alpha < 0 ? 0 : alpha > 255 ? 255 : alpha);
  1139. i += 4;
  1140. ++x;
  1141. }
  1142. return bitmap;
  1143. };
  1144. geometrize_bitmap_Bitmap.createFromByteArray = function (w, h, bytes) {
  1145. var data = new haxe_io_Bytes(new ArrayBuffer(bytes.length));
  1146. var i = 0;
  1147. while (i < bytes.length) {
  1148. data.b[i] = bytes[i];
  1149. ++i;
  1150. }
  1151. var bitmap = new geometrize_bitmap_Bitmap();
  1152. if (data == null) {
  1153. throw haxe_Exception.thrown("FAIL: bytes != null");
  1154. }
  1155. var actual = data.length;
  1156. var expected = w * h * 4;
  1157. if (actual != expected) {
  1158. throw haxe_Exception.thrown("FAIL: values are not equal (expected: " + expected + ", actual: " + actual + ")");
  1159. }
  1160. bitmap.width = w;
  1161. bitmap.height = h;
  1162. var this1 = new Array((data.length / 4) | 0);
  1163. bitmap.data = this1;
  1164. var i = 0;
  1165. var x = 0;
  1166. while (i < data.length) {
  1167. var red = data.b[i];
  1168. var green = data.b[i + 1];
  1169. var blue = data.b[i + 2];
  1170. var alpha = data.b[i + 3];
  1171. bitmap.data[x] =
  1172. ((red < 0 ? 0 : red > 255 ? 255 : red) << 24) +
  1173. ((green < 0 ? 0 : green > 255 ? 255 : green) << 16) +
  1174. ((blue < 0 ? 0 : blue > 255 ? 255 : blue) << 8) +
  1175. (alpha < 0 ? 0 : alpha > 255 ? 255 : alpha);
  1176. i += 4;
  1177. ++x;
  1178. }
  1179. return bitmap;
  1180. };
  1181. geometrize_bitmap_Bitmap.prototype = {
  1182. getPixel: function (x, y) {
  1183. return this.data[this.width * y + x];
  1184. },
  1185. setPixel: function (x, y, color) {
  1186. this.data[this.width * y + x] = color;
  1187. },
  1188. clone: function () {
  1189. var bitmap = new geometrize_bitmap_Bitmap();
  1190. bitmap.width = this.width;
  1191. bitmap.height = this.height;
  1192. var this1 = new Array(this.data.length);
  1193. bitmap.data = this1;
  1194. var _g = 0;
  1195. var _g1 = this.data.length;
  1196. while (_g < _g1) {
  1197. var i = _g++;
  1198. bitmap.data[i] = this.data[i];
  1199. }
  1200. return bitmap;
  1201. },
  1202. fill: function (color) {
  1203. var idx = 0;
  1204. while (idx < this.data.length) {
  1205. this.data[idx] = (color >> 24) & 255;
  1206. this.data[idx + 1] = (color >> 16) & 255;
  1207. this.data[idx + 2] = (color >> 8) & 255;
  1208. this.data[idx + 3] = color & 255;
  1209. idx += 4;
  1210. }
  1211. },
  1212. getBytes: function () {
  1213. var bytes = new haxe_io_Bytes(new ArrayBuffer(this.data.length * 4));
  1214. var i = 0;
  1215. while (i < this.data.length) {
  1216. var idx = i * 4;
  1217. bytes.b[idx] = (this.data[i] >> 24) & 255;
  1218. bytes.b[idx + 1] = (this.data[i] >> 16) & 255;
  1219. bytes.b[idx + 2] = (this.data[i] >> 8) & 255;
  1220. bytes.b[idx + 3] = this.data[i] & 255;
  1221. ++i;
  1222. }
  1223. return bytes;
  1224. },
  1225. };
  1226. var geometrize_exporter_ShapeJsonExporter = ($hx_exports["geometrize"]["exporter"]["ShapeJsonExporter"] = function () {});
  1227. geometrize_exporter_ShapeJsonExporter.__name__ = true;
  1228. geometrize_exporter_ShapeJsonExporter.export = function (shapes) {
  1229. return "[\n" + geometrize_exporter_ShapeJsonExporter.exportShapes(shapes) + "\n]";
  1230. };
  1231. geometrize_exporter_ShapeJsonExporter.exportShapes = function (shapes) {
  1232. var results = "";
  1233. var _g = 0;
  1234. var _g1 = shapes.length;
  1235. while (_g < _g1) {
  1236. var i = _g++;
  1237. results += geometrize_exporter_ShapeJsonExporter.exportShape(shapes[i]);
  1238. if (i != shapes.length - 1) {
  1239. results += ",\n";
  1240. }
  1241. }
  1242. return results;
  1243. };
  1244. geometrize_exporter_ShapeJsonExporter.exportShape = function (shape) {
  1245. var result = " {\n";
  1246. var type = shape.shape.getType();
  1247. var data = shape.shape.getRawShapeData();
  1248. var color = shape.color;
  1249. var score = shape.score;
  1250. result += ' "type":' + type + ",\n";
  1251. result += ' "data":' + "[";
  1252. var _g = 0;
  1253. var _g1 = data.length;
  1254. while (_g < _g1) {
  1255. var item = _g++;
  1256. result += data[item];
  1257. if (item <= data.length - 2) {
  1258. result += ",";
  1259. }
  1260. }
  1261. result += "],\n";
  1262. result += ' "color":' + "[";
  1263. result += ((color >> 24) & 255) + ",";
  1264. result += ((color >> 16) & 255) + ",";
  1265. result += ((color >> 8) & 255) + ",";
  1266. result += color & 255;
  1267. result += "],\n";
  1268. result += ' "score":' + score + "\n";
  1269. result += " }";
  1270. return result;
  1271. };
  1272. var geometrize_exporter_SvgExporter = ($hx_exports["geometrize"]["exporter"]["SvgExporter"] = function () {});
  1273. geometrize_exporter_SvgExporter.__name__ = true;
  1274. geometrize_exporter_SvgExporter.export = function (shapes, width, height) {
  1275. var results = geometrize_exporter_SvgExporter.getSvgPrelude();
  1276. results += geometrize_exporter_SvgExporter.getSvgNodeOpen(width, height);
  1277. results += geometrize_exporter_SvgExporter.exportShapes(shapes);
  1278. results += geometrize_exporter_SvgExporter.getSvgNodeClose();
  1279. return results;
  1280. };
  1281. geometrize_exporter_SvgExporter.exportShapes = function (shapes) {
  1282. var results = "";
  1283. var _g = 0;
  1284. var _g1 = shapes.length;
  1285. while (_g < _g1) {
  1286. var i = _g++;
  1287. results += geometrize_exporter_SvgExporter.exportShape(shapes[i]);
  1288. if (i != shapes.length - 1) {
  1289. results += "\n";
  1290. }
  1291. }
  1292. return results;
  1293. };
  1294. geometrize_exporter_SvgExporter.exportShape = function (shape) {
  1295. return StringTools.replace(shape.shape.getSvgShapeData(), geometrize_exporter_SvgExporter.SVG_STYLE_HOOK, geometrize_exporter_SvgExporter.stylesForShape(shape));
  1296. };
  1297. geometrize_exporter_SvgExporter.getSvgPrelude = function () {
  1298. return '<?xml version="1.0" standalone="no"?>\n';
  1299. };
  1300. geometrize_exporter_SvgExporter.getSvgNodeOpen = function (width, height) {
  1301. return '<svg xmlns="http://www.w3.org/2000/svg" version="1.2" baseProfile="tiny" width="' + width + '" height="' + height + '">\n';
  1302. };
  1303. geometrize_exporter_SvgExporter.getSvgNodeClose = function () {
  1304. return "</svg>";
  1305. };
  1306. geometrize_exporter_SvgExporter.stylesForShape = function (shape) {
  1307. switch (shape.shape.getType()) {
  1308. case 6:
  1309. case 7:
  1310. return geometrize_exporter_SvgExporter.strokeForColor(shape.color) + ' stroke-width="1" fill="none" ' + geometrize_exporter_SvgExporter.strokeOpacityForAlpha(shape.color & 255);
  1311. default:
  1312. return geometrize_exporter_SvgExporter.fillForColor(shape.color) + " " + geometrize_exporter_SvgExporter.fillOpacityForAlpha(shape.color & 255);
  1313. }
  1314. };
  1315. geometrize_exporter_SvgExporter.rgbForColor = function (color) {
  1316. return "rgb(" + ((color >> 24) & 255) + "," + ((color >> 16) & 255) + "," + ((color >> 8) & 255) + ")";
  1317. };
  1318. geometrize_exporter_SvgExporter.strokeForColor = function (color) {
  1319. return 'stroke="' + geometrize_exporter_SvgExporter.rgbForColor(color) + '"';
  1320. };
  1321. geometrize_exporter_SvgExporter.fillForColor = function (color) {
  1322. return 'fill="' + geometrize_exporter_SvgExporter.rgbForColor(color) + '"';
  1323. };
  1324. geometrize_exporter_SvgExporter.fillOpacityForAlpha = function (alpha) {
  1325. return 'fill-opacity="' + alpha / 255.0 + '"';
  1326. };
  1327. geometrize_exporter_SvgExporter.strokeOpacityForAlpha = function (alpha) {
  1328. return 'stroke-opacity="' + alpha / 255.0 + '"';
  1329. };
  1330. var geometrize_rasterizer_Rasterizer = function () {};
  1331. geometrize_rasterizer_Rasterizer.__name__ = true;
  1332. geometrize_rasterizer_Rasterizer.drawLines = function (image, c, lines) {
  1333. if (image == null) {
  1334. throw haxe_Exception.thrown("FAIL: image != null");
  1335. }
  1336. if (lines == null) {
  1337. throw haxe_Exception.thrown("FAIL: lines != null");
  1338. }
  1339. var sr = (c >> 24) & 255;
  1340. sr |= sr << 8;
  1341. sr *= c & 255;
  1342. sr = (sr / 255) | 0;
  1343. var sg = (c >> 16) & 255;
  1344. sg |= sg << 8;
  1345. sg *= c & 255;
  1346. sg = (sg / 255) | 0;
  1347. var sb = (c >> 8) & 255;
  1348. sb |= sb << 8;
  1349. sb *= c & 255;
  1350. sb = (sb / 255) | 0;
  1351. var sa = c & 255;
  1352. sa |= sa << 8;
  1353. var _g = 0;
  1354. while (_g < lines.length) {
  1355. var line = lines[_g];
  1356. ++_g;
  1357. var y = line.y;
  1358. var ma = 65535;
  1359. var m = 65535;
  1360. var as = (m - sa * (ma / m)) * 257;
  1361. var a = as | 0;
  1362. var _g1 = line.x1;
  1363. var _g2 = line.x2 + 1;
  1364. while (_g1 < _g2) {
  1365. var x = _g1++;
  1366. var d = image.data[image.width * y + x];
  1367. var dr = (d >> 24) & 255;
  1368. var dg = (d >> 16) & 255;
  1369. var db = (d >> 8) & 255;
  1370. var da = d & 255;
  1371. var r = ((UInt.toFloat(dr * a + sr * ma) / UInt.toFloat(m)) | 0) >> 8;
  1372. var g = ((UInt.toFloat(dg * a + sg * ma) / UInt.toFloat(m)) | 0) >> 8;
  1373. var b = ((UInt.toFloat(db * a + sb * ma) / UInt.toFloat(m)) | 0) >> 8;
  1374. var a1 = ((UInt.toFloat(da * a + sa * ma) / UInt.toFloat(m)) | 0) >> 8;
  1375. image.data[image.width * y + x] =
  1376. ((r < 0 ? 0 : r > 255 ? 255 : r) << 24) + ((g < 0 ? 0 : g > 255 ? 255 : g) << 16) + ((b < 0 ? 0 : b > 255 ? 255 : b) << 8) + (a1 < 0 ? 0 : a1 > 255 ? 255 : a1);
  1377. }
  1378. }
  1379. };
  1380. geometrize_rasterizer_Rasterizer.copyLines = function (destination, source, lines) {
  1381. if (destination == null) {
  1382. throw haxe_Exception.thrown("FAIL: destination != null");
  1383. }
  1384. if (source == null) {
  1385. throw haxe_Exception.thrown("FAIL: source != null");
  1386. }
  1387. if (lines == null) {
  1388. throw haxe_Exception.thrown("FAIL: lines != null");
  1389. }
  1390. var _g = 0;
  1391. while (_g < lines.length) {
  1392. var line = lines[_g];
  1393. ++_g;
  1394. var y = line.y;
  1395. var _g1 = line.x1;
  1396. var _g2 = line.x2 + 1;
  1397. while (_g1 < _g2) {
  1398. var x = _g1++;
  1399. destination.data[destination.width * y + x] = source.data[source.width * y + x];
  1400. }
  1401. }
  1402. };
  1403. geometrize_rasterizer_Rasterizer.bresenham = function (x1, y1, x2, y2) {
  1404. var dx = x2 - x1;
  1405. var ix = (dx > 0 ? 1 : 0) - (dx < 0 ? 1 : 0);
  1406. dx = (dx < 0 ? -dx : dx) << 1;
  1407. var dy = y2 - y1;
  1408. var iy = (dy > 0 ? 1 : 0) - (dy < 0 ? 1 : 0);
  1409. dy = (dy < 0 ? -dy : dy) << 1;
  1410. var points = [];
  1411. points.push({ x: x1, y: y1 });
  1412. if (dx >= dy) {
  1413. var error = dy - (dx >> 1);
  1414. while (x1 != x2) {
  1415. if (error >= 0 && (error != 0 || ix > 0)) {
  1416. error -= dx;
  1417. y1 += iy;
  1418. }
  1419. error += dy;
  1420. x1 += ix;
  1421. points.push({ x: x1, y: y1 });
  1422. }
  1423. } else {
  1424. var error = dx - (dy >> 1);
  1425. while (y1 != y2) {
  1426. if (error >= 0 && (error != 0 || iy > 0)) {
  1427. error -= dy;
  1428. x1 += ix;
  1429. }
  1430. error += dx;
  1431. y1 += iy;
  1432. points.push({ x: x1, y: y1 });
  1433. }
  1434. }
  1435. return points;
  1436. };
  1437. geometrize_rasterizer_Rasterizer.scanlinesForPolygon = function (points) {
  1438. var lines = [];
  1439. var edges = [];
  1440. var _g = 0;
  1441. var _g1 = points.length;
  1442. while (_g < _g1) {
  1443. var i = _g++;
  1444. var p1 = points[i];
  1445. var p2 = i == points.length - 1 ? points[0] : points[i + 1];
  1446. var p1p2 = geometrize_rasterizer_Rasterizer.bresenham(p1.x, p1.y, p2.x, p2.y);
  1447. edges = edges.concat(p1p2);
  1448. }
  1449. var yToXs = new haxe_ds_IntMap();
  1450. var _g = 0;
  1451. while (_g < edges.length) {
  1452. var point = edges[_g];
  1453. ++_g;
  1454. var s = yToXs.h[point.y];
  1455. if (s != null) {
  1456. geometrize_ArraySet.add(s, point.x);
  1457. } else {
  1458. s = geometrize_ArraySet.create();
  1459. geometrize_ArraySet.add(s, point.x);
  1460. yToXs.h[point.y] = s;
  1461. }
  1462. }
  1463. var key = yToXs.keys();
  1464. while (key.hasNext()) {
  1465. var key1 = key.next();
  1466. var a = geometrize_ArraySet.toArray(yToXs.h[key1]);
  1467. var minMaxElements;
  1468. if (a == null || a.length == 0) {
  1469. minMaxElements = { x: 0, y: 0 };
  1470. } else {
  1471. var min = a[0];
  1472. var max = a[0];
  1473. var _g = 0;
  1474. while (_g < a.length) {
  1475. var value = a[_g];
  1476. ++_g;
  1477. if (min > value) {
  1478. min = value;
  1479. }
  1480. if (max < value) {
  1481. max = value;
  1482. }
  1483. }
  1484. minMaxElements = { x: min, y: max };
  1485. }
  1486. lines.push(new geometrize_rasterizer_Scanline(key1, minMaxElements.x, minMaxElements.y));
  1487. }
  1488. return lines;
  1489. };
  1490. var geometrize_rasterizer_Scanline = function (y, x1, x2) {
  1491. this.y = y;
  1492. this.x1 = x1;
  1493. this.x2 = x2;
  1494. };
  1495. geometrize_rasterizer_Scanline.__name__ = true;
  1496. geometrize_rasterizer_Scanline.trim = function (scanlines, w, h) {
  1497. if (scanlines == null) {
  1498. throw haxe_Exception.thrown("FAIL: scanlines != null");
  1499. }
  1500. var w1 = w;
  1501. var h1 = h;
  1502. var f = function (line) {
  1503. if (line.y < 0 || line.y >= h1 || line.x1 >= w1 || line.x2 < 0) {
  1504. return false;
  1505. } else {
  1506. var value = line.x1;
  1507. var max = w1 - 1;
  1508. if (0 > max) {
  1509. throw haxe_Exception.thrown("FAIL: min <= max");
  1510. }
  1511. line.x1 = value < 0 ? 0 : value > max ? max : value;
  1512. var value = line.x2;
  1513. var max = w1 - 1;
  1514. if (0 > max) {
  1515. throw haxe_Exception.thrown("FAIL: min <= max");
  1516. }
  1517. line.x2 = value < 0 ? 0 : value > max ? max : value;
  1518. return line.x1 <= line.x2;
  1519. }
  1520. };
  1521. var _g = [];
  1522. var _g1 = 0;
  1523. var _g2 = scanlines;
  1524. while (_g1 < _g2.length) {
  1525. var v = _g2[_g1];
  1526. ++_g1;
  1527. if (f(v)) {
  1528. _g.push(v);
  1529. }
  1530. }
  1531. return _g;
  1532. };
  1533. var geometrize_runner_ImageRunner = ($hx_exports["geometrize"]["runner"]["ImageRunner"] = function (inputImage, backgroundColor) {
  1534. this.model = null;
  1535. this.model = new geometrize_Model(inputImage, backgroundColor);
  1536. });
  1537. geometrize_runner_ImageRunner.__name__ = true;
  1538. geometrize_runner_ImageRunner.prototype = {
  1539. step: function (options) {
  1540. var finalOptions_shapeTypes = options.shapeTypes != null && options.shapeTypes.length != 0 ? options.shapeTypes : geometrize_runner_Default.options.shapeTypes;
  1541. var finalOptions_alpha = options.alpha != null ? options.alpha : geometrize_runner_Default.options.alpha;
  1542. var finalOptions_candidateShapesPerStep = options.candidateShapesPerStep != null ? options.candidateShapesPerStep : geometrize_runner_Default.options.candidateShapesPerStep;
  1543. var finalOptions_shapeMutationsPerStep = options.shapeMutationsPerStep != null ? options.shapeMutationsPerStep : geometrize_runner_Default.options.shapeMutationsPerStep;
  1544. return this.model.step(finalOptions_shapeTypes, finalOptions_alpha, finalOptions_candidateShapesPerStep, finalOptions_shapeMutationsPerStep);
  1545. },
  1546. getImageData: function () {
  1547. if (this.model == null) {
  1548. throw haxe_Exception.thrown("FAIL: model != null");
  1549. }
  1550. return this.model.current;
  1551. },
  1552. };
  1553. var geometrize_runner_Default = function () {};
  1554. geometrize_runner_Default.__name__ = true;
  1555. var geometrize_shape_Ellipse = function (xBound, yBound) {
  1556. this.x = Std.random(xBound);
  1557. this.y = Std.random(yBound);
  1558. this.rx = Std.random(32) + 1;
  1559. this.ry = Std.random(32) + 1;
  1560. this.xBound = xBound;
  1561. this.yBound = yBound;
  1562. };
  1563. geometrize_shape_Ellipse.__name__ = true;
  1564. geometrize_shape_Ellipse.prototype = {
  1565. rasterize: function () {
  1566. var lines = [];
  1567. var aspect = this.rx / this.ry;
  1568. var w = this.xBound;
  1569. var h = this.yBound;
  1570. var _g = 0;
  1571. var _g1 = this.ry;
  1572. while (_g < _g1) {
  1573. var dy = _g++;
  1574. var y1 = this.y - dy;
  1575. var y2 = this.y + dy;
  1576. if ((y1 < 0 || y1 >= h) && (y2 < 0 || y2 >= h)) {
  1577. continue;
  1578. }
  1579. var s = (Math.sqrt(this.ry * this.ry - dy * dy) * aspect) | 0;
  1580. var x1 = this.x - s;
  1581. var x2 = this.x + s;
  1582. if (x1 < 0) {
  1583. x1 = 0;
  1584. }
  1585. if (x2 >= w) {
  1586. x2 = w - 1;
  1587. }
  1588. if (y1 >= 0 && y1 < h) {
  1589. lines.push(new geometrize_rasterizer_Scanline(y1, x1, x2));
  1590. }
  1591. if (y2 >= 0 && y2 < h && dy > 0) {
  1592. lines.push(new geometrize_rasterizer_Scanline(y2, x1, x2));
  1593. }
  1594. }
  1595. return lines;
  1596. },
  1597. mutate: function () {
  1598. var r = Std.random(3);
  1599. switch (r) {
  1600. case 0:
  1601. var value = this.x + (-16 + Math.floor(33 * Math.random()));
  1602. var max = this.xBound - 1;
  1603. if (0 > max) {
  1604. throw haxe_Exception.thrown("FAIL: min <= max");
  1605. }
  1606. this.x = value < 0 ? 0 : value > max ? max : value;
  1607. var value = this.y + (-16 + Math.floor(33 * Math.random()));
  1608. var max = this.yBound - 1;
  1609. if (0 > max) {
  1610. throw haxe_Exception.thrown("FAIL: min <= max");
  1611. }
  1612. this.y = value < 0 ? 0 : value > max ? max : value;
  1613. break;
  1614. case 1:
  1615. var value = this.rx + (-16 + Math.floor(33 * Math.random()));
  1616. var max = this.xBound - 1;
  1617. if (1 > max) {
  1618. throw haxe_Exception.thrown("FAIL: min <= max");
  1619. }
  1620. this.rx = value < 1 ? 1 : value > max ? max : value;
  1621. break;
  1622. case 2:
  1623. var value = this.ry + (-16 + Math.floor(33 * Math.random()));
  1624. var max = this.xBound - 1;
  1625. if (1 > max) {
  1626. throw haxe_Exception.thrown("FAIL: min <= max");
  1627. }
  1628. this.ry = value < 1 ? 1 : value > max ? max : value;
  1629. break;
  1630. }
  1631. },
  1632. clone: function () {
  1633. var ellipse = new geometrize_shape_Ellipse(this.xBound, this.yBound);
  1634. ellipse.x = this.x;
  1635. ellipse.y = this.y;
  1636. ellipse.rx = this.rx;
  1637. ellipse.ry = this.ry;
  1638. return ellipse;
  1639. },
  1640. getType: function () {
  1641. return 3;
  1642. },
  1643. getRawShapeData: function () {
  1644. return [this.x, this.y, this.rx, this.ry];
  1645. },
  1646. getSvgShapeData: function () {
  1647. return '<ellipse cx="' + this.x + '" cy="' + this.y + '" rx="' + this.rx + '" ry="' + this.ry + '" ' + geometrize_exporter_SvgExporter.SVG_STYLE_HOOK + " />";
  1648. },
  1649. };
  1650. var geometrize_shape_Circle = function (xBound, yBound) {
  1651. geometrize_shape_Ellipse.call(this, xBound, yBound);
  1652. this.rx = Std.random(32) + 1;
  1653. this.ry = this.rx;
  1654. };
  1655. geometrize_shape_Circle.__name__ = true;
  1656. geometrize_shape_Circle.__super__ = geometrize_shape_Ellipse;
  1657. geometrize_shape_Circle.prototype = $extend(geometrize_shape_Ellipse.prototype, {
  1658. mutate: function () {
  1659. var r = Std.random(2);
  1660. switch (r) {
  1661. case 0:
  1662. var value = this.x + (-16 + Math.floor(33 * Math.random()));
  1663. var max = this.xBound - 1;
  1664. if (0 > max) {
  1665. throw haxe_Exception.thrown("FAIL: min <= max");
  1666. }
  1667. this.x = value < 0 ? 0 : value > max ? max : value;
  1668. var value = this.y + (-16 + Math.floor(33 * Math.random()));
  1669. var max = this.yBound - 1;
  1670. if (0 > max) {
  1671. throw haxe_Exception.thrown("FAIL: min <= max");
  1672. }
  1673. this.y = value < 0 ? 0 : value > max ? max : value;
  1674. break;
  1675. case 1:
  1676. var value = this.rx + (-16 + Math.floor(33 * Math.random()));
  1677. var max = this.xBound - 1;
  1678. if (1 > max) {
  1679. throw haxe_Exception.thrown("FAIL: min <= max");
  1680. }
  1681. var r = value < 1 ? 1 : value > max ? max : value;
  1682. this.rx = r;
  1683. this.ry = r;
  1684. break;
  1685. }
  1686. },
  1687. clone: function () {
  1688. var circle = new geometrize_shape_Circle(this.xBound, this.yBound);
  1689. circle.x = this.x;
  1690. circle.y = this.y;
  1691. circle.rx = this.rx;
  1692. circle.ry = this.ry;
  1693. return circle;
  1694. },
  1695. getType: function () {
  1696. return 5;
  1697. },
  1698. getRawShapeData: function () {
  1699. return [this.x, this.y, this.rx];
  1700. },
  1701. getSvgShapeData: function () {
  1702. return '<circle cx="' + this.x + '" cy="' + this.y + '" r="' + this.rx + '" ' + geometrize_exporter_SvgExporter.SVG_STYLE_HOOK + " />";
  1703. },
  1704. });
  1705. var geometrize_shape_Line = function (xBound, yBound) {
  1706. this.x1 = Std.random(xBound);
  1707. this.y1 = Std.random(yBound);
  1708. var value = this.x1 + Std.random(32) + 1;
  1709. if (0 > xBound) {
  1710. throw haxe_Exception.thrown("FAIL: min <= max");
  1711. }
  1712. this.x2 = value < 0 ? 0 : value > xBound ? xBound : value;
  1713. var value = this.y1 + Std.random(32) + 1;
  1714. if (0 > yBound) {
  1715. throw haxe_Exception.thrown("FAIL: min <= max");
  1716. }
  1717. this.y2 = value < 0 ? 0 : value > yBound ? yBound : value;
  1718. this.xBound = xBound;
  1719. this.yBound = yBound;
  1720. };
  1721. geometrize_shape_Line.__name__ = true;
  1722. geometrize_shape_Line.prototype = {
  1723. rasterize: function () {
  1724. var lines = [];
  1725. var points = geometrize_rasterizer_Rasterizer.bresenham(this.x1, this.y1, this.x2, this.y2);
  1726. var _g = 0;
  1727. while (_g < points.length) {
  1728. var point = points[_g];
  1729. ++_g;
  1730. lines.push(new geometrize_rasterizer_Scanline(point.y, point.x, point.x));
  1731. }
  1732. return geometrize_rasterizer_Scanline.trim(lines, this.xBound, this.yBound);
  1733. },
  1734. mutate: function () {
  1735. var r = Std.random(4);
  1736. switch (r) {
  1737. case 0:
  1738. var value = this.x1 + (-16 + Math.floor(33 * Math.random()));
  1739. var max = this.xBound - 1;
  1740. if (0 > max) {
  1741. throw haxe_Exception.thrown("FAIL: min <= max");
  1742. }
  1743. this.x1 = value < 0 ? 0 : value > max ? max : value;
  1744. var value = this.y1 + (-16 + Math.floor(33 * Math.random()));
  1745. var max = this.yBound - 1;
  1746. if (0 > max) {
  1747. throw haxe_Exception.thrown("FAIL: min <= max");
  1748. }
  1749. this.y1 = value < 0 ? 0 : value > max ? max : value;
  1750. break;
  1751. case 1:
  1752. var value = this.x2 + (-16 + Math.floor(33 * Math.random()));
  1753. var max = this.xBound - 1;
  1754. if (0 > max) {
  1755. throw haxe_Exception.thrown("FAIL: min <= max");
  1756. }
  1757. this.x2 = value < 0 ? 0 : value > max ? max : value;
  1758. var value = this.y2 + (-16 + Math.floor(33 * Math.random()));
  1759. var max = this.yBound - 1;
  1760. if (0 > max) {
  1761. throw haxe_Exception.thrown("FAIL: min <= max");
  1762. }
  1763. this.y2 = value < 0 ? 0 : value > max ? max : value;
  1764. break;
  1765. }
  1766. },
  1767. clone: function () {
  1768. var line = new geometrize_shape_Line(this.xBound, this.yBound);
  1769. line.x1 = this.x1;
  1770. line.y1 = this.y1;
  1771. line.x2 = this.x2;
  1772. line.y2 = this.y2;
  1773. return line;
  1774. },
  1775. getType: function () {
  1776. return 6;
  1777. },
  1778. getRawShapeData: function () {
  1779. return [this.x1, this.y1, this.x2, this.y2];
  1780. },
  1781. getSvgShapeData: function () {
  1782. return '<line x1="' + this.x1 + '" y1="' + this.y1 + '" x2="' + this.x2 + '" y2="' + this.y2 + '" ' + geometrize_exporter_SvgExporter.SVG_STYLE_HOOK + " />";
  1783. },
  1784. };
  1785. var geometrize_shape_QuadraticBezier = function (xBound, yBound) {
  1786. var upper = xBound - 1;
  1787. if (0 > upper) {
  1788. throw haxe_Exception.thrown("FAIL: lower <= upper");
  1789. }
  1790. this.x1 = Math.floor((upper + 1) * Math.random());
  1791. var upper = yBound - 1;
  1792. if (0 > upper) {
  1793. throw haxe_Exception.thrown("FAIL: lower <= upper");
  1794. }
  1795. this.y1 = Math.floor((upper + 1) * Math.random());
  1796. var upper = xBound - 1;
  1797. if (0 > upper) {
  1798. throw haxe_Exception.thrown("FAIL: lower <= upper");
  1799. }
  1800. this.cx = Math.floor((upper + 1) * Math.random());
  1801. var upper = yBound - 1;
  1802. if (0 > upper) {
  1803. throw haxe_Exception.thrown("FAIL: lower <= upper");
  1804. }
  1805. this.cy = Math.floor((upper + 1) * Math.random());
  1806. var upper = xBound - 1;
  1807. if (0 > upper) {
  1808. throw haxe_Exception.thrown("FAIL: lower <= upper");
  1809. }
  1810. this.x2 = Math.floor((upper + 1) * Math.random());
  1811. var upper = yBound - 1;
  1812. if (0 > upper) {
  1813. throw haxe_Exception.thrown("FAIL: lower <= upper");
  1814. }
  1815. this.y2 = Math.floor((upper + 1) * Math.random());
  1816. this.xBound = xBound;
  1817. this.yBound = yBound;
  1818. };
  1819. geometrize_shape_QuadraticBezier.__name__ = true;
  1820. geometrize_shape_QuadraticBezier.prototype = {
  1821. rasterize: function () {
  1822. var lines = [];
  1823. var points = [];
  1824. var pointCount = 20;
  1825. var _g = 0;
  1826. var _g1 = pointCount - 1;
  1827. while (_g < _g1) {
  1828. var i = _g++;
  1829. var t = i / pointCount;
  1830. var tp = 1 - t;
  1831. var x = (tp * (tp * this.x1 + t * this.cx) + t * (tp * this.cx + t * this.x2)) | 0;
  1832. var y = (tp * (tp * this.y1 + t * this.cy) + t * (tp * this.cy + t * this.y2)) | 0;
  1833. points.push({ x: x, y: y });
  1834. }
  1835. var _g = 0;
  1836. var _g1 = points.length - 1;
  1837. while (_g < _g1) {
  1838. var i = _g++;
  1839. var p0 = points[i];
  1840. var p1 = points[i + 1];
  1841. var pts = geometrize_rasterizer_Rasterizer.bresenham(p0.x, p0.y, p1.x, p1.y);
  1842. var _g2 = 0;
  1843. while (_g2 < pts.length) {
  1844. var point = pts[_g2];
  1845. ++_g2;
  1846. if (lines.length > 0) {
  1847. var lastLine = lines[lines.length - 1];
  1848. if (lastLine.y == point.y && lastLine.x1 == point.x && lastLine.x2 == point.x) {
  1849. continue;
  1850. }
  1851. }
  1852. lines.push(new geometrize_rasterizer_Scanline(point.y, point.x, point.x));
  1853. }
  1854. }
  1855. return geometrize_rasterizer_Scanline.trim(lines, this.xBound, this.yBound);
  1856. },
  1857. mutate: function () {
  1858. var r = Math.floor(3 * Math.random());
  1859. switch (r) {
  1860. case 0:
  1861. var value = this.cx + (-8 + Math.floor(17 * Math.random()));
  1862. var max = this.xBound - 1;
  1863. if (0 > max) {
  1864. throw haxe_Exception.thrown("FAIL: min <= max");
  1865. }
  1866. this.cx = value < 0 ? 0 : value > max ? max : value;
  1867. var value = this.cy + (-8 + Math.floor(17 * Math.random()));
  1868. var max = this.yBound - 1;
  1869. if (0 > max) {
  1870. throw haxe_Exception.thrown("FAIL: min <= max");
  1871. }
  1872. this.cy = value < 0 ? 0 : value > max ? max : value;
  1873. break;
  1874. case 1:
  1875. var value = this.x1 + (-8 + Math.floor(17 * Math.random()));
  1876. var max = this.xBound - 1;
  1877. if (1 > max) {
  1878. throw haxe_Exception.thrown("FAIL: min <= max");
  1879. }
  1880. this.x1 = value < 1 ? 1 : value > max ? max : value;
  1881. var value = this.y1 + (-8 + Math.floor(17 * Math.random()));
  1882. var max = this.yBound - 1;
  1883. if (1 > max) {
  1884. throw haxe_Exception.thrown("FAIL: min <= max");
  1885. }
  1886. this.y1 = value < 1 ? 1 : value > max ? max : value;
  1887. break;
  1888. case 2:
  1889. var value = this.x2 + (-8 + Math.floor(17 * Math.random()));
  1890. var max = this.xBound - 1;
  1891. if (1 > max) {
  1892. throw haxe_Exception.thrown("FAIL: min <= max");
  1893. }
  1894. this.x2 = value < 1 ? 1 : value > max ? max : value;
  1895. var value = this.y2 + (-8 + Math.floor(17 * Math.random()));
  1896. var max = this.yBound - 1;
  1897. if (1 > max) {
  1898. throw haxe_Exception.thrown("FAIL: min <= max");
  1899. }
  1900. this.y2 = value < 1 ? 1 : value > max ? max : value;
  1901. break;
  1902. }
  1903. },
  1904. clone: function () {
  1905. var bezier = new geometrize_shape_QuadraticBezier(this.xBound, this.yBound);
  1906. bezier.cx = this.cx;
  1907. bezier.cy = this.cy;
  1908. bezier.x1 = this.x1;
  1909. bezier.y1 = this.y1;
  1910. bezier.x2 = this.x2;
  1911. bezier.y2 = this.y2;
  1912. return bezier;
  1913. },
  1914. getType: function () {
  1915. return 7;
  1916. },
  1917. getRawShapeData: function () {
  1918. return [this.x1, this.y1, this.cx, this.cy, this.x2, this.y2];
  1919. },
  1920. getSvgShapeData: function () {
  1921. return '<path d="M' + this.x1 + " " + this.y1 + " Q " + this.cx + " " + this.cy + " " + this.x2 + " " + this.y2 + '" ' + geometrize_exporter_SvgExporter.SVG_STYLE_HOOK + " />";
  1922. },
  1923. };
  1924. var geometrize_shape_Rectangle = function (xBound, yBound) {
  1925. this.x1 = Std.random(xBound);
  1926. this.y1 = Std.random(yBound);
  1927. var value = this.x1 + Std.random(32) + 1;
  1928. var max = xBound - 1;
  1929. if (0 > max) {
  1930. throw haxe_Exception.thrown("FAIL: min <= max");
  1931. }
  1932. this.x2 = value < 0 ? 0 : value > max ? max : value;
  1933. var value = this.y1 + Std.random(32) + 1;
  1934. var max = yBound - 1;
  1935. if (0 > max) {
  1936. throw haxe_Exception.thrown("FAIL: min <= max");
  1937. }
  1938. this.y2 = value < 0 ? 0 : value > max ? max : value;
  1939. this.xBound = xBound;
  1940. this.yBound = yBound;
  1941. };
  1942. geometrize_shape_Rectangle.__name__ = true;
  1943. geometrize_shape_Rectangle.prototype = {
  1944. rasterize: function () {
  1945. var lines = [];
  1946. var first = this.y1;
  1947. var second = this.y2;
  1948. var yMin = first < second ? first : second;
  1949. var first = this.y1;
  1950. var second = this.y2;
  1951. var yMax = first > second ? first : second;
  1952. if (yMin == yMax) {
  1953. var first = this.x1;
  1954. var second = this.x2;
  1955. var first1 = this.x1;
  1956. var second1 = this.x2;
  1957. lines.push(new geometrize_rasterizer_Scanline(yMin, first < second ? first : second, first1 > second1 ? first1 : second1));
  1958. } else {
  1959. var _g = yMin;
  1960. var _g1 = yMax;
  1961. while (_g < _g1) {
  1962. var y = _g++;
  1963. var first = this.x1;
  1964. var second = this.x2;
  1965. var first1 = this.x1;
  1966. var second1 = this.x2;
  1967. lines.push(new geometrize_rasterizer_Scanline(y, first < second ? first : second, first1 > second1 ? first1 : second1));
  1968. }
  1969. }
  1970. return lines;
  1971. },
  1972. mutate: function () {
  1973. var r = Std.random(2);
  1974. switch (r) {
  1975. case 0:
  1976. var value = this.x1 + (-16 + Math.floor(33 * Math.random()));
  1977. var max = this.xBound - 1;
  1978. if (0 > max) {
  1979. throw haxe_Exception.thrown("FAIL: min <= max");
  1980. }
  1981. this.x1 = value < 0 ? 0 : value > max ? max : value;
  1982. var value = this.y1 + (-16 + Math.floor(33 * Math.random()));
  1983. var max = this.yBound - 1;
  1984. if (0 > max) {
  1985. throw haxe_Exception.thrown("FAIL: min <= max");
  1986. }
  1987. this.y1 = value < 0 ? 0 : value > max ? max : value;
  1988. break;
  1989. case 1:
  1990. var value = this.x2 + (-16 + Math.floor(33 * Math.random()));
  1991. var max = this.xBound - 1;
  1992. if (0 > max) {
  1993. throw haxe_Exception.thrown("FAIL: min <= max");
  1994. }
  1995. this.x2 = value < 0 ? 0 : value > max ? max : value;
  1996. var value = this.y2 + (-16 + Math.floor(33 * Math.random()));
  1997. var max = this.yBound - 1;
  1998. if (0 > max) {
  1999. throw haxe_Exception.thrown("FAIL: min <= max");
  2000. }
  2001. this.y2 = value < 0 ? 0 : value > max ? max : value;
  2002. break;
  2003. }
  2004. },
  2005. clone: function () {
  2006. var rectangle = new geometrize_shape_Rectangle(this.xBound, this.yBound);
  2007. rectangle.x1 = this.x1;
  2008. rectangle.y1 = this.y1;
  2009. rectangle.x2 = this.x2;
  2010. rectangle.y2 = this.y2;
  2011. return rectangle;
  2012. },
  2013. getType: function () {
  2014. return 0;
  2015. },
  2016. getRawShapeData: function () {
  2017. var first = this.x1;
  2018. var second = this.x2;
  2019. var first1 = this.y1;
  2020. var second1 = this.y2;
  2021. var first2 = this.x1;
  2022. var second2 = this.x2;
  2023. var first3 = this.y1;
  2024. var second3 = this.y2;
  2025. return [first < second ? first : second, first1 < second1 ? first1 : second1, first2 > second2 ? first2 : second2, first3 > second3 ? first3 : second3];
  2026. },
  2027. getSvgShapeData: function () {
  2028. var first = this.x1;
  2029. var second = this.x2;
  2030. var first1 = this.y1;
  2031. var second1 = this.y2;
  2032. var first2 = this.x1;
  2033. var second2 = this.x2;
  2034. var first3 = this.x1;
  2035. var second3 = this.x2;
  2036. var first4 = this.y1;
  2037. var second4 = this.y2;
  2038. var first5 = this.y1;
  2039. var second5 = this.y2;
  2040. return (
  2041. '<rect x="' +
  2042. (first < second ? first : second) +
  2043. '" y="' +
  2044. (first1 < second1 ? first1 : second1) +
  2045. '" width="' +
  2046. ((first2 > second2 ? first2 : second2) - (first3 < second3 ? first3 : second3)) +
  2047. '" height="' +
  2048. ((first4 > second4 ? first4 : second4) - (first5 < second5 ? first5 : second5)) +
  2049. '" ' +
  2050. geometrize_exporter_SvgExporter.SVG_STYLE_HOOK +
  2051. " />"
  2052. );
  2053. },
  2054. };
  2055. var geometrize_shape_RotatedEllipse = function (xBound, yBound) {
  2056. this.x = Std.random(xBound);
  2057. this.y = Std.random(yBound);
  2058. this.rx = Std.random(32) + 1;
  2059. this.ry = Std.random(32) + 1;
  2060. this.angle = Std.random(360);
  2061. this.xBound = xBound;
  2062. this.yBound = yBound;
  2063. };
  2064. geometrize_shape_RotatedEllipse.__name__ = true;
  2065. geometrize_shape_RotatedEllipse.prototype = {
  2066. rasterize: function () {
  2067. var pointCount = 20;
  2068. var points = [];
  2069. var rads = this.angle * (Math.PI / 180.0);
  2070. var c = Math.cos(rads);
  2071. var s = Math.sin(rads);
  2072. var _g = 0;
  2073. var _g1 = pointCount;
  2074. while (_g < _g1) {
  2075. var i = _g++;
  2076. var rot = (360.0 / pointCount) * i * (Math.PI / 180.0);
  2077. var crx = this.rx * Math.cos(rot);
  2078. var cry = this.ry * Math.sin(rot);
  2079. var tx = (crx * c - cry * s + this.x) | 0;
  2080. var ty = (crx * s + cry * c + this.y) | 0;
  2081. points.push({ x: tx, y: ty });
  2082. }
  2083. return geometrize_rasterizer_Scanline.trim(geometrize_rasterizer_Rasterizer.scanlinesForPolygon(points), this.xBound, this.yBound);
  2084. },
  2085. mutate: function () {
  2086. var r = Std.random(4);
  2087. switch (r) {
  2088. case 0:
  2089. var value = this.x + (-16 + Math.floor(33 * Math.random()));
  2090. var max = this.xBound - 1;
  2091. if (0 > max) {
  2092. throw haxe_Exception.thrown("FAIL: min <= max");
  2093. }
  2094. this.x = value < 0 ? 0 : value > max ? max : value;
  2095. var value = this.y + (-16 + Math.floor(33 * Math.random()));
  2096. var max = this.yBound - 1;
  2097. if (0 > max) {
  2098. throw haxe_Exception.thrown("FAIL: min <= max");
  2099. }
  2100. this.y = value < 0 ? 0 : value > max ? max : value;
  2101. break;
  2102. case 1:
  2103. var value = this.rx + (-16 + Math.floor(33 * Math.random()));
  2104. var max = this.xBound - 1;
  2105. if (1 > max) {
  2106. throw haxe_Exception.thrown("FAIL: min <= max");
  2107. }
  2108. this.rx = value < 1 ? 1 : value > max ? max : value;
  2109. break;
  2110. case 2:
  2111. var value = this.ry + (-16 + Math.floor(33 * Math.random()));
  2112. var max = this.yBound - 1;
  2113. if (1 > max) {
  2114. throw haxe_Exception.thrown("FAIL: min <= max");
  2115. }
  2116. this.ry = value < 1 ? 1 : value > max ? max : value;
  2117. break;
  2118. case 3:
  2119. var value = this.angle + (-4 + Math.floor(9 * Math.random()));
  2120. this.angle = value < 0 ? 0 : value > 360 ? 360 : value;
  2121. break;
  2122. }
  2123. },
  2124. clone: function () {
  2125. var ellipse = new geometrize_shape_RotatedEllipse(this.xBound, this.yBound);
  2126. ellipse.x = this.x;
  2127. ellipse.y = this.y;
  2128. ellipse.rx = this.rx;
  2129. ellipse.ry = this.ry;
  2130. ellipse.angle = this.angle;
  2131. return ellipse;
  2132. },
  2133. getType: function () {
  2134. return 4;
  2135. },
  2136. getRawShapeData: function () {
  2137. return [this.x, this.y, this.rx, this.ry, this.angle];
  2138. },
  2139. getSvgShapeData: function () {
  2140. var s = '<g transform="translate(' + this.x + " " + this.y + ") rotate(" + this.angle + ") scale(" + this.rx + " " + this.ry + ')">';
  2141. s += '<ellipse cx="' + 0 + '" cy="' + 0 + '" rx="' + 1 + '" ry="' + 1 + '" ' + geometrize_exporter_SvgExporter.SVG_STYLE_HOOK + " />";
  2142. s += "</g>";
  2143. return s;
  2144. },
  2145. };
  2146. var geometrize_shape_RotatedRectangle = function (xBound, yBound) {
  2147. this.x1 = Std.random(xBound);
  2148. this.y1 = Std.random(yBound);
  2149. var value = this.x1 + Std.random(32) + 1;
  2150. if (0 > xBound) {
  2151. throw haxe_Exception.thrown("FAIL: min <= max");
  2152. }
  2153. this.x2 = value < 0 ? 0 : value > xBound ? xBound : value;
  2154. var value = this.y1 + Std.random(32) + 1;
  2155. if (0 > yBound) {
  2156. throw haxe_Exception.thrown("FAIL: min <= max");
  2157. }
  2158. this.y2 = value < 0 ? 0 : value > yBound ? yBound : value;
  2159. this.angle = Math.floor(361 * Math.random());
  2160. this.xBound = xBound;
  2161. this.yBound = yBound;
  2162. };
  2163. geometrize_shape_RotatedRectangle.__name__ = true;
  2164. geometrize_shape_RotatedRectangle.prototype = {
  2165. rasterize: function () {
  2166. var first = this.x1;
  2167. var second = this.x2;
  2168. var xm1 = first < second ? first : second;
  2169. var first = this.x1;
  2170. var second = this.x2;
  2171. var xm2 = first > second ? first : second;
  2172. var first = this.y1;
  2173. var second = this.y2;
  2174. var ym1 = first < second ? first : second;
  2175. var first = this.y1;
  2176. var second = this.y2;
  2177. var ym2 = first > second ? first : second;
  2178. var cx = ((xm1 + xm2) / 2) | 0;
  2179. var cy = ((ym1 + ym2) / 2) | 0;
  2180. var ox1 = xm1 - cx;
  2181. var ox2 = xm2 - cx;
  2182. var oy1 = ym1 - cy;
  2183. var oy2 = ym2 - cy;
  2184. var rads = (this.angle * Math.PI) / 180.0;
  2185. var c = Math.cos(rads);
  2186. var s = Math.sin(rads);
  2187. var ulx = (ox1 * c - oy1 * s + cx) | 0;
  2188. var uly = (ox1 * s + oy1 * c + cy) | 0;
  2189. var blx = (ox1 * c - oy2 * s + cx) | 0;
  2190. var bly = (ox1 * s + oy2 * c + cy) | 0;
  2191. var urx = (ox2 * c - oy1 * s + cx) | 0;
  2192. var ury = (ox2 * s + oy1 * c + cy) | 0;
  2193. var brx = (ox2 * c - oy2 * s + cx) | 0;
  2194. var bry = (ox2 * s + oy2 * c + cy) | 0;
  2195. return geometrize_rasterizer_Scanline.trim(
  2196. geometrize_rasterizer_Rasterizer.scanlinesForPolygon([
  2197. { x: ulx, y: uly },
  2198. { x: urx, y: ury },
  2199. { x: brx, y: bry },
  2200. { x: blx, y: bly },
  2201. ]),
  2202. this.xBound,
  2203. this.yBound
  2204. );
  2205. },
  2206. mutate: function () {
  2207. var r = Std.random(3);
  2208. switch (r) {
  2209. case 0:
  2210. var value = this.x1 + (-16 + Math.floor(33 * Math.random()));
  2211. var max = this.xBound - 1;
  2212. if (0 > max) {
  2213. throw haxe_Exception.thrown("FAIL: min <= max");
  2214. }
  2215. this.x1 = value < 0 ? 0 : value > max ? max : value;
  2216. var value = this.y1 + (-16 + Math.floor(33 * Math.random()));
  2217. var max = this.yBound - 1;
  2218. if (0 > max) {
  2219. throw haxe_Exception.thrown("FAIL: min <= max");
  2220. }
  2221. this.y1 = value < 0 ? 0 : value > max ? max : value;
  2222. break;
  2223. case 1:
  2224. var value = this.x2 + (-16 + Math.floor(33 * Math.random()));
  2225. var max = this.xBound - 1;
  2226. if (0 > max) {
  2227. throw haxe_Exception.thrown("FAIL: min <= max");
  2228. }
  2229. this.x2 = value < 0 ? 0 : value > max ? max : value;
  2230. var value = this.y2 + (-16 + Math.floor(33 * Math.random()));
  2231. var max = this.yBound - 1;
  2232. if (0 > max) {
  2233. throw haxe_Exception.thrown("FAIL: min <= max");
  2234. }
  2235. this.y2 = value < 0 ? 0 : value > max ? max : value;
  2236. break;
  2237. case 2:
  2238. var value = this.angle + (-4 + Math.floor(9 * Math.random()));
  2239. this.angle = value < 0 ? 0 : value > 360 ? 360 : value;
  2240. break;
  2241. }
  2242. },
  2243. clone: function () {
  2244. var rectangle = new geometrize_shape_RotatedRectangle(this.xBound, this.yBound);
  2245. rectangle.x1 = this.x1;
  2246. rectangle.y1 = this.y1;
  2247. rectangle.x2 = this.x2;
  2248. rectangle.y2 = this.y2;
  2249. rectangle.angle = this.angle;
  2250. return rectangle;
  2251. },
  2252. getType: function () {
  2253. return 1;
  2254. },
  2255. getRawShapeData: function () {
  2256. var first = this.x1;
  2257. var second = this.x2;
  2258. var first1 = this.y1;
  2259. var second1 = this.y2;
  2260. var first2 = this.x1;
  2261. var second2 = this.x2;
  2262. var first3 = this.y1;
  2263. var second3 = this.y2;
  2264. return [first < second ? first : second, first1 < second1 ? first1 : second1, first2 > second2 ? first2 : second2, first3 > second3 ? first3 : second3, this.angle];
  2265. },
  2266. getSvgShapeData: function () {
  2267. var first = this.x1;
  2268. var second = this.x2;
  2269. var xm1 = first < second ? first : second;
  2270. var first = this.x1;
  2271. var second = this.x2;
  2272. var xm2 = first > second ? first : second;
  2273. var first = this.y1;
  2274. var second = this.y2;
  2275. var ym1 = first < second ? first : second;
  2276. var first = this.y1;
  2277. var second = this.y2;
  2278. var ym2 = first > second ? first : second;
  2279. var cx = ((xm1 + xm2) / 2) | 0;
  2280. var cy = ((ym1 + ym2) / 2) | 0;
  2281. var ox1 = xm1 - cx;
  2282. var ox2 = xm2 - cx;
  2283. var oy1 = ym1 - cy;
  2284. var oy2 = ym2 - cy;
  2285. var rads = (this.angle * Math.PI) / 180.0;
  2286. var c = Math.cos(rads);
  2287. var s = Math.sin(rads);
  2288. var ulx = (ox1 * c - oy1 * s + cx) | 0;
  2289. var uly = (ox1 * s + oy1 * c + cy) | 0;
  2290. var blx = (ox1 * c - oy2 * s + cx) | 0;
  2291. var bly = (ox1 * s + oy2 * c + cy) | 0;
  2292. var urx = (ox2 * c - oy1 * s + cx) | 0;
  2293. var ury = (ox2 * s + oy1 * c + cy) | 0;
  2294. var brx = (ox2 * c - oy2 * s + cx) | 0;
  2295. var bry = (ox2 * s + oy2 * c + cy) | 0;
  2296. var points = [
  2297. { x: ulx, y: uly },
  2298. { x: urx, y: ury },
  2299. { x: brx, y: bry },
  2300. { x: blx, y: bly },
  2301. ];
  2302. var s = '<polygon points="';
  2303. var _g = 0;
  2304. var _g1 = points.length;
  2305. while (_g < _g1) {
  2306. var i = _g++;
  2307. s += points[i].x + " " + points[i].y;
  2308. if (i != points.length - 1) {
  2309. s += " ";
  2310. }
  2311. }
  2312. s += '" ' + geometrize_exporter_SvgExporter.SVG_STYLE_HOOK + "/>";
  2313. return s;
  2314. },
  2315. };
  2316. var geometrize_shape_ShapeFactory = function () {};
  2317. geometrize_shape_ShapeFactory.__name__ = true;
  2318. geometrize_shape_ShapeFactory.create = function (type, xBound, yBound) {
  2319. switch (type) {
  2320. case 0:
  2321. return new geometrize_shape_Rectangle(xBound, yBound);
  2322. case 1:
  2323. return new geometrize_shape_RotatedRectangle(xBound, yBound);
  2324. case 2:
  2325. return new geometrize_shape_Triangle(xBound, yBound);
  2326. case 3:
  2327. return new geometrize_shape_Ellipse(xBound, yBound);
  2328. case 4:
  2329. return new geometrize_shape_RotatedEllipse(xBound, yBound);
  2330. case 5:
  2331. return new geometrize_shape_Circle(xBound, yBound);
  2332. case 6:
  2333. return new geometrize_shape_Line(xBound, yBound);
  2334. case 7:
  2335. return new geometrize_shape_QuadraticBezier(xBound, yBound);
  2336. }
  2337. };
  2338. geometrize_shape_ShapeFactory.randomShapeOf = function (types, xBound, yBound) {
  2339. if (!(types != null && types.length > 0)) {
  2340. throw haxe_Exception.thrown("FAIL: a != null && a.length > 0");
  2341. }
  2342. var upper = types.length - 1;
  2343. if (0 > upper) {
  2344. throw haxe_Exception.thrown("FAIL: lower <= upper");
  2345. }
  2346. return geometrize_shape_ShapeFactory.create(types[Math.floor((upper + 1) * Math.random())], xBound, yBound);
  2347. };
  2348. var geometrize_shape_ShapeTypes = ($hx_exports["geometrize"]["shape"]["ShapeTypes"] = function () {});
  2349. geometrize_shape_ShapeTypes.__name__ = true;
  2350. var geometrize_shape_Triangle = function (xBound, yBound) {
  2351. this.x1 = Std.random(xBound);
  2352. this.y1 = Std.random(yBound);
  2353. this.x2 = this.x1 + (-16 + Math.floor(33 * Math.random()));
  2354. this.y2 = this.y1 + (-16 + Math.floor(33 * Math.random()));
  2355. this.x3 = this.x1 + (-16 + Math.floor(33 * Math.random()));
  2356. this.y3 = this.y1 + (-16 + Math.floor(33 * Math.random()));
  2357. this.xBound = xBound;
  2358. this.yBound = yBound;
  2359. };
  2360. geometrize_shape_Triangle.__name__ = true;
  2361. geometrize_shape_Triangle.prototype = {
  2362. rasterize: function () {
  2363. return geometrize_rasterizer_Scanline.trim(
  2364. geometrize_rasterizer_Rasterizer.scanlinesForPolygon([
  2365. { x: this.x1, y: this.y1 },
  2366. { x: this.x2, y: this.y2 },
  2367. { x: this.x3, y: this.y3 },
  2368. ]),
  2369. this.xBound,
  2370. this.yBound
  2371. );
  2372. },
  2373. mutate: function () {
  2374. var r = Std.random(3);
  2375. switch (r) {
  2376. case 0:
  2377. var value = this.x1 + (-16 + Math.floor(33 * Math.random()));
  2378. var max = this.xBound - 1;
  2379. if (0 > max) {
  2380. throw haxe_Exception.thrown("FAIL: min <= max");
  2381. }
  2382. this.x1 = value < 0 ? 0 : value > max ? max : value;
  2383. var value = this.y1 + (-16 + Math.floor(33 * Math.random()));
  2384. var max = this.yBound - 1;
  2385. if (0 > max) {
  2386. throw haxe_Exception.thrown("FAIL: min <= max");
  2387. }
  2388. this.y1 = value < 0 ? 0 : value > max ? max : value;
  2389. break;
  2390. case 1:
  2391. var value = this.x2 + (-16 + Math.floor(33 * Math.random()));
  2392. var max = this.xBound - 1;
  2393. if (0 > max) {
  2394. throw haxe_Exception.thrown("FAIL: min <= max");
  2395. }
  2396. this.x2 = value < 0 ? 0 : value > max ? max : value;
  2397. var value = this.y2 + (-16 + Math.floor(33 * Math.random()));
  2398. var max = this.yBound - 1;
  2399. if (0 > max) {
  2400. throw haxe_Exception.thrown("FAIL: min <= max");
  2401. }
  2402. this.y2 = value < 0 ? 0 : value > max ? max : value;
  2403. break;
  2404. case 2:
  2405. var value = this.x3 + (-16 + Math.floor(33 * Math.random()));
  2406. var max = this.xBound - 1;
  2407. if (0 > max) {
  2408. throw haxe_Exception.thrown("FAIL: min <= max");
  2409. }
  2410. this.x3 = value < 0 ? 0 : value > max ? max : value;
  2411. var value = this.y3 + (-16 + Math.floor(33 * Math.random()));
  2412. var max = this.yBound - 1;
  2413. if (0 > max) {
  2414. throw haxe_Exception.thrown("FAIL: min <= max");
  2415. }
  2416. this.y3 = value < 0 ? 0 : value > max ? max : value;
  2417. break;
  2418. }
  2419. },
  2420. clone: function () {
  2421. var triangle = new geometrize_shape_Triangle(this.xBound, this.yBound);
  2422. triangle.x1 = this.x1;
  2423. triangle.y1 = this.y1;
  2424. triangle.x2 = this.x2;
  2425. triangle.y2 = this.y2;
  2426. triangle.x3 = this.x3;
  2427. triangle.y3 = this.y3;
  2428. return triangle;
  2429. },
  2430. getType: function () {
  2431. return 2;
  2432. },
  2433. getRawShapeData: function () {
  2434. return [this.x1, this.y1, this.x2, this.y2, this.x3, this.y3];
  2435. },
  2436. getSvgShapeData: function () {
  2437. return '<polygon points="' + this.x1 + "," + this.y1 + " " + this.x2 + "," + this.y2 + " " + this.x3 + "," + this.y3 + '" ' + geometrize_exporter_SvgExporter.SVG_STYLE_HOOK + "/>";
  2438. },
  2439. };
  2440. var haxe_Exception = function (message, previous, native) {
  2441. Error.call(this, message);
  2442. this.message = message;
  2443. this.__previousException = previous;
  2444. this.__nativeException = native != null ? native : this;
  2445. };
  2446. haxe_Exception.__name__ = true;
  2447. haxe_Exception.thrown = function (value) {
  2448. if (value instanceof haxe_Exception) {
  2449. return value.get_native();
  2450. } else if (value instanceof Error) {
  2451. return value;
  2452. } else {
  2453. var e = new haxe_ValueException(value);
  2454. return e;
  2455. }
  2456. };
  2457. haxe_Exception.__super__ = Error;
  2458. haxe_Exception.prototype = $extend(Error.prototype, {
  2459. get_native: function () {
  2460. return this.__nativeException;
  2461. },
  2462. });
  2463. var haxe_ValueException = function (value, previous, native) {
  2464. haxe_Exception.call(this, String(value), previous, native);
  2465. this.value = value;
  2466. };
  2467. haxe_ValueException.__name__ = true;
  2468. haxe_ValueException.__super__ = haxe_Exception;
  2469. haxe_ValueException.prototype = $extend(haxe_Exception.prototype, {});
  2470. var haxe_ds_IntMap = function () {
  2471. this.h = {};
  2472. };
  2473. haxe_ds_IntMap.__name__ = true;
  2474. haxe_ds_IntMap.prototype = {
  2475. keys: function () {
  2476. var a = [];
  2477. for (var key in this.h) if (this.h.hasOwnProperty(key)) a.push(+key);
  2478. return new haxe_iterators_ArrayIterator(a);
  2479. },
  2480. };
  2481. var haxe_io_Bytes = function (data) {
  2482. this.length = data.byteLength;
  2483. this.b = new Uint8Array(data);
  2484. this.b.bufferValue = data;
  2485. data.hxBytes = this;
  2486. data.bytes = this.b;
  2487. };
  2488. haxe_io_Bytes.__name__ = true;
  2489. var haxe_iterators_ArrayIterator = function (array) {
  2490. this.current = 0;
  2491. this.array = array;
  2492. };
  2493. haxe_iterators_ArrayIterator.__name__ = true;
  2494. haxe_iterators_ArrayIterator.prototype = {
  2495. hasNext: function () {
  2496. return this.current < this.array.length;
  2497. },
  2498. next: function () {
  2499. return this.array[this.current++];
  2500. },
  2501. };
  2502. var js_Boot = function () {};
  2503. js_Boot.__name__ = true;
  2504. js_Boot.__string_rec = function (o, s) {
  2505. if (o == null) {
  2506. return "null";
  2507. }
  2508. if (s.length >= 5) {
  2509. return "<...>";
  2510. }
  2511. var t = typeof o;
  2512. if (t == "function" && (o.__name__ || o.__ename__)) {
  2513. t = "object";
  2514. }
  2515. switch (t) {
  2516. case "function":
  2517. return "<function>";
  2518. case "object":
  2519. if (o instanceof Array) {
  2520. var str = "[";
  2521. s += "\t";
  2522. var _g = 0;
  2523. var _g1 = o.length;
  2524. while (_g < _g1) {
  2525. var i = _g++;
  2526. str += (i > 0 ? "," : "") + js_Boot.__string_rec(o[i], s);
  2527. }
  2528. str += "]";
  2529. return str;
  2530. }
  2531. var tostr;
  2532. try {
  2533. tostr = o.toString;
  2534. } catch (_g) {
  2535. return "???";
  2536. }
  2537. if (tostr != null && tostr != Object.toString && typeof tostr == "function") {
  2538. var s2 = o.toString();
  2539. if (s2 != "[object Object]") {
  2540. return s2;
  2541. }
  2542. }
  2543. var str = "{\n";
  2544. s += "\t";
  2545. var hasp = o.hasOwnProperty != null;
  2546. var k = null;
  2547. for (k in o) {
  2548. if (hasp && !o.hasOwnProperty(k)) {
  2549. continue;
  2550. }
  2551. if (k == "prototype" || k == "__class__" || k == "__super__" || k == "__interfaces__" || k == "__properties__") {
  2552. continue;
  2553. }
  2554. if (str.length != 2) {
  2555. str += ", \n";
  2556. }
  2557. str += s + k + " : " + js_Boot.__string_rec(o[k], s);
  2558. }
  2559. s = s.substring(1);
  2560. str += "\n" + s + "}";
  2561. return str;
  2562. case "string":
  2563. return o;
  2564. default:
  2565. return String(o);
  2566. }
  2567. };
  2568. var $_;
  2569. function $bind(o, m) {
  2570. if (m == null) return null;
  2571. if (m.__id__ == null) m.__id__ = $global.$haxeUID++;
  2572. var f;
  2573. if (o.hx__closures__ == null) o.hx__closures__ = {};
  2574. else f = o.hx__closures__[m.__id__];
  2575. if (f == null) {
  2576. f = m.bind(o);
  2577. o.hx__closures__[m.__id__] = f;
  2578. }
  2579. return f;
  2580. }
  2581. $global.$haxeUID |= 0;
  2582. if (typeof performance != "undefined" ? typeof performance.now == "function" : false) {
  2583. HxOverrides.now = performance.now.bind(performance);
  2584. }
  2585. String.__name__ = true;
  2586. Array.__name__ = true;
  2587. js_Boot.__toStr = {}.toString;
  2588. // Main.runPauseButton = window.document.getElementById("runpausebutton");
  2589. // Main.stepButton = window.document.getElementById("stepbutton");
  2590. // Main.openImageFileInput = window.document.getElementById("openimageinput");
  2591. // Main.randomImageButton = window.document.getElementById("randomimagebutton");
  2592. // Main.resetButton = window.document.getElementById("resetbutton");
  2593. // Main.saveImageButton = window.document.getElementById("saveimagebutton");
  2594. // Main.saveSvgButton = window.document.getElementById("savesvgbutton");
  2595. // Main.saveJsonButton = window.document.getElementById("savejsonbutton");
  2596. // Main.rectanglesCheckbox = window.document.getElementById("rectangles");
  2597. // Main.rotatedRectanglesCheckbox = window.document.getElementById("rotatedrectangles");
  2598. // Main.trianglesCheckbox = window.document.getElementById("triangles");
  2599. // Main.ellipsesCheckbox = window.document.getElementById("ellipses");
  2600. // Main.rotatedEllipsesCheckbox = window.document.getElementById("rotatedellipses");
  2601. // Main.circlesCheckbox = window.document.getElementById("circles");
  2602. // Main.linesCheckbox = window.document.getElementById("lines");
  2603. // Main.quadraticBeziersCheckbox = window.document.getElementById("quadraticbeziers");
  2604. // Main.shapeOpacitySlider = window.document.getElementById("shapeopacity");
  2605. // Main.initialBackgroundOpacitySlider = window.document.getElementById("initialbackgroundopacity");
  2606. // Main.randomShapesPerStepSlider = window.document.getElementById("randomshapesperstep");
  2607. // Main.shapeMutationsPerStepSlider = window.document.getElementById("shapemutationsperstep");
  2608. // Main.shapesAddedText = window.document.getElementById("shapesaddedtext");
  2609. // Main.maxShapesCapTextEdit = window.document.getElementById("maxshapescaptextedit");
  2610. // Main.currentSvgContainer = window.document.getElementById("currentsvgcontainer");
  2611. // Main.sampleImagesContainer = window.document.getElementById("sampleimages");
  2612. // Main.defaultImageElement = window.document.getElementById("defaultimage");
  2613. Main.imagesToGeometrize = [];
  2614. geometrize_exporter_SvgExporter.SVG_STYLE_HOOK = "::svg_style_hook::";
  2615. geometrize_runner_Default.options = {
  2616. shapeTypes: [5, 6],
  2617. candidateShapesPerStep: 50,
  2618. shapeMutationsPerStep: 100,
  2619. alpha: 255,
  2620. };
  2621. geometrize_shape_ShapeTypes.RECTANGLE = 0;
  2622. geometrize_shape_ShapeTypes.ROTATED_RECTANGLE = 1;
  2623. geometrize_shape_ShapeTypes.TRIANGLE = 2;
  2624. geometrize_shape_ShapeTypes.ELLIPSE = 3;
  2625. geometrize_shape_ShapeTypes.ROTATED_ELLIPSE = 4;
  2626. geometrize_shape_ShapeTypes.CIRCLE = 5;
  2627. geometrize_shape_ShapeTypes.LINE = 6;
  2628. geometrize_shape_ShapeTypes.QUADRATIC_BEZIER = 7;
  2629. Main.main();
  2630. })(
  2631. typeof exports != "undefined" ? exports : typeof window != "undefined" ? window : typeof self != "undefined" ? self : this,
  2632. typeof window != "undefined" ? window : typeof global != "undefined" ? global : typeof self != "undefined" ? self : this,
  2633. `(function ($hx_exports, $global) {
  2634. "use strict";
  2635. $hx_exports["geometrize"] = $hx_exports["geometrize"] || {};
  2636. $hx_exports["geometrize"]["bitmap"] = $hx_exports["geometrize"]["bitmap"] || {};
  2637. $hx_exports["geometrize"]["exporter"] = $hx_exports["geometrize"]["exporter"] || {};
  2638. $hx_exports["geometrize"]["runner"] = $hx_exports["geometrize"]["runner"] || {};
  2639. $hx_exports["geometrize"]["shape"] = $hx_exports["geometrize"]["shape"] || {};
  2640. function $extend(from, fields) {
  2641. var proto = Object.create(from);
  2642. for (var name in fields) proto[name] = fields[name];
  2643. if (fields.toString !== Object.prototype.toString) proto.toString = fields.toString;
  2644. return proto;
  2645. }
  2646. var GeometrizeWorker = function () {};
  2647. GeometrizeWorker.prototype = {
  2648. messageHandler: function (event) {
  2649. if (event == null || event.data == null) {
  2650. return;
  2651. }
  2652. var message = event.data;
  2653. switch (message.id) {
  2654. case "should_set_target_image":
  2655. var target = message.data;
  2656. this.runner = new geometrize_runner_ImageRunner(target, geometrize_Util.getAverageImageColor(target));
  2657. this.postMessage({ id: "did_set_target_image" });
  2658. break;
  2659. case "should_step":
  2660. var options = message.data;
  2661. var results = this.runner.step(options);
  2662. var svgData = geometrize_exporter_SvgExporter.exportShapes(results);
  2663. var jsonData = geometrize_exporter_ShapeJsonExporter.exportShapes(results);
  2664. this.postMessage({ id: "did_step", svgData: svgData, jsonData: jsonData });
  2665. break;
  2666. }
  2667. },
  2668. postMessage: function (message) {},
  2669. };
  2670. var Std = function () {};
  2671. Std.random = function (x) {
  2672. if (x <= 0) {
  2673. return 0;
  2674. } else {
  2675. return Math.floor(Math.random() * x);
  2676. }
  2677. };
  2678. var StringTools = function () {};
  2679. StringTools.replace = function (s, sub, by) {
  2680. return s.split(sub).join(by);
  2681. };
  2682. var UInt = {};
  2683. UInt.toFloat = function (this1) {
  2684. var int = this1;
  2685. if (int < 0) {
  2686. return 4294967296.0 + int;
  2687. } else {
  2688. return int + 0.0;
  2689. }
  2690. };
  2691. var geometrize_ArraySet = {};
  2692. geometrize_ArraySet.create = function (array) {
  2693. if (array == null) {
  2694. var this1 = [];
  2695. return this1;
  2696. }
  2697. return geometrize_ArraySet.toSet(array);
  2698. };
  2699. geometrize_ArraySet.add = function (this1, element) {
  2700. if (element == null) {
  2701. throw haxe_Exception.thrown("FAIL: element != null");
  2702. }
  2703. if (geometrize_ArraySet.contains(this1, element)) {
  2704. return false;
  2705. }
  2706. this1.push(element);
  2707. return true;
  2708. };
  2709. geometrize_ArraySet.contains = function (this1, element) {
  2710. var _g = 0;
  2711. while (_g < this1.length) {
  2712. var i = this1[_g];
  2713. ++_g;
  2714. if (i == element) {
  2715. return true;
  2716. }
  2717. }
  2718. return false;
  2719. };
  2720. geometrize_ArraySet.toArray = function (this1) {
  2721. return this1.slice();
  2722. };
  2723. geometrize_ArraySet.toSet = function (array) {
  2724. var this1 = [];
  2725. var set = this1;
  2726. var _g = 0;
  2727. while (_g < array.length) {
  2728. var v = array[_g];
  2729. ++_g;
  2730. geometrize_ArraySet.add(set, v);
  2731. }
  2732. return set;
  2733. };
  2734. var geometrize_Core = function () {};
  2735. geometrize_Core.computeColor = function (target, current, lines, alpha) {
  2736. if (target == null) {
  2737. throw haxe_Exception.thrown("FAIL: target != null");
  2738. }
  2739. if (current == null) {
  2740. throw haxe_Exception.thrown("FAIL: current != null");
  2741. }
  2742. if (lines == null) {
  2743. throw haxe_Exception.thrown("FAIL: lines != null");
  2744. }
  2745. if (alpha < 0) {
  2746. throw haxe_Exception.thrown("FAIL: alpha >= 0");
  2747. }
  2748. var totalRed = 0;
  2749. var totalGreen = 0;
  2750. var totalBlue = 0;
  2751. var count = 0;
  2752. var f = 65535 / alpha;
  2753. var a = f | 0;
  2754. var _g = 0;
  2755. while (_g < lines.length) {
  2756. var line = lines[_g];
  2757. ++_g;
  2758. var y = line.y;
  2759. var _g1 = line.x1;
  2760. var _g2 = line.x2 + 1;
  2761. while (_g1 < _g2) {
  2762. var x = _g1++;
  2763. var t = target.data[target.width * y + x];
  2764. var c = current.data[current.width * y + x];
  2765. totalRed += (((t >> 24) & 255) - ((c >> 24) & 255)) * a + ((c >> 24) & 255) * 257;
  2766. totalGreen += (((t >> 16) & 255) - ((c >> 16) & 255)) * a + ((c >> 16) & 255) * 257;
  2767. totalBlue += (((t >> 8) & 255) - ((c >> 8) & 255)) * a + ((c >> 8) & 255) * 257;
  2768. ++count;
  2769. }
  2770. }
  2771. if (count == 0) {
  2772. return 0;
  2773. }
  2774. var value = ((totalRed / count) | 0) >> 8;
  2775. var r = value < 0 ? 0 : value > 255 ? 255 : value;
  2776. var value = ((totalGreen / count) | 0) >> 8;
  2777. var g = value < 0 ? 0 : value > 255 ? 255 : value;
  2778. var value = ((totalBlue / count) | 0) >> 8;
  2779. var b = value < 0 ? 0 : value > 255 ? 255 : value;
  2780. return ((r < 0 ? 0 : r > 255 ? 255 : r) << 24) + ((g < 0 ? 0 : g > 255 ? 255 : g) << 16) + ((b < 0 ? 0 : b > 255 ? 255 : b) << 8) + (alpha < 0 ? 0 : alpha > 255 ? 255 : alpha);
  2781. };
  2782. geometrize_Core.differenceFull = function (first, second) {
  2783. if (first == null) {
  2784. throw haxe_Exception.thrown("FAIL: first != null");
  2785. }
  2786. if (second == null) {
  2787. throw haxe_Exception.thrown("FAIL: second != null");
  2788. }
  2789. if (first.width == 0) {
  2790. throw haxe_Exception.thrown("FAIL: first.width != 0");
  2791. }
  2792. if (first.height == 0) {
  2793. throw haxe_Exception.thrown("FAIL: first.height != 0");
  2794. }
  2795. if (second.width == 0) {
  2796. throw haxe_Exception.thrown("FAIL: second.width != 0");
  2797. }
  2798. if (second.height == 0) {
  2799. throw haxe_Exception.thrown("FAIL: second.height != 0");
  2800. }
  2801. var actual = first.width;
  2802. var expected = second.width;
  2803. if (actual != expected) {
  2804. throw haxe_Exception.thrown("FAIL: values are not equal (expected: " + expected + ", actual: " + actual + ")");
  2805. }
  2806. var actual = first.height;
  2807. var expected = second.height;
  2808. if (actual != expected) {
  2809. throw haxe_Exception.thrown("FAIL: values are not equal (expected: " + expected + ", actual: " + actual + ")");
  2810. }
  2811. var total = 0;
  2812. var width = first.width;
  2813. var height = first.height;
  2814. var _g = 0;
  2815. var _g1 = height;
  2816. while (_g < _g1) {
  2817. var y = _g++;
  2818. var _g2 = 0;
  2819. var _g3 = width;
  2820. while (_g2 < _g3) {
  2821. var x = _g2++;
  2822. var f = first.data[first.width * y + x];
  2823. var s = second.data[second.width * y + x];
  2824. var dr = ((f >> 24) & 255) - ((s >> 24) & 255);
  2825. var dg = ((f >> 16) & 255) - ((s >> 16) & 255);
  2826. var db = ((f >> 8) & 255) - ((s >> 8) & 255);
  2827. var da = (f & 255) - (s & 255);
  2828. total += dr * dr + dg * dg + db * db + da * da;
  2829. }
  2830. }
  2831. var result = Math.sqrt(total / (width * height * 4.0)) / 255;
  2832. if (!isFinite(result)) {
  2833. throw haxe_Exception.thrown("FAIL: Math.isFinite(result)");
  2834. }
  2835. return result;
  2836. };
  2837. geometrize_Core.differencePartial = function (target, before, after, score, lines) {
  2838. if (target == null) {
  2839. throw haxe_Exception.thrown("FAIL: target != null");
  2840. }
  2841. if (before == null) {
  2842. throw haxe_Exception.thrown("FAIL: before != null");
  2843. }
  2844. if (after == null) {
  2845. throw haxe_Exception.thrown("FAIL: after != null");
  2846. }
  2847. if (lines == null) {
  2848. throw haxe_Exception.thrown("FAIL: lines != null");
  2849. }
  2850. if (lines.length == 0) {
  2851. throw haxe_Exception.thrown("FAIL: lines.length != 0");
  2852. }
  2853. var width = target.width;
  2854. var height = target.height;
  2855. var rgbaCount = width * height * 4;
  2856. var total = Math.pow(score * 255, 2) * rgbaCount;
  2857. var _g = 0;
  2858. while (_g < lines.length) {
  2859. var line = lines[_g];
  2860. ++_g;
  2861. var y = line.y;
  2862. var _g1 = line.x1;
  2863. var _g2 = line.x2 + 1;
  2864. while (_g1 < _g2) {
  2865. var x = _g1++;
  2866. var t = target.data[target.width * y + x];
  2867. var b = before.data[before.width * y + x];
  2868. var a = after.data[after.width * y + x];
  2869. var dtbr = ((t >> 24) & 255) - ((b >> 24) & 255);
  2870. var dtbg = ((t >> 16) & 255) - ((b >> 16) & 255);
  2871. var dtbb = ((t >> 8) & 255) - ((b >> 8) & 255);
  2872. var dtba = (t & 255) - (b & 255);
  2873. var dtar = ((t >> 24) & 255) - ((a >> 24) & 255);
  2874. var dtag = ((t >> 16) & 255) - ((a >> 16) & 255);
  2875. var dtab = ((t >> 8) & 255) - ((a >> 8) & 255);
  2876. var dtaa = (t & 255) - (a & 255);
  2877. total -= dtbr * dtbr + dtbg * dtbg + dtbb * dtbb + dtba * dtba;
  2878. total += dtar * dtar + dtag * dtag + dtab * dtab + dtaa * dtaa;
  2879. }
  2880. }
  2881. var result = Math.sqrt(total / rgbaCount) / 255;
  2882. if (!isFinite(result)) {
  2883. throw haxe_Exception.thrown("FAIL: Math.isFinite(result)");
  2884. }
  2885. return result;
  2886. };
  2887. geometrize_Core.bestRandomState = function (shapes, alpha, n, target, current, buffer, lastScore) {
  2888. var bestEnergy = 0;
  2889. var bestState = null;
  2890. var _g = 0;
  2891. var _g1 = n;
  2892. while (_g < _g1) {
  2893. var i = _g++;
  2894. var state = new geometrize_State(geometrize_shape_ShapeFactory.randomShapeOf(shapes, current.width, current.height), alpha, target, current, buffer);
  2895. var energy = state.energy(lastScore);
  2896. if (i == 0 || energy < bestEnergy) {
  2897. bestEnergy = energy;
  2898. bestState = state;
  2899. }
  2900. }
  2901. return bestState;
  2902. };
  2903. geometrize_Core.bestHillClimbState = function (shapes, alpha, n, age, target, current, buffer, lastScore) {
  2904. var state = geometrize_Core.bestRandomState(shapes, alpha, n, target, current, buffer, lastScore);
  2905. state = geometrize_Core.hillClimb(state, age, lastScore);
  2906. return state;
  2907. };
  2908. geometrize_Core.hillClimb = function (state, maxAge, lastScore) {
  2909. if (state == null) {
  2910. throw haxe_Exception.thrown("FAIL: state != null");
  2911. }
  2912. if (maxAge < 0) {
  2913. throw haxe_Exception.thrown("FAIL: maxAge >= 0");
  2914. }
  2915. var state1 = state.clone();
  2916. var bestState = state1.clone();
  2917. var bestEnergy = state1.energy(lastScore);
  2918. var age = 0;
  2919. while (age < maxAge) {
  2920. var undo = state1.mutate();
  2921. var energy = state1.energy(lastScore);
  2922. if (energy >= bestEnergy) {
  2923. state1 = undo;
  2924. } else {
  2925. bestEnergy = energy;
  2926. bestState = state1.clone();
  2927. age = -1;
  2928. }
  2929. ++age;
  2930. }
  2931. return bestState;
  2932. };
  2933. geometrize_Core.energy = function (shape, alpha, target, current, buffer, score) {
  2934. if (shape == null) {
  2935. throw haxe_Exception.thrown("FAIL: shape != null");
  2936. }
  2937. if (target == null) {
  2938. throw haxe_Exception.thrown("FAIL: target != null");
  2939. }
  2940. if (current == null) {
  2941. throw haxe_Exception.thrown("FAIL: current != null");
  2942. }
  2943. if (buffer == null) {
  2944. throw haxe_Exception.thrown("FAIL: buffer != null");
  2945. }
  2946. var lines = shape.rasterize();
  2947. if (lines == null) {
  2948. throw haxe_Exception.thrown("FAIL: lines != null");
  2949. }
  2950. if (lines.length == 0) {
  2951. throw haxe_Exception.thrown("FAIL: lines.length != 0");
  2952. }
  2953. var color = geometrize_Core.computeColor(target, current, lines, alpha);
  2954. geometrize_rasterizer_Rasterizer.copyLines(buffer, current, lines);
  2955. geometrize_rasterizer_Rasterizer.drawLines(buffer, color, lines);
  2956. return geometrize_Core.differencePartial(target, current, buffer, score, lines);
  2957. };
  2958. var geometrize_Model = function (target, backgroundColor) {
  2959. if (target == null) {
  2960. throw haxe_Exception.thrown("FAIL: target != null");
  2961. }
  2962. this.width = target.width;
  2963. this.height = target.height;
  2964. this.target = target;
  2965. var w = target.width;
  2966. var h = target.height;
  2967. var bitmap = new geometrize_bitmap_Bitmap();
  2968. bitmap.width = w;
  2969. bitmap.height = h;
  2970. var this1 = new Array(w * h);
  2971. bitmap.data = this1;
  2972. var i = 0;
  2973. while (i < bitmap.data.length) {
  2974. bitmap.data[i] = backgroundColor;
  2975. ++i;
  2976. }
  2977. this.current = bitmap;
  2978. var w = target.width;
  2979. var h = target.height;
  2980. var bitmap = new geometrize_bitmap_Bitmap();
  2981. bitmap.width = w;
  2982. bitmap.height = h;
  2983. var this1 = new Array(w * h);
  2984. bitmap.data = this1;
  2985. var i = 0;
  2986. while (i < bitmap.data.length) {
  2987. bitmap.data[i] = backgroundColor;
  2988. ++i;
  2989. }
  2990. this.buffer = bitmap;
  2991. this.score = geometrize_Core.differenceFull(target, this.current);
  2992. };
  2993. geometrize_Model.prototype = {
  2994. step: function (shapeTypes, alpha, n, age) {
  2995. var state = geometrize_Core.bestHillClimbState(shapeTypes, alpha, n, age, this.target, this.current, this.buffer, this.score);
  2996. var results = [this.addShape(state.shape, state.alpha)];
  2997. return results;
  2998. },
  2999. addShape: function (shape, alpha) {
  3000. if (shape == null) {
  3001. throw haxe_Exception.thrown("FAIL: shape != null");
  3002. }
  3003. var _this = this.current;
  3004. var bitmap = new geometrize_bitmap_Bitmap();
  3005. bitmap.width = _this.width;
  3006. bitmap.height = _this.height;
  3007. var this1 = new Array(_this.data.length);
  3008. bitmap.data = this1;
  3009. var _g = 0;
  3010. var _g1 = _this.data.length;
  3011. while (_g < _g1) {
  3012. var i = _g++;
  3013. bitmap.data[i] = _this.data[i];
  3014. }
  3015. var before = bitmap;
  3016. var lines = shape.rasterize();
  3017. var color = geometrize_Core.computeColor(this.target, this.current, lines, alpha);
  3018. geometrize_rasterizer_Rasterizer.drawLines(this.current, color, lines);
  3019. this.score = geometrize_Core.differencePartial(this.target, before, this.current, this.score, lines);
  3020. var result = { score: this.score, color: color, shape: shape };
  3021. return result;
  3022. },
  3023. };
  3024. var geometrize_State = function (shape, alpha, target, current, buffer) {
  3025. if (shape == null) {
  3026. throw haxe_Exception.thrown("FAIL: shape != null");
  3027. }
  3028. this.shape = shape;
  3029. this.alpha = alpha;
  3030. this.score = -1;
  3031. this.target = target;
  3032. this.current = current;
  3033. this.buffer = buffer;
  3034. };
  3035. geometrize_State.prototype = {
  3036. energy: function (lastScore) {
  3037. if (this.score < 0) {
  3038. this.score = geometrize_Core.energy(this.shape, this.alpha, this.target, this.current, this.buffer, lastScore);
  3039. }
  3040. return this.score;
  3041. },
  3042. mutate: function () {
  3043. var oldState = this.clone();
  3044. this.shape.mutate();
  3045. return oldState;
  3046. },
  3047. clone: function () {
  3048. return new geometrize_State(this.shape.clone(), this.alpha, this.target, this.current, this.buffer);
  3049. },
  3050. };
  3051. var geometrize_Util = function () {};
  3052. geometrize_Util.getAverageImageColor = function (image, alpha) {
  3053. if (alpha == null) {
  3054. alpha = 255;
  3055. }
  3056. if (image == null) {
  3057. throw haxe_Exception.thrown("FAIL: image != null");
  3058. }
  3059. var totalRed = 0;
  3060. var totalGreen = 0;
  3061. var totalBlue = 0;
  3062. var _g = 0;
  3063. var _g1 = image.width;
  3064. while (_g < _g1) {
  3065. var x = _g++;
  3066. var _g2 = 0;
  3067. var _g3 = image.height;
  3068. while (_g2 < _g3) {
  3069. var y = _g2++;
  3070. var pixel = image.data[image.width * y + x];
  3071. totalRed += (pixel >> 24) & 255;
  3072. totalGreen += (pixel >> 16) & 255;
  3073. totalBlue += (pixel >> 8) & 255;
  3074. }
  3075. }
  3076. var size = image.width * image.height;
  3077. var red = (totalRed / size) | 0;
  3078. var green = (totalGreen / size) | 0;
  3079. var blue = (totalBlue / size) | 0;
  3080. return (
  3081. ((red < 0 ? 0 : red > 255 ? 255 : red) << 24) +
  3082. ((green < 0 ? 0 : green > 255 ? 255 : green) << 16) +
  3083. ((blue < 0 ? 0 : blue > 255 ? 255 : blue) << 8) +
  3084. (alpha < 0 ? 0 : alpha > 255 ? 255 : alpha)
  3085. );
  3086. };
  3087. var geometrize_bitmap_Bitmap = ($hx_exports["geometrize"]["bitmap"]["Bitmap"] = function () {});
  3088. geometrize_bitmap_Bitmap.create = function (w, h, color) {
  3089. var bitmap = new geometrize_bitmap_Bitmap();
  3090. bitmap.width = w;
  3091. bitmap.height = h;
  3092. var this1 = new Array(w * h);
  3093. bitmap.data = this1;
  3094. var i = 0;
  3095. while (i < bitmap.data.length) {
  3096. bitmap.data[i] = color;
  3097. ++i;
  3098. }
  3099. return bitmap;
  3100. };
  3101. geometrize_bitmap_Bitmap.createFromBytes = function (w, h, bytes) {
  3102. var bitmap = new geometrize_bitmap_Bitmap();
  3103. if (bytes == null) {
  3104. throw haxe_Exception.thrown("FAIL: bytes != null");
  3105. }
  3106. var actual = bytes.length;
  3107. var expected = w * h * 4;
  3108. if (actual != expected) {
  3109. throw haxe_Exception.thrown("FAIL: values are not equal (expected: " + expected + ", actual: " + actual + ")");
  3110. }
  3111. bitmap.width = w;
  3112. bitmap.height = h;
  3113. var this1 = new Array((bytes.length / 4) | 0);
  3114. bitmap.data = this1;
  3115. var i = 0;
  3116. var x = 0;
  3117. while (i < bytes.length) {
  3118. var red = bytes.b[i];
  3119. var green = bytes.b[i + 1];
  3120. var blue = bytes.b[i + 2];
  3121. var alpha = bytes.b[i + 3];
  3122. bitmap.data[x] =
  3123. ((red < 0 ? 0 : red > 255 ? 255 : red) << 24) +
  3124. ((green < 0 ? 0 : green > 255 ? 255 : green) << 16) +
  3125. ((blue < 0 ? 0 : blue > 255 ? 255 : blue) << 8) +
  3126. (alpha < 0 ? 0 : alpha > 255 ? 255 : alpha);
  3127. i += 4;
  3128. ++x;
  3129. }
  3130. return bitmap;
  3131. };
  3132. geometrize_bitmap_Bitmap.createFromByteArray = function (w, h, bytes) {
  3133. var data = new haxe_io_Bytes(new ArrayBuffer(bytes.length));
  3134. var i = 0;
  3135. while (i < bytes.length) {
  3136. data.b[i] = bytes[i];
  3137. ++i;
  3138. }
  3139. var bitmap = new geometrize_bitmap_Bitmap();
  3140. if (data == null) {
  3141. throw haxe_Exception.thrown("FAIL: bytes != null");
  3142. }
  3143. var actual = data.length;
  3144. var expected = w * h * 4;
  3145. if (actual != expected) {
  3146. throw haxe_Exception.thrown("FAIL: values are not equal (expected: " + expected + ", actual: " + actual + ")");
  3147. }
  3148. bitmap.width = w;
  3149. bitmap.height = h;
  3150. var this1 = new Array((data.length / 4) | 0);
  3151. bitmap.data = this1;
  3152. var i = 0;
  3153. var x = 0;
  3154. while (i < data.length) {
  3155. var red = data.b[i];
  3156. var green = data.b[i + 1];
  3157. var blue = data.b[i + 2];
  3158. var alpha = data.b[i + 3];
  3159. bitmap.data[x] =
  3160. ((red < 0 ? 0 : red > 255 ? 255 : red) << 24) +
  3161. ((green < 0 ? 0 : green > 255 ? 255 : green) << 16) +
  3162. ((blue < 0 ? 0 : blue > 255 ? 255 : blue) << 8) +
  3163. (alpha < 0 ? 0 : alpha > 255 ? 255 : alpha);
  3164. i += 4;
  3165. ++x;
  3166. }
  3167. return bitmap;
  3168. };
  3169. geometrize_bitmap_Bitmap.prototype = {
  3170. getPixel: function (x, y) {
  3171. return this.data[this.width * y + x];
  3172. },
  3173. setPixel: function (x, y, color) {
  3174. this.data[this.width * y + x] = color;
  3175. },
  3176. clone: function () {
  3177. var bitmap = new geometrize_bitmap_Bitmap();
  3178. bitmap.width = this.width;
  3179. bitmap.height = this.height;
  3180. var this1 = new Array(this.data.length);
  3181. bitmap.data = this1;
  3182. var _g = 0;
  3183. var _g1 = this.data.length;
  3184. while (_g < _g1) {
  3185. var i = _g++;
  3186. bitmap.data[i] = this.data[i];
  3187. }
  3188. return bitmap;
  3189. },
  3190. fill: function (color) {
  3191. var idx = 0;
  3192. while (idx < this.data.length) {
  3193. this.data[idx] = (color >> 24) & 255;
  3194. this.data[idx + 1] = (color >> 16) & 255;
  3195. this.data[idx + 2] = (color >> 8) & 255;
  3196. this.data[idx + 3] = color & 255;
  3197. idx += 4;
  3198. }
  3199. },
  3200. getBytes: function () {
  3201. var bytes = new haxe_io_Bytes(new ArrayBuffer(this.data.length * 4));
  3202. var i = 0;
  3203. while (i < this.data.length) {
  3204. var idx = i * 4;
  3205. bytes.b[idx] = (this.data[i] >> 24) & 255;
  3206. bytes.b[idx + 1] = (this.data[i] >> 16) & 255;
  3207. bytes.b[idx + 2] = (this.data[i] >> 8) & 255;
  3208. bytes.b[idx + 3] = this.data[i] & 255;
  3209. ++i;
  3210. }
  3211. return bytes;
  3212. },
  3213. };
  3214. var geometrize_exporter_ShapeJsonExporter = ($hx_exports["geometrize"]["exporter"]["ShapeJsonExporter"] = function () {});
  3215. geometrize_exporter_ShapeJsonExporter.export = function (shapes) {
  3216. return "[\\n" + geometrize_exporter_ShapeJsonExporter.exportShapes(shapes) + "\\n]";
  3217. };
  3218. geometrize_exporter_ShapeJsonExporter.exportShapes = function (shapes) {
  3219. var results = "";
  3220. var _g = 0;
  3221. var _g1 = shapes.length;
  3222. while (_g < _g1) {
  3223. var i = _g++;
  3224. results += geometrize_exporter_ShapeJsonExporter.exportShape(shapes[i]);
  3225. if (i != shapes.length - 1) {
  3226. results += ",\\n";
  3227. }
  3228. }
  3229. return results;
  3230. };
  3231. geometrize_exporter_ShapeJsonExporter.exportShape = function (shape) {
  3232. var result = " {\\n";
  3233. var type = shape.shape.getType();
  3234. var data = shape.shape.getRawShapeData();
  3235. var color = shape.color;
  3236. var score = shape.score;
  3237. result += ' "type":' + type + ",\\n";
  3238. result += ' "data":' + "[";
  3239. var _g = 0;
  3240. var _g1 = data.length;
  3241. while (_g < _g1) {
  3242. var item = _g++;
  3243. result += data[item];
  3244. if (item <= data.length - 2) {
  3245. result += ",";
  3246. }
  3247. }
  3248. result += "],\\n";
  3249. result += ' "color":' + "[";
  3250. result += ((color >> 24) & 255) + ",";
  3251. result += ((color >> 16) & 255) + ",";
  3252. result += ((color >> 8) & 255) + ",";
  3253. result += color & 255;
  3254. result += "],\\n";
  3255. result += ' "score":' + score + "\\n";
  3256. result += " }";
  3257. return result;
  3258. };
  3259. var geometrize_exporter_SvgExporter = ($hx_exports["geometrize"]["exporter"]["SvgExporter"] = function () {});
  3260. geometrize_exporter_SvgExporter.export = function (shapes, width, height) {
  3261. var results = geometrize_exporter_SvgExporter.getSvgPrelude();
  3262. results += geometrize_exporter_SvgExporter.getSvgNodeOpen(width, height);
  3263. results += geometrize_exporter_SvgExporter.exportShapes(shapes);
  3264. results += geometrize_exporter_SvgExporter.getSvgNodeClose();
  3265. return results;
  3266. };
  3267. geometrize_exporter_SvgExporter.exportShapes = function (shapes) {
  3268. var results = "";
  3269. var _g = 0;
  3270. var _g1 = shapes.length;
  3271. while (_g < _g1) {
  3272. var i = _g++;
  3273. results += geometrize_exporter_SvgExporter.exportShape(shapes[i]);
  3274. if (i != shapes.length - 1) {
  3275. results += "\\n";
  3276. }
  3277. }
  3278. return results;
  3279. };
  3280. geometrize_exporter_SvgExporter.exportShape = function (shape) {
  3281. return StringTools.replace(shape.shape.getSvgShapeData(), geometrize_exporter_SvgExporter.SVG_STYLE_HOOK, geometrize_exporter_SvgExporter.stylesForShape(shape));
  3282. };
  3283. geometrize_exporter_SvgExporter.getSvgPrelude = function () {
  3284. return '<?xml version="1.0" standalone="no"?>\\n';
  3285. };
  3286. geometrize_exporter_SvgExporter.getSvgNodeOpen = function (width, height) {
  3287. return '<svg xmlns="http://www.w3.org/2000/svg" version="1.2" baseProfile="tiny" width="' + width + '" height="' + height + '">\\n';
  3288. };
  3289. geometrize_exporter_SvgExporter.getSvgNodeClose = function () {
  3290. return "</svg>";
  3291. };
  3292. geometrize_exporter_SvgExporter.stylesForShape = function (shape) {
  3293. switch (shape.shape.getType()) {
  3294. case 6:
  3295. case 7:
  3296. return geometrize_exporter_SvgExporter.strokeForColor(shape.color) + ' stroke-width="1" fill="none" ' + geometrize_exporter_SvgExporter.strokeOpacityForAlpha(shape.color & 255);
  3297. default:
  3298. return geometrize_exporter_SvgExporter.fillForColor(shape.color) + " " + geometrize_exporter_SvgExporter.fillOpacityForAlpha(shape.color & 255);
  3299. }
  3300. };
  3301. geometrize_exporter_SvgExporter.rgbForColor = function (color) {
  3302. return "rgb(" + ((color >> 24) & 255) + "," + ((color >> 16) & 255) + "," + ((color >> 8) & 255) + ")";
  3303. };
  3304. geometrize_exporter_SvgExporter.strokeForColor = function (color) {
  3305. return 'stroke="' + geometrize_exporter_SvgExporter.rgbForColor(color) + '"';
  3306. };
  3307. geometrize_exporter_SvgExporter.fillForColor = function (color) {
  3308. return 'fill="' + geometrize_exporter_SvgExporter.rgbForColor(color) + '"';
  3309. };
  3310. geometrize_exporter_SvgExporter.fillOpacityForAlpha = function (alpha) {
  3311. return 'fill-opacity="' + alpha / 255.0 + '"';
  3312. };
  3313. geometrize_exporter_SvgExporter.strokeOpacityForAlpha = function (alpha) {
  3314. return 'stroke-opacity="' + alpha / 255.0 + '"';
  3315. };
  3316. var geometrize_rasterizer_Rasterizer = function () {};
  3317. geometrize_rasterizer_Rasterizer.drawLines = function (image, c, lines) {
  3318. if (image == null) {
  3319. throw haxe_Exception.thrown("FAIL: image != null");
  3320. }
  3321. if (lines == null) {
  3322. throw haxe_Exception.thrown("FAIL: lines != null");
  3323. }
  3324. var sr = (c >> 24) & 255;
  3325. sr |= sr << 8;
  3326. sr *= c & 255;
  3327. sr = (sr / 255) | 0;
  3328. var sg = (c >> 16) & 255;
  3329. sg |= sg << 8;
  3330. sg *= c & 255;
  3331. sg = (sg / 255) | 0;
  3332. var sb = (c >> 8) & 255;
  3333. sb |= sb << 8;
  3334. sb *= c & 255;
  3335. sb = (sb / 255) | 0;
  3336. var sa = c & 255;
  3337. sa |= sa << 8;
  3338. var _g = 0;
  3339. while (_g < lines.length) {
  3340. var line = lines[_g];
  3341. ++_g;
  3342. var y = line.y;
  3343. var ma = 65535;
  3344. var m = 65535;
  3345. var as = (m - sa * (ma / m)) * 257;
  3346. var a = as | 0;
  3347. var _g1 = line.x1;
  3348. var _g2 = line.x2 + 1;
  3349. while (_g1 < _g2) {
  3350. var x = _g1++;
  3351. var d = image.data[image.width * y + x];
  3352. var dr = (d >> 24) & 255;
  3353. var dg = (d >> 16) & 255;
  3354. var db = (d >> 8) & 255;
  3355. var da = d & 255;
  3356. var r = ((UInt.toFloat(dr * a + sr * ma) / UInt.toFloat(m)) | 0) >> 8;
  3357. var g = ((UInt.toFloat(dg * a + sg * ma) / UInt.toFloat(m)) | 0) >> 8;
  3358. var b = ((UInt.toFloat(db * a + sb * ma) / UInt.toFloat(m)) | 0) >> 8;
  3359. var a1 = ((UInt.toFloat(da * a + sa * ma) / UInt.toFloat(m)) | 0) >> 8;
  3360. image.data[image.width * y + x] =
  3361. ((r < 0 ? 0 : r > 255 ? 255 : r) << 24) + ((g < 0 ? 0 : g > 255 ? 255 : g) << 16) + ((b < 0 ? 0 : b > 255 ? 255 : b) << 8) + (a1 < 0 ? 0 : a1 > 255 ? 255 : a1);
  3362. }
  3363. }
  3364. };
  3365. geometrize_rasterizer_Rasterizer.copyLines = function (destination, source, lines) {
  3366. if (destination == null) {
  3367. throw haxe_Exception.thrown("FAIL: destination != null");
  3368. }
  3369. if (source == null) {
  3370. throw haxe_Exception.thrown("FAIL: source != null");
  3371. }
  3372. if (lines == null) {
  3373. throw haxe_Exception.thrown("FAIL: lines != null");
  3374. }
  3375. var _g = 0;
  3376. while (_g < lines.length) {
  3377. var line = lines[_g];
  3378. ++_g;
  3379. var y = line.y;
  3380. var _g1 = line.x1;
  3381. var _g2 = line.x2 + 1;
  3382. while (_g1 < _g2) {
  3383. var x = _g1++;
  3384. destination.data[destination.width * y + x] = source.data[source.width * y + x];
  3385. }
  3386. }
  3387. };
  3388. geometrize_rasterizer_Rasterizer.bresenham = function (x1, y1, x2, y2) {
  3389. var dx = x2 - x1;
  3390. var ix = (dx > 0 ? 1 : 0) - (dx < 0 ? 1 : 0);
  3391. dx = (dx < 0 ? -dx : dx) << 1;
  3392. var dy = y2 - y1;
  3393. var iy = (dy > 0 ? 1 : 0) - (dy < 0 ? 1 : 0);
  3394. dy = (dy < 0 ? -dy : dy) << 1;
  3395. var points = [];
  3396. points.push({ x: x1, y: y1 });
  3397. if (dx >= dy) {
  3398. var error = dy - (dx >> 1);
  3399. while (x1 != x2) {
  3400. if (error >= 0 && (error != 0 || ix > 0)) {
  3401. error -= dx;
  3402. y1 += iy;
  3403. }
  3404. error += dy;
  3405. x1 += ix;
  3406. points.push({ x: x1, y: y1 });
  3407. }
  3408. } else {
  3409. var error = dx - (dy >> 1);
  3410. while (y1 != y2) {
  3411. if (error >= 0 && (error != 0 || iy > 0)) {
  3412. error -= dy;
  3413. x1 += ix;
  3414. }
  3415. error += dx;
  3416. y1 += iy;
  3417. points.push({ x: x1, y: y1 });
  3418. }
  3419. }
  3420. return points;
  3421. };
  3422. geometrize_rasterizer_Rasterizer.scanlinesForPolygon = function (points) {
  3423. var lines = [];
  3424. var edges = [];
  3425. var _g = 0;
  3426. var _g1 = points.length;
  3427. while (_g < _g1) {
  3428. var i = _g++;
  3429. var p1 = points[i];
  3430. var p2 = i == points.length - 1 ? points[0] : points[i + 1];
  3431. var p1p2 = geometrize_rasterizer_Rasterizer.bresenham(p1.x, p1.y, p2.x, p2.y);
  3432. edges = edges.concat(p1p2);
  3433. }
  3434. var yToXs = new haxe_ds_IntMap();
  3435. var _g = 0;
  3436. while (_g < edges.length) {
  3437. var point = edges[_g];
  3438. ++_g;
  3439. var s = yToXs.h[point.y];
  3440. if (s != null) {
  3441. geometrize_ArraySet.add(s, point.x);
  3442. } else {
  3443. s = geometrize_ArraySet.create();
  3444. geometrize_ArraySet.add(s, point.x);
  3445. yToXs.h[point.y] = s;
  3446. }
  3447. }
  3448. var key = yToXs.keys();
  3449. while (key.hasNext()) {
  3450. var key1 = key.next();
  3451. var a = geometrize_ArraySet.toArray(yToXs.h[key1]);
  3452. var minMaxElements;
  3453. if (a == null || a.length == 0) {
  3454. minMaxElements = { x: 0, y: 0 };
  3455. } else {
  3456. var min = a[0];
  3457. var max = a[0];
  3458. var _g = 0;
  3459. while (_g < a.length) {
  3460. var value = a[_g];
  3461. ++_g;
  3462. if (min > value) {
  3463. min = value;
  3464. }
  3465. if (max < value) {
  3466. max = value;
  3467. }
  3468. }
  3469. minMaxElements = { x: min, y: max };
  3470. }
  3471. lines.push(new geometrize_rasterizer_Scanline(key1, minMaxElements.x, minMaxElements.y));
  3472. }
  3473. return lines;
  3474. };
  3475. var geometrize_rasterizer_Scanline = function (y, x1, x2) {
  3476. this.y = y;
  3477. this.x1 = x1;
  3478. this.x2 = x2;
  3479. };
  3480. geometrize_rasterizer_Scanline.trim = function (scanlines, w, h) {
  3481. if (scanlines == null) {
  3482. throw haxe_Exception.thrown("FAIL: scanlines != null");
  3483. }
  3484. var w1 = w;
  3485. var h1 = h;
  3486. var f = function (line) {
  3487. if (line.y < 0 || line.y >= h1 || line.x1 >= w1 || line.x2 < 0) {
  3488. return false;
  3489. } else {
  3490. var value = line.x1;
  3491. var max = w1 - 1;
  3492. if (0 > max) {
  3493. throw haxe_Exception.thrown("FAIL: min <= max");
  3494. }
  3495. line.x1 = value < 0 ? 0 : value > max ? max : value;
  3496. var value = line.x2;
  3497. var max = w1 - 1;
  3498. if (0 > max) {
  3499. throw haxe_Exception.thrown("FAIL: min <= max");
  3500. }
  3501. line.x2 = value < 0 ? 0 : value > max ? max : value;
  3502. return line.x1 <= line.x2;
  3503. }
  3504. };
  3505. var _g = [];
  3506. var _g1 = 0;
  3507. var _g2 = scanlines;
  3508. while (_g1 < _g2.length) {
  3509. var v = _g2[_g1];
  3510. ++_g1;
  3511. if (f(v)) {
  3512. _g.push(v);
  3513. }
  3514. }
  3515. return _g;
  3516. };
  3517. var geometrize_runner_ImageRunner = ($hx_exports["geometrize"]["runner"]["ImageRunner"] = function (inputImage, backgroundColor) {
  3518. this.model = null;
  3519. this.model = new geometrize_Model(inputImage, backgroundColor);
  3520. });
  3521. geometrize_runner_ImageRunner.prototype = {
  3522. step: function (options) {
  3523. var finalOptions_shapeTypes = options.shapeTypes != null && options.shapeTypes.length != 0 ? options.shapeTypes : geometrize_runner_Default.options.shapeTypes;
  3524. var finalOptions_alpha = options.alpha != null ? options.alpha : geometrize_runner_Default.options.alpha;
  3525. var finalOptions_candidateShapesPerStep = options.candidateShapesPerStep != null ? options.candidateShapesPerStep : geometrize_runner_Default.options.candidateShapesPerStep;
  3526. var finalOptions_shapeMutationsPerStep = options.shapeMutationsPerStep != null ? options.shapeMutationsPerStep : geometrize_runner_Default.options.shapeMutationsPerStep;
  3527. return this.model.step(finalOptions_shapeTypes, finalOptions_alpha, finalOptions_candidateShapesPerStep, finalOptions_shapeMutationsPerStep);
  3528. },
  3529. getImageData: function () {
  3530. if (this.model == null) {
  3531. throw haxe_Exception.thrown("FAIL: model != null");
  3532. }
  3533. return this.model.current;
  3534. },
  3535. };
  3536. var geometrize_runner_Default = function () {};
  3537. var geometrize_shape_Ellipse = function (xBound, yBound) {
  3538. this.x = Std.random(xBound);
  3539. this.y = Std.random(yBound);
  3540. this.rx = Std.random(32) + 1;
  3541. this.ry = Std.random(32) + 1;
  3542. this.xBound = xBound;
  3543. this.yBound = yBound;
  3544. };
  3545. geometrize_shape_Ellipse.prototype = {
  3546. rasterize: function () {
  3547. var lines = [];
  3548. var aspect = this.rx / this.ry;
  3549. var w = this.xBound;
  3550. var h = this.yBound;
  3551. var _g = 0;
  3552. var _g1 = this.ry;
  3553. while (_g < _g1) {
  3554. var dy = _g++;
  3555. var y1 = this.y - dy;
  3556. var y2 = this.y + dy;
  3557. if ((y1 < 0 || y1 >= h) && (y2 < 0 || y2 >= h)) {
  3558. continue;
  3559. }
  3560. var s = (Math.sqrt(this.ry * this.ry - dy * dy) * aspect) | 0;
  3561. var x1 = this.x - s;
  3562. var x2 = this.x + s;
  3563. if (x1 < 0) {
  3564. x1 = 0;
  3565. }
  3566. if (x2 >= w) {
  3567. x2 = w - 1;
  3568. }
  3569. if (y1 >= 0 && y1 < h) {
  3570. lines.push(new geometrize_rasterizer_Scanline(y1, x1, x2));
  3571. }
  3572. if (y2 >= 0 && y2 < h && dy > 0) {
  3573. lines.push(new geometrize_rasterizer_Scanline(y2, x1, x2));
  3574. }
  3575. }
  3576. return lines;
  3577. },
  3578. mutate: function () {
  3579. var r = Std.random(3);
  3580. switch (r) {
  3581. case 0:
  3582. var value = this.x + (-16 + Math.floor(33 * Math.random()));
  3583. var max = this.xBound - 1;
  3584. if (0 > max) {
  3585. throw haxe_Exception.thrown("FAIL: min <= max");
  3586. }
  3587. this.x = value < 0 ? 0 : value > max ? max : value;
  3588. var value = this.y + (-16 + Math.floor(33 * Math.random()));
  3589. var max = this.yBound - 1;
  3590. if (0 > max) {
  3591. throw haxe_Exception.thrown("FAIL: min <= max");
  3592. }
  3593. this.y = value < 0 ? 0 : value > max ? max : value;
  3594. break;
  3595. case 1:
  3596. var value = this.rx + (-16 + Math.floor(33 * Math.random()));
  3597. var max = this.xBound - 1;
  3598. if (1 > max) {
  3599. throw haxe_Exception.thrown("FAIL: min <= max");
  3600. }
  3601. this.rx = value < 1 ? 1 : value > max ? max : value;
  3602. break;
  3603. case 2:
  3604. var value = this.ry + (-16 + Math.floor(33 * Math.random()));
  3605. var max = this.xBound - 1;
  3606. if (1 > max) {
  3607. throw haxe_Exception.thrown("FAIL: min <= max");
  3608. }
  3609. this.ry = value < 1 ? 1 : value > max ? max : value;
  3610. break;
  3611. }
  3612. },
  3613. clone: function () {
  3614. var ellipse = new geometrize_shape_Ellipse(this.xBound, this.yBound);
  3615. ellipse.x = this.x;
  3616. ellipse.y = this.y;
  3617. ellipse.rx = this.rx;
  3618. ellipse.ry = this.ry;
  3619. return ellipse;
  3620. },
  3621. getType: function () {
  3622. return 3;
  3623. },
  3624. getRawShapeData: function () {
  3625. return [this.x, this.y, this.rx, this.ry];
  3626. },
  3627. getSvgShapeData: function () {
  3628. return '<ellipse cx="' + this.x + '" cy="' + this.y + '" rx="' + this.rx + '" ry="' + this.ry + '" ' + geometrize_exporter_SvgExporter.SVG_STYLE_HOOK + " />";
  3629. },
  3630. };
  3631. var geometrize_shape_Circle = function (xBound, yBound) {
  3632. geometrize_shape_Ellipse.call(this, xBound, yBound);
  3633. this.rx = Std.random(32) + 1;
  3634. this.ry = this.rx;
  3635. };
  3636. geometrize_shape_Circle.__super__ = geometrize_shape_Ellipse;
  3637. geometrize_shape_Circle.prototype = $extend(geometrize_shape_Ellipse.prototype, {
  3638. mutate: function () {
  3639. var r = Std.random(2);
  3640. switch (r) {
  3641. case 0:
  3642. var value = this.x + (-16 + Math.floor(33 * Math.random()));
  3643. var max = this.xBound - 1;
  3644. if (0 > max) {
  3645. throw haxe_Exception.thrown("FAIL: min <= max");
  3646. }
  3647. this.x = value < 0 ? 0 : value > max ? max : value;
  3648. var value = this.y + (-16 + Math.floor(33 * Math.random()));
  3649. var max = this.yBound - 1;
  3650. if (0 > max) {
  3651. throw haxe_Exception.thrown("FAIL: min <= max");
  3652. }
  3653. this.y = value < 0 ? 0 : value > max ? max : value;
  3654. break;
  3655. case 1:
  3656. var value = this.rx + (-16 + Math.floor(33 * Math.random()));
  3657. var max = this.xBound - 1;
  3658. if (1 > max) {
  3659. throw haxe_Exception.thrown("FAIL: min <= max");
  3660. }
  3661. var r = value < 1 ? 1 : value > max ? max : value;
  3662. this.rx = r;
  3663. this.ry = r;
  3664. break;
  3665. }
  3666. },
  3667. clone: function () {
  3668. var circle = new geometrize_shape_Circle(this.xBound, this.yBound);
  3669. circle.x = this.x;
  3670. circle.y = this.y;
  3671. circle.rx = this.rx;
  3672. circle.ry = this.ry;
  3673. return circle;
  3674. },
  3675. getType: function () {
  3676. return 5;
  3677. },
  3678. getRawShapeData: function () {
  3679. return [this.x, this.y, this.rx];
  3680. },
  3681. getSvgShapeData: function () {
  3682. return '<circle cx="' + this.x + '" cy="' + this.y + '" r="' + this.rx + '" ' + geometrize_exporter_SvgExporter.SVG_STYLE_HOOK + " />";
  3683. },
  3684. });
  3685. var geometrize_shape_Line = function (xBound, yBound) {
  3686. this.x1 = Std.random(xBound);
  3687. this.y1 = Std.random(yBound);
  3688. var value = this.x1 + Std.random(32) + 1;
  3689. if (0 > xBound) {
  3690. throw haxe_Exception.thrown("FAIL: min <= max");
  3691. }
  3692. this.x2 = value < 0 ? 0 : value > xBound ? xBound : value;
  3693. var value = this.y1 + Std.random(32) + 1;
  3694. if (0 > yBound) {
  3695. throw haxe_Exception.thrown("FAIL: min <= max");
  3696. }
  3697. this.y2 = value < 0 ? 0 : value > yBound ? yBound : value;
  3698. this.xBound = xBound;
  3699. this.yBound = yBound;
  3700. };
  3701. geometrize_shape_Line.prototype = {
  3702. rasterize: function () {
  3703. var lines = [];
  3704. var points = geometrize_rasterizer_Rasterizer.bresenham(this.x1, this.y1, this.x2, this.y2);
  3705. var _g = 0;
  3706. while (_g < points.length) {
  3707. var point = points[_g];
  3708. ++_g;
  3709. lines.push(new geometrize_rasterizer_Scanline(point.y, point.x, point.x));
  3710. }
  3711. return geometrize_rasterizer_Scanline.trim(lines, this.xBound, this.yBound);
  3712. },
  3713. mutate: function () {
  3714. var r = Std.random(4);
  3715. switch (r) {
  3716. case 0:
  3717. var value = this.x1 + (-16 + Math.floor(33 * Math.random()));
  3718. var max = this.xBound - 1;
  3719. if (0 > max) {
  3720. throw haxe_Exception.thrown("FAIL: min <= max");
  3721. }
  3722. this.x1 = value < 0 ? 0 : value > max ? max : value;
  3723. var value = this.y1 + (-16 + Math.floor(33 * Math.random()));
  3724. var max = this.yBound - 1;
  3725. if (0 > max) {
  3726. throw haxe_Exception.thrown("FAIL: min <= max");
  3727. }
  3728. this.y1 = value < 0 ? 0 : value > max ? max : value;
  3729. break;
  3730. case 1:
  3731. var value = this.x2 + (-16 + Math.floor(33 * Math.random()));
  3732. var max = this.xBound - 1;
  3733. if (0 > max) {
  3734. throw haxe_Exception.thrown("FAIL: min <= max");
  3735. }
  3736. this.x2 = value < 0 ? 0 : value > max ? max : value;
  3737. var value = this.y2 + (-16 + Math.floor(33 * Math.random()));
  3738. var max = this.yBound - 1;
  3739. if (0 > max) {
  3740. throw haxe_Exception.thrown("FAIL: min <= max");
  3741. }
  3742. this.y2 = value < 0 ? 0 : value > max ? max : value;
  3743. break;
  3744. }
  3745. },
  3746. clone: function () {
  3747. var line = new geometrize_shape_Line(this.xBound, this.yBound);
  3748. line.x1 = this.x1;
  3749. line.y1 = this.y1;
  3750. line.x2 = this.x2;
  3751. line.y2 = this.y2;
  3752. return line;
  3753. },
  3754. getType: function () {
  3755. return 6;
  3756. },
  3757. getRawShapeData: function () {
  3758. return [this.x1, this.y1, this.x2, this.y2];
  3759. },
  3760. getSvgShapeData: function () {
  3761. return '<line x1="' + this.x1 + '" y1="' + this.y1 + '" x2="' + this.x2 + '" y2="' + this.y2 + '" ' + geometrize_exporter_SvgExporter.SVG_STYLE_HOOK + " />";
  3762. },
  3763. };
  3764. var geometrize_shape_QuadraticBezier = function (xBound, yBound) {
  3765. var upper = xBound - 1;
  3766. if (0 > upper) {
  3767. throw haxe_Exception.thrown("FAIL: lower <= upper");
  3768. }
  3769. this.x1 = Math.floor((upper + 1) * Math.random());
  3770. var upper = yBound - 1;
  3771. if (0 > upper) {
  3772. throw haxe_Exception.thrown("FAIL: lower <= upper");
  3773. }
  3774. this.y1 = Math.floor((upper + 1) * Math.random());
  3775. var upper = xBound - 1;
  3776. if (0 > upper) {
  3777. throw haxe_Exception.thrown("FAIL: lower <= upper");
  3778. }
  3779. this.cx = Math.floor((upper + 1) * Math.random());
  3780. var upper = yBound - 1;
  3781. if (0 > upper) {
  3782. throw haxe_Exception.thrown("FAIL: lower <= upper");
  3783. }
  3784. this.cy = Math.floor((upper + 1) * Math.random());
  3785. var upper = xBound - 1;
  3786. if (0 > upper) {
  3787. throw haxe_Exception.thrown("FAIL: lower <= upper");
  3788. }
  3789. this.x2 = Math.floor((upper + 1) * Math.random());
  3790. var upper = yBound - 1;
  3791. if (0 > upper) {
  3792. throw haxe_Exception.thrown("FAIL: lower <= upper");
  3793. }
  3794. this.y2 = Math.floor((upper + 1) * Math.random());
  3795. this.xBound = xBound;
  3796. this.yBound = yBound;
  3797. };
  3798. geometrize_shape_QuadraticBezier.prototype = {
  3799. rasterize: function () {
  3800. var lines = [];
  3801. var points = [];
  3802. var pointCount = 20;
  3803. var _g = 0;
  3804. var _g1 = pointCount - 1;
  3805. while (_g < _g1) {
  3806. var i = _g++;
  3807. var t = i / pointCount;
  3808. var tp = 1 - t;
  3809. var x = (tp * (tp * this.x1 + t * this.cx) + t * (tp * this.cx + t * this.x2)) | 0;
  3810. var y = (tp * (tp * this.y1 + t * this.cy) + t * (tp * this.cy + t * this.y2)) | 0;
  3811. points.push({ x: x, y: y });
  3812. }
  3813. var _g = 0;
  3814. var _g1 = points.length - 1;
  3815. while (_g < _g1) {
  3816. var i = _g++;
  3817. var p0 = points[i];
  3818. var p1 = points[i + 1];
  3819. var pts = geometrize_rasterizer_Rasterizer.bresenham(p0.x, p0.y, p1.x, p1.y);
  3820. var _g2 = 0;
  3821. while (_g2 < pts.length) {
  3822. var point = pts[_g2];
  3823. ++_g2;
  3824. if (lines.length > 0) {
  3825. var lastLine = lines[lines.length - 1];
  3826. if (lastLine.y == point.y && lastLine.x1 == point.x && lastLine.x2 == point.x) {
  3827. continue;
  3828. }
  3829. }
  3830. lines.push(new geometrize_rasterizer_Scanline(point.y, point.x, point.x));
  3831. }
  3832. }
  3833. return geometrize_rasterizer_Scanline.trim(lines, this.xBound, this.yBound);
  3834. },
  3835. mutate: function () {
  3836. var r = Math.floor(3 * Math.random());
  3837. switch (r) {
  3838. case 0:
  3839. var value = this.cx + (-8 + Math.floor(17 * Math.random()));
  3840. var max = this.xBound - 1;
  3841. if (0 > max) {
  3842. throw haxe_Exception.thrown("FAIL: min <= max");
  3843. }
  3844. this.cx = value < 0 ? 0 : value > max ? max : value;
  3845. var value = this.cy + (-8 + Math.floor(17 * Math.random()));
  3846. var max = this.yBound - 1;
  3847. if (0 > max) {
  3848. throw haxe_Exception.thrown("FAIL: min <= max");
  3849. }
  3850. this.cy = value < 0 ? 0 : value > max ? max : value;
  3851. break;
  3852. case 1:
  3853. var value = this.x1 + (-8 + Math.floor(17 * Math.random()));
  3854. var max = this.xBound - 1;
  3855. if (1 > max) {
  3856. throw haxe_Exception.thrown("FAIL: min <= max");
  3857. }
  3858. this.x1 = value < 1 ? 1 : value > max ? max : value;
  3859. var value = this.y1 + (-8 + Math.floor(17 * Math.random()));
  3860. var max = this.yBound - 1;
  3861. if (1 > max) {
  3862. throw haxe_Exception.thrown("FAIL: min <= max");
  3863. }
  3864. this.y1 = value < 1 ? 1 : value > max ? max : value;
  3865. break;
  3866. case 2:
  3867. var value = this.x2 + (-8 + Math.floor(17 * Math.random()));
  3868. var max = this.xBound - 1;
  3869. if (1 > max) {
  3870. throw haxe_Exception.thrown("FAIL: min <= max");
  3871. }
  3872. this.x2 = value < 1 ? 1 : value > max ? max : value;
  3873. var value = this.y2 + (-8 + Math.floor(17 * Math.random()));
  3874. var max = this.yBound - 1;
  3875. if (1 > max) {
  3876. throw haxe_Exception.thrown("FAIL: min <= max");
  3877. }
  3878. this.y2 = value < 1 ? 1 : value > max ? max : value;
  3879. break;
  3880. }
  3881. },
  3882. clone: function () {
  3883. var bezier = new geometrize_shape_QuadraticBezier(this.xBound, this.yBound);
  3884. bezier.cx = this.cx;
  3885. bezier.cy = this.cy;
  3886. bezier.x1 = this.x1;
  3887. bezier.y1 = this.y1;
  3888. bezier.x2 = this.x2;
  3889. bezier.y2 = this.y2;
  3890. return bezier;
  3891. },
  3892. getType: function () {
  3893. return 7;
  3894. },
  3895. getRawShapeData: function () {
  3896. return [this.x1, this.y1, this.cx, this.cy, this.x2, this.y2];
  3897. },
  3898. getSvgShapeData: function () {
  3899. return '<path d="M' + this.x1 + " " + this.y1 + " Q " + this.cx + " " + this.cy + " " + this.x2 + " " + this.y2 + '" ' + geometrize_exporter_SvgExporter.SVG_STYLE_HOOK + " />";
  3900. },
  3901. };
  3902. var geometrize_shape_Rectangle = function (xBound, yBound) {
  3903. this.x1 = Std.random(xBound);
  3904. this.y1 = Std.random(yBound);
  3905. var value = this.x1 + Std.random(32) + 1;
  3906. var max = xBound - 1;
  3907. if (0 > max) {
  3908. throw haxe_Exception.thrown("FAIL: min <= max");
  3909. }
  3910. this.x2 = value < 0 ? 0 : value > max ? max : value;
  3911. var value = this.y1 + Std.random(32) + 1;
  3912. var max = yBound - 1;
  3913. if (0 > max) {
  3914. throw haxe_Exception.thrown("FAIL: min <= max");
  3915. }
  3916. this.y2 = value < 0 ? 0 : value > max ? max : value;
  3917. this.xBound = xBound;
  3918. this.yBound = yBound;
  3919. };
  3920. geometrize_shape_Rectangle.prototype = {
  3921. rasterize: function () {
  3922. var lines = [];
  3923. var first = this.y1;
  3924. var second = this.y2;
  3925. var yMin = first < second ? first : second;
  3926. var first = this.y1;
  3927. var second = this.y2;
  3928. var yMax = first > second ? first : second;
  3929. if (yMin == yMax) {
  3930. var first = this.x1;
  3931. var second = this.x2;
  3932. var first1 = this.x1;
  3933. var second1 = this.x2;
  3934. lines.push(new geometrize_rasterizer_Scanline(yMin, first < second ? first : second, first1 > second1 ? first1 : second1));
  3935. } else {
  3936. var _g = yMin;
  3937. var _g1 = yMax;
  3938. while (_g < _g1) {
  3939. var y = _g++;
  3940. var first = this.x1;
  3941. var second = this.x2;
  3942. var first1 = this.x1;
  3943. var second1 = this.x2;
  3944. lines.push(new geometrize_rasterizer_Scanline(y, first < second ? first : second, first1 > second1 ? first1 : second1));
  3945. }
  3946. }
  3947. return lines;
  3948. },
  3949. mutate: function () {
  3950. var r = Std.random(2);
  3951. switch (r) {
  3952. case 0:
  3953. var value = this.x1 + (-16 + Math.floor(33 * Math.random()));
  3954. var max = this.xBound - 1;
  3955. if (0 > max) {
  3956. throw haxe_Exception.thrown("FAIL: min <= max");
  3957. }
  3958. this.x1 = value < 0 ? 0 : value > max ? max : value;
  3959. var value = this.y1 + (-16 + Math.floor(33 * Math.random()));
  3960. var max = this.yBound - 1;
  3961. if (0 > max) {
  3962. throw haxe_Exception.thrown("FAIL: min <= max");
  3963. }
  3964. this.y1 = value < 0 ? 0 : value > max ? max : value;
  3965. break;
  3966. case 1:
  3967. var value = this.x2 + (-16 + Math.floor(33 * Math.random()));
  3968. var max = this.xBound - 1;
  3969. if (0 > max) {
  3970. throw haxe_Exception.thrown("FAIL: min <= max");
  3971. }
  3972. this.x2 = value < 0 ? 0 : value > max ? max : value;
  3973. var value = this.y2 + (-16 + Math.floor(33 * Math.random()));
  3974. var max = this.yBound - 1;
  3975. if (0 > max) {
  3976. throw haxe_Exception.thrown("FAIL: min <= max");
  3977. }
  3978. this.y2 = value < 0 ? 0 : value > max ? max : value;
  3979. break;
  3980. }
  3981. },
  3982. clone: function () {
  3983. var rectangle = new geometrize_shape_Rectangle(this.xBound, this.yBound);
  3984. rectangle.x1 = this.x1;
  3985. rectangle.y1 = this.y1;
  3986. rectangle.x2 = this.x2;
  3987. rectangle.y2 = this.y2;
  3988. return rectangle;
  3989. },
  3990. getType: function () {
  3991. return 0;
  3992. },
  3993. getRawShapeData: function () {
  3994. var first = this.x1;
  3995. var second = this.x2;
  3996. var first1 = this.y1;
  3997. var second1 = this.y2;
  3998. var first2 = this.x1;
  3999. var second2 = this.x2;
  4000. var first3 = this.y1;
  4001. var second3 = this.y2;
  4002. return [first < second ? first : second, first1 < second1 ? first1 : second1, first2 > second2 ? first2 : second2, first3 > second3 ? first3 : second3];
  4003. },
  4004. getSvgShapeData: function () {
  4005. var first = this.x1;
  4006. var second = this.x2;
  4007. var first1 = this.y1;
  4008. var second1 = this.y2;
  4009. var first2 = this.x1;
  4010. var second2 = this.x2;
  4011. var first3 = this.x1;
  4012. var second3 = this.x2;
  4013. var first4 = this.y1;
  4014. var second4 = this.y2;
  4015. var first5 = this.y1;
  4016. var second5 = this.y2;
  4017. return (
  4018. '<rect x="' +
  4019. (first < second ? first : second) +
  4020. '" y="' +
  4021. (first1 < second1 ? first1 : second1) +
  4022. '" width="' +
  4023. ((first2 > second2 ? first2 : second2) - (first3 < second3 ? first3 : second3)) +
  4024. '" height="' +
  4025. ((first4 > second4 ? first4 : second4) - (first5 < second5 ? first5 : second5)) +
  4026. '" ' +
  4027. geometrize_exporter_SvgExporter.SVG_STYLE_HOOK +
  4028. " />"
  4029. );
  4030. },
  4031. };
  4032. var geometrize_shape_RotatedEllipse = function (xBound, yBound) {
  4033. this.x = Std.random(xBound);
  4034. this.y = Std.random(yBound);
  4035. this.rx = Std.random(32) + 1;
  4036. this.ry = Std.random(32) + 1;
  4037. this.angle = Std.random(360);
  4038. this.xBound = xBound;
  4039. this.yBound = yBound;
  4040. };
  4041. geometrize_shape_RotatedEllipse.prototype = {
  4042. rasterize: function () {
  4043. var pointCount = 20;
  4044. var points = [];
  4045. var rads = this.angle * (Math.PI / 180.0);
  4046. var c = Math.cos(rads);
  4047. var s = Math.sin(rads);
  4048. var _g = 0;
  4049. var _g1 = pointCount;
  4050. while (_g < _g1) {
  4051. var i = _g++;
  4052. var rot = (360.0 / pointCount) * i * (Math.PI / 180.0);
  4053. var crx = this.rx * Math.cos(rot);
  4054. var cry = this.ry * Math.sin(rot);
  4055. var tx = (crx * c - cry * s + this.x) | 0;
  4056. var ty = (crx * s + cry * c + this.y) | 0;
  4057. points.push({ x: tx, y: ty });
  4058. }
  4059. return geometrize_rasterizer_Scanline.trim(geometrize_rasterizer_Rasterizer.scanlinesForPolygon(points), this.xBound, this.yBound);
  4060. },
  4061. mutate: function () {
  4062. var r = Std.random(4);
  4063. switch (r) {
  4064. case 0:
  4065. var value = this.x + (-16 + Math.floor(33 * Math.random()));
  4066. var max = this.xBound - 1;
  4067. if (0 > max) {
  4068. throw haxe_Exception.thrown("FAIL: min <= max");
  4069. }
  4070. this.x = value < 0 ? 0 : value > max ? max : value;
  4071. var value = this.y + (-16 + Math.floor(33 * Math.random()));
  4072. var max = this.yBound - 1;
  4073. if (0 > max) {
  4074. throw haxe_Exception.thrown("FAIL: min <= max");
  4075. }
  4076. this.y = value < 0 ? 0 : value > max ? max : value;
  4077. break;
  4078. case 1:
  4079. var value = this.rx + (-16 + Math.floor(33 * Math.random()));
  4080. var max = this.xBound - 1;
  4081. if (1 > max) {
  4082. throw haxe_Exception.thrown("FAIL: min <= max");
  4083. }
  4084. this.rx = value < 1 ? 1 : value > max ? max : value;
  4085. break;
  4086. case 2:
  4087. var value = this.ry + (-16 + Math.floor(33 * Math.random()));
  4088. var max = this.yBound - 1;
  4089. if (1 > max) {
  4090. throw haxe_Exception.thrown("FAIL: min <= max");
  4091. }
  4092. this.ry = value < 1 ? 1 : value > max ? max : value;
  4093. break;
  4094. case 3:
  4095. var value = this.angle + (-4 + Math.floor(9 * Math.random()));
  4096. this.angle = value < 0 ? 0 : value > 360 ? 360 : value;
  4097. break;
  4098. }
  4099. },
  4100. clone: function () {
  4101. var ellipse = new geometrize_shape_RotatedEllipse(this.xBound, this.yBound);
  4102. ellipse.x = this.x;
  4103. ellipse.y = this.y;
  4104. ellipse.rx = this.rx;
  4105. ellipse.ry = this.ry;
  4106. ellipse.angle = this.angle;
  4107. return ellipse;
  4108. },
  4109. getType: function () {
  4110. return 4;
  4111. },
  4112. getRawShapeData: function () {
  4113. return [this.x, this.y, this.rx, this.ry, this.angle];
  4114. },
  4115. getSvgShapeData: function () {
  4116. var s = '<g transform="translate(' + this.x + " " + this.y + ") rotate(" + this.angle + ") scale(" + this.rx + " " + this.ry + ')">';
  4117. s += '<ellipse cx="' + 0 + '" cy="' + 0 + '" rx="' + 1 + '" ry="' + 1 + '" ' + geometrize_exporter_SvgExporter.SVG_STYLE_HOOK + " />";
  4118. s += "</g>";
  4119. return s;
  4120. },
  4121. };
  4122. var geometrize_shape_RotatedRectangle = function (xBound, yBound) {
  4123. this.x1 = Std.random(xBound);
  4124. this.y1 = Std.random(yBound);
  4125. var value = this.x1 + Std.random(32) + 1;
  4126. if (0 > xBound) {
  4127. throw haxe_Exception.thrown("FAIL: min <= max");
  4128. }
  4129. this.x2 = value < 0 ? 0 : value > xBound ? xBound : value;
  4130. var value = this.y1 + Std.random(32) + 1;
  4131. if (0 > yBound) {
  4132. throw haxe_Exception.thrown("FAIL: min <= max");
  4133. }
  4134. this.y2 = value < 0 ? 0 : value > yBound ? yBound : value;
  4135. this.angle = Math.floor(361 * Math.random());
  4136. this.xBound = xBound;
  4137. this.yBound = yBound;
  4138. };
  4139. geometrize_shape_RotatedRectangle.prototype = {
  4140. rasterize: function () {
  4141. var first = this.x1;
  4142. var second = this.x2;
  4143. var xm1 = first < second ? first : second;
  4144. var first = this.x1;
  4145. var second = this.x2;
  4146. var xm2 = first > second ? first : second;
  4147. var first = this.y1;
  4148. var second = this.y2;
  4149. var ym1 = first < second ? first : second;
  4150. var first = this.y1;
  4151. var second = this.y2;
  4152. var ym2 = first > second ? first : second;
  4153. var cx = ((xm1 + xm2) / 2) | 0;
  4154. var cy = ((ym1 + ym2) / 2) | 0;
  4155. var ox1 = xm1 - cx;
  4156. var ox2 = xm2 - cx;
  4157. var oy1 = ym1 - cy;
  4158. var oy2 = ym2 - cy;
  4159. var rads = (this.angle * Math.PI) / 180.0;
  4160. var c = Math.cos(rads);
  4161. var s = Math.sin(rads);
  4162. var ulx = (ox1 * c - oy1 * s + cx) | 0;
  4163. var uly = (ox1 * s + oy1 * c + cy) | 0;
  4164. var blx = (ox1 * c - oy2 * s + cx) | 0;
  4165. var bly = (ox1 * s + oy2 * c + cy) | 0;
  4166. var urx = (ox2 * c - oy1 * s + cx) | 0;
  4167. var ury = (ox2 * s + oy1 * c + cy) | 0;
  4168. var brx = (ox2 * c - oy2 * s + cx) | 0;
  4169. var bry = (ox2 * s + oy2 * c + cy) | 0;
  4170. return geometrize_rasterizer_Scanline.trim(
  4171. geometrize_rasterizer_Rasterizer.scanlinesForPolygon([
  4172. { x: ulx, y: uly },
  4173. { x: urx, y: ury },
  4174. { x: brx, y: bry },
  4175. { x: blx, y: bly },
  4176. ]),
  4177. this.xBound,
  4178. this.yBound
  4179. );
  4180. },
  4181. mutate: function () {
  4182. var r = Std.random(3);
  4183. switch (r) {
  4184. case 0:
  4185. var value = this.x1 + (-16 + Math.floor(33 * Math.random()));
  4186. var max = this.xBound - 1;
  4187. if (0 > max) {
  4188. throw haxe_Exception.thrown("FAIL: min <= max");
  4189. }
  4190. this.x1 = value < 0 ? 0 : value > max ? max : value;
  4191. var value = this.y1 + (-16 + Math.floor(33 * Math.random()));
  4192. var max = this.yBound - 1;
  4193. if (0 > max) {
  4194. throw haxe_Exception.thrown("FAIL: min <= max");
  4195. }
  4196. this.y1 = value < 0 ? 0 : value > max ? max : value;
  4197. break;
  4198. case 1:
  4199. var value = this.x2 + (-16 + Math.floor(33 * Math.random()));
  4200. var max = this.xBound - 1;
  4201. if (0 > max) {
  4202. throw haxe_Exception.thrown("FAIL: min <= max");
  4203. }
  4204. this.x2 = value < 0 ? 0 : value > max ? max : value;
  4205. var value = this.y2 + (-16 + Math.floor(33 * Math.random()));
  4206. var max = this.yBound - 1;
  4207. if (0 > max) {
  4208. throw haxe_Exception.thrown("FAIL: min <= max");
  4209. }
  4210. this.y2 = value < 0 ? 0 : value > max ? max : value;
  4211. break;
  4212. case 2:
  4213. var value = this.angle + (-4 + Math.floor(9 * Math.random()));
  4214. this.angle = value < 0 ? 0 : value > 360 ? 360 : value;
  4215. break;
  4216. }
  4217. },
  4218. clone: function () {
  4219. var rectangle = new geometrize_shape_RotatedRectangle(this.xBound, this.yBound);
  4220. rectangle.x1 = this.x1;
  4221. rectangle.y1 = this.y1;
  4222. rectangle.x2 = this.x2;
  4223. rectangle.y2 = this.y2;
  4224. rectangle.angle = this.angle;
  4225. return rectangle;
  4226. },
  4227. getType: function () {
  4228. return 1;
  4229. },
  4230. getRawShapeData: function () {
  4231. var first = this.x1;
  4232. var second = this.x2;
  4233. var first1 = this.y1;
  4234. var second1 = this.y2;
  4235. var first2 = this.x1;
  4236. var second2 = this.x2;
  4237. var first3 = this.y1;
  4238. var second3 = this.y2;
  4239. return [first < second ? first : second, first1 < second1 ? first1 : second1, first2 > second2 ? first2 : second2, first3 > second3 ? first3 : second3, this.angle];
  4240. },
  4241. getSvgShapeData: function () {
  4242. var first = this.x1;
  4243. var second = this.x2;
  4244. var xm1 = first < second ? first : second;
  4245. var first = this.x1;
  4246. var second = this.x2;
  4247. var xm2 = first > second ? first : second;
  4248. var first = this.y1;
  4249. var second = this.y2;
  4250. var ym1 = first < second ? first : second;
  4251. var first = this.y1;
  4252. var second = this.y2;
  4253. var ym2 = first > second ? first : second;
  4254. var cx = ((xm1 + xm2) / 2) | 0;
  4255. var cy = ((ym1 + ym2) / 2) | 0;
  4256. var ox1 = xm1 - cx;
  4257. var ox2 = xm2 - cx;
  4258. var oy1 = ym1 - cy;
  4259. var oy2 = ym2 - cy;
  4260. var rads = (this.angle * Math.PI) / 180.0;
  4261. var c = Math.cos(rads);
  4262. var s = Math.sin(rads);
  4263. var ulx = (ox1 * c - oy1 * s + cx) | 0;
  4264. var uly = (ox1 * s + oy1 * c + cy) | 0;
  4265. var blx = (ox1 * c - oy2 * s + cx) | 0;
  4266. var bly = (ox1 * s + oy2 * c + cy) | 0;
  4267. var urx = (ox2 * c - oy1 * s + cx) | 0;
  4268. var ury = (ox2 * s + oy1 * c + cy) | 0;
  4269. var brx = (ox2 * c - oy2 * s + cx) | 0;
  4270. var bry = (ox2 * s + oy2 * c + cy) | 0;
  4271. var points = [
  4272. { x: ulx, y: uly },
  4273. { x: urx, y: ury },
  4274. { x: brx, y: bry },
  4275. { x: blx, y: bly },
  4276. ];
  4277. var s = '<polygon points="';
  4278. var _g = 0;
  4279. var _g1 = points.length;
  4280. while (_g < _g1) {
  4281. var i = _g++;
  4282. s += points[i].x + " " + points[i].y;
  4283. if (i != points.length - 1) {
  4284. s += " ";
  4285. }
  4286. }
  4287. s += '" ' + geometrize_exporter_SvgExporter.SVG_STYLE_HOOK + "/>";
  4288. return s;
  4289. },
  4290. };
  4291. var geometrize_shape_ShapeFactory = function () {};
  4292. geometrize_shape_ShapeFactory.create = function (type, xBound, yBound) {
  4293. switch (type) {
  4294. case 0:
  4295. return new geometrize_shape_Rectangle(xBound, yBound);
  4296. case 1:
  4297. return new geometrize_shape_RotatedRectangle(xBound, yBound);
  4298. case 2:
  4299. return new geometrize_shape_Triangle(xBound, yBound);
  4300. case 3:
  4301. return new geometrize_shape_Ellipse(xBound, yBound);
  4302. case 4:
  4303. return new geometrize_shape_RotatedEllipse(xBound, yBound);
  4304. case 5:
  4305. return new geometrize_shape_Circle(xBound, yBound);
  4306. case 6:
  4307. return new geometrize_shape_Line(xBound, yBound);
  4308. case 7:
  4309. return new geometrize_shape_QuadraticBezier(xBound, yBound);
  4310. }
  4311. };
  4312. geometrize_shape_ShapeFactory.randomShapeOf = function (types, xBound, yBound) {
  4313. if (!(types != null && types.length > 0)) {
  4314. throw haxe_Exception.thrown("FAIL: a != null && a.length > 0");
  4315. }
  4316. var upper = types.length - 1;
  4317. if (0 > upper) {
  4318. throw haxe_Exception.thrown("FAIL: lower <= upper");
  4319. }
  4320. return geometrize_shape_ShapeFactory.create(types[Math.floor((upper + 1) * Math.random())], xBound, yBound);
  4321. };
  4322. var geometrize_shape_ShapeTypes = ($hx_exports["geometrize"]["shape"]["ShapeTypes"] = function () {});
  4323. var geometrize_shape_Triangle = function (xBound, yBound) {
  4324. this.x1 = Std.random(xBound);
  4325. this.y1 = Std.random(yBound);
  4326. this.x2 = this.x1 + (-16 + Math.floor(33 * Math.random()));
  4327. this.y2 = this.y1 + (-16 + Math.floor(33 * Math.random()));
  4328. this.x3 = this.x1 + (-16 + Math.floor(33 * Math.random()));
  4329. this.y3 = this.y1 + (-16 + Math.floor(33 * Math.random()));
  4330. this.xBound = xBound;
  4331. this.yBound = yBound;
  4332. };
  4333. geometrize_shape_Triangle.prototype = {
  4334. rasterize: function () {
  4335. return geometrize_rasterizer_Scanline.trim(
  4336. geometrize_rasterizer_Rasterizer.scanlinesForPolygon([
  4337. { x: this.x1, y: this.y1 },
  4338. { x: this.x2, y: this.y2 },
  4339. { x: this.x3, y: this.y3 },
  4340. ]),
  4341. this.xBound,
  4342. this.yBound
  4343. );
  4344. },
  4345. mutate: function () {
  4346. var r = Std.random(3);
  4347. switch (r) {
  4348. case 0:
  4349. var value = this.x1 + (-16 + Math.floor(33 * Math.random()));
  4350. var max = this.xBound - 1;
  4351. if (0 > max) {
  4352. throw haxe_Exception.thrown("FAIL: min <= max");
  4353. }
  4354. this.x1 = value < 0 ? 0 : value > max ? max : value;
  4355. var value = this.y1 + (-16 + Math.floor(33 * Math.random()));
  4356. var max = this.yBound - 1;
  4357. if (0 > max) {
  4358. throw haxe_Exception.thrown("FAIL: min <= max");
  4359. }
  4360. this.y1 = value < 0 ? 0 : value > max ? max : value;
  4361. break;
  4362. case 1:
  4363. var value = this.x2 + (-16 + Math.floor(33 * Math.random()));
  4364. var max = this.xBound - 1;
  4365. if (0 > max) {
  4366. throw haxe_Exception.thrown("FAIL: min <= max");
  4367. }
  4368. this.x2 = value < 0 ? 0 : value > max ? max : value;
  4369. var value = this.y2 + (-16 + Math.floor(33 * Math.random()));
  4370. var max = this.yBound - 1;
  4371. if (0 > max) {
  4372. throw haxe_Exception.thrown("FAIL: min <= max");
  4373. }
  4374. this.y2 = value < 0 ? 0 : value > max ? max : value;
  4375. break;
  4376. case 2:
  4377. var value = this.x3 + (-16 + Math.floor(33 * Math.random()));
  4378. var max = this.xBound - 1;
  4379. if (0 > max) {
  4380. throw haxe_Exception.thrown("FAIL: min <= max");
  4381. }
  4382. this.x3 = value < 0 ? 0 : value > max ? max : value;
  4383. var value = this.y3 + (-16 + Math.floor(33 * Math.random()));
  4384. var max = this.yBound - 1;
  4385. if (0 > max) {
  4386. throw haxe_Exception.thrown("FAIL: min <= max");
  4387. }
  4388. this.y3 = value < 0 ? 0 : value > max ? max : value;
  4389. break;
  4390. }
  4391. },
  4392. clone: function () {
  4393. var triangle = new geometrize_shape_Triangle(this.xBound, this.yBound);
  4394. triangle.x1 = this.x1;
  4395. triangle.y1 = this.y1;
  4396. triangle.x2 = this.x2;
  4397. triangle.y2 = this.y2;
  4398. triangle.x3 = this.x3;
  4399. triangle.y3 = this.y3;
  4400. return triangle;
  4401. },
  4402. getType: function () {
  4403. return 2;
  4404. },
  4405. getRawShapeData: function () {
  4406. return [this.x1, this.y1, this.x2, this.y2, this.x3, this.y3];
  4407. },
  4408. getSvgShapeData: function () {
  4409. return '<polygon points="' + this.x1 + "," + this.y1 + " " + this.x2 + "," + this.y2 + " " + this.x3 + "," + this.y3 + '" ' + geometrize_exporter_SvgExporter.SVG_STYLE_HOOK + "/>";
  4410. },
  4411. };
  4412. var haxe_Exception = function (message, previous, native) {
  4413. Error.call(this, message);
  4414. this.message = message;
  4415. this.__previousException = previous;
  4416. this.__nativeException = native != null ? native : this;
  4417. };
  4418. haxe_Exception.thrown = function (value) {
  4419. if (value instanceof haxe_Exception) {
  4420. return value.get_native();
  4421. } else if (value instanceof Error) {
  4422. return value;
  4423. } else {
  4424. var e = new haxe_ValueException(value);
  4425. return e;
  4426. }
  4427. };
  4428. haxe_Exception.__super__ = Error;
  4429. haxe_Exception.prototype = $extend(Error.prototype, {
  4430. get_native: function () {
  4431. return this.__nativeException;
  4432. },
  4433. });
  4434. var haxe_ValueException = function (value, previous, native) {
  4435. haxe_Exception.call(this, String(value), previous, native);
  4436. this.value = value;
  4437. };
  4438. haxe_ValueException.__super__ = haxe_Exception;
  4439. haxe_ValueException.prototype = $extend(haxe_Exception.prototype, {});
  4440. var haxe_ds_IntMap = function () {
  4441. this.h = {};
  4442. };
  4443. haxe_ds_IntMap.prototype = {
  4444. keys: function () {
  4445. var a = [];
  4446. for (var key in this.h) if (this.h.hasOwnProperty(key)) a.push(+key);
  4447. return new haxe_iterators_ArrayIterator(a);
  4448. },
  4449. };
  4450. var haxe_io_Bytes = function (data) {
  4451. this.length = data.byteLength;
  4452. this.b = new Uint8Array(data);
  4453. this.b.bufferValue = data;
  4454. data.hxBytes = this;
  4455. data.bytes = this.b;
  4456. };
  4457. var haxe_iterators_ArrayIterator = function (array) {
  4458. this.current = 0;
  4459. this.array = array;
  4460. };
  4461. haxe_iterators_ArrayIterator.prototype = {
  4462. hasNext: function () {
  4463. return this.current < this.array.length;
  4464. },
  4465. next: function () {
  4466. return this.array[this.current++];
  4467. },
  4468. };
  4469. onmessage = GeometrizeWorker.prototype.messageHandler;
  4470. geometrize_exporter_SvgExporter.SVG_STYLE_HOOK = "::svg_style_hook::";
  4471. geometrize_runner_Default.options = {
  4472. shapeTypes: [2],
  4473. candidateShapesPerStep: 50,
  4474. shapeMutationsPerStep: 100,
  4475. alpha: 128,
  4476. };
  4477. geometrize_shape_ShapeTypes.RECTANGLE = 0;
  4478. geometrize_shape_ShapeTypes.ROTATED_RECTANGLE = 1;
  4479. geometrize_shape_ShapeTypes.TRIANGLE = 2;
  4480. geometrize_shape_ShapeTypes.ELLIPSE = 3;
  4481. geometrize_shape_ShapeTypes.ROTATED_ELLIPSE = 4;
  4482. geometrize_shape_ShapeTypes.CIRCLE = 5;
  4483. geometrize_shape_ShapeTypes.LINE = 6;
  4484. geometrize_shape_ShapeTypes.QUADRATIC_BEZIER = 7;
  4485. })(typeof exports != "undefined" ? exports : typeof window != "undefined" ? window : typeof self != "undefined" ? self : this, {})`
  4486. );