// "Therefore those skilled at the unorthodox
// are infinite as heaven and earth,
// inexhaustible as the great rivers.
// When they come to an end,
// they begin again,
// like the days and months;
// they die and are reborn,
// like the four seasons."
//
// - Sun Tsu,
// "The Art of War"
using System;
namespace TheArtOfDev.HtmlRenderer.Adapters.Entities
{
///
/// Represents an ordered pair of floating-point x- and y-coordinates that defines a point in a two-dimensional plane.
///
public struct RPoint
{
///
/// Represents a new instance of the class with member data left uninitialized.
///
/// 1
public static readonly RPoint Empty = new RPoint();
private double _x;
private double _y;
static RPoint()
{
}
///
/// Initializes a new instance of the class with the specified coordinates.
///
/// The horizontal position of the point.
/// The vertical position of the point.
///
///
public RPoint(double x, double y,PageList pagelist=null, int page = 0)
{
_y = y;
_x = x;
}
///
/// Gets a value indicating whether this is empty.
///
///
/// true if both and
///
/// are 0; otherwise, false.
///
/// 1
public bool IsEmpty
{
get
{
if (Math.Abs(_x - 0.0) < 0.001)
return Math.Abs(_y - 0.0) < 0.001;
else
return false;
}
}
///
/// Gets or sets the x-coordinate of this .
///
///
/// The x-coordinate of this .
///
/// 1
public double X
{
get { return _x; }
set { _x = value; }
}
///
/// Gets or sets the y-coordinate of this .
///
///
/// The y-coordinate of this .
///
/// 1
public double Y
{
get { return _y; }
set { _y = value; }
}
///
/// Translates the by the specified
///
/// .
///
///
/// The translated .
///
///
/// The to translate.
///
///
/// The that specifies the numbers to add to the x- and y-coordinates of the
///
/// .
///
public static RPoint operator +(RPoint pt, RSize sz)
{
return Add(pt, sz);
}
///
/// Translates a by the negative of a specified
///
/// .
///
///
/// The translated .
///
///
/// The to translate.
///
///
/// The that specifies the numbers to subtract from the coordinates of
///
/// .
///
public static RPoint operator -(RPoint pt, RSize sz)
{
return Subtract(pt, sz);
}
///
/// Compares two structures. The result specifies whether the values of the
///
/// and properties of the two
///
/// structures are equal.
///
///
/// true if the and
///
/// values of the left and right
///
/// structures are equal; otherwise, false.
///
///
/// A to compare.
///
///
/// A to compare.
///
/// 3
public static bool operator ==(RPoint left, RPoint right)
{
if (left.X == right.X)
return left.Y == right.Y;
else
return false;
}
///
/// Determines whether the coordinates of the specified points are not equal.
///
///
/// true to indicate the and
///
/// values of and
///
/// are not equal; otherwise, false.
///
///
/// A to compare.
///
///
/// A to compare.
///
/// 3
public static bool operator !=(RPoint left, RPoint right)
{
return !(left == right);
}
///
/// Translates a given by a specified
///
/// .
///
///
/// The translated .
///
///
/// The to translate.
///
///
/// The that specifies the numbers to add to the coordinates of
///
/// .
///
public static RPoint Add(RPoint pt, RSize sz)
{
return new RPoint(pt.X + sz.Width, pt.Y + sz.Height);
}
///
/// Translates a by the negative of a specified size.
///
///
/// The translated .
///
///
/// The to translate.
///
///
/// The that specifies the numbers to subtract from the coordinates of
///
/// .
///
public static RPoint Subtract(RPoint pt, RSize sz)
{
return new RPoint(pt.X - sz.Width, pt.Y - sz.Height);
}
///
/// Specifies whether this contains the same coordinates as the specified
///
/// .
///
///
/// This method returns true if is a and has the same coordinates as this
///
/// .
///
///
/// The to test.
///
/// 1
public override bool Equals(object obj)
{
if (!(obj is RPoint))
return false;
var pointF = (RPoint)obj;
if (pointF.X == X && pointF.Y == Y)
return pointF.GetType().Equals(GetType());
else
return false;
}
///
/// Returns a hash code for this structure.
///
///
/// An integer value that specifies a hash value for this structure.
///
/// 1
public override int GetHashCode()
{
return base.GetHashCode();
}
///
/// Converts this to a human readable string.
///
///
/// A string that represents this .
///
/// 1
public override string ToString()
{
return string.Format("{{X={0}, Y={1}}}", new object[]
{
_x,
_y
});
}
}
}