Improve PdfRectangle.GetWidthHeight();

Improve and simplify Word's oriented bounding box
This commit is contained in:
BobLd
2020-02-18 14:58:55 +00:00
committed by Eliot Jones
parent 67c5abf2b6
commit 42245d70ca
4 changed files with 58 additions and 47 deletions

View File

@@ -86,18 +86,7 @@
{
get
{
double t;
if (!BottomRight.Equals(BottomLeft))
{
t = Math.Atan2(BottomRight.Y - BottomLeft.Y, BottomRight.X - BottomLeft.X);
}
else
{
// handle the case where both bottom points are identical
t = Math.Atan2(TopLeft.Y - BottomLeft.Y, TopLeft.X - BottomLeft.X) - Math.PI / 2;
}
return t * 180 / Math.PI;
return GetT() * 180 / Math.PI;
}
}
@@ -184,11 +173,32 @@
BottomLeft.Translate(dx, dy), BottomRight.Translate(dx, dy));
}
private double GetT()
{
if (!BottomRight.Equals(BottomLeft))
{
return Math.Atan2(BottomRight.Y - BottomLeft.Y, BottomRight.X - BottomLeft.X);
}
else
{
// handle the case where both bottom points are identical
return Math.Atan2(TopLeft.Y - BottomLeft.Y, TopLeft.X - BottomLeft.X) - Math.PI / 2;
}
}
private void GetWidthHeight()
{
var tm = TransformationMatrix.GetRotationMatrix(Rotation).Inverse();
width = tm.Transform(BottomRight).X - tm.Transform(BottomLeft).X;
height = tm.Transform(TopLeft).Y - tm.Transform(BottomLeft).Y;
var t = GetT();
var cos = Math.Cos(t);
var sin = Math.Sin(t);
var inverseRotation = new TransformationMatrix(
cos, -sin, 0,
sin, cos, 0,
0, 0, 1);
width = inverseRotation.Transform(BottomRight).X - inverseRotation.Transform(BottomLeft).X;
height = inverseRotation.Transform(TopLeft).Y - inverseRotation.Transform(BottomLeft).Y;
}
/// <inheritdoc />