How to determine the dimensions of an Object2D?

I have a program where I build random shapes (amongst other objects, and the issue is the same for them all), in this example it is a triangle. When the triangle is normal, I know it’s widths and height, so I know how large to set the BitmapForCaching(???, ???), but if I rotate the triangle the object may be higher or wider. I use the BitmapForCaching(???, ???) to create a masked picture.

Is there a way to determine the dimensions of an Object2D (ArcShape, FigureShape, Oval, etc) BEFORE the drawPicture.Graphics.DrawObject(…) adds it to the picture?

[code]Dim tempFigureShape As New FigureShape
Dim drawPicture As Picture

[tempFigureShape created here]
…
If app.RotateShapes Then
tempFigureShape.Rotation = commonMaths.getDegreesToRadians(tempRandom.InRange(0, 360)) 'what will the width and height be now?
End If

drawPicture = BitmapForCaching(???, ???)
drawPicture.Graphics.DrawObject(tempFigureShape, ???, ???)
[/code]

There may be a better way to do it than this, but what I did was to write extension functions for Height and Width for Object2D. I didn’t implement rotation because I wasn’t using it when I wrote these, but it would not be hard to do. Just use some trig to factor in the rotation value when getting the points. (I’ve copied only the code for FigureShape below).

[code]Public Function Height(extends o as Object2D) as integer
’ not all Object2D shapes have a height property
’ so this helper method calculates the value
’ when it doesn’t exist

if o isa FigureShape then
dim fx as FigureShape = FigureShape(o)
dim T, B, j, c as integer
c = fx.Count-1
for j = 0 to c
T = min( T, fx.item(j).Y )
T = min( T, fx.item(j).Y2 )
B = max( B, fx.item(j).Y )
B = max( B, fx.item(j).Y2 )
next
return abs( B - T )
'…
end if
End Function[/code]

[code]Public Function Width(extends o as Object2D) as integer
’ not all Object2D shapes have a width property
’ so this helper method calculates the value
’ when it doesn’t exist

if o isa FigureShape then
dim fx as FigureShape = FigureShape(o)
dim R, L, j, c as integer
c = fx.Count-1
for j = 0 to c
L = min( L, fx.item(j).X )
L = min( L, fx.item(j).X2 )
R = max( R, fx.item(j).X )
R = max( R, fx.item(j).X2 )
next
return abs( R - L )
’ …
end if
End Function
[/code]