Struct Point
A Point represents an x- and y-coordinate pair in two-dimensional space.
Namespace: Northwoods.Go
Assembly: Northwoods.GoDiagram.WinForms.dll
Syntax
[JsonConverter(typeof(PointJsonConverter))]
public struct Point
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.
Declaration
public Point(double x = 0, double y = 0)
Parameters
Type | Name | Description |
---|---|---|
double | x | The x value. |
double | y | The y value. |
Properties
X
Gets or sets the x value of the Point.
Declaration
public double X { readonly get; set; }
Property Value
Type | Description |
---|---|
double |
Y
Gets or sets the y value of the Point.
Declaration
public double Y { readonly get; set; }
Property Value
Type | Description |
---|---|
double |
Methods
Add(Point)
Returns a new Point that is the sum of this Point and the x and y coordinates of the given Point.
Declaration
public Point Add(Point p)
Parameters
Type | Name | Description |
---|---|---|
Point | p | The Point to add to this Point. |
Returns
Type | Description |
---|---|
Point | A new Point. |
See Also
CompareWithLineSegment(Point, Point)
Compare this point with a finite line segment given by two Points.
Declaration
public double CompareWithLineSegment(Point p, Point q)
Parameters
Type | Name | Description |
---|---|---|
Point | p | one end of the finite line segment |
Point | q | the other end of the finite line segment |
Returns
Type | Description |
---|---|
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.
Declaration
public static double CompareWithLineSegment(double a1x, double a1y, double a2x, double a2y, double px, double py)
Parameters
Type | Name | Description |
---|---|---|
double | a1x | start of line segment A1 |
double | a1y | start of line segment A1 |
double | a2x | end of line segment A2 |
double | a2y | end of line segment A2 |
double | px | point to be compared with the line segment A1-A2 |
double | py | point to be compared with the line segment A1-A2 |
Returns
Type | Description |
---|---|
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.
Declaration
public double Direction(Point p)
Parameters
Type | Name | Description |
---|---|---|
Point | p | the other Point to which to measure the relative angle. |
Returns
Type | Description |
---|---|
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.
Declaration
public static double Direction(double px, double py, double qx, double qy)
Parameters
Type | Name | Description |
---|---|---|
double | px | |
double | py | |
double | qx | |
double | qy |
Returns
Type | Description |
---|---|
double |
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.
Declaration
public double Direction(double px, double py)
Parameters
Type | Name | Description |
---|---|---|
double | px | |
double | py |
Returns
Type | Description |
---|---|
double | The angle, in degrees, of the line from this Point to the given point. |
See Also
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.
Declaration
public static double DistanceLineSegmentSquared(double px, double py, double ax, double ay, double bx, double by)
Parameters
Type | Name | Description |
---|---|---|
double | px | |
double | py | |
double | ax | |
double | ay | |
double | bx | |
double | by |
Returns
Type | Description |
---|---|
double | The euclidean distance. |
DistanceSquared(Point)
Returns the square of the distance from this Point to a given Point.
Declaration
public double DistanceSquared(Point p)
Parameters
Type | Name | Description |
---|---|---|
Point | p | the other Point to measure to. |
Returns
Type | Description |
---|---|
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.
Declaration
public static double DistanceSquared(double px, double py, double qx, double qy)
Parameters
Type | Name | Description |
---|---|---|
double | px | |
double | py | |
double | qx | |
double | qy |
Returns
Type | Description |
---|---|
double |
DistanceSquared(double, double)
Returns the square of the distance from this point to a given point (px, py).
Declaration
public double DistanceSquared(double px, double py)
Parameters
Type | Name | Description |
---|---|---|
double | px | |
double | py |
Returns
Type | Description |
---|---|
double | The square of the euclidean distance. |
See Also
Equals(double, double)
Indicates whether the given point (x, y) is equal to this Point.
Declaration
public bool Equals(double x, double y)
Parameters
Type | Name | Description |
---|---|---|
double | x | |
double | y |
Returns
Type | Description |
---|---|
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.
Declaration
public override bool Equals(object obj)
Parameters
Type | Name | Description |
---|---|---|
object | obj | The Point to compare to the current Point. |
Returns
Type | Description |
---|---|
bool | True if the two Points have identical X and Y values, false otherwise. |
Overrides
See Also
EqualsApprox(Point)
Indicates whether the given Point is nearly equal to this Point.
Declaration
public bool EqualsApprox(Point p)
Parameters
Type | Name | Description |
---|---|---|
Point | p | The Point to compare to the current Point. |
Returns
Type | Description |
---|---|
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.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
int | A hash code for the current point structure. |
Overrides
IntersectingLineSegments(double, double, double, double, double, double, double, double)
This static function is true if two finite straight line segments intersect each other.
Declaration
public static bool IntersectingLineSegments(double a1x, double a1y, double a2x, double a2y, double b1x, double b1y, double b2x, double b2y)
Parameters
Type | Name | Description |
---|---|---|
double | a1x | |
double | a1y | |
double | a2x | |
double | a2y | |
double | b1x | |
double | b1y | |
double | b2x | |
double | b2y |
Returns
Type | Description |
---|---|
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.
Declaration
public bool IsReal()
Returns
Type | Description |
---|---|
bool |
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.
Declaration
public Point Normalize()
Returns
Type | Description |
---|---|
Point | A new Point. |
Offset(double, double)
Returns a new point by shifting this Point's values with the given DX and DY offsets.
Declaration
public Point Offset(double dx, double dy)
Parameters
Type | Name | Description |
---|---|---|
double | dx | |
double | dy |
Returns
Type | Description |
---|---|
Point | A new Point. |
See Also
Parse(object)
This is a convenience method for Parse(string) that can be used as a Converter.
Declaration
public static object Parse(object str)
Parameters
Type | Name | Description |
---|---|---|
object | str |
Returns
Type | Description |
---|---|
object |
Parse(string)
This static method can be used to read in a Point from a string that was produced by Stringify(Point).
Declaration
public static Point Parse(string str)
Parameters
Type | Name | Description |
---|---|---|
string | str |
Returns
Type | Description |
---|---|
Point |
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.
Declaration
public Point ProjectOntoLineSegment(Point p, Point q)
Parameters
Type | Name | Description |
---|---|---|
Point | p | one end of the finite line segment |
Point | q | the other end of the finite line segment |
Returns
Type | Description |
---|---|
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.
Declaration
public Point ProjectOntoLineSegment(double px, double py, double qx, double qy)
Parameters
Type | Name | Description |
---|---|---|
double | px | one end of the finite line segment |
double | py | one end of the finite line segment |
double | qx | the other end of the finite line segment |
double | qy | the other end of the finite line segment |
Returns
Type | Description |
---|---|
Point | A new Point. |
See Also
Rotate(double)
Returns a new Point that is this Point rotated about the origin by the given angle.
Declaration
public Point Rotate(double angle)
Parameters
Type | Name | Description |
---|---|---|
double | angle | an angle in degrees. |
Returns
Type | Description |
---|---|
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.
Declaration
public Point Scale(double sx, double sy)
Parameters
Type | Name | Description |
---|---|---|
double | sx | |
double | sy |
Returns
Type | Description |
---|---|
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.
Declaration
public static Point SetSpot(Rect r, Spot spot)
Parameters
Type | Name | Description |
---|---|---|
Rect | r | the Rect for which we are finding the point. |
Spot | spot | the Spot; IsSpot() must be true for this Spot. |
Returns
Type | Description |
---|---|
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.
Declaration
public static Point SetSpot(double x, double y, double w, double h, Spot spot)
Parameters
Type | Name | Description |
---|---|---|
double | x | The X coordinate of the Rect for which we are finding the point. |
double | y | The Y coordinate of the Rect for which we are finding the point. |
double | w | The Width of the Rect for which we are finding the point. |
double | h | The Height of the Rect for which we are finding the point. |
Spot | spot | the Spot; IsSpot() must be true for this Spot. |
Returns
Type | Description |
---|---|
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.
Declaration
public Point SnapToGrid(Point origin, Size cellsize)
Parameters
Type | Name | Description |
---|---|---|
Point | origin | the top-left point of the grid |
Size | cellsize | the size of each grid cell |
Returns
Type | Description |
---|---|
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.
Declaration
public Point SnapToGrid(double originx, double originy, double cellwidth, double cellheight)
Parameters
Type | Name | Description |
---|---|---|
double | originx | the x value of the top-left point of the grid |
double | originy | the y value of the top-left point of the grid |
double | cellwidth | the width of each grid cell -- must be a real number larger than zero |
double | cellheight | the height of each grid cell -- must be a real number larger than zero |
Returns
Type | Description |
---|---|
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).
Declaration
public static string Stringify(Point val)
Parameters
Type | Name | Description |
---|---|---|
Point | val |
Returns
Type | Description |
---|---|
string |
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.
Declaration
public static object Stringify(object pt)
Parameters
Type | Name | Description |
---|---|---|
object | pt |
Returns
Type | Description |
---|---|
object |
Subtract(Point)
Returns a new Point that is the difference of this Point and the x and y coordinates of the given Point.
Declaration
public Point Subtract(Point p)
Parameters
Type | Name | Description |
---|---|---|
Point | p | The Point to subtract from the current Point. |
Returns
Type | Description |
---|---|
Point | A new Point. |
See Also
ToString()
Returns a string representation of the point.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
string | A string representation of the current point. |
Overrides
Operators
operator ==(Point, Point)
Declaration
public static bool operator ==(Point left, Point right)
Parameters
Type | Name | Description |
---|---|---|
Point | left | |
Point | right |
Returns
Type | Description |
---|---|
bool |
operator !=(Point, Point)
Declaration
public static bool operator !=(Point left, Point right)
Parameters
Type | Name | Description |
---|---|---|
Point | left | |
Point | right |
Returns
Type | Description |
---|---|
bool |