在paper.js中修改边界矩形

时间:2019-04-12 14:43:32

标签: paperjs

我正在尝试在paperjs中修改对象的边界矩形。 这是我的代码:

project.currentStyle = {
    fillColor: 'green',
    strokeColor: 'black'
};

var circle = new Path.Circle(new Point(150, 150), 50);

var bounds = circle.bounds;
bounds.insert(2, new Point(bounds.center.x, bounds.top));
bounds.insert(2, new Point(bounds.center.x, bounds.top-25));
bounds.insert(2, new Point(bounds.center.x, bounds.top));

我收到一个错误,指出bounds.insert不是一个函数。 如果无法做到这一点,如何将分段添加到边界矩形?

1 个答案:

答案 0 :(得分:1)

创建矩形Path的{​​{3}}方法和对应于抽象几何形状的Path.Rectangle()之间存在区别:

  

Rectangle指定了一个由其左上角点(x,y),其宽度和高度包围的区域。不应将其与矩形路径混淆,它不是项目。

您可以轻松地从圈子边界创建一个Path

let rectanglePath = new Path.Rectangle(circle.bounds);
rectanglePath.strokeColor = 'red';