Table of Contents

Struct GeoPoint2D

Namespace
CADability
Assembly
CADability.dll

A 2-dimensional point with double x and y components. Keep in mind that this is a value type. Passing a value type as a (non ref) parameter and changing it's value inside the invoked method leaves the original unchanged.

[JsonVersion(serializeAsStruct = true, version = 1)]
public struct GeoPoint2D : ISerializable, IJsonSerialize
Implements
Inherited Members

Constructors

GeoPoint2D(GeoPoint2D, GeoPoint2D)

Creates a new GeoPoint2D in the middle of the two given points

public GeoPoint2D(GeoPoint2D p1, GeoPoint2D p2)

Parameters

p1 GeoPoint2D

first point

p2 GeoPoint2D

second point

GeoPoint2D(GeoPoint2D, GeoPoint2D, double)

Constructs a new GeoPoint2D by linear interpolation between two points: (1 - ratio) * p1 + ratio * p2. A ratio of 0.0 yields p1, 1.0 yields p2, values outside the range [0, 1] extrapolate beyond the two points.

public GeoPoint2D(GeoPoint2D p1, GeoPoint2D p2, double ratio)

Parameters

p1 GeoPoint2D

first point

p2 GeoPoint2D

second point

ratio double

position between the two points

GeoPoint2D(GeoPoint2D, double, Angle)

Creates a new GeoPoint2D at the specified offset to the provided GeoPoint2D c

public GeoPoint2D(GeoPoint2D c, double d, Angle a)

Parameters

c GeoPoint2D

Original point

d double

Distance to the original point

a Angle

Angle to the original point

GeoPoint2D(GeoPoint2D, double, double)

Creates a new GeoPoint2D at the specified offset to the provided GeoPoint2D p

public GeoPoint2D(GeoPoint2D p, double x, double y)

Parameters

p GeoPoint2D

Original point

x double

Offset in x

y double

Offset in y

GeoPoint2D(params GeoPoint2D[])

Constructs a ne GeoPoint at the geometric middle of the provided points

public GeoPoint2D(params GeoPoint2D[] p)

Parameters

p GeoPoint2D[]

GeoPoint2D(IJsonReadStruct)

Constructor for the JSON deserialization (IJsonSerialize): reads the two components in the order GetObjectData(IJsonWriteData) wrote them. It is found by reflection, there is no need to call it directly.

public GeoPoint2D(IJsonReadStruct data)

Parameters

data IJsonReadStruct

supplies the values

GeoPoint2D(double, double)

Creates a new GeoPoint2D with the given components

public GeoPoint2D(double x, double y)

Parameters

x double

x-component

y double

y-component

Fields

CompareX

A non-generic IComparer that orders points by their x-component only, for use with Sort(Array, IComparer). GeoPoint2D.GeoPoint2DICompareX is the generic counterpart.

public static IComparer CompareX

Field Value

IComparer

Invalid

A point marked as invalid, both components are NaN. Returned by methods that could not compute a point; test with IsValid, because comparisons with NaN are always false. This is a static field rather than a property for speed; do not assign to it.

public static GeoPoint2D Invalid

Field Value

GeoPoint2D

Origin

The origin (0.0, 0.0). This is a static field rather than a property for speed; do not assign to it.

public static GeoPoint2D Origin

Field Value

GeoPoint2D

x

x-component

public double x

Field Value

double

y

y-component

public double y

Field Value

double

Properties

IsNan

True, when at least one component is NaN; the negation of IsValid.

public bool IsNan { get; }

Property Value

bool

IsValid

True, when neither component is NaN, false for Invalid and for points that could not be computed. Infinite components are not detected, unlike IsValid.

public bool IsValid { get; }

Property Value

bool

PointF

The point as a PointF with single precision components, for use with System.Drawing. Precision is lost in the conversion.

public PointF PointF { get; }

Property Value

PointF

Methods

Area(GeoPoint2D[])

Returns the signed area of the closed polygon through the given points (the last point is connected to the first). The area is positive when the polygon runs counterclockwise and negative when it runs clockwise, so the sign also tells the orientation of an outline. Returns 0.0 for an empty array.

public static double Area(GeoPoint2D[] polygon)

Parameters

polygon GeoPoint2D[]

the vertices of the polygon in order

Returns

double

the signed area

Center(params GeoPoint2D[])

Returns the geometric center (arithmetic mean) of the given points. The list must not be empty.

public static GeoPoint2D Center(params GeoPoint2D[] p)

Parameters

p GeoPoint2D[]

the points

Returns

GeoPoint2D

the center of the points

Equals(object)

public override bool Equals(object o)

Parameters

o object

Returns

bool

GetHashCode()

public override int GetHashCode()

Returns

int

GetObjectData(IJsonWriteData)

Writes the two components for the JSON serialization (IJsonSerialize). The struct is serialized inline as a plain list of values and read back by the constructor taking an IJsonReadStruct.

public void GetObjectData(IJsonWriteData data)

Parameters

data IJsonWriteData

receives the values

GetObjectData(SerializationInfo, StreamingContext)

Writes the data of this object for the legacy binary serialization (ISerializable). Files are written in the JSON format (IJsonSerialize) now; the binary format is still read.

public void GetObjectData(SerializationInfo info, StreamingContext context)

Parameters

info SerializationInfo

receives the data

context StreamingContext

the destination of the serialization

IsLeftOf(GeoPoint2D, GeoPoint2D)

Returns true, if this point is left of the given line.

public bool IsLeftOf(GeoPoint2D from, GeoPoint2D to)

Parameters

from GeoPoint2D

Startpoint of the line

to GeoPoint2D

Endpoint of the line

Returns

bool

true if left

SetObjectData(IJsonReadData)

Does nothing. Value types serialized inline are restored by the constructor taking an IJsonReadStruct; this method only exists to satisfy IJsonSerialize.

public void SetObjectData(IJsonReadData data)

Parameters

data IJsonReadData

not used

ToString()

public override string ToString()

Returns

string

ToVector()

Returns a 2d vector that points to this point from the origin

public GeoVector2D ToVector()

Returns

GeoVector2D

The 2d vector

Operators

operator +(GeoPoint2D, GeoVector2D)

Returns the 2D point which is the offset of v from p.

public static GeoPoint2D operator +(GeoPoint2D p, GeoVector2D v)

Parameters

p GeoPoint2D

Original point

v GeoVector2D

Offset

Returns

GeoPoint2D

The offset point

operator &(GeoPoint2D, GeoPoint2D)

Square distance. Not a very nice operator symbol, but cannot overload ||, which I would prefer

public static double operator &(GeoPoint2D p1, GeoPoint2D p2)

Parameters

p1 GeoPoint2D
p2 GeoPoint2D

Returns

double

operator |(GeoPoint2D, GeoPoint2D)

Returns the distance of the two points

public static double operator |(GeoPoint2D p1, GeoPoint2D p2)

Parameters

p1 GeoPoint2D

first point

p2 GeoPoint2D

second point

Returns

double

the distance

operator /(GeoPoint2D, GeoPoint2D)

Returns the point in the middle of the two points, same as new GeoPoint2D(a, b). An unusual use of the division operator, kept as a shorthand.

public static GeoPoint2D operator /(GeoPoint2D a, GeoPoint2D b)

Parameters

a GeoPoint2D

first point

b GeoPoint2D

second point

Returns

GeoPoint2D

the midpoint

operator ==(GeoPoint2D, GeoPoint2D)

Determines whether two points are exactly equal. Use IsEqual(GeoPoint2D, GeoPoint2D) if you need more control over precision.

public static bool operator ==(GeoPoint2D p1, GeoPoint2D p2)

Parameters

p1 GeoPoint2D

first point

p2 GeoPoint2D

second point

Returns

bool

true if equal

implicit operator double[](GeoPoint2D)

Converts the point to an array of its components, e.g. to pass it to numerical routines.

public static implicit operator double[](GeoPoint2D p)

Parameters

p GeoPoint2D

the point

Returns

double[]

the array {x, y}

operator !=(GeoPoint2D, GeoPoint2D)

Determines whether two points are not exactly equal. Use IsEqual(GeoPoint2D, GeoPoint2D) if you need more control over precision.

public static bool operator !=(GeoPoint2D p1, GeoPoint2D p2)

Parameters

p1 GeoPoint2D

first point

p2 GeoPoint2D

second point

Returns

bool

true if not equal

operator -(GeoPoint2D, GeoPoint2D)

Returns the vector that points from b to a.

public static GeoVector2D operator -(GeoPoint2D a, GeoPoint2D b)

Parameters

a GeoPoint2D

end point of the vector

b GeoPoint2D

start point of the vector

Returns

GeoVector2D

the vector from b to a

operator -(GeoPoint2D, GeoVector2D)

Subtracts a vector (offset) from a point.

public static GeoPoint2D operator -(GeoPoint2D p, GeoVector2D v)

Parameters

p GeoPoint2D

the point

v GeoVector2D

the offset

Returns

GeoPoint2D

the offset point