Table of Contents

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

x double

The x value.

y double

The y value.

Properties

X

Gets or sets the x value of the Point.

public double X { readonly get; set; }

Property Value

double

Y

Gets or sets the y value of the Point.

public double Y { readonly get; set; }

Property Value

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.

public Point Add(Point p)

Parameters

p Point

The 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

p Point

one end of the finite line segment

q Point

the other end of the finite line segment

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 double

start of line segment A1

a1y double

start of line segment A1

a2x double

end of line segment A2

a2y double

end of line segment A2

px double

point to be compared with the line segment A1-A2

py double

point 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 Point

the 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

px double
py double

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

px double
py double
qx double
qy double

Returns

double

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

px double
py double
ax double
ay double
bx double
by double

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 Point

the 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

px double
py double

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

px double
py double
qx double
qy double

Returns

double

Equals(double, double)

Indicates whether the given point (x, y) is equal to this Point.

public bool Equals(double x, double y)

Parameters

x double
y double

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 object

The 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 Point

The 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

a1x double
a1y double
a2x double
a2y double
b1x double
b1y double
b2x double
b2y double

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

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.

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

dx double
dy double

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

object

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

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.

public Point ProjectOntoLineSegment(Point p, Point q)

Parameters

p Point

one end of the finite line segment

q Point

the other end of the finite line segment

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 double

one end of the finite line segment

py double

one end of the finite line segment

qx double

the other end of the finite line segment

qy double

the 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 double

an 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

sx double
sy double

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 Rect

the Rect for which we are finding the point.

spot Spot

the 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 double

The X coordinate of the Rect for which we are finding the point.

y double

The Y coordinate of the Rect for which we are finding the point.

w double

The Width of the Rect for which we are finding the point.

h double

The Height of the Rect for which we are finding the point.

spot Spot

the 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

origin Point

the top-left point of the grid

cellsize Size

the size of each grid cell

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 double

the x value of the top-left point of the grid

originy double

the y value of the top-left point of the grid

cellwidth double

the width of each grid cell -- must be a real number larger than zero

cellheight double

the 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

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.

public static object Stringify(object pt)

Parameters

pt object

Returns

object

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

val Point

the Point

digits int

the number of decimals to output

Returns

string

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

object

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 Point

The 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

left Point
right Point

Returns

bool

operator !=(Point, Point)

public static bool operator !=(Point left, Point right)

Parameters

left Point
right Point

Returns

bool