extending paperjs types

340 views
Skip to first unread message

Christopher Best

unread,
Dec 15, 2011, 8:28:28 PM12/15/11
to pap...@googlegroups.com
Is there an official or recommended way to add methods to paperjs objects?
I would like to define something like paper.Path.isInteriorPoint = function(point) { /*...*/ }

Jonathan Puckey

unread,
Dec 17, 2011, 12:22:33 PM12/17/11
to pap...@googlegroups.com
Hi Christopher,

Yes, you can use:

paper.Path.inject({
isInteriorPoint: function(point) {
// function here
}
});

greetings,
Jonathan

Christopher Best

unread,
Dec 17, 2011, 4:35:23 PM12/17/11
to pap...@googlegroups.com
Perfect! thanks

Strae

unread,
Nov 23, 2012, 5:27:36 AM11/23/12
to pap...@googlegroups.com
Hi Jonathan, i did something like:


        paper.Item.inject({
            myRotate: function(angle) {
                this.my_rotation += angle;
                this.rotate(angle);
            },
            my_rotation: 0
        });

in order to track the absolute rotation angle of a item (https://groups.google.com/forum/?fromgroups=#!topic/paperjs/WHMlboZmUQw)
The "problem" is that i have to repeat this inject for all the types (raster, group, etc..)
Giving that all the other items types extend the Item type, is possible to automatically extend the inject to all the sub-types?
Reply all
Reply to author
Forward
0 new messages