diff --git a/src/UglyToad.PdfPig.Core/PdfRectangle.cs b/src/UglyToad.PdfPig.Core/PdfRectangle.cs
index dc6257c6..eca7e944 100644
--- a/src/UglyToad.PdfPig.Core/PdfRectangle.cs
+++ b/src/UglyToad.PdfPig.Core/PdfRectangle.cs
@@ -58,24 +58,24 @@
public double Area { get; }
///
- /// Left.
+ /// Left. This value is only valid if the rectangle is not rotated, check .
///
- public double Left => TopLeft.X;
+ public double Left => TopLeft.X < TopRight.X ? TopLeft.X : TopRight.X;
///
- /// Top.
+ /// Top. This value is only valid if the rectangle is not rotated, check .
///
- public double Top => TopLeft.Y;
+ public double Top => TopLeft.Y > BottomLeft.Y ? TopLeft.Y : BottomLeft.Y;
///
- /// Right.
+ /// Right. This value is only valid if the rectangle is not rotated, check .
///
- public double Right => BottomRight.X;
+ public double Right => BottomRight.X > BottomLeft.X ? BottomRight.X : BottomLeft.X;
///
- /// Bottom.
+ /// Bottom. This value is only valid if the rectangle is not rotated, check .
///
- public double Bottom => BottomRight.Y;
+ public double Bottom => BottomRight.Y < TopRight.Y ? BottomRight.Y : TopRight.Y;
///
/// Create a new .
@@ -136,7 +136,7 @@
double sinT = Math.Sin(t);
double cosSqSinSqInv = 1.0 / (cosT * cosT - sinT * sinT);
- Rotation = t * 57.2957795130823; // 180 / PI
+ Rotation = t * 180 / Math.PI;
Width = cosSqSinSqInv * (bx * cosT - by * sinT);
Height = cosSqSinSqInv * (-bx * sinT + by * cosT);
Area = Width * Height;
diff --git a/src/UglyToad.PdfPig.Tests/Geometry/PdfRectangleTests.cs b/src/UglyToad.PdfPig.Tests/Geometry/PdfRectangleTests.cs
index 3df83b34..48409d77 100644
--- a/src/UglyToad.PdfPig.Tests/Geometry/PdfRectangleTests.cs
+++ b/src/UglyToad.PdfPig.Tests/Geometry/PdfRectangleTests.cs
@@ -7,6 +7,7 @@
public class PdfRectangleTests
{
private static readonly DoubleComparer DoubleComparer = new DoubleComparer(3);
+ private static readonly DoubleComparer PreciseDoubleComparer = new DoubleComparer(6);
private static readonly PointComparer PointComparer = new PointComparer(DoubleComparer);
private static readonly PdfRectangle UnitRectangle = new PdfRectangle(new PdfPoint(0, 0), new PdfPoint(1, 1));
@@ -134,8 +135,9 @@
Assert.Equal(new PdfPoint(-1, 0), rotated.TopLeft);
Assert.Equal(new PdfPoint(-1, 1), rotated.TopRight);
- Assert.Equal(1, rotated.Width);
- Assert.Equal(-1, rotated.Height);
+ Assert.Equal(1, rotated.Width, PreciseDoubleComparer);
+ Assert.Equal(-1, rotated.Height, PreciseDoubleComparer);
+ Assert.Equal(90, rotated.Rotation, PreciseDoubleComparer);
}
[Fact]
@@ -150,8 +152,9 @@
Assert.Equal(new PdfPoint(0, -1), rotated.TopLeft);
Assert.Equal(new PdfPoint(-1, -1), rotated.TopRight);
- Assert.Equal(-1, rotated.Width);
- Assert.Equal(-1, rotated.Height);
+ Assert.Equal(-1, rotated.Width, PreciseDoubleComparer);
+ Assert.Equal(-1, rotated.Height, PreciseDoubleComparer);
+ Assert.Equal(180, rotated.Rotation, PreciseDoubleComparer);
}
}
}
diff --git a/src/UglyToad.PdfPig/Annotations/HyperlinkFactory.cs b/src/UglyToad.PdfPig/Annotations/HyperlinkFactory.cs
index 7e0e275a..0ad3c0f1 100644
--- a/src/UglyToad.PdfPig/Annotations/HyperlinkFactory.cs
+++ b/src/UglyToad.PdfPig/Annotations/HyperlinkFactory.cs
@@ -41,7 +41,7 @@
var bounds = annotation.Rectangle;
// Build in tolerance for letters close to the link region.
- var tolerantBounds = new PdfRectangle(bounds.TopLeft.Translate(-0.5, 0), bounds.BottomRight.Translate(0.5, 0));
+ var tolerantBounds = new PdfRectangle(bounds.BottomLeft.Translate(-0.5, -0.5), bounds.TopRight.Translate(0.5, 0.5));
var linkLetters = new List();