/test/tests/Path_Boolean.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
- /*
- * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
- * http://paperjs.org/
- *
- * Copyright (c) 2011 - 2020, Jürg Lehni & Jonathan Puckey
- * http://juerglehni.com/ & https://puckey.studio/
- *
- * Distributed under the MIT license. See LICENSE file for details.
- *
- * All rights reserved.
- */
- QUnit.module('Path Boolean Operations');
- function testOperations(path1, path2, results) {
- compareBoolean(function() { return path1.unite(path2); }, results[0]);
- compareBoolean(function() { return path2.unite(path1); }, results[0]);
- compareBoolean(function() { return path1.subtract(path2); }, results[1]);
- compareBoolean(function() { return path2.subtract(path1); }, results[2]);
- compareBoolean(function() { return path1.intersect(path2); }, results[3]);
- compareBoolean(function() { return path2.intersect(path1); }, results[3]);
- compareBoolean(function() { return path1.exclude(path2); }, results[4]);
- compareBoolean(function() { return path2.exclude(path1); }, results[4]);
- }
- test('Boolean operations without crossings', function() {
- var path1 = new Path.Rectangle({
- point: [0, 0],
- size: [200, 200]
- });
- var path2 = new Path.Rectangle({
- point: [50, 50],
- size: [100, 100]
- });
- var path3 = new Path.Rectangle({
- point: [250, 50],
- size: [100, 100]
- });
- testOperations(path1, path2, [
- 'M0,200v-200h200v200z', // path1.unite(path2);
- 'M0,200v-200h200v200zM150,150v-100h-100v100z', // path1.subtract(path2);
- '', // path2.subtract(path1);
- 'M50,150v-100h100v100z', // path1.intersect(path2);
- 'M0,200v-200h200v200zM150,150v-100h-100v100z' // path1.exclude(path2);
- ]);
- testOperations(path1, path3, [
- 'M0,200v-200h200v200zM250,150v-100h100v100z', // path1.unite(path3);
- 'M0,200v-200h200v200z', // path1.subtract(path3);
- 'M350,150v-100h-100v100z', // path3.subtract(path1);
- '', // path1.intersect(path3);
- 'M0,200v-200h200v200zM250,150v-100h100v100z' // path1.exclude(path3);
- ]);
- });
- test('frame.intersect(rect)', function() {
- var frame = new CompoundPath();
- frame.addChild(new Path.Rectangle(new Point(140, 10), [100, 300]));
- frame.addChild(new Path.Rectangle(new Point(150, 80), [50, 80]));
- var rect = new Path.Rectangle(new Point(50, 50), [100, 150]);
- compareBoolean(function() { return frame.intersect(rect); },
- 'M140,50l10,0l0,150l-10,0z');
- });
- test('PathItem#resolveCrossings()', function() {
- var paths = [
- 'M100,300l0,-50l50,-50l-50,0l150,0l-150,0l50,0l-50,0l100,0l-100,0l0,-100l200,0l0,200z',
- 'M50,300l0,-150l50,25l0,-75l200,0l0,200z M100,200l50,0l-50,-25z',
- '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',
- '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',
- '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'
- ];
- var results = [
- 'M100,300l0,-50l50,-50l-50,0l0,-100l200,0l0,200z',
- 'M50,300l0,-150l50,25l0,-75l200,0l0,200z M100,200l50,0l-50,-25z',
- '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',
- 'M570,290l5.8176,33.58557l-28.17314,-14.439c-14.32289,2.0978 -28.17688,4.12693 -28.17688,4.12693z',
- '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'
- ];
- for (var i = 0; i < paths.length; i++) {
- var path = PathItem.create(paths[i]),
- result = PathItem.create(results[i]);
- path.fillRule = 'evenodd';
- compareBoolean(path.resolveCrossings(), result, 'path.resolveCrossings(); // Test ' + (i + 1));
- }
- });
- test('#541', function() {
- var shape0 = new Path.Rectangle({
- insert: false,
- point: [304, 226],
- size: [328, 328]
- });
- var shape1 = new Path({
- insert: false,
- segments: [
- [213.5, 239],
- [476.5, 279],
- [716, 233.5],
- [469, 74]
- ],
- closed: true
- });
- var res1 = shape0.exclude(shape1);
- var shape2 = new Path.Rectangle({
- insert: false,
- point: [174, 128],
- size: [309, 251]
- });
- var res2 = res1.exclude(shape2);
- // shape3
- var shape3 = new Path.Rectangle({
- insert: false,
- point: [318, 148],
- size: [302, 302]
- });
- // exclude res2 & shape3
- compareBoolean(function() { return res2.exclude(shape3); },
- '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');
- });
- test('#609', function() {
- // path1 and path2 are half circles, applying unite should result in a circle
- var path1 = new Path();
- path1.moveTo(new Point(100, 100));
- path1.arcTo(new Point(100, 200));
- path1.closePath();
- var path2 = new Path();
- path2.moveTo(new Point(100, 200));
- path2.arcTo(new Point(100, 100));
- path2.closePath();
- compareBoolean(function() { return path1.unite(path2); },
- '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');
- });
- test('#610', function() {
- var square = new Path.Rectangle({
- position: [140, 0],
- size: 300
- });
- // Make a ring using subtraction of two circles:
- var inner = new Path.Circle({
- center: [0, 0],
- radius: 100
- });
- var outer = new Path.Circle({
- center: [0, 0],
- radius: 132
- });
- var ring = outer.subtract(inner);
- compareBoolean(function() { return ring.subtract(square); },
- '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');
- });
- test('#719', function() {
- var radius = 50;
- var circle = new Path.Circle([0, 0], radius);
- var arc = new Path.Arc([0, -radius], [radius, 0], [0, radius]);
- arc.closed = true;
- arc.pivot = arc.bounds.leftCenter;
- var result = circle.subtract(arc);
- // Rotate the arc by 180 to receive the expected shape to compare against
- var expected = arc.rotate(180);
- compareBoolean(result, expected);
- });
- test('#757 (path1.intersect(pat2, { trace: false }))', function() {
- var rect = new Path.Rectangle({
- from: [100, 250],
- to: [350, 350]
- });
- var line = new Path({
- segments: [
- [100, 200],
- [150, 400],
- [200, 200],
- [250, 400],
- [300, 200],
- [350, 400]
- ]
- });
- var res = line.intersect(rect, { trace: false });
- var children = res.removeChildren();
- var first = children[0];
- for (var i = 1; i < children.length; i++) {
- first.join(children[i]);
- }
- first.insertAbove(res);
- res.remove();
- res = first;
- compareBoolean(res,
- 'M112.5,250l25,100l25,0l25,-100l25,0l25,100l25,0l25,-100l25,0l25,100');
- });
- test('#784', function() {
- 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');
- 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');
- compareBoolean(function() { return path1.unite(path2); },
- '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');
- 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');
- 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');
- compareBoolean(function() { return path1.unite(path2); },
- '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');
- });
- test('#784#issuecomment-144653463', function() {
- var path1 = new Path({
- segments: [
- [400, 300],
- [396.4240965757225, 386.760212367686],
- [363.8902430603039, 336.3464406833805]
- ],
- closed: true
- });
- var path2 = new Path({
- segments: [
- [380.15716053320796, 361.5533174872367],
- [368.9579765078272, 389.3845783631412],
- [352.11749924000907, 372.22000125020173]
- ],
- closed: true
- });
- var path3 = new Path({
- segments: [
- [381.9248139754118, 360.88087710036456],
- [352.11749931845384, 372.22000145641056],
- [353.8723170322086, 346.9400510828104]
- ],
- closed: true
- });
- compareBoolean(function() { return path1.unite(path2).unite(path3); },
- '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');
- });
- test('#784#issuecomment-144993215', function() {
- var path1 = new Path({
- segments: [
- [428.65986693122585, 123.24312916360232],
- [448.9732353341095, 290.23336023178985, -1.297313778199964, -0.24666929481787747, -0.06896642337790126, -0.004714867204086204],
- [448.9732339473677, 290.2333601369859, 0.22704183013848933, 0.04316939284507271, 0.24127512029406262, 0.016494695478172616],
- [375.34013306877415, 150.7568708363977]
- ],
- closed: true
- });
- compareBoolean(function() { return path1.unite(); },
- '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',
- null, { tolerance: 1e-3 });
- });
- test('#784#issuecomment-168605018', function() {
- var path1 = new CompoundPath();
- path1.setChildren([
- new Path({
- segments: [
- [401.77542835664826, 286.9803609495646],
- [410.6261525310172, 207.97354059345616],
- [460.3783408790767, 174.43669899386418],
- ],
- closed: true
- }), new Path({
- segments: [
- [410.6261524612045, 207.9735406405153],
- [410.6261525310172, 207.97354059345614, -0.0005059167983745283, -0.0007686158121771314]
- ],
- closed: true
- })
- ], true);
- var path2 = new Path({
- segments: [
- [410.6261524612047, 207.97354064051552, 0, 0, 0.19904749518872222, 0.2952886437272184],
- [409.163896522797, 207.2586618457598, 1.6828473498011363, 0.6114523237241087],
- [460.3783408790765, 174.43669899386396]
- ],
- closed: true
- });
- compareBoolean(function() { return path1.unite(path2); },
- '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');
- });
- test('#854', function() {
- var p = new Path({
- segments:[
- [110, 60],
- [99.09349390368303, 54.102707245527334, 0, 0, 0.2109804080034046, -0.3885775729842338],
- [99.76298270272372, 52.95998195277986, -0.2353176636361775, 0.3732505490504639,],
- [107.23497309089953, 78.84996109436266, 0, 0, -9.106249727572695, -5.544212301393825],
- [100.0593186152821, 52.32387941069251, -5.08710486250942, 9.369281629969153, 0, 0],
- ],
- closed:true
- });
- p.translate(100, 100);
- p.scale(4);
- compareBoolean(function() {
- p.windingRule = 'evenodd';
- return p.unite();
- },
- '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');
- compareBoolean(function() {
- p.windingRule = 'nonzero';
- return p.unite();
- },
- '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');
- });
- test('#859', function() {
- var p1 = new Path({
- segments: [
- [230, 360],
- [326.04999999999995, 361.95, 0, 0, 7.100000000000023, 5.300000000000011],
- [347.74999999999994, 377.3, -7.300000000000011, -5, 0, 0],
- [260, 400],
- ],
- closed: true
- });
- var p2 = new Path({
- segments: [
- [329.8373529833907, 360.99927475751736, 0, 0, -0.5084518552435497, 1.7136677994218417],
- [327.9816245617005, 366.0401044369074, 0.7293957729680756, -1.645975116174725, 0, 0],
- [300, 380]
- ],
- closed: true
- });
- compareBoolean(function() { return p1.subtract(p2); },
- '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');
- });
- test('#839', function() {
- var p1 = new Path({
- segments: [
- [522, 352],
- [500, 400],
- [480, 400],
- [448, 448],
- [100, 448],
- [100, 352]
- ],
- closed: true
- });
- var p2 = new Path.Rectangle(250, 300, 100, 200);
- compareBoolean(function() { return p1.subtract(p2); },
- 'M522,352l-22,48l-20,0l-32,48l-98,0l0,-96z M250,448l-150,0l0,-96l150,0z');
- });
- test('#865', function() {
- function executeTest(offset) {
- var p1 = new Path({
- segments:[
- [300, 100],
- [300, 350],
- [256.00000000000006, 350],
- [256.00000000000006, 250],
- [230, 224],
- [256.00000000000006, 200],
- [256.00000000000006, 100]
- ],
- closed:true
- });
- var p2 = new Path({
- segments:[
- [256, 150],
- [256, 300],
- [200, 300],
- [200, 150]
- ],
- closed:true
- });
- p1.position = p1.position.add([offset, 0]);
- compareBoolean(p1.subtract(p2),
- 'M300,100l0,250l-44,0l0,-250z',
- 'p1.subtract(p2); // with offset = ' + offset);
- }
- // Attempt different x-offsets since that produced different version of the
- // issue:
- executeTest(0);
- executeTest(-0.0000001);
- executeTest( 0.0000001);
- executeTest(-0.000000001);
- executeTest( 0.000000001);
- });
- test('#870', function() {
- var path1 = new Path.Rectangle({
- point: [50, 50],
- size: [150, 50]
- });
- var path2 = new Path.Rectangle({
- point: [70, 50],
- size: [150, 50]
- });
- compareBoolean(function() { return path1.intersect(path2); },
- 'M70,50l130,0l0,50l-130,0z');
- var path1 = new Path.Rectangle({
- point: [50, 150],
- size: [50, 100]
- });
- var path2 = new Path.Rectangle({
- point: [50, 175],
- size: [50, 100]
- });
- compareBoolean(function() { return path1.intersect(path2); },
- 'M50,250l0,-75l50,0l0,75z');
- });
- test('#875', function() {
- var p1 = new Path({
- segments: [
- [158.7, 389.3, 0, 0, -4.95, 4.95],
- [158.7, 407.2, -4.95, -4.95, 4.95, 4.95],
- [176.6, 407.2, -4.95, 4.95, 4.95, -4.95],
- [176.6, 389.3, 4.95, 4.95, -4.95, -4.95],
- [158.7, 389.3, 4.95, -4.95, 0, 0]
- ],
- closed: true
- });
- var p2 = new Path.Circle(260, 320, 100);
- compareBoolean(function() { return p1.subtract(p2); },
- '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');
- });
- test('#877', function() {
- var cp = new CompoundPath({
- children: [
- new Path.Circle(100, 60, 50),
- new Path.Circle(100, 60, 30),
- new Path({
- segments: [
- [120, 140],
- [150, 140],
- [150, 190],
- [120, 190]
- ],
- closed: true
- }),
- ],
- fillRule: 'evenodd'
- });
- var p = new Path({
- segments: [
- [135, 200],
- [135, 120],
- [170, 120],
- [170, 200]
- ],
- closed: true
- });
- compareBoolean(function() { return cp.subtract(p); },
- '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');
- });
- test('#878', function() {
- var p1 = new Path({ segments:[ [431.90000000000003, 479.99999999999994], [128.00000000000003, 370], [80.00000000000003, 479.99999999999994], ], closed:true });
- var p2 = new Path({ segments:[ [400, 480, 10, 0, 0, 0], [140, 480, 0, 0, -10, 0], [300, 300]], closed:true });
- compareBoolean(function() { return p1.unite(p2); },
- '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');
- compareBoolean(function() { return p1.subtract(p2); },
- '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');
- });
- test('#885', function() {
- var p1 = new Path.Rectangle(100, 100, 100, 100);
- var p2 = p1.clone();
- var empty = new Path();
- compareBoolean(function() { return p1.unite(p2); }, p1);
- compareBoolean(function() { return p1.intersect(p2); }, p1);
- compareBoolean(function() { return p1.subtract(p2); }, empty);
- compareBoolean(function() { return p1.exclude(p2); }, empty);
- });
- test('#889', function() {
- var cp = new CompoundPath([
- new Path({ segments: [ [340.26, 358.4], [576, 396.8], [345.78, 396.8] ], closed: true }),
- new Path({ segments: [ [691.2, 685.76], [672, 550.4, 0, 0, 10, 0], [729.6, 608, 0, -20, 0, 0] ], closed: true })
- ]);
- var p = new Path({ segments: [ [739, 418], [637, 704], [205, 704], [204.30709922574619, 356.553500194953] ], closed: true });
- compareBoolean(function() { return cp.subtract(p); },
- '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');
- });
- test('#890', function() {
- var cp = new CompoundPath([
- new Path({ segments: [ [676, 396.8], [445.78, 396.8], [426, 260] ], closed: true }),
- new Path({ segments: [ [672, 550.4, 0, 0, 31.74000000000001, 0], [633.5999999999999, 732.8, 0, 26.519999999999982] ], closed: true })
- ]);
- 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 });
- compareBoolean(function() { return cp.subtract(p); },
- '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');
- var cp = new CompoundPath([
- new Path({segments:[[576, 396.8], [345.78, 396.8], [249.6, 243.20000000000002]], closed:true}),
- new Path({segments:[[624.84, 550.46], [672, 550.4], [729.6, 608]], closed:true})
- ]);
- 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});
- compareBoolean(function() { return cp.subtract(p); },
- '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');
- });
- test('#899', function() {
- 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});
- compareBoolean(function() { return path.unite(); },
- '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');
- });
- test('#936', function() {
- var p1 = new Path({
- segments:[
- [437.02857142857147, 121.64285714285714],
- [390.3571428571429, 74.97142857142856],
- [390.3571428571429, 437.02857142857147],
- [437.02857142857147, 390.3571428571429],
- [74.97142857142862, 390.3571428571429],
- [121.6428571428572, 437.02857142857147],
- [121.64285714285714, 74.97142857142858],
- [74.97142857142859, 121.64285714285714]
- ],
- closed:true
- });
- compareBoolean(function() { return p1.unite(); },
- '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');
- var p2 = new Path({
- segments:[
- [384.0884708724184, 194.49096034834812, -66.07592496222571, -39.741588860234515],
- [364.2895784370851, 164.00333956484477, 0, 0, 9.430248075502885, 76.52772155228502],
- [317.5090396516519, 384.0884708724184, 39.74158886023454, -66.07592496222564],
- [347.9966604351552, 364.2895784370851, 0, 0, -76.52772155228439, 9.430248075502845],
- [127.91152912758163, 317.50903965165196, 66.0759249622259, 39.74158886023463],
- [147.71042156291495, 347.9966604351553, 0, 0, -9.43024807550288, -76.52772155228509],
- [194.49096034834812, 127.91152912758156, -39.74158886023451, 66.07592496222576],
- [164.00333956484474, 147.7104215629149, 0, 0, 76.52772155228499, -9.430248075502845]
- ],
- closed:true
- });
- compareBoolean(function() { return p2.unite(); },
- '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');
- });
- test('#923', function() {
- var p1 = new Path.Circle({center: [100, 100], radius: 20});
- var p2 = new Path.Circle({center: [150, 100], radius: 20});
- var cp = new CompoundPath([p1, p2]);
- var p3 = new Path.Circle({center: [100, 100], radius: 20});
- cp.strokeColor = 'red';
- p3.strokeColor = 'green';
- compareBoolean(function() { return cp.unite(p3); },
- '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');
- });
- test('#958', function() {
- var p1 = new Path.Rectangle(100, 200, 200, 20);
- var p2 = new Path.Rectangle(140, 100, 20, 20);
- var cp = new CompoundPath({children: [p1, p2]});
- var bounds = new Path.Rectangle(cp.bounds);
- compareBoolean(function() { return bounds.intersect(cp); },
- 'M100,220l0,-20l200,0l0,20z M140,100l20,0l0,20l-20,0z');
- });
- test('#968', function() {
- var p1 = new paper.Path({
- segments: [
- [352, 280, 0, -26.5, 0, 0],
- [352, 356, 0, 0, 0, 2.1999999999999886],
- [348, 360, 2.1999999999999886, 0, -72, 0]
- ],
- closed: true
- });
- var p2 = new paper.Path({
- segments: [
- [352, 344],
- [352, 356, 0, 0, 0, 2.1999999999999886],
- [348, 360, 2.1999999999999886, 0, 0, 0],
- [232, 360, 0, 0, -2.1999999999999886, 0]
- ],
- closed: true
- });
- compareBoolean(function() { return p1.subtract(p2); },
- 'M352,280l0,64c0,0 -13.69105,1.79261 -31.82528,4.17778c-15.66463,-26.96617 31.82528,-89.12564 31.82528,-68.17778z');
- });
- test('#973', function() {
- var path = new Path.Ellipse(100, 100, 150, 110);
- path.segments[1].point.y += 60;
- path.segments[3].point.y -= 60;
- var resolved = path.resolveCrossings();
- var orientation = resolved.children.map(function(child) {
- return child.isClockwise();
- });
- equals(orientation, [true, false, true],
- 'children orientation after calling path.resolveCrossings()');
- });
- test('#1036', function() {
- var line1 = new Path([
- [[305.10732,101.34786],[0,0],[62.9214,0]],
- [[499.20274,169.42611],[-29.38716,-68.57004],[5.78922,13.50818]],
- [[497.75426,221.57115],[2.90601,-13.5614],[-9.75434,45.52027]],
- [[416.63976,331.65512],[31.9259,-30.40562],[-21.77284,20.73604]],
- [[350.00999,391.04252],[23.92578,-18.22917],[-23.33885,17.78198]],
- [[277.58633,431.59977],[27.45996,-10.67887],[-1.72805,0.67202]],
- [[251.51381,437.39367],[0,5.7145],[0,0]]
- ]);
- var line2 = new Path([
- [[547.00236,88.31161],[0,0],[-1.36563,0]],
- [[544.10541,85.41466],[1.29555,0.43185],[-9.83725,-3.27908]],
- [[509.34205,82.51771],[10.32634,-1.29079],[-10.20055,1.27507]],
- [[444.16075,97.00245],[7.10741,-4.06138],[-4.93514,2.82008]],
- [[431.12449,105.69328],[4.27047,-2.13524],[-14.94798,7.47399]],
- [[407.94892,175.22],[1.27008,-13.33587],[-3.16966,33.28138]],
- [[399.25808,279.51008],[-5.61644,-33.69865],[1.73417,10.40499]],
- [[415.19129,307.03107],[-5.98792,-8.16534],[2.74694,3.74583]],
- [[432.57297,328.75817],[-3.89061,-3.29206],[2.9716,2.51443]],
- [[442.71228,334.55206],[-3.01275,-2.46498],[2.39275,1.95771]],
- [[448.50617,341.79443],[-2.37502,-1.97918],[39.75954,33.13295]],
- [[578.86877,378.00626],[-51.65429,10.33086],[11.28627,-2.25725]],
- [[612.18365,366.41848],[-10.6547,4.26188],[3.10697,-1.24279]],
- [[617.97755,362.07306],[-3.19904,0],[0,0]]
- ]);
- compareBoolean(function() { return line1.intersect(line2); },
- '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');
- });
- test('#1054', function() {
- var p1 = new Path({
- segments: [
- [310, 170],
- [200, 170],
- [200, 350],
- [190, 350],
- [190, 160],
- [320, 160],
- [320, 350],
- [310, 350]
- ],
- closed: true
- });
- var p2 = new Path({
- segments: [
- [195, 165],
- [315, 165],
- [315, 350],
- [195, 350]
- ],
- closed: true
- });
- compareBoolean(function() { return p1.unite(p2); },
- 'M190,350l0,-190l130,0l0,190z');
- var cp = new CompoundPath();
- cp.addChild(new Path({
- segments: [
- [150, 100],
- [150, 150],
- [100, 150],
- [100, 100]
- ],
- closed: true
- }));
- cp.addChild(new Path({
- segments: [
- [200, 150],
- [200, 100],
- [220, 100],
- [220, 150]
- ],
- closed: true
- }));
- var p = new Path({
- segments: [
- [200, 100],
- [200, 150],
- [120, 150],
- [120, 100]
- ],
- closed: true
- });
- compareBoolean(function() { return cp.unite(p); },
- 'M100,150l0,-50l120,0l0,50z');
- });
- test('#1059', function() {
- var p1 = new paper.Path({
- segments: [
- [428.48408954611784, 189.03444010371618, 0, 0, -21.46171522996096, 0],
- [369.18465116477694, 213.5984519858447, 16.376007921419017, -16.376007921419017, 0, 0],
- [209.1846511647769, 213.5984519858447, 0, 0, 16.376007921419017, -16.376007921419017],
- [268.48408954611784, 189.03444010371618, -21.46171522996096, 0, 0, 0]
- ],
- closed: true
- });
- var p2 = new paper.Path({
- segments: [
- [369.18465470031083, 213.59844845031083, 0, 0, -32.75201584283798, 32.752015842838006],
- [369.18465470031083, 332.1973252129927, -32.752015842838034, -32.75201584283809, 0, 0],
- [209.1846547003108, 332.1973252129927],
- [209.1846547003108, 213.59844845031083, -32.75201584283798, 32.752015842838006, 0, 0]
- ],
- closed: true
- });
- compareBoolean(function() { return p1.unite(p2); },
- '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');
- });
- test('#1075', function() {
- var p1 = new paper.Path({
- segments: [
- [150, 120],
- [150, 85],
- [178, 85],
- [178, 110],
- [315, 110],
- [315, 85],
- [342, 85],
- [342, 120],
- ],
- closed: true
- });
- var p2 = new paper.Path({
- segments: [
- [350, 60],
- [350, 125],
- [315, 125],
- [315, 85],
- [178, 85],
- [178, 125],
- [140, 125],
- [140, 60]
- ],
- closed: true
- });
- compareBoolean(function() { return p1.unite(p2); },
- 'M140,125l0,-65l210,0l0,65l-35,0l0,-5l-137,0l0,5z M315,85l-137,0l0,25l137,0z');
- });
- test('#1091', function() {
- var data = [
- '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',
- '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',
- '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',
- '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',
- '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',
- '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',
- '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',
- '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',
- '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',
- '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',
- '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'
- ];
- var res = new CompoundPath();
- for (var i = 0; i < data.length; i++) {
- var path = PathItem.create(data[i]);
- path.remove();
- var prev = res;
- res = res.unite(path);
- prev.remove();
- };
- compareBoolean(function() { return res; },
- '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');
- });
- test('#1109', function() {
- var segments = [
- [274.616046379547, 215.30654471841746],
- [296.47810618021146, 202.68940186127458],
- [297.0266776087829, 160.32607960213838],
- [260.5870762798793, 181.99677727655697],
- [260.5870762798793, 207.20554804067655],
- ];
- var p1 = new CompoundPath([
- new Path.Rectangle(200, 100, 200, 200),
- new Path({ segments: segments, closed: true })
- ]);
- var p2 = new paper.CompoundPath([
- new Path.Rectangle(210, 110, 180, 180),
- new Path({ segments: segments, closed: true })
- ]);
- // Rotate segments to produce different sequence that describes same shape.
- segments.push(segments.shift());
- var p3 = new paper.CompoundPath([
- new Path.Rectangle(210, 110, 180, 180),
- new Path({ segments: segments, closed: true })
- ]);
- // Add a little spike, see #issuecomment-236026445
- segments.splice(3, 0,
- [260.5870762798793, 200],
- [265.5870762798793, 201],
- [260.5870762798793, 202]);
- var p4 = new paper.CompoundPath([
- new Path.Rectangle(210, 110, 180, 180),
- new Path({ segments: segments, closed: true })
- ]);
- compareBoolean(function() { return p1.unite(p2); },
- 'M200,300v-200h200v200zM274.61605,215.30654l21.86206,-12.61714l0.54857,-42.36332l-36.4396,21.6707v25.20877z');
- compareBoolean(function() { return p1.unite(p3); },
- 'M200,300v-200h200v200zM274.61605,215.30654l21.86206,-12.61714l0.54857,-42.36332l-36.4396,21.6707v25.20877z');
- compareBoolean(function() { return p1.unite(p4); },
- 'M200,300v-200h200v200zM265.58708,201l-5,1v5.20555l14.02897,8.101l21.86206,-12.61714l0.54857,-42.36332l-36.4396,21.6707v18.00322z');
- });
- test('#1123', function() {
- var p1 = new paper.Path({
- segments: [
- [29.562573408343212, 132.54192488999095, 0, 0, -1.417935581083043, 0.174100597711913],
- [2.5662795205536213, 124.83546947214427, 13.887634830511104, -1.705187144644185, 0, 0],
- [18.447017946814753, 122.88555997766193, 0, 0, 13.88763483051116, -1.7051871446442135],
- [45.443311834604344, 130.5920153955086, -1.417935581083043, 0.17410059771188457, 0, 0]
- ],
- closed: true
- });
- var p2 = new paper.Path({
- segments: [
- [5.684341886080802e-14, 132.07000000000002, 12.910000000000025, 27.075000000000017, 21.125, -21.119999999999976],
- [44.59500000000003, 130.54000000000005, 0, 2.3300000000000125, 4.816669792192272, -4.501887430254385],
- [56.887403180177614, 116.74936916538223, -3.66267533741933, 4.517228939026069, 0.002528361414420033, 50]
- ],
- closed: true
- });
- compareBoolean(function() { return p1.intersect(p2); },
- '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');
- });
- test('#1123', function() {
- var p1 = new Path.Rectangle(100, 100, 100, 100);
- var p2 = new Path.Rectangle(120, 120, 60, 60);
- compareBoolean(function() { return p1.subtract(p2).subtract(p2); },
- 'M100,200v-100h100v100zM180,180v-60h-60v60z');
- });
- test('#1221', function() {
- var rect1 = new Path.Rectangle({
- point: [100, 100],
- size: [200, 200]
- });
- var circle = new Path.Circle({
- center: [100, 100],
- radius: 100
- });
- compareBoolean(function() { return rect1.subtract(circle, { trace: false }); },
- 'M200,100h100v200h-200v-100');
- compareBoolean(function() { return rect1.subtract(circle, { trace: true }); },
- 'M100,300v-100c55.22847,0 100,-44.77153 100,-100h100v200z');
- 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")
- var rect2 = new Path.Rectangle({
- point: [150, 100],
- size: [300, 300]
- });
- compareBoolean(function() { return blob.subtract(rect2, { trace: false }); },
- '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');
- compareBoolean(function() { return blob.subtract(rect2, { trace: true }); },
- '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');
- var rect3 = new Path.Rectangle({
- point: [150, 100],
- size: [300, 150]
- });
- compareBoolean(function() { return blob.subtract(rect3, { trace: false }); },
- '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');
- compareBoolean(function() { return blob.subtract(rect3, { trace: true }); },
- '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');
- var rect4 = new Path.Rectangle({
- point: [200, 200],
- size: [400, 200]
- });
- var line = new Path.Line({
- from: [400, 300],
- to: [400, 600]
- });
- var division = line.divide(rect4, { trace: false });
- equals(function() { return division.children.length; }, 2);
- compareBoolean(function() { return division.children[0]; }, 'M400,300v100');
- compareBoolean(function() { return division.children[1]; }, 'M400,400v200');
- });
- test('#1239 / #1073', function() {
- 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]);
- 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]);
- project.activeLayer.scale(0.25);
- compareBoolean(function() { return p1.unite(p2); },
- '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');
- });
- test('#1261', function() {
- var p1 = PathItem.create("M933.13,1023.97l-516.19,-171.71l607.1,-101.57z");
- 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");
- compareBoolean(function() { return p1.unite(p2); },
- 'M933.13,1023.97l-516.19,-171.71l67.33,-11.27l0.0109,0.00363l539.7591,-90.30363z');
- });
- test('#1321', function() {
- 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')
- compareBoolean(function() { return path.unite(); },
- 'M24,38l6,3…
Large files files are truncated, but you can click here to view the full file