Skip to main content



      Home
Home » Eclipse Projects » GEF » translateToRelative
translateToRelative [message #105213] Fri, 14 November 2003 14:41 Go to next message
Eclipse UserFriend
I thought I had got my head around draw2d's coordinate system - but
obviously not. I'll try simplify my problem to get to the point. If I
have a root edit part with a rectangle edit part as its child say at
location 50,50. I now have a point (p) in absolute coordinates which I
want to understand as a relative coordinate to the rectangle's figure. I
thought that I could call:

Rectangle.translateToRelative(p)

Obviously not, because the result is exactly the same as before the call.
What am I doing wrong?

James
Re: translateToRelative [message #105229 is a reply to message #105213] Fri, 14 November 2003 14:49 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.us.ibm.com

The resulting point will be relative to the rectangle's *bounds*.

So, you can then call Rectangle.getBounds().containsPoint(pt);

The resulting point will not be the same when scrolling vertically. Make
sure you are not translating a point you don't own.

"James Willans" <jwillans@cs.york.ac.uk> wrote in message
news:bp3b56$l4i$1@eclipse.org...
> I thought I had got my head around draw2d's coordinate system - but
> obviously not. I'll try simplify my problem to get to the point. If I
> have a root edit part with a rectangle edit part as its child say at
> location 50,50. I now have a point (p) in absolute coordinates which I
> want to understand as a relative coordinate to the rectangle's figure. I
> thought that I could call:
>
> Rectangle.translateToRelative(p)
>
> Obviously not, because the result is exactly the same as before the call.
> What am I doing wrong?
>
> James
>
Re: translateToRelative [message #105244 is a reply to message #105229] Fri, 14 November 2003 16:07 Go to previous messageGo to next message
Eclipse UserFriend
Thanks Randy, I'm not sure I fully understand. The result I'm expecting
(trying) to get is given a rectangle figure at 50,50 (as a child of the
root figure), then an absolute point 150,150 should be translated to
100,100. I thought by calling Rectangle.translateToRelative(p), that
would be the resulting value of p.

James

Randy Hudson wrote:

> The resulting point will be relative to the rectangle's *bounds*.

> So, you can then call Rectangle.getBounds().containsPoint(pt);

> The resulting point will not be the same when scrolling vertically. Make
> sure you are not translating a point you don't own.

> "James Willans" <jwillans@cs.york.ac.uk> wrote in message
> news:bp3b56$l4i$1@eclipse.org...
> > I thought I had got my head around draw2d's coordinate system - but
> > obviously not. I'll try simplify my problem to get to the point. If I
> > have a root edit part with a rectangle edit part as its child say at
> > location 50,50. I now have a point (p) in absolute coordinates which I
> > want to understand as a relative coordinate to the rectangle's figure. I
> > thought that I could call:
> >
> > Rectangle.translateToRelative(p)
> >
> > Obviously not, because the result is exactly the same as before the call.
> > What am I doing wrong?
> >
> > James
> >
Re: translateToRelative [message #105255 is a reply to message #105244] Fri, 14 November 2003 16:53 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.us.ibm.com

Nope, it doesn't do that. You can always easily do that by making the
following additional call:
point.translate(rectangle.getClientArea().getLocation().nega te();

the reason that "relative" is defined is relative to the figure's bounds, is
because hit-testing is performed using the figure's bounds. So, you may be
asking when does translateToRelative do anything? The answer is when a
figure's *parent* affects the coordinates in which the figure exists/paints.
For example, a wrapper figure which applies a zoom factor, or Viewport,
which provides scrolling by translating the coordinate system.

"James Willans" <jwillans@cs.york.ac.uk> wrote in message
news:bp3g61$qoa$1@eclipse.org...
> Thanks Randy, I'm not sure I fully understand. The result I'm expecting
> (trying) to get is given a rectangle figure at 50,50 (as a child of the
> root figure), then an absolute point 150,150 should be translated to
> 100,100. I thought by calling Rectangle.translateToRelative(p), that
> would be the resulting value of p.
>
> James
>
> Randy Hudson wrote:
>
> > The resulting point will be relative to the rectangle's *bounds*.
>
> > So, you can then call Rectangle.getBounds().containsPoint(pt);
>
> > The resulting point will not be the same when scrolling vertically.
Make
> > sure you are not translating a point you don't own.
>
> > "James Willans" <jwillans@cs.york.ac.uk> wrote in message
> > news:bp3b56$l4i$1@eclipse.org...
> > > I thought I had got my head around draw2d's coordinate system - but
> > > obviously not. I'll try simplify my problem to get to the point. If
I
> > > have a root edit part with a rectangle edit part as its child say at
> > > location 50,50. I now have a point (p) in absolute coordinates which
I
> > > want to understand as a relative coordinate to the rectangle's figure.
I
> > > thought that I could call:
> > >
> > > Rectangle.translateToRelative(p)
> > >
> > > Obviously not, because the result is exactly the same as before the
call.
> > > What am I doing wrong?
> > >
> > > James
> > >
>
>
Re: translateToRelative [message #105269 is a reply to message #105255] Fri, 14 November 2003 19:30 Go to previous message
Eclipse UserFriend
Thanks Randy. The coordinate system is beginning to make sense.

James

Randy Hudson wrote:

> Nope, it doesn't do that. You can always easily do that by making the
> following additional call:
> point.translate(rectangle.getClientArea().getLocation().nega te();

> the reason that "relative" is defined is relative to the figure's bounds, is
> because hit-testing is performed using the figure's bounds. So, you may be
> asking when does translateToRelative do anything? The answer is when a
> figure's *parent* affects the coordinates in which the figure exists/paints.
> For example, a wrapper figure which applies a zoom factor, or Viewport,
> which provides scrolling by translating the coordinate system.

> "James Willans" <jwillans@cs.york.ac.uk> wrote in message
> news:bp3g61$qoa$1@eclipse.org...
> > Thanks Randy, I'm not sure I fully understand. The result I'm expecting
> > (trying) to get is given a rectangle figure at 50,50 (as a child of the
> > root figure), then an absolute point 150,150 should be translated to
> > 100,100. I thought by calling Rectangle.translateToRelative(p), that
> > would be the resulting value of p.
> >
> > James
> >
> > Randy Hudson wrote:
> >
> > > The resulting point will be relative to the rectangle's *bounds*.
> >
> > > So, you can then call Rectangle.getBounds().containsPoint(pt);
> >
> > > The resulting point will not be the same when scrolling vertically.
> Make
> > > sure you are not translating a point you don't own.
> >
> > > "James Willans" <jwillans@cs.york.ac.uk> wrote in message
> > > news:bp3b56$l4i$1@eclipse.org...
> > > > I thought I had got my head around draw2d's coordinate system - but
> > > > obviously not. I'll try simplify my problem to get to the point. If
> I
> > > > have a root edit part with a rectangle edit part as its child say at
> > > > location 50,50. I now have a point (p) in absolute coordinates which
> I
> > > > want to understand as a relative coordinate to the rectangle's figure.
> I
> > > > thought that I could call:
> > > >
> > > > Rectangle.translateToRelative(p)
> > > >
> > > > Obviously not, because the result is exactly the same as before the
> call.
> > > > What am I doing wrong?
> > > >
> > > > James
> > > >
> >
> >
Previous Topic:Open Request and Elements within the same editor
Next Topic:Who wants to fix something?
Goto Forum:
  


Current Time: Wed Jul 16 03:12:57 EDT 2025

Powered by FUDForum. Page generated in 0.07125 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top