Table of Contents

Struct vec2d_t

Namespace
Hi.Geom
Assembly
HiGeom.dll

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

src Vec2i

Source Vec2i vector with integer coordinates

vec2d_t(vec2d_t)

Copy ctor.

public vec2d_t(vec2d_t src)

Parameters

src vec2d_t

src

vec2d_t(double, double)

Ctor.

public vec2d_t(double x, double y)

Parameters

x double

x

y double

y

vec2d_t(Func<int, double>)

Ctor using a function that maps direction index to value.

public vec2d_t(Func<int, double> dirToValueFunc)

Parameters

dirToValueFunc Func<int, double>

Function that maps direction index to value

vec2d_t(BinaryReader)

Ctor by bytes: x = reader.ReadDouble(); y = reader.ReadDouble();

public vec2d_t(BinaryReader reader)

Parameters

reader BinaryReader

reader

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

dir int

direction offset

a double

value at direction (0+dir)%2

b double

value at direction (1+dir)%2

vec2d_t(string)

Ctor by string. The format is (x,y).

public vec2d_t(string src)

Parameters

src string

src

Fields

x

Value at x direction.

public double x

Field Value

double

y

Value at y direction.

public double y

Field Value

double

Properties

AbsSum

Sum of abs(x) and abs(y).

public readonly double AbsSum { get; }

Property Value

double

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

AmpPhase

Angle_deg

Angle in degree between vec(x,y) and vec(1,0).

public readonly double Angle_deg { get; }

Property Value

double

Angle_rad

Angle in radian between vec(x,y) and vec(1,0).

public readonly double Angle_rad { get; }

Property Value

double

CsvText

Csv text.

public readonly string CsvText { get; }

Property Value

string

CsvTitleText

Csv titles text.

public readonly string CsvTitleText { get; }

Property Value

string

IsAllFinite

public readonly bool IsAllFinite { get; }

Property Value

bool

Is x,y,z all finite.

IsAllNaN

public readonly bool IsAllNaN { get; }

Property Value

bool

is x,y all NaN.

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

bool

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

dir int

Property Value

double

The element at the specified index.

Length

Length.

public readonly double Length { get; }

Property Value

double

LengthSquare

Length square.

public readonly double LengthSquare { get; }

Property Value

double

MaxAbsDir

Get the direction of the max absolute value.

public readonly int MaxAbsDir { get; }

Property Value

int

MaxDir

Get the direction of the max value.

public readonly int MaxDir { get; }

Property Value

int

MaxValue

Get max value from {x,y}.

public readonly double MaxValue { get; }

Property Value

double

MinDir

Get the direction index with minimum value. If {x,y} is the smallest, return {0,1}.

public readonly int MinDir { get; }

Property Value

int

MinValue

Get min value from {x,y}.

public readonly double MinValue { get; }

Property Value

double

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

int

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

double

Y

Gets or sets the Y coordinate value.

public double Y { readonly get; set; }

Property Value

double

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

v double

Returns

vec2d_t

At(int)

Member at direction.

public readonly double At(int dir)

Parameters

dir int

direction

Returns

double

member

Cross(vec2d_t)

Cross.

public readonly double Cross(vec2d_t src)

Parameters

src vec2d_t

src

Returns

double

cross value

Dot(vec2d_t)

Dot.

public readonly double Dot(vec2d_t src)

Parameters

src vec2d_t

src

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

other vec2d_t

An object to compare with this object.

Returns

bool

true if the current object is equal to the other parameter; otherwise, false.

Equals(vec2d_t, double)

check equals for each component with tolerance.

public readonly bool Equals(vec2d_t other, double toleranceForEachComponent)

Parameters

other vec2d_t

other vec

toleranceForEachComponent double

tolerance for each component

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

obj object

The object to compare with the current instance.

Returns

bool

true if obj and 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

dst box2d_t

Destination 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

src vec2d_t

one 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

v vec2d_t

v

Returns

double

cos(angle)

GetCsvText(string)

Get CSV text with specified format.

public readonly string GetCsvText(string format)

Parameters

format string

Format 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

vec vec2d_t

The 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

v vec2d_t

one 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

transformingFunc Func<double, double>

Returns

vec2d_t

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

a vec2d_t

a

b vec2d_t

b

alpha double

ratio

Returns

vec2d_t

interpolation

IsNormalized(double)

Check if this vector is normalized.

public readonly bool IsNormalized(double toleranceSquare = 1E-07)

Parameters

toleranceSquare double

Tolerance 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

csvText string

CSV 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

reader BinaryReader

reader

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

format string

Format 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

format string

The format to use for each component

formatProvider IFormatProvider

The 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

format string

Format string for each component

leftPadding int

Left padding for each component

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

dir int

direction index

value double

new component value

Returns

vec2d_t

the modified copy

WriteBin(BinaryWriter)

Output to bytes: writer.Write(x); writer.Write(y);

public readonly void WriteBin(BinaryWriter writer)

Parameters

writer BinaryWriter

writer

Operators

operator +(vec2d_t, vec2d_t)

Plus.

public static vec2d_t operator +(vec2d_t left, vec2d_t right)

Parameters

left vec2d_t

a

right vec2d_t

b

Returns

vec2d_t

a+b

operator /(vec2d_t, double)

a/d.

public static vec2d_t operator /(vec2d_t a, double d)

Parameters

a vec2d_t

a

d double

d

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

left vec2d_t

Left operand

right vec2d_t

Right operand

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

left vec2d_t

Left operand

right vec2d_t

Right operand

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

a vec2d_t

a

s double

s

Returns

vec2d_t

a*s

operator -(vec2d_t, vec2d_t)

a-b.

public static vec2d_t operator -(vec2d_t a, vec2d_t b)

Parameters

a vec2d_t

a

b vec2d_t

b

Returns

vec2d_t

a-b

operator -(vec2d_t)

Negate.

public static vec2d_t operator -(vec2d_t src)

Parameters

src vec2d_t

src

Returns

vec2d_t

Negate