public void DotWithVector_WorksInBothDirections() { var vec = new Vector(4.5f, 2.7f); var prod1 = Line1 * vec; var prod2 = vec * Line1; Assert.IsTrue(prod1 == prod2); }
public void AdditionWithVector_WorksInBothDirections() { var vec = new Vector(3.2f, 5.3f); var sum1 = Line1 + vec; var sum2 = vec + Line1; Assert.IsTrue(sum1 == sum2); }
public Line(Vector start, Vector end) { this.Start = start; this.End = end; }
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; }
public virtual Line PerpendicularThrough(Vector point) { throw new NotImplementedException("Not yet implemented."); }
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; }
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); }
public Vector Subtract(Vector subtrahend) { return new Vector(this.X - subtrahend.X, this.Y - subtrahend.Y); }
public bool Equals(Vector other) { if (other != null) { return this.GetHashCode() == other.GetHashCode(); } return false; }
public float Dot(Vector other) { return this.X * other.X + this.Y * other.Y + this.Z * other.Z; }
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); }
public Vector Add(Vector addend) { return new Vector(this.X + addend.X, this.Y + addend.Y); }
public void SubtractionWithVector_WorksInBothDirections() { var vec = new Vector(3.5f, 2.3f); var diff1 = Line1 - vec; var diff2 = vec - Line1; Assert.IsTrue(diff1 == -diff2); }
public void Render(Graphics g, Vector pos) { ToRender.Render(g, pos); }
public void EmptyConstructor_ReturnsZeroVector() { var zero = new Vector(); Assert.IsTrue(zero.X == 0 && zero.Y == 0 && zero.Length == 0); }
public void Setup() { this.Vector1 = new Vector(2.5f, 3.6f); this.Vector2 = new Vector(1.3f, 4.2f); }