mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-11-28 17:47:12 +08:00
Use Euclidean distance in PdfRectangle's width and height
This commit is contained in:
@@ -49,6 +49,7 @@
|
|||||||
private double width;
|
private double width;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Width of the rectangle.
|
/// Width of the rectangle.
|
||||||
|
/// <para>A positive number.</para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public double Width
|
public double Width
|
||||||
{
|
{
|
||||||
@@ -66,6 +67,7 @@
|
|||||||
private double height;
|
private double height;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Height of the rectangle.
|
/// Height of the rectangle.
|
||||||
|
/// <para>A positive number.</para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public double Height
|
public double Height
|
||||||
{
|
{
|
||||||
@@ -202,8 +204,11 @@
|
|||||||
sin, cos, 0,
|
sin, cos, 0,
|
||||||
0, 0, 1);
|
0, 0, 1);
|
||||||
|
|
||||||
width = inverseRotation.Transform(BottomRight).X - inverseRotation.Transform(BottomLeft).X;
|
// Using Abs as a proxy for Euclidean distance in 1D
|
||||||
height = inverseRotation.Transform(TopLeft).Y - inverseRotation.Transform(BottomLeft).Y;
|
// as it might happen that points have negative coordinates.
|
||||||
|
var bl = inverseRotation.Transform(BottomLeft);
|
||||||
|
width = Math.Abs(inverseRotation.Transform(BottomRight).X - bl.X);
|
||||||
|
height = Math.Abs(inverseRotation.Transform(TopLeft).Y - bl.Y);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@@ -1682,5 +1682,17 @@
|
|||||||
Assert.Equal(expected[2], rectR.TopLeft, PointComparer);
|
Assert.Equal(expected[2], rectR.TopLeft, PointComparer);
|
||||||
Assert.Equal(expected[3], rectR.BottomLeft, PointComparer);
|
Assert.Equal(expected[3], rectR.BottomLeft, PointComparer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Issue261()
|
||||||
|
{
|
||||||
|
// Some points have negative coordinates after rotation, resulting in negative Height
|
||||||
|
PdfRectangle rect = new PdfRectangle(new PdfPoint(401.51, 461.803424),
|
||||||
|
new PdfPoint(300.17322363281249, 461.803424),
|
||||||
|
new PdfPoint(401.51, 291.45),
|
||||||
|
new PdfPoint(300.17322363281249, 291.45));
|
||||||
|
|
||||||
|
Assert.True(rect.Height > 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user