Create generic methods for lines in GeometryExtensions

This commit is contained in:
BobLd
2020-02-17 15:37:31 +00:00
committed by Eliot Jones
parent 6fe0ef0351
commit 36566f42e6
5 changed files with 647 additions and 135 deletions

View File

@@ -411,6 +411,19 @@
/// </summary>
public PdfPoint To { get; }
/// <summary>
/// Length of the line.
/// </summary>
public double Length
{
get
{
var l = (From.X - To.X) * (From.X - To.X) +
(From.Y - To.Y) * (From.Y - To.Y);
return Math.Sqrt(l);
}
}
/// <summary>
/// Create a new <see cref="Line"/>.
/// </summary>

View File

@@ -86,7 +86,18 @@
{
get
{
return GetT() * 180 / Math.PI;
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;
}
}
@@ -173,22 +184,6 @@
BottomLeft.Translate(dx, dy), BottomRight.Translate(dx, dy));
}
private double GetT()
{
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;
}
private void GetWidthHeight()
{
var tm = TransformationMatrix.GetRotationMatrix(Rotation).Inverse();