Struct Point
- Namespace
- Northwoods.Go
- Assembly
- Northwoods.GoDiagram.WinForms.dll
A Point represents an x- and y-coordinate pair in two-dimensional space.
[JsonConverter(typeof(PointJsonConverter))]
public struct Point
- Inherited Members
Remarks
Use the static functions Parse(string) and Stringify(Point) to convert to and from a standard string representation that is independent of the current locale.
Constructors
Point(double, double)
The default constructor produces the Point(0,0). This constructor may take either zero arguments or two arguments.
public Point(double x = 0, double y = 0)
Parameters
Properties
X
Gets or sets the x value of the Point.
public double X { readonly get; set; }
Property Value
Y
Gets or sets the y value of the Point.
public double Y { readonly get; set; }
Property Value
Methods
Add(Point)
Returns a new Point that is the sum of this Point and the x and y coordinates of the given Point.
public Point Add(Point p)
Parameters
p
PointThe Point to add to this Point.
Returns
- Point
A new Point.
- See Also
CompareWithLineSegment(Point, Point)
Compare this point with a finite line segment given by two Points.
public double CompareWithLineSegment(Point p, Point q)
Parameters
Returns
- double
<0 if on the left side, or >0 if on the right side, or zero if exactly on the finite line segment
Remarks
This method compares this point with a finite line segment determined by the given two Points. If the point is on the finite line segment, this returns zero. If the point is on the left side of the segment, this returns a positive number. If the point is on the right side of the segment, this returns a negative number. If the point is on the infinitely extended line but not within the segment, then this returns a positive number if the point is beyond the end of the segment when going from A1 to A2, or this returns a negative number if the point comes before the segment's start at A1.
CompareWithLineSegment(double, double, double, double, double, double)
This static function compares a point with a finite line segment. If the point is on the finite line segment, this returns zero. If the point is on the left side of the segment, this returns a positive number. If the point is on the right side of the segment, this returns a negative number. If the point is on the infinitely extended line but not within the segment, then this returns a positive number if the point is beyond the end of the segment when going from A1 to A2, or this returns a negative number if the point comes before the segment's start at A1.
public static double CompareWithLineSegment(double a1x, double a1y, double a2x, double a2y, double px, double py)
Parameters
a1x
doublestart of line segment A1
a1y
doublestart of line segment A1
a2x
doubleend of line segment A2
a2y
doubleend of line segment A2
px
doublepoint to be compared with the line segment A1-A2
py
doublepoint to be compared with the line segment A1-A2
Returns
- double
<0 if on the left side, or >0 if on the right side, or zero if exactly on the finite line segment
Direction(Point)
Compute the angle from this Point to a given Point. However, if the given Point is the same as this Point, the direction is zero.
public double Direction(Point p)
Parameters
p
Pointthe other Point to which to measure the relative angle.
Returns
- double
The angle, in degrees, of the line from this Point to the given point.
- See Also
Direction(double, double)
Compute the angle from this Point to a given (px, py) point. However, if the point is the same as this Point, the direction is zero.
public double Direction(double px, double py)
Parameters
Returns
- double
The angle, in degrees, of the line from this Point to the given point.
- See Also
Direction(double, double, double, double)
This static function returns the angle in degrees of the line from point P to point Q.
public static double Direction(double px, double py, double qx, double qy)
Parameters
Returns
DistanceLineSegmentSquared(double, double, double, double, double, double)
This static function returns the square of the distance from the point P to the finite line segment from point A to point B.
public static double DistanceLineSegmentSquared(double px, double py, double ax, double ay, double bx, double by)
Parameters
Returns
- double
The euclidean distance.
DistanceSquared(Point)
Returns the square of the distance from this Point to a given Point.
public double DistanceSquared(Point p)
Parameters
p
Pointthe other Point to measure to.
Returns
- double
The square of the euclidean distance.
- See Also
DistanceSquared(double, double)
Returns the square of the distance from this point to a given point (px, py).
public double DistanceSquared(double px, double py)
Parameters
Returns
- double
The square of the euclidean distance.
- See Also
DistanceSquared(double, double, double, double)
This static function returns the square of the distance from the point P to the point Q.
public static double DistanceSquared(double px, double py, double qx, double qy)
Parameters
Returns
Equals(double, double)
Indicates whether the given point (x, y) is equal to this Point.
public bool Equals(double x, double y)
Parameters
Returns
- bool
True if the two Points have identical X and Y values, false otherwise.
- See Also
Equals(object)
Indicates whether the given Point is equal to this Point.
public override bool Equals(object obj)
Parameters
obj
objectThe Point to compare to the current Point.
Returns
- bool
True if the two Points have identical X and Y values, false otherwise.
- See Also
EqualsApprox(Point)
Indicates whether the given Point is nearly equal to this Point.
public bool EqualsApprox(Point p)
Parameters
p
PointThe Point to compare to the current Point.
Returns
- bool
True if the two Points have x and y values that are equal with a tolerance of 0.5, false otherwise.
GetHashCode()
Creates a hash code for the point.
public override int GetHashCode()
Returns
- int
A hash code for the current point structure.
IntersectingLineSegments(double, double, double, double, double, double, double, double)
This static function is true if two finite straight line segments intersect each other.
public static bool IntersectingLineSegments(double a1x, double a1y, double a2x, double a2y, double b1x, double b1y, double b2x, double b2y)
Parameters
Returns
- bool
True if the two given finite line segments intersect with each other, false otherwise.
IsReal()
True if this Point has X and Y values that are real numbers and not infinity.
public bool IsReal()
Returns
Normalize()
Returns a new Point that is this Point normalized to a unit length. However, if this Point is the origin (zero, zero), its length remains zero.
public Point Normalize()
Returns
- Point
A new Point.
Offset(double, double)
Returns a new point by shifting this Point's values with the given DX and DY offsets.
public Point Offset(double dx, double dy)
Parameters
Returns
- Point
A new Point.
- See Also
Parse(object)
This is a convenience method for Parse(string) that can be used as a Converter.
public static object Parse(object str)
Parameters
str
object
Returns
Parse(string)
This static method can be used to read in a Point from a string that was produced by Stringify(Point).
public static Point Parse(string str)
Parameters
str
string
Returns
Remarks
Point.Parse("1 2")
produces the Point new Point(1, 2)
.
ProjectOntoLineSegment(Point, Point)
Returns the closest Point to this Point that is on a finite line segment.
public Point ProjectOntoLineSegment(Point p, Point q)
Parameters
Returns
- Point
A new Point.
- See Also
ProjectOntoLineSegment(double, double, double, double)
Returns the closest Point to this Point that is on a finite line segment.
public Point ProjectOntoLineSegment(double px, double py, double qx, double qy)
Parameters
px
doubleone end of the finite line segment
py
doubleone end of the finite line segment
qx
doublethe other end of the finite line segment
qy
doublethe other end of the finite line segment
Returns
- Point
A new Point.
- See Also
Rotate(double)
Returns a new Point that is this Point rotated about the origin by the given angle.
public Point Rotate(double angle)
Parameters
angle
doublean angle in degrees.
Returns
- Point
A new Point.
Scale(double, double)
Returns a new Point that is this Point scaled by given factors along the X and Y axes.
public Point Scale(double sx, double sy)
Parameters
Returns
- Point
A new Point.
SetSpot(Rect, Spot)
Returns a new Point that's X and Y values correspond to a particular Spot in a given Rect.
public static Point SetSpot(Rect r, Spot spot)
Parameters
r
Rectthe Rect for which we are finding the point.
spot
Spotthe Spot; IsSpot() must be true for this Spot.
Returns
- Point
A new Point.
Remarks
The result is meaningless if IsNoSpot() is true for the given Spot.
- See Also
SetSpot(double, double, double, double, Spot)
Returns a new Point that's X and Y values correspond to a particular Spot in a given rectangle.
public static Point SetSpot(double x, double y, double w, double h, Spot spot)
Parameters
x
doubleThe X coordinate of the Rect for which we are finding the point.
y
doubleThe Y coordinate of the Rect for which we are finding the point.
w
doubleThe Width of the Rect for which we are finding the point.
h
doubleThe Height of the Rect for which we are finding the point.
spot
Spotthe Spot; IsSpot() must be true for this Spot.
Returns
- Point
A new Point, the spot in the rectangle.
Remarks
The result is meaningless if IsNoSpot() is true for the given Spot.
- See Also
SnapToGrid(Point, Size)
Returns the closest Point to this Point on an infinite grid, given the grid's origin and size of each grid cell.
public Point SnapToGrid(Point origin, Size cellsize)
Parameters
Returns
- Point
A new Point.
SnapToGrid(double, double, double, double)
Returns the closest Point to this Point on an infinite grid, given the grid's x and y origin and the width and height of its cells.
public Point SnapToGrid(double originx, double originy, double cellwidth, double cellheight)
Parameters
originx
doublethe x value of the top-left point of the grid
originy
doublethe y value of the top-left point of the grid
cellwidth
doublethe width of each grid cell -- must be a real number larger than zero
cellheight
doublethe height of each grid cell -- must be a real number larger than zero
Returns
- Point
A new Point.
Stringify(Point)
This static method can be used to write out a Point as a string that can be read by Parse(string).
public static string Stringify(Point val)
Parameters
val
Point
Returns
Remarks
Point.Stringify(new Point(1, 2))
produces the string "1 2".
Stringify(object)
This is a convenience method for Stringify(Point) that can be used as a BackConverter.
public static object Stringify(object pt)
Parameters
pt
object
Returns
StringifyFixed(Point, int)
This static method can be used to write out a Point as a string with its numbers at a fixed number of digits after the decimal point.
public static string StringifyFixed(Point val, int digits)
Parameters
Returns
Remarks
This is useful for limiting the size of JSON output and making it more legible. It might also be useful for regression testing.
StringifyFixed(object)
This is a convenience method for StringifyFixed(Point, int) that can be used as a BackConverter. This convenience method uses two decimal places.
public static object StringifyFixed(object pt)
Parameters
pt
object
Returns
Subtract(Point)
Returns a new Point that is the difference of this Point and the x and y coordinates of the given Point.
public Point Subtract(Point p)
Parameters
p
PointThe Point to subtract from the current Point.
Returns
- Point
A new Point.
- See Also
ToString()
Returns a string representation of the point.
public override string ToString()
Returns
- string
A string representation of the current point.
Operators
operator ==(Point, Point)
public static bool operator ==(Point left, Point right)
Parameters
Returns
operator !=(Point, Point)
public static bool operator !=(Point left, Point right)