肯定shape1.subtract(shape2).intersects(shape2)應該永遠是假的?
但是在我的 paper.js 代碼中,從其中洗掉了第二條路徑的路徑仍然始終與第二條路徑相交。請問這是為什么?
我正在嘗試遍歷路徑串列并將它們全部減去,以免重疊。但由于這個錯誤,我無法測驗剩余形狀的重疊:(
這是錯誤的演示:
'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 src="https://cdnjs.cloudflare.com/ajax/libs/paper.js/0.12.15/paper-full.js"></script>
<body>
<canvas id="canvasId" width="1500" height="750"></canvas>
</main>
uj5u.com熱心網友回復:
這取決于。
請記住,至少在數學上,這兩個形狀將共享一個邊界。如果您有兩條線遵循完全相同的路徑,它們是否相交?至少在數學上,它們共享無限多的交點。
但最終這取決于 paper.js 如何生成新路徑。這取決于 Paper 中布爾運算的準確程度。這取決于 paper.js 用于測驗交集的演算法。
如果您呼叫subtract()了兩條路徑,那么您可能只需要假設它們在視覺上不會重疊。但是要在代碼方面解決這個問題,您可能必須自己跟蹤已減去哪些路徑。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/486832.html
下一篇:在畫布內使用圖案(不是img)
