# How get a Rect that contains all the quads from TextSearch class?

Question:

How to convert quads to a Rect?

Here is C# code, other languages should be sufficiently similar. The following code takes Orientated Bounding Boxes (OBB) quads to a single Axis Aligned Bounding Box (AABB) Rect instance.

This code would be useful for taking quads from TextSearch or viewer highlights to create an annotation. To create a PDF annotation you need a Rect that is a union of all the quads.

``````// Create a AABB Rect that is a union of all the OBB quads passed in
{
pdftron.PDF.Rect result = null;
{

double rectX1 = Math.Min(Math.Min(Math.Min(x1, x2), x3), x4);
double rectX2 = Math.Max(Math.Max(Math.Max(x1, x2), x3), x4);
double rectY1 = Math.Min(Math.Min(Math.Min(y1, y2), y3), y4);
double rectY2 = Math.Max(Math.Max(Math.Max(y1, y2), y3), y4);

if(result == null)
{
result = new pdftron.PDF.Rect(rectX1, rectY1, rectX2, rectY2);
}
else
{
result.x1 = Math.Min(result.x1, rectX1);
result.y1 = Math.Min(result.y1, rectY1);
result.x2 = Math.Max(result.x2, rectX2);
result.y2 = Math.Max(result.y2, rectY2);
}
}
return result;
}
``````

Here is JAVA code for the same.

``````// Create a AABB Rect that is a union of all the OBB quads passed in
{
com.pdftron.pdf.Rect result = null;
if(quads.length % 8 != 0) throw new Exception("incorrect number of quad numbers");

{

double rectX1 = Math.min(Math.min(Math.min(x1, x2), x3), x4);
double rectX2 = Math.max(Math.max(Math.max(x1, x2), x3), x4);
double rectY1 = Math.min(Math.min(Math.min(y1, y2), y3), y4);
double rectY2 = Math.max(Math.max(Math.max(y1, y2), y3), y4);

if(result == null)
{
result = new com.pdftron.pdf.Rect(rectX1, rectY1, rectX2, rectY2);
}
else
{
result.setX1(Math.min(result.getX1(), rectX1));
result.setY1(Math.min(result.getY1(), rectY1));
result.setX2(Math.max(result.getX2(), rectX2));
result.setY2(Math.max(result.getY2(), rectY2));
}
}
return result;
}
``````