namespace UglyToad.PdfPig.Geometry
{
using System.Diagnostics;
///
/// A point in a PDF file.
///
///
/// 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).
///
public struct PdfPoint
{
///
/// The origin of the coordinates system.
///
public static PdfPoint Origin { get; } = new PdfPoint(0m, 0m);
///
/// The X coordinate for this point. (Horizontal axis).
///
public double X { get; }
///
/// The Y coordinate of this point. (Vertical axis).
///
public double Y { get; }
///
/// Create a new at this position.
///
[DebuggerStepThrough]
public PdfPoint(decimal x, decimal y)
{
X = (double)x;
Y = (double)y;
}
///
/// Create a new at this position.
///
[DebuggerStepThrough]
public PdfPoint(int x, int y)
{
X = x;
Y = y;
}
///
/// Create a new at this position.
///
[DebuggerStepThrough]
public PdfPoint(double x, double y)
{
X = x;
Y = y;
}
///
/// Creates a new which is the current point moved in the x direction relative to its current position by a value.
///
/// The distance to move the point in the x direction relative to its current location.
/// A new point shifted on the x axis by the given delta value.
public PdfPoint MoveX(double dx)
{
return new PdfPoint(X + dx, Y);
}
///
/// Creates a new which is the current point moved in the y direction relative to its current position by a value.
///
/// The distance to move the point in the y direction relative to its current location.
/// A new point shifted on the y axis by the given delta value.
public PdfPoint MoveY(double dy)
{
return new PdfPoint(X, Y + dy);
}
///
/// Creates a new which is the current point moved in the x and y directions relative to its current position by a value.
///
/// The distance to move the point in the x direction relative to its current location.
/// The distance to move the point in the y direction relative to its current location.
/// A new point shifted on the y axis by the given delta value.
public PdfPoint Translate(double dx, double dy)
{
return new PdfPoint(X + dx, Y + dy);
}
internal PdfVector ToVector()
{
return new PdfVector(X, Y);
}
///
/// Returns a value indicating whether this is equal to a specified .
///
///
public override bool Equals(object obj)
{
if (obj is PdfPoint point)
{
return point.X == X && point.Y == Y;
}
return false;
}
///
/// Returns the hash code for this .
///
public override int GetHashCode()
{
return (X, Y).GetHashCode();
}
///
public override string ToString()
{
return $"(x:{X}, y:{Y})";
}
}
}