Current filter:
You should refresh the page.
Support Center
Sidebar

Convert a PdfOrientedRectangle to a PdfRectangle

1Solution

Creation Date Importance Sort by

Hello Matthias,
Please take a look at the following code snippet showing how you can perform conversion:

[C#]
static PdfRectangle CreateBoundingRectangle(IList<PdfPoint> points) { int count = points.Count; PdfPoint point = points; double xMin = point.X; double xMax = xMin; double yMin = point.Y; double yMax = yMin; for (int i = 1; i < count; i++) { point = points[i]; double x = point.X; if (x < xMin) xMin = x; else if (x > xMax) xMax = x; double y = point.Y; if (y < yMin) yMin = y; else if (y > yMax) yMax = y; } return new PdfRectangle(xMin, yMin, xMax, yMax); } static PdfRectangle ConvertToRectangle(PdfOrientedRectangle rectangle) { var vertices = new List<PdfPoint>(); double cos = Math.Cos(rectangle.Angle); double sin = Math.Sin(rectangle.Angle); var left = rectangle.Left; var top = rectangle.Top; var width = rectangle.Width; var height = rectangle.Height; vertices.Add(new PdfPoint(left, top)); vertices.Add(new PdfPoint(left + width * cos, top + width * sin)); vertices.Add(new PdfPoint(left + width * cos + height * sin, top - height * cos + width * sin)); vertices.Add(new PdfPoint(left + height * sin, top - height * cos)); return CreateBoundingRectangle(vertices); }

Does this approach meet your requirements? If not, please describe your end-goal in greater detail.
I look forward to your results.

• Matthias Reincke 02.22.2019

Thank you very much, Mariya! It works very well.

Have a nice day.
Matthias

• Mariya (DevExpress Support) 02.22.2019

You are always welcome!

• Scott Gross 06.05.2019

as a feature enhancement, I would like to be able to just cast to it, I'll add as an extension method for now. thanks.

• Mariya (DevExpress Support) 06.06.2019

Thank you for the suggestion, Scott. I'll inform our developers about that and we'll think how to improve the API in this regard.