Struct vec2d_t
Basic 2D point (or vector): a sequential-layout value type with mutable fields (the mirror of
the C++ geom::vec2<double>). It has no in-place mutating method: write a component
through x/y, X/Y or the indexer on a
variable, field or array element, or build a new value with WithAt(int, double).
public struct vec2d_t : IExpandToBox2d, IEquatable<vec2d_t>, ICsvRowIo, IEqualityOperators<vec2d_t, vec2d_t, bool>, IAdditionOperators<vec2d_t, vec2d_t, vec2d_t>, ISubtractionOperators<vec2d_t, vec2d_t, vec2d_t>, IMultiplyOperators<vec2d_t, double, vec2d_t>, IDivisionOperators<vec2d_t, double, vec2d_t>, IVec<double>, IFormattable
- Implements
- Inherited Members
- Extension Methods
Constructors
vec2d_t(Vec2i)
Creates a vector from Vec2i by converting integer coordinates to double.
public vec2d_t(Vec2i src)
Parameters
srcVec2iSource Vec2i vector with integer coordinates
vec2d_t(vec2d_t)
Copy ctor.
public vec2d_t(vec2d_t src)
Parameters
srcvec2d_tsrc
vec2d_t(double, double)
Ctor.
public vec2d_t(double x, double y)
Parameters
vec2d_t(Func<int, double>)
Ctor using a function that maps direction index to value.
public vec2d_t(Func<int, double> dirToValueFunc)
Parameters
vec2d_t(BinaryReader)
Ctor by bytes: x = reader.ReadDouble(); y = reader.ReadDouble();
public vec2d_t(BinaryReader reader)
Parameters
readerBinaryReaderreader
vec2d_t(int, double, double)
Ctor by direction offset. Direction 0,1 indicate x,y respectively.
public vec2d_t(int dir, double a, double b)
Parameters
dirintdirection offset
adoublevalue at direction (0+dir)%2
bdoublevalue at direction (1+dir)%2
vec2d_t(string)
Ctor by string. The format is (x,y).
public vec2d_t(string src)
Parameters
srcstringsrc
Fields
x
Value at x direction.
public double x
Field Value
y
Value at y direction.
public double y
Field Value
Properties
AbsSum
Sum of abs(x) and abs(y).
public readonly double AbsSum { get; }
Property Value
AllOne
Generate vec (1,1).
public static vec2d_t AllOne { get; }
Property Value
- vec2d_t
(1,1)
AmpPhase
Create AmpPhase instance.
public readonly AmpPhase AmpPhase { get; }
Property Value
Angle_deg
Angle in degree between vec(x,y) and vec(1,0).
public readonly double Angle_deg { get; }
Property Value
Angle_rad
Angle in radian between vec(x,y) and vec(1,0).
public readonly double Angle_rad { get; }
Property Value
CsvText
Csv text.
public readonly string CsvText { get; }
Property Value
CsvTitleText
Csv titles text.
public readonly string CsvTitleText { get; }
Property Value
IsAllFinite
public readonly bool IsAllFinite { get; }
Property Value
- bool
Is x,y,z all finite.
IsAllNaN
public readonly bool IsAllNaN { get; }
Property Value
IsAllNegativeInfinity
public readonly bool IsAllNegativeInfinity { get; }
Property Value
- bool
is x,y all NegativeInfinity.
IsAllPositiveInfinity
public readonly bool IsAllPositiveInfinity { get; }
Property Value
- bool
is x,y all PositiveInfinity.
IsAnyFinite
public readonly bool IsAnyFinite { get; }
Property Value
- bool
Is at least one of x,y finite.
IsAnyNaN
Is any member nan.
public readonly bool IsAnyNaN { get; }
Property Value
IsZero
public readonly bool IsZero { get; }
Property Value
- bool
Is zero vector. Which is
x == 0 && y == 0.
this[int]
Gets the element at the specified index. Writing goes through the concrete type's indexer or fields, never through this interface: a struct behind an interface is a boxed copy.
public double this[int dir] { readonly get; set; }
Parameters
dirint
Property Value
- double
The element at the specified index.
Length
Length.
public readonly double Length { get; }
Property Value
LengthSquare
Length square.
public readonly double LengthSquare { get; }
Property Value
MaxAbsDir
Get the direction of the max absolute value.
public readonly int MaxAbsDir { get; }
Property Value
MaxDir
Get the direction of the max value.
public readonly int MaxDir { get; }
Property Value
MaxValue
Get max value from {x,y}.
public readonly double MaxValue { get; }
Property Value
MinDir
Get the direction index with minimum value. If {x,y} is the smallest, return {0,1}.
public readonly int MinDir { get; }
Property Value
MinValue
Get min value from {x,y}.
public readonly double MinValue { get; }
Property Value
NaN
Generate NAN vec.
public static vec2d_t NaN { get; }
Property Value
- vec2d_t
(nan,nan)
NativeByteSize
public static int NativeByteSize { get; }
Property Value
- int
Byte size of the struct as core.dll sees it:
sizeof(vec2d_t), two doubles.
NegativeInfinity
Generate negative infinity vec.
public static vec2d_t NegativeInfinity { get; }
Property Value
- vec2d_t
(-inf,-inf)
PositiveInfinity
Generate positive infinity vec.
public static vec2d_t PositiveInfinity { get; }
Property Value
- vec2d_t
(inf,inf)
Rank
Dimension (i.e. Size) of the Vector.
public readonly int Rank { get; }
Property Value
UnitX
Generate vec (1,0).
public static vec2d_t UnitX { get; }
Property Value
- vec2d_t
(1,0)
UnitY
Generate vec (0,1).
public static vec2d_t UnitY { get; }
Property Value
- vec2d_t
(0,1)
X
Gets or sets the X coordinate value.
public double X { readonly get; set; }
Property Value
Y
Gets or sets the Y coordinate value.
public double Y { readonly get; set; }
Property Value
Zero
Generate vec (0,0).
public static vec2d_t Zero { get; }
Property Value
- vec2d_t
(0,0)
Methods
All(double)
Generate vec2d_t with all components set to the given value.
public static vec2d_t All(double v)
Parameters
vdouble
Returns
At(int)
Member at direction.
public readonly double At(int dir)
Parameters
dirintdirection
Returns
- double
member
Cross(vec2d_t)
Cross.
public readonly double Cross(vec2d_t src)
Parameters
srcvec2d_tsrc
Returns
- double
cross value
Dot(vec2d_t)
Dot.
public readonly double Dot(vec2d_t src)
Parameters
srcvec2d_tsrc
Returns
- double
dotted value
Equals(vec2d_t)
Indicates whether the current object is equal to another object of the same type.
public readonly bool Equals(vec2d_t other)
Parameters
othervec2d_tAn object to compare with this object.
Returns
Equals(vec2d_t, double)
check equals for each component with tolerance.
public readonly bool Equals(vec2d_t other, double toleranceForEachComponent)
Parameters
Returns
- bool
check equals for each component with tolerance.
Equals(object)
Indicates whether this instance and a specified object are equal.
public override readonly bool Equals(object obj)
Parameters
objobjectThe object to compare with the current instance.
Returns
- bool
true if
objand this instance are the same type and represent the same value; otherwise, false.
ExpandToBox2d(ref box2d_t)
Expands the destination box.
This function is usually used to compute the bounding box of elements.
box2d_t is a value type, so the destination is passed by reference
(the C++ expand_to_box2d(box2&) shape).
public readonly void ExpandToBox2d(ref box2d_t dst)
Parameters
dstbox2d_tDestination box, expanded in place
GenNaN()
Generate NAN vec.
public static vec2d_t GenNaN()
Returns
- vec2d_t
(nan,nan)
GenNegativeInfinity()
Generate negative infinity vec.
public static vec2d_t GenNegativeInfinity()
Returns
- vec2d_t
(-inf,-inf)
GenOne()
Generate vec (1,1).
public static vec2d_t GenOne()
Returns
- vec2d_t
(1,1)
GenPositiveInfinity()
Generate positive infinity vec.
public static vec2d_t GenPositiveInfinity()
Returns
- vec2d_t
(inf,inf)
GenUnitX()
Generate vec (1,0).
public static vec2d_t GenUnitX()
Returns
- vec2d_t
(1,0)
GenUnitY()
Generate vec (0,1).
public static vec2d_t GenUnitY()
Returns
- vec2d_t
(0,1)
GenZero()
Generate vec (0,0).
public static vec2d_t GenZero()
Returns
- vec2d_t
(0,0)
GetCosSquareWith(vec2d_t)
Get Cos(theta)^2. theta is the angle between this and src.
This function is faster than GetCosWith(vec2d_t) since it lacks one square root operation.
public readonly double GetCosSquareWith(vec2d_t src)
Parameters
srcvec2d_tone of edge vector
Returns
- double
Cos(theta)^2
GetCosWith(vec2d_t)
Get cos(angle). The angle is between v and this.
public readonly double GetCosWith(vec2d_t v)
Parameters
vvec2d_tv
Returns
- double
cos(angle)
GetCsvText(string)
Get CSV text with specified format.
public readonly string GetCsvText(string format)
Parameters
formatstringFormat string for each component
Returns
- string
CSV formatted string
GetEachNanToZero()
Creates a new vector with each NaN component replaced by 0.
public readonly vec2d_t GetEachNanToZero()
Returns
- vec2d_t
A new vector with NaN components set to 0
GetEachValueAbs()
Get a new vector with each value set to its absolute value.
public readonly vec2d_t GetEachValueAbs()
Returns
- vec2d_t
A new vector with absolute values
GetHashCode()
Returns the hash code for this instance.
public override readonly int GetHashCode()
Returns
- int
A 32-bit signed integer that is the hash code for this instance.
GetMulEach(vec2d_t)
Get a new vector with each component multiplied with the corresponding component of the given vector.
public readonly vec2d_t GetMulEach(vec2d_t vec)
Parameters
vecvec2d_tThe vector to multiply with
Returns
- vec2d_t
A new vector with multiplied components
GetNormalized()
Generate normalized vec.
public readonly vec2d_t GetNormalized()
Returns
- vec2d_t
Normalized vec
GetRadian(vec2d_t)
Get angle between this and v.
The angle has no sign.
This vector is not required to be an unit vector.
public readonly double GetRadian(vec2d_t v)
Parameters
vvec2d_tone of the edge vector. Not required to be an unit vector.
Returns
- double
Angle in radian
GetTransform(Func<double, double>)
Get the new vec2d_t by transforming each element by the function.
public readonly vec2d_t GetTransform(Func<double, double> transformingFunc)
Parameters
Returns
Interpolate(vec2d_t, vec2d_t, double)
Linear interpolate between a and b.
public static vec2d_t Interpolate(vec2d_t a, vec2d_t b, double alpha)
Parameters
Returns
- vec2d_t
interpolation
IsNormalized(double)
Check if this vector is normalized.
public readonly bool IsNormalized(double toleranceSquare = 1E-07)
Parameters
toleranceSquaredoubleTolerance for checking if length squared is 1
Returns
- bool
True if the vector is normalized
ParseByCsv(string)
Parses a vector from a CSV text string “x,y”.
public static vec2d_t ParseByCsv(string csvText)
Parameters
csvTextstringCSV formatted string containing the two components
Returns
- vec2d_t
A new vector parsed from the CSV text
ReadBin(BinaryReader)
Reads a vector written by WriteBin(BinaryWriter): two doubles x, y.
public static vec2d_t ReadBin(BinaryReader reader)
Parameters
readerBinaryReaderreader
Returns
- vec2d_t
the vector read
ToString()
Returns the fully qualified type name of this instance.
public override readonly string ToString()
Returns
- string
The fully qualified type name.
ToString(string)
To string with format: (x,y)
public readonly string ToString(string format)
Parameters
formatstringFormat string for the double values
Returns
- string
Formatted string representation of the vector
ToString(string, IFormatProvider)
Returns a string representation of the vector formatted according to the specified format.
public readonly string ToString(string format, IFormatProvider formatProvider)
Parameters
formatstringThe format to use for each component
formatProviderIFormatProviderThe format provider to use
Returns
- string
A formatted string representation of the vector
ToString(string, int)
Format the vector with padding.
public readonly string ToString(string format, int leftPadding)
Parameters
Returns
- string
Formatted string
WithAt(int, double)
Creates a copy of this vector with the component at dir replaced by value.
Direction 0,1 are x,y; a larger index addresses y, as At(int) does.
public readonly vec2d_t WithAt(int dir, double value)
Parameters
Returns
- vec2d_t
the modified copy
WriteBin(BinaryWriter)
Output to bytes: writer.Write(x); writer.Write(y);
public readonly void WriteBin(BinaryWriter writer)
Parameters
writerBinaryWriterwriter
Operators
operator +(vec2d_t, vec2d_t)
Plus.
public static vec2d_t operator +(vec2d_t left, vec2d_t right)
Parameters
Returns
- vec2d_t
a+b
operator /(vec2d_t, double)
a/d.
public static vec2d_t operator /(vec2d_t a, double d)
Parameters
Returns
- vec2d_t
a/d
operator ==(vec2d_t, vec2d_t)
Equality operator for comparing two vec2d_t objects.
public static bool operator ==(vec2d_t left, vec2d_t right)
Parameters
Returns
- bool
True if the vectors are equal, false otherwise
operator !=(vec2d_t, vec2d_t)
Inequality operator for comparing two vec2d_t objects.
public static bool operator !=(vec2d_t left, vec2d_t right)
Parameters
Returns
- bool
True if the vectors are not equal, false otherwise
operator *(vec2d_t, double)
a*s.
public static vec2d_t operator *(vec2d_t a, double s)
Parameters
Returns
- vec2d_t
a*s
operator -(vec2d_t, vec2d_t)
a-b.
public static vec2d_t operator -(vec2d_t a, vec2d_t b)
Parameters
Returns
- vec2d_t
a-b
operator -(vec2d_t)
Negate.
public static vec2d_t operator -(vec2d_t src)
Parameters
srcvec2d_tsrc
Returns
- vec2d_t
Negate