paperjs / paper.js

The Swiss Army Knife of Vector Graphics Scripting – Scriptographer ported to JavaScript and the browser, using HTML5 Canvas. Created by @lehni & @puckey
http://paperjs.org
Other
14.45k stars 1.22k forks source link

Make className universal #576

Closed georeith closed 9 years ago

georeith commented 9 years ago

I'm not sure if there is a reason for this, but classes like Curve or Segment don't have the className property.

I would like to see className implemented as a property of all PaperJS classes. Consider my use case where I use the same function to apply a transformation to both a Segment or Path. I can't use the inbuilt transform() function as I need to memorise the origin and Segment doesn't implement a transformation matrix.

I can easily duck type test the Segment by checking for point vs position but it feels wrong when most other classes have the className which makes my code much more readable for someone new to the library.

Is there any reason why this shouldn't be implemented?

lehni commented 9 years ago

At the moment it's only implemented on Item. But you're right, it should exist on all classes. You can always use instanceof for your use-case though.

georeith commented 9 years ago

@lehni Ah okay, I was just checking if there was a reason why not. I'll work on a pull request for this.

lehni commented 9 years ago

Thanks, but no need for a pull request. I know exactly what to do for this to materialize.

georeith commented 9 years ago

@lehni Didn't doubt it, I've noticed in the mean time they still have the private property _class set, so I just put that in a function getClassName() which I will swap out later.