Hi. Seems like a noob question, but didn't find a way yet how it works to add custom properties without touching the core code.
I've read that adding custom methods to class objects is done for example with "paper.PathItem.inject({myMethod:function(){...}});", using it by calling "paper.pathItem[0].myMethod()".
Here's what I'm trying to do:
I want to extend paper.Curve with the property "bounds", so whenever I call myPath.curves[0].bounds I get a rectangle object describing the boundaries of the specified straight line segment in myPath. As Method, it would look like this:
"paper.Curve.inject({bounds:function(){
var l,t,w,h,c=this;
l=Math.min(c.point1.x,c.point2.x);
t=Math.min(c.point1.y,c.point2.y);
w=(l==c.point1.x)?(c.point2.x-c.point1.x):(c.point1.x-c.point2.x);
h=(t==c.point1.y)?(c.point2.y-c.point1.y):(c.point1.y-c.point2.y);
return new Rectangle(l,t,w,h);
}});"
How do I code that to get "bounds" as property (object) of paper.Curve? I also tried paper.Curve.define() and wrote the "get" function as the descriptor (whereas I don't need the setter, cause resulting rectangle should be calculated instead of changed manually), but couldn't get anything else than 'undefined' as returned statement...
Many thanks for help!