Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get a boundingbox for multiple items in wpf?

I have several items, i want to calculate a minimum rectangle in which they can be fit, but items are rotated to some degree, or skewed or both. So how do i get the least rectangle which can contain all ?

like image 872
Code0987 Avatar asked Nov 05 '22 21:11

Code0987


2 Answers

You can get the bounding Box for each item, calculate its four extreme points, then apply the transforms on them (skew, rotate, ...)

Then you can easily calculate the bounding box by computing the min and max x and y for all of these points.

like image 97
Alireza Avatar answered Nov 09 '22 10:11

Alireza


Here is an link to an implementation of a Dynamic Canvas. This control automatically sizes itself to fit its contents, so the answer to your problem can be found in this code. Look at the MeasureOverride function.

like image 20
davisoa Avatar answered Nov 09 '22 09:11

davisoa