namespace UglyToad.PdfPig.Core { using System; /// /// A line 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 PdfLine { /// /// Length of the line. /// public double Length { get { var dx = Point1.X - Point2.X; var dy = Point1.Y - Point2.Y; return Math.Sqrt(dx * dx + dy * dy); } } /// /// First point of the line. /// public PdfPoint Point1 { get; } /// /// Second point of the line. /// public PdfPoint Point2 { get; } /// /// Create a new . /// /// The x coordinate of the first point on the line. /// The y coordinate of the first point on the line. /// The x coordinate of the second point on the line. /// The y coordinate of the second point on the line. public PdfLine(double x1, double y1, double x2, double y2) : this(new PdfPoint(x1, y1), new PdfPoint(x2, y2)) { } /// /// Create a new . /// /// First point of the line. /// Second point of the line. public PdfLine(PdfPoint point1, PdfPoint point2) { Point1 = point1; Point2 = point2; } /// /// The rectangle completely containing the . /// public PdfRectangle GetBoundingRectangle() { return new PdfRectangle( Math.Min(Point1.X, Point2.X), Math.Min(Point1.Y, Point2.Y), Math.Max(Point1.X, Point2.X), Math.Max(Point1.Y, Point2.Y)); } /// /// Returns a value indicating whether this is equal to a specified . /// /// /// public override bool Equals(object obj) { if (obj is PdfLine line) { return line.Point1.Equals(Point1) && line.Point2.Equals(Point2); } return false; } /// /// Returns the hash code for this . /// /// public override int GetHashCode() { return (Point1, Point2).GetHashCode(); } } }