Re: Retrieving transformed points of BezierPath
Re: Retrieving transformed points of BezierPath
- Subject: Re: Retrieving transformed points of BezierPath
- From: "Dennis C. De Mars" <email@hidden>
- Date: Sat, 02 Jun 2001 20:03:05 -0700
on 6/2/01 6:29 PM, Youngjin Kim at email@hidden wrote:
>
How can I retrieve transformed points of NSBezierPath?
>
My bezier path was constructed with moveToPoint()/lineToPoint() methods
>
and transformed using transformUsingAffineTransform() and my custom view
>
reflects this change correctly. but when I retrieve individual points
>
using elementAtIndex(), it retrieves points in untransformed
>
coordinates. It seems that NSBezierPath has it's transform object
>
internally and using it when displaying. but I don't want to keep track
>
of transform objects of each paths unnecessarily. How do I retrieve
>
transform object or transformed points of bezier path?
>
>
>
NSPoint *pts = malloc(sizeof(NSPoint));
>
NSBezierPath *path;
>
NSAffineTransform* transform = (NSAffineTransform transform);
>
...
>
transform = [NSAffineTransform transform];
>
[transform translateXBy:dx yBy:dy];
>
[path transformUsingAffineTransform:transform];
>
...
>
for (j=0;j<[path elementCount]-1;j++) {
>
[path elementAtIndex:j associatedPoints:pts];
>
*((NSPoint*)(path_pts+j)) = *pts;
>
printf("x:%f,",pts->x);
>
printf("y:%f\n",pts->y); // will print untransfomed coordinates
>
}
>
>
Youngjin
Well, gee, are you sure dx and dy aren't zero?
I took a look at the header for NSBezierPath and I couldn't see any way it
could be storing the transform; if it did, then it would have to be some
roundabout way. Plus, if you think about it, it doesn't make much sense for
it not to just apply the transform to the component points; since there are
no methods provided to reverse the transform or retrieve the original path,
there wouldn't be anything to be gained by storing the path and the
transform separately.
Well, I happen to have a little application sitting around that draws an
triangle using NSBezierPath and lets me drag it around with the mouse (using
NSAffineTransform for the translations). So, I put in a call to
elementAtIndex:associatedPoints: to get one of the vertices and an NSLog
call to spit out the coordinates as I move it around. As far as I can see,
the point is getting transformed.
So, you might want to double check your code. Maybe your transfrom is
inadvertently being set to the identity...
- Dennis D.