PageRenderTime 61ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/test/tests/Path_Boolean.js

http://github.com/paperjs/paper.js
JavaScript | 1253 lines | 1115 code | 114 blank | 24 comment | 5 complexity | 84e93b6a02b871921e6ce98d3bbeb778 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. /*
  2. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
  3. * http://paperjs.org/
  4. *
  5. * Copyright (c) 2011 - 2020, Jürg Lehni & Jonathan Puckey
  6. * http://juerglehni.com/ & https://puckey.studio/
  7. *
  8. * Distributed under the MIT license. See LICENSE file for details.
  9. *
  10. * All rights reserved.
  11. */
  12. QUnit.module('Path Boolean Operations');
  13. function testOperations(path1, path2, results) {
  14. compareBoolean(function() { return path1.unite(path2); }, results[0]);
  15. compareBoolean(function() { return path2.unite(path1); }, results[0]);
  16. compareBoolean(function() { return path1.subtract(path2); }, results[1]);
  17. compareBoolean(function() { return path2.subtract(path1); }, results[2]);
  18. compareBoolean(function() { return path1.intersect(path2); }, results[3]);
  19. compareBoolean(function() { return path2.intersect(path1); }, results[3]);
  20. compareBoolean(function() { return path1.exclude(path2); }, results[4]);
  21. compareBoolean(function() { return path2.exclude(path1); }, results[4]);
  22. }
  23. test('Boolean operations without crossings', function() {
  24. var path1 = new Path.Rectangle({
  25. point: [0, 0],
  26. size: [200, 200]
  27. });
  28. var path2 = new Path.Rectangle({
  29. point: [50, 50],
  30. size: [100, 100]
  31. });
  32. var path3 = new Path.Rectangle({
  33. point: [250, 50],
  34. size: [100, 100]
  35. });
  36. testOperations(path1, path2, [
  37. 'M0,200v-200h200v200z', // path1.unite(path2);
  38. 'M0,200v-200h200v200zM150,150v-100h-100v100z', // path1.subtract(path2);
  39. '', // path2.subtract(path1);
  40. 'M50,150v-100h100v100z', // path1.intersect(path2);
  41. 'M0,200v-200h200v200zM150,150v-100h-100v100z' // path1.exclude(path2);
  42. ]);
  43. testOperations(path1, path3, [
  44. 'M0,200v-200h200v200zM250,150v-100h100v100z', // path1.unite(path3);
  45. 'M0,200v-200h200v200z', // path1.subtract(path3);
  46. 'M350,150v-100h-100v100z', // path3.subtract(path1);
  47. '', // path1.intersect(path3);
  48. 'M0,200v-200h200v200zM250,150v-100h100v100z' // path1.exclude(path3);
  49. ]);
  50. });
  51. test('frame.intersect(rect)', function() {
  52. var frame = new CompoundPath();
  53. frame.addChild(new Path.Rectangle(new Point(140, 10), [100, 300]));
  54. frame.addChild(new Path.Rectangle(new Point(150, 80), [50, 80]));
  55. var rect = new Path.Rectangle(new Point(50, 50), [100, 150]);
  56. compareBoolean(function() { return frame.intersect(rect); },
  57. 'M140,50l10,0l0,150l-10,0z');
  58. });
  59. test('PathItem#resolveCrossings()', function() {
  60. var paths = [
  61. 'M100,300l0,-50l50,-50l-50,0l150,0l-150,0l50,0l-50,0l100,0l-100,0l0,-100l200,0l0,200z',
  62. 'M50,300l0,-150l50,25l0,-75l200,0l0,200z M100,200l50,0l-50,-25z',
  63. 'M330.1,388.5l-65,65c0,0 -49.1,-14.5 -36.6,-36.6c12.5,-22.1 92.4,25.1 92.4,25.1c0,0 -33.3,-73.3 -23.2,-85.9c10,-12.8 32.4,32.4 32.4,32.4z',
  64. 'M570,290l5.8176000300452415,33.58556812220928l-28.17314339506561,-14.439003967264455l31.189735425395614,-4.568209255479985c-5.7225406635552645e-9,-3.907138079739525e-8 -59.366611385062015,8.695139599513823 -59.366611385062015,8.695139599513823z',
  65. 'M228.26666666666668,222.72h55.46666666666667c3.05499999999995,0 5.546666666666624,2.4916666666666742 5.546666666666624,5.546666666666681v55.46666666666667c0,3.05499999999995 -2.4916666666666742,5.546666666666624 -5.546666666666624,5.546666666666624h-55.46666666666667c-3.055000000000007,0 -5.546666666666681,-2.4916666666666742 -5.546666666666681,-5.546666666666624v-55.46666666666667c0,-3.055000000000007 2.4916666666666742,-5.546666666666681 5.546666666666681,-5.546666666666681zM283.73333399705655,289.2799999999998c-2.212411231994338e-7,1.1368683772161603e-13 2.212409526691772e-7,0 0,0z'
  66. ];
  67. var results = [
  68. 'M100,300l0,-50l50,-50l-50,0l0,-100l200,0l0,200z',
  69. 'M50,300l0,-150l50,25l0,-75l200,0l0,200z M100,200l50,0l-50,-25z',
  70. 'M291.85631,426.74369l-26.75631,26.75631c0,0 -49.1,-14.5 -36.6,-36.6c7.48773,-13.23831 39.16013,-1.61018 63.35631,9.84369z M330.1,388.5l-22.09831,22.09831c-8.06306,-21.54667 -15.93643,-47.46883 -10.30169,-54.49831c10,-12.8 32.4,32.4 32.4,32.4z M320.9,442c0,0 -12.84682,-7.58911 -29.04369,-15.25631l16.14539,-16.14539c6.38959,17.07471 12.89831,31.40169 12.89831,31.40169z',
  71. 'M570,290l5.8176,33.58557l-28.17314,-14.439c-14.32289,2.0978 -28.17688,4.12693 -28.17688,4.12693z',
  72. 'M228.26666666666668,222.72h55.46666666666667c3.05499999999995,0 5.546666666666624,2.4916666666666742 5.546666666666624,5.546666666666681v55.46666666666667c0,3.05499999999995 -2.4916666666666742,5.546666666666624 -5.546666666666624,5.546666666666624h-55.46666666666667c-3.055000000000007,0 -5.546666666666681,-2.4916666666666742 -5.546666666666681,-5.546666666666624v-55.46666666666667c0,-3.055000000000007 2.4916666666666742,-5.546666666666681 5.546666666666681,-5.546666666666681z'
  73. ];
  74. for (var i = 0; i < paths.length; i++) {
  75. var path = PathItem.create(paths[i]),
  76. result = PathItem.create(results[i]);
  77. path.fillRule = 'evenodd';
  78. compareBoolean(path.resolveCrossings(), result, 'path.resolveCrossings(); // Test ' + (i + 1));
  79. }
  80. });
  81. test('#541', function() {
  82. var shape0 = new Path.Rectangle({
  83. insert: false,
  84. point: [304, 226],
  85. size: [328, 328]
  86. });
  87. var shape1 = new Path({
  88. insert: false,
  89. segments: [
  90. [213.5, 239],
  91. [476.5, 279],
  92. [716, 233.5],
  93. [469, 74]
  94. ],
  95. closed: true
  96. });
  97. var res1 = shape0.exclude(shape1);
  98. var shape2 = new Path.Rectangle({
  99. insert: false,
  100. point: [174, 128],
  101. size: [309, 251]
  102. });
  103. var res2 = res1.exclude(shape2);
  104. // shape3
  105. var shape3 = new Path.Rectangle({
  106. insert: false,
  107. point: [318, 148],
  108. size: [302, 302]
  109. });
  110. // exclude res2 & shape3
  111. compareBoolean(function() { return res2.exclude(shape3); },
  112. 'M304,554l0,-175l14,0l0,71l302,0l0,-198.262l12,-2.27975l0,304.54175z M318,379l165,0l0,-101.23486l137,-26.02714l0,-25.738l-137,0l0,-78l-128.58788,0l-36.41212,23.51468l0,54.48532l165,0l0,51.76514l-6.5,1.23486l-158.5,-24.10646z M174,379l0,-251l211.38182,0l-30.9697,20l-36.41212,0l0,23.51468l-104.5,67.48532l90.5,13.76426l0,-26.76426l14,0l0,28.89354l-14,-2.12928l0,126.23574z M385.38182,128l83.61818,-54l114.59561,74l-100.59561,0l0,-20z M583.59561,148l36.40439,23.5081l0,-23.5081z M620,171.5081l96,61.9919l-84,15.95825l0,-23.45825l-12,0z');
  113. });
  114. test('#609', function() {
  115. // path1 and path2 are half circles, applying unite should result in a circle
  116. var path1 = new Path();
  117. path1.moveTo(new Point(100, 100));
  118. path1.arcTo(new Point(100, 200));
  119. path1.closePath();
  120. var path2 = new Path();
  121. path2.moveTo(new Point(100, 200));
  122. path2.arcTo(new Point(100, 100));
  123. path2.closePath();
  124. compareBoolean(function() { return path1.unite(path2); },
  125. 'M150,150c0,27.61424 -22.38576,50 -50,50c-27.61424,0 -50,-22.38576 -50,-50c0,-27.61424 22.38576,-50 50,-50c27.61424,0 50,22.38576 50,50z');
  126. });
  127. test('#610', function() {
  128. var square = new Path.Rectangle({
  129. position: [140, 0],
  130. size: 300
  131. });
  132. // Make a ring using subtraction of two circles:
  133. var inner = new Path.Circle({
  134. center: [0, 0],
  135. radius: 100
  136. });
  137. var outer = new Path.Circle({
  138. center: [0, 0],
  139. radius: 132
  140. });
  141. var ring = outer.subtract(inner);
  142. compareBoolean(function() { return ring.subtract(square); },
  143. 'M-132,0c0,-69.53737 53.7698,-126.51614 122,-131.62689l0,32.12064c-50.53323,5.01724 -90,47.65277 -90,99.50625c0,51.85348 39.46677,94.489 90,99.50625l0,32.12064c-68.2302,-5.11075 -122,-62.08951 -122,-131.62689z');
  144. });
  145. test('#719', function() {
  146. var radius = 50;
  147. var circle = new Path.Circle([0, 0], radius);
  148. var arc = new Path.Arc([0, -radius], [radius, 0], [0, radius]);
  149. arc.closed = true;
  150. arc.pivot = arc.bounds.leftCenter;
  151. var result = circle.subtract(arc);
  152. // Rotate the arc by 180 to receive the expected shape to compare against
  153. var expected = arc.rotate(180);
  154. compareBoolean(result, expected);
  155. });
  156. test('#757 (path1.intersect(pat2, { trace: false }))', function() {
  157. var rect = new Path.Rectangle({
  158. from: [100, 250],
  159. to: [350, 350]
  160. });
  161. var line = new Path({
  162. segments: [
  163. [100, 200],
  164. [150, 400],
  165. [200, 200],
  166. [250, 400],
  167. [300, 200],
  168. [350, 400]
  169. ]
  170. });
  171. var res = line.intersect(rect, { trace: false });
  172. var children = res.removeChildren();
  173. var first = children[0];
  174. for (var i = 1; i < children.length; i++) {
  175. first.join(children[i]);
  176. }
  177. first.insertAbove(res);
  178. res.remove();
  179. res = first;
  180. compareBoolean(res,
  181. 'M112.5,250l25,100l25,0l25,-100l25,0l25,100l25,0l25,-100l25,0l25,100');
  182. });
  183. test('#784', function() {
  184. var path1 = PathItem.create('M495.9,1693.5c-42.2-203.5-64.5-304.9-78-299.9 c-1.7,0.6-0.3,6.7,5.3,22.5l209.4-74.8l75.8,303.9L495.9,1693.5z');
  185. var path2 = PathItem.create('M632.6,1341.2l-209.4,74.9c95.4,267,135.6,201-60.1-144.5l202.9-85.7 L632.6,1341.2z');
  186. compareBoolean(function() { return path1.unite(path2); },
  187. 'M495.9,1693.5c-17.51923,-84.48253 -31.60874,-151.36838 -43.06274,-200.34989c-9.02339,-21.58227 -18.9863,-47.24083 -29.63726,-77.05011c-5.6,-15.8 -7,-21.9 -5.3,-22.5c3.68921,-1.36638 8.03561,5.21313 13.26571,19.65076l6.17555,-2.20892c0.00094,0.00191 0.00189,0.00383 0.00283,0.00574l195.25591,-69.74757l75.8,303.9z M632.6,1341.2l-195.25874,69.84183c-19.60056,-39.73292 -44.12819,-86.27851 -74.24126,-139.44183l202.9,-85.7z');
  188. var path1 = new Path('M330.1,388.5l-65,65c0,0-49.1-14.5-36.6-36.6 c12.5-22.1,92.4,25.1,92.4,25.1s-33.3-73.3-23.2-85.9C307.7,343.3,330.1,388.5,330.1,388.5z');
  189. var path2 = new Path('M395.1,453.4c0,15.2-33.8,65-65,65s-65-65-65-65l65-65 C330.1,388.5,395.1,438.2,395.1,453.4z');
  190. compareBoolean(function() { return path1.unite(path2); },
  191. 'M265.13434,453.46566l-0.03434,0.03434c0,0 -49.1,-14.5 -36.6,-36.6c7.48073,-13.22593 39.10093,-1.6319 63.28843,9.81157l16.18604,-16.18604c-8.05354,-21.53223 -15.90287,-47.40397 -10.27447,-54.42553c9.77623,-12.51358 31.40373,30.40618 32.36674,32.33326l0.03326,-0.03326c0,0.1 65,49.8 65,65c0,15.2 -33.8,65 -65,65c-30.62393,0 -63.75273,-62.62185 -64.96566,-64.93434z');
  192. });
  193. test('#784#issuecomment-144653463', function() {
  194. var path1 = new Path({
  195. segments: [
  196. [400, 300],
  197. [396.4240965757225, 386.760212367686],
  198. [363.8902430603039, 336.3464406833805]
  199. ],
  200. closed: true
  201. });
  202. var path2 = new Path({
  203. segments: [
  204. [380.15716053320796, 361.5533174872367],
  205. [368.9579765078272, 389.3845783631412],
  206. [352.11749924000907, 372.22000125020173]
  207. ],
  208. closed: true
  209. });
  210. var path3 = new Path({
  211. segments: [
  212. [381.9248139754118, 360.88087710036456],
  213. [352.11749931845384, 372.22000145641056],
  214. [353.8723170322086, 346.9400510828104]
  215. ],
  216. closed: true
  217. });
  218. compareBoolean(function() { return path1.unite(path2).unite(path3); },
  219. 'M400,300l-3.5759,86.76021l-16.26693,-25.2069l0,0l-11.19918,27.83126l-16.84048,-17.16458l1.75482,-25.27995l24.8115,12.3302l-14.79357,-22.92381z M352.1175,372.22z');
  220. });
  221. test('#784#issuecomment-144993215', function() {
  222. var path1 = new Path({
  223. segments: [
  224. [428.65986693122585, 123.24312916360232],
  225. [448.9732353341095, 290.23336023178985, -1.297313778199964, -0.24666929481787747, -0.06896642337790126, -0.004714867204086204],
  226. [448.9732339473677, 290.2333601369859, 0.22704183013848933, 0.04316939284507271, 0.24127512029406262, 0.016494695478172616],
  227. [375.34013306877415, 150.7568708363977]
  228. ],
  229. closed: true
  230. });
  231. compareBoolean(function() { return path1.unite(); },
  232. 'M428.65987,123.24313c0,0 18.24445,159.97772 20.21157,166.76806c-3.05664,-6.18082 -73.53131,-139.25432 -73.53131,-139.25432z M448.97323,290.23336c0,0 0,0 0,0c0.22704,0.04317 -0.06896,-0.00471 0,0c-0.02659,-0.00506 -0.06063,-0.08007 -0.1018,-0.22217c0.07286,0.14733 0.10741,0.22256 0.1018,0.22217z',
  233. null, { tolerance: 1e-3 });
  234. });
  235. test('#784#issuecomment-168605018', function() {
  236. var path1 = new CompoundPath();
  237. path1.setChildren([
  238. new Path({
  239. segments: [
  240. [401.77542835664826, 286.9803609495646],
  241. [410.6261525310172, 207.97354059345616],
  242. [460.3783408790767, 174.43669899386418],
  243. ],
  244. closed: true
  245. }), new Path({
  246. segments: [
  247. [410.6261524612045, 207.9735406405153],
  248. [410.6261525310172, 207.97354059345614, -0.0005059167983745283, -0.0007686158121771314]
  249. ],
  250. closed: true
  251. })
  252. ], true);
  253. var path2 = new Path({
  254. segments: [
  255. [410.6261524612047, 207.97354064051552, 0, 0, 0.19904749518872222, 0.2952886437272184],
  256. [409.163896522797, 207.2586618457598, 1.6828473498011363, 0.6114523237241087],
  257. [460.3783408790765, 174.43669899386396]
  258. ],
  259. closed: true
  260. });
  261. compareBoolean(function() { return path1.unite(path2); },
  262. 'M401.77543,286.98036l8.85044,-79.00432c-0.16499,-0.13413 -0.57872,-0.39645 -1.46198,-0.71738l51.21444,-32.82196z M410.62615,207.97354c0,0 0,0 0,0z');
  263. });
  264. test('#854', function() {
  265. var p = new Path({
  266. segments:[
  267. [110, 60],
  268. [99.09349390368303, 54.102707245527334, 0, 0, 0.2109804080034046, -0.3885775729842338],
  269. [99.76298270272372, 52.95998195277986, -0.2353176636361775, 0.3732505490504639,],
  270. [107.23497309089953, 78.84996109436266, 0, 0, -9.106249727572695, -5.544212301393825],
  271. [100.0593186152821, 52.32387941069251, -5.08710486250942, 9.369281629969153, 0, 0],
  272. ],
  273. closed:true
  274. });
  275. p.translate(100, 100);
  276. p.scale(4);
  277. compareBoolean(function() {
  278. p.windingRule = 'evenodd';
  279. return p.unite();
  280. },
  281. 'M228.55086,143.23924l-38.88978,-21.02822l27.82967,96.42806c-34.09062,-20.75559 -47.33495,-62.77314 -32.21096,-98.79709l-0.35495,-0.19193c0.64433,-1.18671 1.31713,-2.35551 2.01826,-3.50647c0,0 0,0 0,0c-0.58827,1.22495 -1.1426,2.45812 -1.66331,3.6984l4.38129,2.36902l-2.05829,-7.13185c-0.22261,0.3531 -0.44251,0.70791 -0.6597,1.06443c0.58173,-1.21134 1.19664,-2.41465 1.84504,-3.60884z');
  282. compareBoolean(function() {
  283. p.windingRule = 'nonzero';
  284. return p.unite();
  285. },
  286. 'M228.55086,143.23924l-38.88978,-21.02822l27.82967,96.42806c-34.09062,-20.75559 -47.33495,-62.77314 -32.21096,-98.79709l-0.35495,-0.19193c0.64433,-1.18671 1.31713,-2.35551 2.01826,-3.50647c0.58173,-1.21134 1.19664,-2.41465 1.84504,-3.60884z');
  287. });
  288. test('#859', function() {
  289. var p1 = new Path({
  290. segments: [
  291. [230, 360],
  292. [326.04999999999995, 361.95, 0, 0, 7.100000000000023, 5.300000000000011],
  293. [347.74999999999994, 377.3, -7.300000000000011, -5, 0, 0],
  294. [260, 400],
  295. ],
  296. closed: true
  297. });
  298. var p2 = new Path({
  299. segments: [
  300. [329.8373529833907, 360.99927475751736, 0, 0, -0.5084518552435497, 1.7136677994218417],
  301. [327.9816245617005, 366.0401044369074, 0.7293957729680756, -1.645975116174725, 0, 0],
  302. [300, 380]
  303. ],
  304. closed: true
  305. });
  306. compareBoolean(function() { return p1.subtract(p2); },
  307. 'M230,360l96.05,1.95c0.3523,0.26298 0.70509,0.52535 1.05835,0.78713l-27.10835,17.26287l27.98162,-13.9599c0.29878,-0.67424 0.57885,-1.35439 0.84036,-2.04026c6.22144,4.55915 12.57473,8.94859 18.92802,13.30016l-87.75,22.7z');
  308. });
  309. test('#839', function() {
  310. var p1 = new Path({
  311. segments: [
  312. [522, 352],
  313. [500, 400],
  314. [480, 400],
  315. [448, 448],
  316. [100, 448],
  317. [100, 352]
  318. ],
  319. closed: true
  320. });
  321. var p2 = new Path.Rectangle(250, 300, 100, 200);
  322. compareBoolean(function() { return p1.subtract(p2); },
  323. 'M522,352l-22,48l-20,0l-32,48l-98,0l0,-96z M250,448l-150,0l0,-96l150,0z');
  324. });
  325. test('#865', function() {
  326. function executeTest(offset) {
  327. var p1 = new Path({
  328. segments:[
  329. [300, 100],
  330. [300, 350],
  331. [256.00000000000006, 350],
  332. [256.00000000000006, 250],
  333. [230, 224],
  334. [256.00000000000006, 200],
  335. [256.00000000000006, 100]
  336. ],
  337. closed:true
  338. });
  339. var p2 = new Path({
  340. segments:[
  341. [256, 150],
  342. [256, 300],
  343. [200, 300],
  344. [200, 150]
  345. ],
  346. closed:true
  347. });
  348. p1.position = p1.position.add([offset, 0]);
  349. compareBoolean(p1.subtract(p2),
  350. 'M300,100l0,250l-44,0l0,-250z',
  351. 'p1.subtract(p2); // with offset = ' + offset);
  352. }
  353. // Attempt different x-offsets since that produced different version of the
  354. // issue:
  355. executeTest(0);
  356. executeTest(-0.0000001);
  357. executeTest( 0.0000001);
  358. executeTest(-0.000000001);
  359. executeTest( 0.000000001);
  360. });
  361. test('#870', function() {
  362. var path1 = new Path.Rectangle({
  363. point: [50, 50],
  364. size: [150, 50]
  365. });
  366. var path2 = new Path.Rectangle({
  367. point: [70, 50],
  368. size: [150, 50]
  369. });
  370. compareBoolean(function() { return path1.intersect(path2); },
  371. 'M70,50l130,0l0,50l-130,0z');
  372. var path1 = new Path.Rectangle({
  373. point: [50, 150],
  374. size: [50, 100]
  375. });
  376. var path2 = new Path.Rectangle({
  377. point: [50, 175],
  378. size: [50, 100]
  379. });
  380. compareBoolean(function() { return path1.intersect(path2); },
  381. 'M50,250l0,-75l50,0l0,75z');
  382. });
  383. test('#875', function() {
  384. var p1 = new Path({
  385. segments: [
  386. [158.7, 389.3, 0, 0, -4.95, 4.95],
  387. [158.7, 407.2, -4.95, -4.95, 4.95, 4.95],
  388. [176.6, 407.2, -4.95, 4.95, 4.95, -4.95],
  389. [176.6, 389.3, 4.95, 4.95, -4.95, -4.95],
  390. [158.7, 389.3, 4.95, -4.95, 0, 0]
  391. ],
  392. closed: true
  393. });
  394. var p2 = new Path.Circle(260, 320, 100);
  395. compareBoolean(function() { return p1.subtract(p2); },
  396. 'M158.7,407.2c4.95,4.95 12.95,4.95 17.9,0c4.95,-4.95 4.95,-12.95 0,-17.9c-4.95,-4.95 -12.95,-4.95 -17.9,0c-4.95,4.95 -4.95,12.95 0,17.9z');
  397. });
  398. test('#877', function() {
  399. var cp = new CompoundPath({
  400. children: [
  401. new Path.Circle(100, 60, 50),
  402. new Path.Circle(100, 60, 30),
  403. new Path({
  404. segments: [
  405. [120, 140],
  406. [150, 140],
  407. [150, 190],
  408. [120, 190]
  409. ],
  410. closed: true
  411. }),
  412. ],
  413. fillRule: 'evenodd'
  414. });
  415. var p = new Path({
  416. segments: [
  417. [135, 200],
  418. [135, 120],
  419. [170, 120],
  420. [170, 200]
  421. ],
  422. closed: true
  423. });
  424. compareBoolean(function() { return cp.subtract(p); },
  425. 'M50,60c0,-27.61424 22.38576,-50 50,-50c27.61424,0 50,22.38576 50,50c0,27.61424 -22.38576,50 -50,50c-27.61424,0 -50,-22.38576 -50,-50z M100,90c16.56854,0 30,-13.43146 30,-30c0,-16.56854 -13.43146,-30 -30,-30c-16.56854,0 -30,13.43146 -30,30c0,16.56854 13.43146,30 30,30z M120,140l15,0l0,50l-15,0z');
  426. });
  427. test('#878', function() {
  428. var p1 = new Path({ segments:[ [431.90000000000003, 479.99999999999994], [128.00000000000003, 370], [80.00000000000003, 479.99999999999994], ], closed:true });
  429. var p2 = new Path({ segments:[ [400, 480, 10, 0, 0, 0], [140, 480, 0, 0, -10, 0], [300, 300]], closed:true });
  430. compareBoolean(function() { return p1.unite(p2); },
  431. 'M431.9,480l-35.62956,-12.89652c-19.34292,-41.22209 -96.27044,-167.10348 -96.27044,-167.10348c0,0 -48.3459,51.18977 -91.9573,98.97235l-80.0427,-28.97235l-48,110z');
  432. compareBoolean(function() { return p1.subtract(p2); },
  433. 'M431.9,480l-35.62956,-12.89652c3.78718,8.07094 5.3669,12.89652 3.72956,12.89652z M208.0427,398.97235l-80.0427,-28.97235l-48,110l60,0c-4.6672,0 29.87455,-39.20895 68.0427,-81.02765z');
  434. });
  435. test('#885', function() {
  436. var p1 = new Path.Rectangle(100, 100, 100, 100);
  437. var p2 = p1.clone();
  438. var empty = new Path();
  439. compareBoolean(function() { return p1.unite(p2); }, p1);
  440. compareBoolean(function() { return p1.intersect(p2); }, p1);
  441. compareBoolean(function() { return p1.subtract(p2); }, empty);
  442. compareBoolean(function() { return p1.exclude(p2); }, empty);
  443. });
  444. test('#889', function() {
  445. var cp = new CompoundPath([
  446. new Path({ segments: [ [340.26, 358.4], [576, 396.8], [345.78, 396.8] ], closed: true }),
  447. new Path({ segments: [ [691.2, 685.76], [672, 550.4, 0, 0, 10, 0], [729.6, 608, 0, -20, 0, 0] ], closed: true })
  448. ]);
  449. var p = new Path({ segments: [ [739, 418], [637, 704], [205, 704], [204.30709922574619, 356.553500194953] ], closed: true });
  450. compareBoolean(function() { return cp.subtract(p); },
  451. 'M340.26,358.4l235.74,38.4l-21.47738,0l-212.24889,-24.39148z M691.2,685.76l-13.57151,-95.67911l11.09506,-31.10967c17.43794,12.2938 40.87645,34.99446 40.87645,49.02878z');
  452. });
  453. test('#890', function() {
  454. var cp = new CompoundPath([
  455. new Path({ segments: [ [676, 396.8], [445.78, 396.8], [426, 260] ], closed: true }),
  456. new Path({ segments: [ [672, 550.4, 0, 0, 31.74000000000001, 0], [633.5999999999999, 732.8, 0, 26.519999999999982] ], closed: true })
  457. ]);
  458. var p = new Path({ segments: [ [732, 418, 0, 0, 0, 52.45802606694065], [676.3444534355956, 552.3444534355972, 34.385686865893945, -34.38568686589349], [630, 704], [400, 704], [542, 228] ], closed: true });
  459. compareBoolean(function() { return cp.subtract(p); },
  460. 'M491.6437,396.8l-45.8637,0l-19.78,-136.8l91.51486,50.07693z M676.40276,552.28613c19.70425,20.76653 -42.80276,205.5493 -42.80276,180.51387l27.46296,-130.44906l15.28149,-50.00648c0.01944,-0.01944 0.03887,-0.03888 0.0583,-0.05833z');
  461. var cp = new CompoundPath([
  462. new Path({segments:[[576, 396.8], [345.78, 396.8], [249.6, 243.20000000000002]], closed:true}),
  463. new Path({segments:[[624.84, 550.46], [672, 550.4], [729.6, 608]], closed:true})
  464. ]);
  465. var p = new Path({segments:[[323.0000000000002, 228.0000000000001, 0, 0, 51.95879291356505, 0], [410.9999999999998, 704.0000000000002], [-21.000000000000227, 703.9999999999998], [-21.692900774253758, 356.5535001949528]], closed:true});
  466. compareBoolean(function() { return cp.subtract(p); },
  467. 'M576,396.8l-199.38152,0c-6.06278,-38.62456 -12.80947,-74.58601 -20.1433,-103.3058z M255.78013,253.06971l-6.18013,-9.86971l14.43275,6.79188z M624.84,550.46l47.16,-0.06l57.6,57.6z');
  468. });
  469. test('#899', function() {
  470. var path = new Path({segments:[[349.31714952528665, 176.97192499841802, 2.0667935742653185, -10.850610233997372, 0, 0], [308.23418424120047, 394.39737504104323, 0, 0, -0.3852007263769224, 2.0386172397749647], [273.60284923271973, 415.7138856106701, 9.194683617471242, 1.7373535056759692, 0, 0], [340.6967045975081, 152.3115389894092, -4.006231967752797, -3.6687868382265094, 5.694026309937783, 5.214418174126138], [349.72123243229134, 170.85618880187394, -0.36146393999291604, -6.612268801346318, 0.1110858449889065, 2.0320961120115726], [349.31714952528654, 176.97192499841861, 0.3852007263769224, -2.038617239775249, -2.0667935742656027, 10.850610233997315], [333.4126425432937, 153.58289639999975, -10.850610233997315, -2.0667935742653754, 10.850610233997372, 2.0667935742653754]], closed:true});
  471. compareBoolean(function() { return path.unite(); },
  472. 'M349.31715,176.97192l-41.08297,217.42545c-0.3852,2.03862 -25.43665,23.05386 -34.63134,21.31651c0,0 45.72613,-193.57408 61.79225,-248.85827c-4.42287,-6.99195 -6.99542,-14.22758 -1.98246,-13.27272c1.9865,0.37838 3.84798,1.03847 5.55095,1.93102c0.85247,-2.33202 1.44527,-3.46596 1.73311,-3.20238c5.69403,5.21442 8.66306,11.93238 9.02453,18.54465c0.10579,1.93513 -0.00703,3.88198 -0.35068,5.82386c-0.01706,0.09726 -0.03486,0.19455 -0.0534,0.29188z');
  473. });
  474. test('#936', function() {
  475. var p1 = new Path({
  476. segments:[
  477. [437.02857142857147, 121.64285714285714],
  478. [390.3571428571429, 74.97142857142856],
  479. [390.3571428571429, 437.02857142857147],
  480. [437.02857142857147, 390.3571428571429],
  481. [74.97142857142862, 390.3571428571429],
  482. [121.6428571428572, 437.02857142857147],
  483. [121.64285714285714, 74.97142857142858],
  484. [74.97142857142859, 121.64285714285714]
  485. ],
  486. closed:true
  487. });
  488. compareBoolean(function() { return p1.unite(); },
  489. 'M390.35714,121.64286l0,268.71429l-268.71429,0l0,-268.71429z M121.64286,437.02857l-46.67143,-46.67143l46.67143,0z M390.35714,121.64286l0,-46.67143l46.67143,46.67143z M437.02857,390.35714l-46.67143,46.67143l0,-46.67143z M74.97143,121.64286l46.67143,-46.67143l0,46.67143z');
  490. var p2 = new Path({
  491. segments:[
  492. [384.0884708724184, 194.49096034834812, -66.07592496222571, -39.741588860234515],
  493. [364.2895784370851, 164.00333956484477, 0, 0, 9.430248075502885, 76.52772155228502],
  494. [317.5090396516519, 384.0884708724184, 39.74158886023454, -66.07592496222564],
  495. [347.9966604351552, 364.2895784370851, 0, 0, -76.52772155228439, 9.430248075502845],
  496. [127.91152912758163, 317.50903965165196, 66.0759249622259, 39.74158886023463],
  497. [147.71042156291495, 347.9966604351553, 0, 0, -9.43024807550288, -76.52772155228509],
  498. [194.49096034834812, 127.91152912758156, -39.74158886023451, 66.07592496222576],
  499. [164.00333956484474, 147.7104215629149, 0, 0, 76.52772155228499, -9.430248075502845]
  500. ],
  501. closed:true
  502. });
  503. compareBoolean(function() { return p2.unite(); },
  504. 'M366.1932,184.4397c3.98163,62.97187 -9.38253,125.8453 -38.6329,181.75349c-62.97187,3.98163 -125.8453,-9.38253 -181.75349,-38.6329c-3.98163,-62.97187 9.38253,-125.8453 38.6329,-181.75349c62.97187,-3.98163 125.8453,9.38253 181.75349,38.6329z M164.00334,147.71042l30.48762,-19.79889c-3.53519,5.87774 -6.88622,11.84573 -10.05126,17.89528c-6.81387,0.43083 -13.62889,1.06475 -20.43636,1.90362z M147.71042,347.99666l-19.79889,-30.48762c5.87774,3.53519 11.84573,6.88622 17.89528,10.05126c0.43083,6.81387 1.06475,13.62889 1.90362,20.43636z M366.1932,184.4397c-0.43083,-6.81387 -1.06475,-13.62889 -1.90362,-20.43636l19.79889,30.48762c-5.87774,-3.53519 -11.84573,-6.88622 -17.89528,-10.05126z M347.99666,364.28958l-30.48762,19.79889c3.53519,-5.87774 6.88622,-11.84573 10.05126,-17.89528c6.81387,-0.43083 13.62889,-1.06475 20.43636,-1.90362z');
  505. });
  506. test('#923', function() {
  507. var p1 = new Path.Circle({center: [100, 100], radius: 20});
  508. var p2 = new Path.Circle({center: [150, 100], radius: 20});
  509. var cp = new CompoundPath([p1, p2]);
  510. var p3 = new Path.Circle({center: [100, 100], radius: 20});
  511. cp.strokeColor = 'red';
  512. p3.strokeColor = 'green';
  513. compareBoolean(function() { return cp.unite(p3); },
  514. 'M80,100c0,-11.04569 8.95431,-20 20,-20c11.04569,0 20,8.95431 20,20c0,11.04569 -8.95431,20 -20,20c-11.04569,0 -20,-8.95431 -20,-20z M130,100c0,-11.04569 8.95431,-20 20,-20c11.04569,0 20,8.95431 20,20c0,11.04569 -8.95431,20 -20,20c-11.04569,0 -20,-8.95431 -20,-20z');
  515. });
  516. test('#958', function() {
  517. var p1 = new Path.Rectangle(100, 200, 200, 20);
  518. var p2 = new Path.Rectangle(140, 100, 20, 20);
  519. var cp = new CompoundPath({children: [p1, p2]});
  520. var bounds = new Path.Rectangle(cp.bounds);
  521. compareBoolean(function() { return bounds.intersect(cp); },
  522. 'M100,220l0,-20l200,0l0,20z M140,100l20,0l0,20l-20,0z');
  523. });
  524. test('#968', function() {
  525. var p1 = new paper.Path({
  526. segments: [
  527. [352, 280, 0, -26.5, 0, 0],
  528. [352, 356, 0, 0, 0, 2.1999999999999886],
  529. [348, 360, 2.1999999999999886, 0, -72, 0]
  530. ],
  531. closed: true
  532. });
  533. var p2 = new paper.Path({
  534. segments: [
  535. [352, 344],
  536. [352, 356, 0, 0, 0, 2.1999999999999886],
  537. [348, 360, 2.1999999999999886, 0, 0, 0],
  538. [232, 360, 0, 0, -2.1999999999999886, 0]
  539. ],
  540. closed: true
  541. });
  542. compareBoolean(function() { return p1.subtract(p2); },
  543. 'M352,280l0,64c0,0 -13.69105,1.79261 -31.82528,4.17778c-15.66463,-26.96617 31.82528,-89.12564 31.82528,-68.17778z');
  544. });
  545. test('#973', function() {
  546. var path = new Path.Ellipse(100, 100, 150, 110);
  547. path.segments[1].point.y += 60;
  548. path.segments[3].point.y -= 60;
  549. var resolved = path.resolveCrossings();
  550. var orientation = resolved.children.map(function(child) {
  551. return child.isClockwise();
  552. });
  553. equals(orientation, [true, false, true],
  554. 'children orientation after calling path.resolveCrossings()');
  555. });
  556. test('#1036', function() {
  557. var line1 = new Path([
  558. [[305.10732,101.34786],[0,0],[62.9214,0]],
  559. [[499.20274,169.42611],[-29.38716,-68.57004],[5.78922,13.50818]],
  560. [[497.75426,221.57115],[2.90601,-13.5614],[-9.75434,45.52027]],
  561. [[416.63976,331.65512],[31.9259,-30.40562],[-21.77284,20.73604]],
  562. [[350.00999,391.04252],[23.92578,-18.22917],[-23.33885,17.78198]],
  563. [[277.58633,431.59977],[27.45996,-10.67887],[-1.72805,0.67202]],
  564. [[251.51381,437.39367],[0,5.7145],[0,0]]
  565. ]);
  566. var line2 = new Path([
  567. [[547.00236,88.31161],[0,0],[-1.36563,0]],
  568. [[544.10541,85.41466],[1.29555,0.43185],[-9.83725,-3.27908]],
  569. [[509.34205,82.51771],[10.32634,-1.29079],[-10.20055,1.27507]],
  570. [[444.16075,97.00245],[7.10741,-4.06138],[-4.93514,2.82008]],
  571. [[431.12449,105.69328],[4.27047,-2.13524],[-14.94798,7.47399]],
  572. [[407.94892,175.22],[1.27008,-13.33587],[-3.16966,33.28138]],
  573. [[399.25808,279.51008],[-5.61644,-33.69865],[1.73417,10.40499]],
  574. [[415.19129,307.03107],[-5.98792,-8.16534],[2.74694,3.74583]],
  575. [[432.57297,328.75817],[-3.89061,-3.29206],[2.9716,2.51443]],
  576. [[442.71228,334.55206],[-3.01275,-2.46498],[2.39275,1.95771]],
  577. [[448.50617,341.79443],[-2.37502,-1.97918],[39.75954,33.13295]],
  578. [[578.86877,378.00626],[-51.65429,10.33086],[11.28627,-2.25725]],
  579. [[612.18365,366.41848],[-10.6547,4.26188],[3.10697,-1.24279]],
  580. [[617.97755,362.07306],[-3.19904,0],[0,0]]
  581. ]);
  582. compareBoolean(function() { return line1.intersect(line2); },
  583. 'M424.54226,112.15158c32.89387,9.15202 61.28089,26.0555 74.66048,57.27453c5.78922,13.50818 1.45753,38.58364 -1.44848,52.14504c-8.75233,40.8442 -41.40003,72.54068 -71.07836,100.58668c-4.48065,-5.55963 -9.68976,-12.67924 -11.48461,-15.12676c-5.98792,-8.16534 -14.19904,-17.116 -15.93321,-27.52099c-5.61644,-33.69865 5.52118,-71.0087 8.69084,-104.29008c1.06648,-11.19805 6.14308,-47.34273 16.59334,-63.06842z');
  584. });
  585. test('#1054', function() {
  586. var p1 = new Path({
  587. segments: [
  588. [310, 170],
  589. [200, 170],
  590. [200, 350],
  591. [190, 350],
  592. [190, 160],
  593. [320, 160],
  594. [320, 350],
  595. [310, 350]
  596. ],
  597. closed: true
  598. });
  599. var p2 = new Path({
  600. segments: [
  601. [195, 165],
  602. [315, 165],
  603. [315, 350],
  604. [195, 350]
  605. ],
  606. closed: true
  607. });
  608. compareBoolean(function() { return p1.unite(p2); },
  609. 'M190,350l0,-190l130,0l0,190z');
  610. var cp = new CompoundPath();
  611. cp.addChild(new Path({
  612. segments: [
  613. [150, 100],
  614. [150, 150],
  615. [100, 150],
  616. [100, 100]
  617. ],
  618. closed: true
  619. }));
  620. cp.addChild(new Path({
  621. segments: [
  622. [200, 150],
  623. [200, 100],
  624. [220, 100],
  625. [220, 150]
  626. ],
  627. closed: true
  628. }));
  629. var p = new Path({
  630. segments: [
  631. [200, 100],
  632. [200, 150],
  633. [120, 150],
  634. [120, 100]
  635. ],
  636. closed: true
  637. });
  638. compareBoolean(function() { return cp.unite(p); },
  639. 'M100,150l0,-50l120,0l0,50z');
  640. });
  641. test('#1059', function() {
  642. var p1 = new paper.Path({
  643. segments: [
  644. [428.48408954611784, 189.03444010371618, 0, 0, -21.46171522996096, 0],
  645. [369.18465116477694, 213.5984519858447, 16.376007921419017, -16.376007921419017, 0, 0],
  646. [209.1846511647769, 213.5984519858447, 0, 0, 16.376007921419017, -16.376007921419017],
  647. [268.48408954611784, 189.03444010371618, -21.46171522996096, 0, 0, 0]
  648. ],
  649. closed: true
  650. });
  651. var p2 = new paper.Path({
  652. segments: [
  653. [369.18465470031083, 213.59844845031083, 0, 0, -32.75201584283798, 32.752015842838006],
  654. [369.18465470031083, 332.1973252129927, -32.752015842838034, -32.75201584283809, 0, 0],
  655. [209.1846547003108, 332.1973252129927],
  656. [209.1846547003108, 213.59844845031083, -32.75201584283798, 32.752015842838006, 0, 0]
  657. ],
  658. closed: true
  659. });
  660. compareBoolean(function() { return p1.unite(p2); },
  661. 'M428.48409,189.03444c-21.46172,0 -42.92343,8.188 -59.29943,24.56401c-32.75202,32.75202 -32.75202,85.84686 0,118.59888l-160,0c0,0 -32.75202,-85.84686 0,-118.59888l0,0c16.37601,-16.37601 37.83772,-24.56401 59.29944,-24.56401z');
  662. });
  663. test('#1075', function() {
  664. var p1 = new paper.Path({
  665. segments: [
  666. [150, 120],
  667. [150, 85],
  668. [178, 85],
  669. [178, 110],
  670. [315, 110],
  671. [315, 85],
  672. [342, 85],
  673. [342, 120],
  674. ],
  675. closed: true
  676. });
  677. var p2 = new paper.Path({
  678. segments: [
  679. [350, 60],
  680. [350, 125],
  681. [315, 125],
  682. [315, 85],
  683. [178, 85],
  684. [178, 125],
  685. [140, 125],
  686. [140, 60]
  687. ],
  688. closed: true
  689. });
  690. compareBoolean(function() { return p1.unite(p2); },
  691. 'M140,125l0,-65l210,0l0,65l-35,0l0,-5l-137,0l0,5z M315,85l-137,0l0,25l137,0z');
  692. });
  693. test('#1091', function() {
  694. var data = [
  695. 'M91.24228100000002,45.622281000000015v396.89171899999997c0,25.195925999999986 -20.426355000000015,45.622281000000044 -45.62000000000001,45.622281000000044c-25.198207000000007,0 -45.620000000000005,-20.42407400000002 -45.620000000000005,-45.622281000000044v-396.889438c0,-25.19820700000001 20.421792999999997,-45.62228100000001 45.620000000000005,-45.62228100000001c25.193644999999997,0 45.617719000000015,20.424074000000015 45.62000000000001,45.62000000000001z0',
  696. 'M223.67029800000003,488.13628100000005h-178.05029800000003c-25.198207000000004,0 -45.620000000000005,-20.426355000000058 -45.620000000000005,-45.622281000000044v0c0,25.198207000000025 20.421793,45.622281000000044 45.620000000000005,45.622281000000044c25.193645000000004,0 45.620000000000005,-20.426355000000058 45.620000000000005,-45.622281000000044v-45.620000000000005h132.430298v0c-25.193645000000004,0 -45.620000000000005,20.42407400000002 -45.620000000000005,45.620000000000005c0.0022810000000106356,25.198207000000025 20.426355,45.622281000000044 45.620000000000005,45.622281000000044',
  697. 'M225.369643,488.13628100000005h-1.6993449999999939c1.0013589999999795,0 2.0004369999999767,-0.006843000000003485 2.9995150000000024,-0.01824800000002824c-0.4311089999999922,0.011404999999967913 -0.8644990000000234,0.01824800000002824 -1.3001700000000085,0.01824800000002824z',
  698. 'M45.62228100000001,488.13628100000005c-25.198207000000007,0 -45.620000000000005,-20.426355000000058 -45.620000000000005,-45.622281000000044c0,-25.193644999999947 20.421792999999997,-45.620000000000005 45.620000000000005,-45.620000000000005h45.62000000000001v45.620000000000005c-0.0022809999999964248,25.198207000000025 -20.426355000000015,45.622281000000044 -45.62000000000001,45.622281000000044z',
  699. 'M223.67029800000003,91.242281h-132.430298v-45.620000000000005c0,-25.195926000000004 -20.424074000000005,-45.62228100000001 -45.620000000000005,-45.62228100000001h179.667527c0.41742300000001364,0 0.8325649999999882,0.004561999999999999 1.2477069999999912,0.015967000000000002c-0.9511770000000013,-0.011405000000000002 -1.9137589999999989,-0.015967000000000002 -2.867217000000011,-0.015967000000000002c-25.193645000000004,0 -45.620000000000005,20.424074 -45.620000000000005,45.62228100000001c0.0045619999999928496,25.195926 20.42863600000004,45.620000000000005 45.622281000000044,45.620000000000005z',
  700. 'M91.24000000000001,91.242281h-45.620000000000005c-25.198207000000004,0 -45.620000000000005,-20.424074000000005 -45.620000000000005,-45.620000000000005c0,-25.195926000000004 20.421793,-45.62228100000001 45.620000000000005,-45.62228100000001v0c25.193645000000004,0 45.620000000000005,20.424074 45.620000000000005,45.62228100000001z',
  701. 'M226.66981300000003,488.118033c24.59146100000001,-0.6888619999999719 44.31982999999997,-20.841497000000004 44.31982999999997,-45.604033000000015c0,-25.193644999999947 -20.42407400000002,-45.620000000000005 -45.620000000000005,-45.620000000000005h-1.6993449999999939c80.626507,0 139.143281,-64.27173699999997 139.143281,-152.827v0c0,25.198207000000025 20.42407400000002,45.620000000000005 45.622281000000044,45.620000000000005c25.193644999999947,0 45.620000000000005,-20.42179299999998 45.620000000000005,-45.620000000000005c0,138.080335 -97.54012200000005,242.46573800000004 -227.38604700000002,244.05103300000002z',
  702. 'M223.67029800000003,488.13628100000005v0c-25.193645000000004,0 -45.620000000000005,-20.426355000000058 -45.620000000000005,-45.622281000000044c0,-25.193644999999947 20.426355,-45.620000000000005 45.620000000000005,-45.620000000000005v0h1.6993450000000223c25.193645000000004,0 45.620000000000005,20.42407400000002 45.620000000000005,45.620000000000005c0,24.76253600000001 -19.726088000000004,44.91517100000004 -44.319829999999996,45.604033000000015c-0.9967969999999866,0.011404999999967913 -1.9958750000000407,0.01824800000002824 -2.999515000000031,0.01824800000002824z',
  703. 'M454.05586000000005,244.06928100000002c0,-25.198206999999996 -20.42407400000002,-45.617718999999994 -45.620000000000005,-45.617718999999994c-25.198207000000025,0 -45.622281000000044,20.421793000000008 -45.622281000000044,45.617718999999994v0c0,-88.55298200000001 -58.516774,-152.827 -139.143281,-152.827v0h1.617229000000009c25.198206999999996,0 45.62228099999999,-20.424074000000005 45.62228099999999,-45.620000000000005c0,-24.778503 -19.755740999999972,-44.942543 -44.372292999999985,-45.606314000000005c129.918917,1.5123030000000002 227.51834500000004,105.922797 227.51834500000004,244.053314z',
  704. 'M225.28980800000002,91.242281h-1.617229000000009c-25.193645000000004,0 -45.620000000000005,-20.424074000000005 -45.620000000000005,-45.620000000000005c0,-25.195926000000004 20.426355,-45.62228100000001 45.620000000000005,-45.62228100000001c0.9534580000000119,0 1.9160400000000095,0.006843000000000001 2.867217000000011,0.015967000000000002c24.618833000000024,0.6637710000000001 44.37229300000001,20.827811 44.37229300000001,45.60631400000001c0,25.195926 -20.426355,45.620000000000005 -45.622281000000015,45.620000000000005z',
  705. 'M408.43586000000005,289.687c-25.198207000000025,0 -45.622281000000044,-20.42179299999998 -45.622281000000044,-45.620000000000005v0v0c0,-25.198206999999996 20.42407400000002,-45.617718999999994 45.622281000000044,-45.617718999999994c25.193644999999947,0 45.620000000000005,20.421793000000008 45.620000000000005,45.617718999999994v0v0c0,25.198207000000025 -20.42407400000002,45.620000000000005 -45.620000000000005,45.620000000000005z'
  706. ];
  707. var res = new CompoundPath();
  708. for (var i = 0; i < data.length; i++) {
  709. var path = PathItem.create(data[i]);
  710. path.remove();
  711. var prev = res;
  712. res = res.unite(path);
  713. prev.remove();
  714. };
  715. compareBoolean(function() { return res; },
  716. 'M91.24228,396.894h132.42802c-25.19365,0 -45.62,20.42407 -45.62,45.62c0,-25.19364 20.42635,-45.62 45.62,-45.62c80.62581,0 139.14228,-64.27063 139.14328,-152.82472l0,-0.00228c-0.001,-88.55097 -58.51636,-152.82351 -139.141,-152.82472l-0.00228,0c-25.1926,-0.00123 -45.61772,-20.42483 -45.61772,-45.62c0,-25.1955 20.42566,-45.62158 45.61871,-45.62228h1.61624c0.4166,0 0.83093,0.00454 1.24526,0.0159c0.00234,0.00002 0.00467,0.00004 0.00701,0.00007c0.00058,0.00002 0.00116,0.00003 0.00173,0.00005c129.91593,1.5144 227.51285,105.92259 227.51433,244.05012c0,0.00029 0,0.00057 0,0.00086c0,0.00012 0,0.00024 0,0.00036l0,0.00192c-0.00107,138.0792 -97.54084,242.46347 -227.38605,244.04875c-0.43111,0.0114 -0.8645,0.01825 -1.30017,0.01825h-1.69934c-12.59632,0 -24.00091,-5.10618 -32.25663,-13.36168c8.2555,8.25572 19.65987,13.36168 32.25663,13.36168l-178.04574,0c-0.00076,0 -0.00152,0 -0.00228,0c-0.00076,0 -0.00152,0 -0.00228,0h0c-25.19716,-0.00123 -45.61772,-20.42483 -45.61772,-45.62228v-396.88944c0,-25.19821 20.42179,-45.62228 45.62,-45.62228c14.89455,0 28.12203,7.13863 36.44812,18.18156c-8.3258,-11.04405 -21.55413,-18.18384 -36.4504,-18.18384h178.04802c-25.19365,0 -45.62,20.42407 -45.62,45.62228c0.00456,25.19593 20.42864,45.62 45.62228,45.62l-132.42802,0zM45.62,488.13628c-25.19821,0 -45.62,-20.42407 -45.62,-45.62228c0,25.19593 20.42179,45.62228 45.62,45.62228zM226.51682,0.01575c-0.93686,-0.01114 -1.88465,-0.01567 -2.82377,-0.01575c0.93909,0.0001 1.88688,0.0068 2.82377,0.01575zM362.81358,244.06928c0.00123,25.19716 20.42483,45.61772 45.62228,45.61772c-25.19745,0 -45.62105,-20.42056 -45.62228,-45.61772z');
  717. });
  718. test('#1109', function() {
  719. var segments = [
  720. [274.616046379547, 215.30654471841746],
  721. [296.47810618021146, 202.68940186127458],
  722. [297.0266776087829, 160.32607960213838],
  723. [260.5870762798793, 181.99677727655697],
  724. [260.5870762798793, 207.20554804067655],
  725. ];
  726. var p1 = new CompoundPath([
  727. new Path.Rectangle(200, 100, 200, 200),
  728. new Path({ segments: segments, closed: true })
  729. ]);
  730. var p2 = new paper.CompoundPath([
  731. new Path.Rectangle(210, 110, 180, 180),
  732. new Path({ segments: segments, closed: true })
  733. ]);
  734. // Rotate segments to produce different sequence that describes same shape.
  735. segments.push(segments.shift());
  736. var p3 = new paper.CompoundPath([
  737. new Path.Rectangle(210, 110, 180, 180),
  738. new Path({ segments: segments, closed: true })
  739. ]);
  740. // Add a little spike, see #issuecomment-236026445
  741. segments.splice(3, 0,
  742. [260.5870762798793, 200],
  743. [265.5870762798793, 201],
  744. [260.5870762798793, 202]);
  745. var p4 = new paper.CompoundPath([
  746. new Path.Rectangle(210, 110, 180, 180),
  747. new Path({ segments: segments, closed: true })
  748. ]);
  749. compareBoolean(function() { return p1.unite(p2); },
  750. 'M200,300v-200h200v200zM274.61605,215.30654l21.86206,-12.61714l0.54857,-42.36332l-36.4396,21.6707v25.20877z');
  751. compareBoolean(function() { return p1.unite(p3); },
  752. 'M200,300v-200h200v200zM274.61605,215.30654l21.86206,-12.61714l0.54857,-42.36332l-36.4396,21.6707v25.20877z');
  753. compareBoolean(function() { return p1.unite(p4); },
  754. 'M200,300v-200h200v200zM265.58708,201l-5,1v5.20555l14.02897,8.101l21.86206,-12.61714l0.54857,-42.36332l-36.4396,21.6707v18.00322z');
  755. });
  756. test('#1123', function() {
  757. var p1 = new paper.Path({
  758. segments: [
  759. [29.562573408343212, 132.54192488999095, 0, 0, -1.417935581083043, 0.174100597711913],
  760. [2.5662795205536213, 124.83546947214427, 13.887634830511104, -1.705187144644185, 0, 0],
  761. [18.447017946814753, 122.88555997766193, 0, 0, 13.88763483051116, -1.7051871446442135],
  762. [45.443311834604344, 130.5920153955086, -1.417935581083043, 0.17410059771188457, 0, 0]
  763. ],
  764. closed: true
  765. });
  766. var p2 = new paper.Path({
  767. segments: [
  768. [5.684341886080802e-14, 132.07000000000002, 12.910000000000025, 27.075000000000017, 21.125, -21.119999999999976],
  769. [44.59500000000003, 130.54000000000005, 0, 2.3300000000000125, 4.816669792192272, -4.501887430254385],
  770. [56.887403180177614, 116.74936916538223, -3.66267533741933, 4.517228939026069, 0.002528361414420033, 50]
  771. ],
  772. closed: true
  773. });
  774. compareBoolean(function() { return p1.intersect(p2); },
  775. 'M29.56257,132.54192c-1.1465,0.14077 -9.00925,-6.09934 -19.31903,-7.59213c2.44054,-1.04008 4.85728,-1.65337 7.21093,-1.94237c13.88763,-1.70519 25.57836,7.88056 26.99629,7.70646zM44.75533,130.3897c0.31974,0.14538 0.55147,0.21908 0.68798,0.20232l-0.99255,0.12187c0.09534,-0.01171 0.14423,-0.06753 0.14423,-0.17388c0.05357,-0.05007 0.10701,-0.10017 0.16033,-0.1503z');
  776. });
  777. test('#1123', function() {
  778. var p1 = new Path.Rectangle(100, 100, 100, 100);
  779. var p2 = new Path.Rectangle(120, 120, 60, 60);
  780. compareBoolean(function() { return p1.subtract(p2).subtract(p2); },
  781. 'M100,200v-100h100v100zM180,180v-60h-60v60z');
  782. });
  783. test('#1221', function() {
  784. var rect1 = new Path.Rectangle({
  785. point: [100, 100],
  786. size: [200, 200]
  787. });
  788. var circle = new Path.Circle({
  789. center: [100, 100],
  790. radius: 100
  791. });
  792. compareBoolean(function() { return rect1.subtract(circle, { trace: false }); },
  793. 'M200,100h100v200h-200v-100');
  794. compareBoolean(function() { return rect1.subtract(circle, { trace: true }); },
  795. 'M100,300v-100c55.22847,0 100,-44.77153 100,-100h100v200z');
  796. var blob = PathItem.create("M534,273C171.7,111,60.5,117.1,30,158c-40.5,54.3,31.5,210.2,111,222c60.8,9,88-71.9,159-66c81.6,6.8,99.6,118.3,179,128c33.8,4.1,83.1-9.7,150-90")
  797. var rect2 = new Path.Rectangle({
  798. point: [150, 100],
  799. size: [300, 300]
  800. });
  801. compareBoolean(function() { return blob.subtract(rect2, { trace: false }); },
  802. 'M534,273c-29.65069,-13.2581 -57.61955,-25.39031 -84,-36.46967M150,138.13156c-71.67127,-11.53613 -105.25987,0.10217 -120,19.86844c-40.5,54.3 31.5,210.2 111,222c3.08303,0.45637 6.07967,0.68158 9,0.69867M409.85616,400c18.87105,20.95032 39.82014,38.41763 69.14384,42c33.8,4.1 83.1,-9.7 150,-90');
  803. compareBoolean(function() { return blob.subtract(rect2, { trace: true }); },
  804. 'M629,352c-66.9,80.3 -116.2,94.1 -150,90c-29.3237,-3.58237 -50.27279,-21.04968 -69.14384,-42h40.14384v-163.46967c26.38045,11.07937 54.34931,23.21157 84,36.46967zM141,380c-79.5,-11.8 -151.5,-167.7 -111,-222c14.74013,-19.76627 48.32873,-31.40457 120,-19.86844v242.56712c-2.92033,-0.01709 -5.91697,-0.24231 -9,-0.69867z');
  805. var rect3 = new Path.Rectangle({
  806. point: [150, 100],
  807. size: [300, 150]
  808. });
  809. compareBoolean(function() { return blob.subtract(rect3, { trace: false }); },
  810. 'M534,273c-29.65069,-13.2581 -57.61955,-25.39031 -84,-36.46967M150,138.13156c-71.67127,-11.53613 -105.25987,0.10217 -120,19.86844c-40.5,54.3 31.5,210.2 111,222c60.8,9 88,-71.9 159,-66c81.6,6.8 99.6,118.3 179,128c33.8,4.1 83.1,-9.7 150,-90');
  811. compareBoolean(function() { return blob.subtract(rect3, { trace: true }); },
  812. 'M629,352c-66.9,80.3 -116.2,94.1 -150,90c-79.4,-9.7 -97.4,-121.2 -179,-128c-71,-5.9 -98.2,75 -159,66c-79.5,-11.8 -151.5,-167.7 -111,-222c14.74013,-19.76627 48.32873,-31.40457 120,-19.86844v111.86844h300v-13.46967c26.38045,11.07937 54.34931,23.21157 84,36.46967z');
  813. var rect4 = new Path.Rectangle({
  814. point: [200, 200],
  815. size: [400, 200]
  816. });
  817. var line = new Path.Line({
  818. from: [400, 300],
  819. to: [400, 600]
  820. });
  821. var division = line.divide(rect4, { trace: false });
  822. equals(function() { return division.children.length; }, 2);
  823. compareBoolean(function() { return division.children[0]; }, 'M400,300v100');
  824. compareBoolean(function() { return division.children[1]; }, 'M400,400v200');
  825. });
  826. test('#1239 / #1073', function() {
  827. var p1 = new Path([[890.91, 7.52, 0, 0, 85.40999999999997, 94.02], [1024, 351.78, 0, -127.03999999999996, 0, 127.14999999999998], [890.69, 696.28, 85.54999999999995, -94.03999999999996, 0, 0], [843.44, 653.28, 0, 0, 75.20000000000005, -82.66999999999996], [960, 351.78, 0, 111.75, 0, -111.63], [843.65, 50.51999999999998, 75.07000000000005, 82.63999999999999, 0, 0], true]);
  828. var p2 = new Path([[960, 352, -0.05999999999994543, 111.67999999999995, 0, 0], [1024, 352, 0, 0, -0.05999999999994543, 127.07], [890.69, 696.28, 85.5, -93.98000000000002, 0, 0], [843.44, 653.28, 0, 0, 75.14999999999998, -82.61000000000001], true]);
  829. project.activeLayer.scale(0.25);
  830. compareBoolean(function() { return p1.unite(p2); },
  831. 'M923.0175,265.805c21.3525,23.505 33.2725,54.305 33.2725,86.065c0,0.01833 0,0.03667 -0.00001,0.055h0.00001c-0.00005,0.10258 -0.00022,0.20515 -0.00052,0.3077c-0.06338,22.18242 -5.9393,43.88534 -16.78017,62.94682c-4.63138,8.14369 -10.16899,15.8051 -16.54682,22.81548l-11.8125,-10.75c8.97181,-9.86302 16.01692,-21.11585 20.93099,-33.22212c5.34364,-13.16533 8.16725,-27.34044 8.20856,-41.83592c0.0003,-0.10564 0.00044,-0.21129 0.00044,-0.31697c0,-27.9075 -10.32,-54.655 -29.0875,-75.315z');
  832. });
  833. test('#1261', function() {
  834. var p1 = PathItem.create("M933.13,1023.97l-516.19,-171.71l607.1,-101.57z");
  835. var p2 = PathItem.create("M933.13,1023.97l-516.19,-171.71l67.33,-11.27l337.49,112.27c16.7,-50.22 71.03,-77.36 121.34,-60.63l45.23,-135.96l35.71,-5.98z");
  836. compareBoolean(function() { return p1.unite(p2); },
  837. 'M933.13,1023.97l-516.19,-171.71l67.33,-11.27l0.0109,0.00363l539.7591,-90.30363z');
  838. });
  839. test('#1321', function() {
  840. var path = PathItem.create('M24,38l2,1l-2,1l-2,-1z M26,39l2,1l-2,1l-2,-1z M28,40l2,1l-2,1l-2,-1z')
  841. compareBoolean(function() { return path.unite(); },
  842. 'M24,38l6,3…

Large files files are truncated, but you can click here to view the full file