mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-09-21 04:17:57 +08:00
Improve PdfRectangle.GetWidthHeight();
Improve and simplify Word's oriented bounding box
This commit is contained in:
@@ -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 />
|
||||
|
Reference in New Issue
Block a user