Beispiel #1
0
 public void DotWithVector_WorksInBothDirections()
 {
     var vec = new Vector(4.5f, 2.7f);
     var prod1 = Line1 * vec;
     var prod2 = vec * Line1;
     Assert.IsTrue(prod1 == prod2);
 }
Beispiel #2
0
 public void AdditionWithVector_WorksInBothDirections()
 {
     var vec = new Vector(3.2f, 5.3f);
     var sum1 = Line1 + vec;
     var sum2 = vec + Line1;
     Assert.IsTrue(sum1 == sum2);
 }
Beispiel #3
0
 public Line(Vector start, Vector end)
 {
     this.Start = start;
     this.End = end;
 }
Beispiel #4
0
 public virtual Vector PointOfIntersection2D(Line intersector)
 {
     var p = new Vector(-intersector.Y, intersector.X);
     var h = ((-this.Start + intersector.Start) * p) / (this * p);
     return this.Start + this * h;
 }
Beispiel #5
0
 public virtual Line PerpendicularThrough(Vector point)
 {
     throw new NotImplementedException("Not yet implemented.");
 }
Beispiel #6
0
 public virtual bool Intersects2D(Line intersector)
 {
     bool intersection = false;
     var p = new Vector(-intersector.Y, intersector.X);
     var h = ((-this.Start + intersector.Start) * p) / (this * p);
     intersection = h >= 0 && h <= 1;
     if (intersection)
     {
         p = new Vector(-this.Y, this.X);
         h = ((-intersector.Start + this.Start) * p) / (intersector * p);
         intersection = h >= 0 && h <= 1;
     }
     return intersection;
 }
Beispiel #7
0
 internal Vector Clamp(Vector minValues, Vector maxValues, out int bx, out int by, out int bz)
 {
     float nx = X, ny = Y, nz = Z;
     bx = by = bz = 0;
     if (X < minValues.X)
     {
         nx = minValues.X;
         bx = -1;
     }
     else if (X > maxValues.X)
     {
         nx = maxValues.X;
         bx = 1;
     }
     if (Y < minValues.Y)
     {
         ny = minValues.Y;
         by = -1;
     }
     else if (Y > maxValues.Y)
     {
         ny = maxValues.Y;
         by = 1;
     }
     if (Z < minValues.Z)
     {
         nz = minValues.Z;
         bz = -1;
     }
     else if (Z > maxValues.Z)
     {
         nz = maxValues.Z;
         bz = 1;
     }
     return new Vector(nx, ny, nz);
 }
Beispiel #8
0
 public Vector Subtract(Vector subtrahend)
 {
     return new Vector(this.X - subtrahend.X, this.Y - subtrahend.Y);
 }
Beispiel #9
0
 public bool Equals(Vector other)
 {
     if (other != null)
     {
         return this.GetHashCode() == other.GetHashCode();
     }
     return false;
 }
Beispiel #10
0
 public float Dot(Vector other)
 {
     return this.X * other.X + this.Y * other.Y + this.Z * other.Z;
 }
Beispiel #11
0
 public Vector Cross(Vector other)
 {
     var u = this;
     var v = other;
     return new Vector(
         this.Y * other.Z - this.Z * other.Y,
         this.Z * other.X - this.X * other.Z,
         this.X * other.Y - this.Y * other.X);
 }
Beispiel #12
0
 public Vector Add(Vector addend)
 {
     return new Vector(this.X + addend.X, this.Y + addend.Y);
 }
Beispiel #13
0
 public void SubtractionWithVector_WorksInBothDirections()
 {
     var vec = new Vector(3.5f, 2.3f);
     var diff1 = Line1 - vec;
     var diff2 = vec - Line1;
     Assert.IsTrue(diff1 == -diff2);
 }
Beispiel #14
0
 public void Render(Graphics g, Vector pos)
 {
     ToRender.Render(g, pos);
 }
Beispiel #15
0
 public void EmptyConstructor_ReturnsZeroVector()
 {
     var zero = new Vector();
     Assert.IsTrue(zero.X == 0 && zero.Y == 0 && zero.Length == 0);
 }
Beispiel #16
0
 public void Setup()
 {
     this.Vector1 = new Vector(2.5f, 3.6f);
     this.Vector2 = new Vector(1.3f, 4.2f);
 }