# Getting size of 2d object

Hi,

if have some type of 2d object / figure shape. That should be drawn on canvs. The origin of that shape should be the center (originX = width/2, OriginY = width/2). But I see no way to get this width. Or is there something i missed in the docs?

Marius

Some object2d have a width and height property but FigureShape does not.

You might need to subclasse FigureShape and calculate the width/height each time you use the AddXX methods.

Hy Jeremie,

I thought about this. But I use something like addCubic to add a cuveshape. I never really understood how these Controlpoints work. I managed to get a result, ok. But to calculate the width by codeâŠ Never everâŠ Is there some documentation about these controlpoints i have never found? Is there some code thats shows me the calculation of what controlpoints do?

The only other way I see is to draw the shape to a picture und go through its rgbsurface pixel by pixelâŠ
Not a nice way.

I think it would be easy for Xojo to give the width and height info for this object. One point more on this really long list of things that - I think - is necessary and not available.
Or From the other side: How do others solve that? I canât be the first one. In short, I have a canvas, there is a backgroundlayer. You can put Shapes on this layer. If you zoom in or out, you could not handle that with an origin of 0,0. It is mandatory to have the origin centered, otherwise the shape is âwalkingâ on the map. And espaceially for this case (zooming in and out) vector is the way to do it, not pixel. Perhaps I miss something, but then I didnât see it.

Marius

Ok, I found a way with some 45Â° shapes that let me know the radius. Works for me. Thanks for your help.

Hi Marius, Hi Jeremie,

for this problem you only need to approximate the Bezier curves with a polygon.
For a FigureShape, you can then build a polygon by concatenating the curve sets.

from that, it is now easy to create:

``````figure.contains( X,Y ) as boolean
width and height of the figure
``````

What you need is to implement curve flattening, using the Casteljau algorithm it is easy.

a fantastic source of information on Bezier curves:

This was already requested 14 years ago in the Xojo tracker.
https://tracker.xojo.com/xojoinc/xojo/-/issues/3448
I have added a workaround.

2 Likes

Really cool. Thank you for this code!