Calculate object.clipTo rectangle path when cropping in Fabric.js

Playing with Fabric.js was fun although one bit I had trouble with was calculating the object.clipTo rectangle path.

The docs say this:

clipTo :function Function that determines clipping of an object (context is passed as a first >argument) Note that context origin is at the object’s center point (not >left/top corner)”

I got turned around with the initial coordinates but working out this derivation helped immensely:

3628bf52-fdb4-427c-81e0-bfdb061820bd2fimg_4481

What do you think?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s