fix usages of rectangle constructor.

now that rectangle constructor uses the order [ llx, lly, urx, ury ] and does not apply correction for points constructor parameters must be passed in the correct order. this change fixes the hyperlink factory which was passing them in the wrong order.

in addition the pdfpath bounding box was using left, right, top and bottom to calculate the minimum bounding box. this produced incorrect values now individual path operator bounding boxes are rotated, since for a rotated rectangle top may be less than bottom.

the performance seems to have taken a hit due to these changes however.
This commit is contained in:
Eliot Jones
2020-01-28 13:37:42 +00:00
parent 0e613fb526
commit 0e84fa34a8
3 changed files with 17 additions and 14 deletions

View File

@@ -58,24 +58,24 @@
public double Area { get; }
/// <summary>
/// Left.
/// Left. This value is only valid if the rectangle is not rotated, check <see cref="Rotation"/>.
/// </summary>
public double Left => TopLeft.X;
public double Left => TopLeft.X < TopRight.X ? TopLeft.X : TopRight.X;
/// <summary>
/// Top.
/// Top. This value is only valid if the rectangle is not rotated, check <see cref="Rotation"/>.
/// </summary>
public double Top => TopLeft.Y;
public double Top => TopLeft.Y > BottomLeft.Y ? TopLeft.Y : BottomLeft.Y;
/// <summary>
/// Right.
/// Right. This value is only valid if the rectangle is not rotated, check <see cref="Rotation"/>.
/// </summary>
public double Right => BottomRight.X;
public double Right => BottomRight.X > BottomLeft.X ? BottomRight.X : BottomLeft.X;
/// <summary>
/// Bottom.
/// Bottom. This value is only valid if the rectangle is not rotated, check <see cref="Rotation"/>.
/// </summary>
public double Bottom => BottomRight.Y;
public double Bottom => BottomRight.Y < TopRight.Y ? BottomRight.Y : TopRight.Y;
/// <summary>
/// Create a new <see cref="PdfRectangle"/>.
@@ -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;

View File

@@ -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);
}
}
}

View File

@@ -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<Letter>();