Struct GeoPoint2D
- Namespace
- CADability
- Assembly
- CADability.dll
A 2-dimensional point with double x and y components.
[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
p1GeoPoint2Dfirst point
p2GeoPoint2Dsecond 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
p1GeoPoint2Dfirst point
p2GeoPoint2Dsecond point
ratiodoubleposition 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
cGeoPoint2DOriginal point
ddoubleDistance to the original point
aAngleAngle 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
pGeoPoint2DOriginal point
xdoubleOffset in x
ydoubleOffset in y
GeoPoint2D(params GeoPoint2D[])
Constructs a ne GeoPoint at the geometric middle of the provided points
public GeoPoint2D(params GeoPoint2D[] p)
Parameters
pGeoPoint2D[]
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
dataIJsonReadStructsupplies the values
GeoPoint2D(double, double)
Creates a new GeoPoint2D with the given components
public GeoPoint2D(double x, double y)
Parameters
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
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
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
x
x-component
public double x
Field Value
y
y-component
public double y
Field Value
Properties
IsNan
True, when at least one component is NaN; the negation of IsValid.
public bool IsNan { get; }
Property Value
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
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
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
polygonGeoPoint2D[]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
pGeoPoint2D[]the points
Returns
- GeoPoint2D
the center of the points
Equals(object)
public override bool Equals(object o)
Parameters
oobject
Returns
GetHashCode()
public override int GetHashCode()
Returns
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
dataIJsonWriteDatareceives 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
infoSerializationInforeceives the data
contextStreamingContextthe 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
fromGeoPoint2DStartpoint of the line
toGeoPoint2DEndpoint 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
dataIJsonReadDatanot used
ToString()
public override string ToString()
Returns
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
pGeoPoint2DOriginal point
vGeoVector2DOffset
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
p1GeoPoint2Dp2GeoPoint2D
Returns
operator |(GeoPoint2D, GeoPoint2D)
Returns the distance of the two points
public static double operator |(GeoPoint2D p1, GeoPoint2D p2)
Parameters
p1GeoPoint2Dfirst point
p2GeoPoint2Dsecond 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
aGeoPoint2Dfirst point
bGeoPoint2Dsecond 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
p1GeoPoint2Dfirst point
p2GeoPoint2Dsecond 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
pGeoPoint2Dthe 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
p1GeoPoint2Dfirst point
p2GeoPoint2Dsecond 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
aGeoPoint2Dend point of the vector
bGeoPoint2Dstart 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
pGeoPoint2Dthe point
vGeoVector2Dthe offset
Returns
- GeoPoint2D
the offset point