Vector meets Point?

0 views
Skip to first unread message

jpjj05...@yahoo.com

unread,
May 8, 2008, 1:23:32 PM5/8/08
to APE General
New to the forum, so I don't know if this has been discussed.
I find it valuable to have the Vector methods work with
flash.geom.Point objects.
(so I can use localToGlobal, polar, etc)

I don't see why the classes are separate
(other than AS3 makes it difficult to add methods to classes like
Point)

I have taken two approaches on this:
1) change Vector to extend Point, and allow Point for the input args.
[this is a half-fix; requires copying Point to Vector if all you
have is a Point]
2) convert the Vector operations to static methods, that work on Point
objects
[this is very general, but like with Math, you need to say
p3=Vec.plus(p1,p2)]

The other suggestion is to reduce the number of methods ( eg "plus"
and "plusEquals")
and add an option last arg for the return value.
so for the Vector methods:
function plus(p1:Point, rv=new Vector(0,0)):Vector {... ;
return rv; }

or for the static Vec methods:
function plus(p1:Point, p2:Point, rv=new Point(0,0)):Point
{...;return rv;}

In either case, if you want to manage your own creation/allocation of
the return object, you just supply the pre-created object; the methods
*should* be implemented to allow the rv to be the same as the other
args without failure. (that is, extract everything you need from the
input args before overwriting the fields of the rv object)
[btw, I'm trying to get adobe to follow this pattern for its Point
functions as well; it is annoying that localToGlobal, polar, etc
*force* an memory allocation]

Is there any interest in extending APE in this direction?

Reply all
Reply to author
Forward
0 new messages