2020-01-05 00:38:18 +08:00
|
|
|
|
namespace UglyToad.PdfPig.Core
|
2017-11-23 02:41:34 +08:00
|
|
|
|
{
|
2018-11-25 21:56:27 +08:00
|
|
|
|
using System.Diagnostics;
|
2020-07-26 20:53:34 +08:00
|
|
|
|
using System.Globalization;
|
2018-11-25 21:56:27 +08:00
|
|
|
|
|
2017-12-31 02:02:59 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// A point in a PDF file.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// PDF coordinates are defined with the origin at the lower left (0, 0).
|
|
|
|
|
/// The Y-axis extends vertically upwards and the X-axis horizontally to the right.
|
|
|
|
|
/// Unless otherwise specified on a per-page basis, units in PDF space are equivalent to a typographic point (1/72 inch).
|
|
|
|
|
/// </remarks>
|
2017-11-23 02:41:34 +08:00
|
|
|
|
public struct PdfPoint
|
|
|
|
|
{
|
2017-12-31 02:02:59 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The origin of the coordinates system.
|
|
|
|
|
/// </summary>
|
2018-11-20 05:43:22 +08:00
|
|
|
|
public static PdfPoint Origin { get; } = new PdfPoint(0m, 0m);
|
2017-11-23 02:41:34 +08:00
|
|
|
|
|
2017-12-31 02:02:59 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The X coordinate for this point. (Horizontal axis).
|
|
|
|
|
/// </summary>
|
2019-12-22 02:09:49 +08:00
|
|
|
|
public double X { get; }
|
2017-11-23 02:41:34 +08:00
|
|
|
|
|
2017-12-31 02:02:59 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The Y coordinate of this point. (Vertical axis).
|
|
|
|
|
/// </summary>
|
2019-12-22 02:09:49 +08:00
|
|
|
|
public double Y { get; }
|
2017-11-23 02:41:34 +08:00
|
|
|
|
|
2018-01-07 20:37:48 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Create a new <see cref="PdfPoint"/> at this position.
|
|
|
|
|
/// </summary>
|
2018-11-25 21:56:27 +08:00
|
|
|
|
[DebuggerStepThrough]
|
2017-11-23 02:41:34 +08:00
|
|
|
|
public PdfPoint(decimal x, decimal y)
|
|
|
|
|
{
|
2019-12-22 02:09:49 +08:00
|
|
|
|
X = (double)x;
|
|
|
|
|
Y = (double)y;
|
2017-11-23 02:41:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-07 20:37:48 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Create a new <see cref="PdfPoint"/> at this position.
|
|
|
|
|
/// </summary>
|
2018-11-25 21:56:27 +08:00
|
|
|
|
[DebuggerStepThrough]
|
2017-11-23 02:41:34 +08:00
|
|
|
|
public PdfPoint(int x, int y)
|
|
|
|
|
{
|
|
|
|
|
X = x;
|
|
|
|
|
Y = y;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-07 20:37:48 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Create a new <see cref="PdfPoint"/> at this position.
|
|
|
|
|
/// </summary>
|
2018-11-25 21:56:27 +08:00
|
|
|
|
[DebuggerStepThrough]
|
2017-11-23 02:41:34 +08:00
|
|
|
|
public PdfPoint(double x, double y)
|
|
|
|
|
{
|
2019-12-22 02:09:49 +08:00
|
|
|
|
X = x;
|
|
|
|
|
Y = y;
|
2017-11-23 02:41:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-20 05:43:22 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Creates a new <see cref="PdfPoint"/> which is the current point moved in the x direction relative to its current position by a value.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="dx">The distance to move the point in the x direction relative to its current location.</param>
|
|
|
|
|
/// <returns>A new point shifted on the x axis by the given delta value.</returns>
|
2019-12-22 02:09:49 +08:00
|
|
|
|
public PdfPoint MoveX(double dx)
|
2018-11-17 22:59:58 +08:00
|
|
|
|
{
|
|
|
|
|
return new PdfPoint(X + dx, Y);
|
|
|
|
|
}
|
2018-11-20 05:43:22 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Creates a new <see cref="PdfPoint"/> which is the current point moved in the y direction relative to its current position by a value.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="dy">The distance to move the point in the y direction relative to its current location.</param>
|
|
|
|
|
/// <returns>A new point shifted on the y axis by the given delta value.</returns>
|
2019-12-22 02:09:49 +08:00
|
|
|
|
public PdfPoint MoveY(double dy)
|
2018-11-17 22:59:58 +08:00
|
|
|
|
{
|
|
|
|
|
return new PdfPoint(X, Y + dy);
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-14 19:41:11 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Creates a new <see cref="PdfPoint"/> which is the current point moved in the x and y directions relative to its current position by a value.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="dx">The distance to move the point in the x direction relative to its current location.</param>
|
|
|
|
|
/// <param name="dy">The distance to move the point in the y direction relative to its current location.</param>
|
|
|
|
|
/// <returns>A new point shifted on the y axis by the given delta value.</returns>
|
2019-12-22 02:09:49 +08:00
|
|
|
|
public PdfPoint Translate(double dx, double dy)
|
2019-12-14 19:41:11 +08:00
|
|
|
|
{
|
|
|
|
|
return new PdfPoint(X + dx, Y + dy);
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-10 02:58:48 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns a value indicating whether this <see cref="PdfPoint"/> is equal to a specified <see cref="PdfPoint"/> .
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="obj"></param>
|
|
|
|
|
public override bool Equals(object obj)
|
|
|
|
|
{
|
2019-08-10 20:05:25 +08:00
|
|
|
|
if (obj is PdfPoint point)
|
2019-08-10 02:58:48 +08:00
|
|
|
|
{
|
2019-12-18 19:41:02 +08:00
|
|
|
|
return point.X == X && point.Y == Y;
|
2019-08-10 02:58:48 +08:00
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns the hash code for this <see cref="PdfPoint"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public override int GetHashCode()
|
|
|
|
|
{
|
2019-08-10 20:05:25 +08:00
|
|
|
|
return (X, Y).GetHashCode();
|
2019-08-10 02:58:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-18 19:41:02 +08:00
|
|
|
|
/// <inheritdoc />
|
2017-11-23 02:41:34 +08:00
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
2020-07-26 20:53:34 +08:00
|
|
|
|
return $"(x:{X.ToString(CultureInfo.InvariantCulture)}, y:{Y.ToString(CultureInfo.InvariantCulture)})";
|
2017-11-23 02:41:34 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|