Why does the subtraction of two shapes still intersect?

73 views
Skip to first unread message

Richard JE Cooke

unread,
May 31, 2022, 4:46:54 PM5/31/22
to Paper.js
Surely shape1.subtract(shape2).intersects(shape2) should always be false?

Why is this happening please?


----

Here's some test code if you want to see:

<!DOCTYPE html>
<html lang="">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
        body { padding: 0; margin: 0; background-color: black; }
        canvas { background-color: darkgrey; }
    </style>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/paper.js/0.12.15/paper-full.js" integrity="sha512-XV5MGZ7Tv+G60rzU8P7tPUlaf0yz7SJ/uI9CLAwyLcZKl9kzxJQFs3nsBNZVNVAwNOkBLqrzMvjGMEycDccqiA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
    <script>


'use strict';
window.onload = setup;
let p = null; // an alias for the paper.js global object.
let canvasWidth, canvasHeight = null;
let em = null; // relative width unit the drawing is based on

function setup()
{
    p = paper;
    const canvas = document.getElementById('canvasId');
    canvasWidth = parseInt(document.getElementById('canvasId').attributes.width.nodeValue);
    canvasHeight = parseInt(document.getElementById('canvasId').attributes.height.nodeValue);
    em = canvasWidth / 100;
    p.setup(canvas);
    drawPicture();
}

function drawPicture()
{
    const shape1 = p.Path.Circle(new p.Point(200, 200), 2*em);
    shape1.fillColor = hsb(50, 0.5, 0.5, 1);
    shape1.strokeColor = hsb(0, 0, 0, 1);

    const shape2 = p.Path.Circle(new p.Point(230, 200), 2*em);
    shape2.fillColor = hsb(100, 0.5, 0.5, 1);
    shape2.strokeColor = hsb(0, 0, 0, 1);

    console.log(`shape1 intersects shape1 ?  ${shape1.intersects(shape1)}`);
    console.log(`shape1 intersects shape2 ?  ${shape1.intersects(shape2)}`);
    console.log(`(shape1 less shape2) intersects shape2 ?  ${shape1.subtract(shape2).intersects(shape2)}`);
}

function hsb(hue = 360, saturation = 1, brightness = 0.5, alpha = 1)
{
    return new p.Color({hue: hue, saturation: saturation, brightness: brightness, alpha: alpha});
}


    </script>
</head>

<body>
    <canvas id="canvasId" width="1500" height="750"></canvas>
</main>
</body>
</html>

Richard JE Cooke

unread,
Jun 3, 2022, 2:36:39 PM6/3/22
to Paper.js
Reply all
Reply to author
Forward
0 new messages