Created
November 7, 2020 16:03
-
-
Save KuroiLight/79a186cf98fc703b1702e9529509724b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public struct Vector | |
{ | |
public double X { get; private set; } | |
public double Y { get; private set; } | |
public Vector(POINT pt) | |
{ | |
X = pt.X; | |
Y = pt.Y; | |
} | |
public Vector(double x, double y) | |
{ | |
X = x; | |
Y = y; | |
} | |
public Vector((double x, double y) tuple) | |
{ | |
(X, Y) = tuple; | |
} | |
public Vector(Vector v) | |
{ | |
X = v.X; | |
Y = v.Y; | |
} | |
public Vector(POINT p1, POINT p2) | |
{ | |
var diff = p2 - p1; | |
X = diff.X; | |
Y = diff.Y; | |
} | |
public Vector Clamp(int absoluteMinMax) | |
{ | |
var absoluteMinMin = absoluteMinMax * -1; | |
return new Vector(this) | |
{ | |
X = Math.Clamp(X, absoluteMinMin, absoluteMinMax), | |
Y = Math.Clamp(Y, absoluteMinMin, absoluteMinMax) | |
}; | |
} | |
public Vector Multiply(double factor) | |
{ | |
return new Vector(X * factor, Y * factor); | |
} | |
public double Length() | |
{ | |
return Math.Abs(Math.Sqrt(X * X + Y * Y)); | |
} | |
public POINT ToPoint() | |
{ | |
return new POINT(X, Y); | |
} | |
public override string ToString() | |
{ | |
return $"/{X}:{Y}/"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment