/// <summary> /// Transforms a point by multiplying it with this matrix. /// </summary> /// <param name="x">X component of the point.</param> /// <param name="y">Y component of the point.</param> /// <returns>A Point2D describing the transformed input.</returns> public Point2D TransformVector(Double x, Double y) { DoubleComponent[] transferPoints = new DoubleComponent[] { x, y, 1 }; MatrixProcessor.Multiply(transferPoints, this); return(new Point2D((Double)transferPoints[0], (Double)transferPoints[1])); }
public void ElementsTest1() { Matrix2D m1 = Matrix2D.Identity; Matrix2D m2 = new Matrix2D(0, 0, 0, 0, 0, 0); Matrix2D m3 = new Matrix2D(1, 2, 4, 5, 3, 6); Assert.AreEqual(3, m1.RowCount); Assert.AreEqual(3, m2.ColumnCount); DoubleComponent[][] expected = new DoubleComponent[][] { new DoubleComponent[] {1, 4, 0}, new DoubleComponent[] {2, 5, 0}, new DoubleComponent[] {3, 6, 1} }; DoubleComponent[][] actual = m3.Elements; Assert.AreEqual(expected[0][0], actual[0][0]); Assert.AreEqual(expected[0][1], actual[0][1]); Assert.AreEqual(expected[0][2], actual[0][2]); Assert.AreEqual(expected[1][0], actual[1][0]); Assert.AreEqual(expected[1][1], actual[1][1]); Assert.AreEqual(expected[1][2], actual[1][2]); Assert.AreEqual(expected[2][0], actual[2][0]); Assert.AreEqual(expected[2][1], actual[2][1]); Assert.AreEqual(expected[2][2], actual[2][2]); m1.Elements = expected; Assert.AreEqual(m1, m3); Assert.IsTrue(m1.Equals(m3 as IMatrixD)); }
public void ElementsTest1() { ColorMatrix m1 = ColorMatrix.Identity; ColorMatrix m2 = new ColorMatrix(0.5, 0.5, 0.5, 1, 0, 0, 0); Assert.AreEqual(5, m1.RowCount); Assert.AreEqual(5, m2.ColumnCount); DoubleComponent[][] expected = new DoubleComponent[][] { new DoubleComponent[] { 0.5, 0, 0, 0, 0 }, new DoubleComponent[] { 0, 0.5, 0, 0, 0 }, new DoubleComponent[] { 0, 0, 0.5, 0, 0 }, new DoubleComponent[] { 0, 0, 0, 1, 0 }, new DoubleComponent[] { 0, 0, 0, 0, 1 } }; DoubleComponent[][] actual = m2.Elements; Assert.AreEqual(expected[0][0], actual[0][0]); Assert.AreEqual(expected[0][1], actual[0][1]); Assert.AreEqual(expected[0][2], actual[0][2]); Assert.AreEqual(expected[1][0], actual[1][0]); Assert.AreEqual(expected[1][1], actual[1][1]); Assert.AreEqual(expected[1][2], actual[1][2]); Assert.AreEqual(expected[2][0], actual[2][0]); Assert.AreEqual(expected[2][1], actual[2][1]); Assert.AreEqual(expected[2][2], actual[2][2]); m1.Elements = expected; Assert.AreEqual(m1, m2); Assert.IsTrue(m1.Equals(m2 as IMatrix<DoubleComponent>)); }
public void ElementsTest1() { Matrix2D m1 = Matrix2D.Identity; Matrix2D m2 = new Matrix2D(0, 0, 0, 0, 0, 0); Matrix2D m3 = new Matrix2D(1, 2, 4, 5, 3, 6); Assert.Equal(3, m1.RowCount); Assert.Equal(3, m2.ColumnCount); DoubleComponent[][] expected = new DoubleComponent[][] { new DoubleComponent[] {1, 4, 0}, new DoubleComponent[] {2, 5, 0}, new DoubleComponent[] {3, 6, 1} }; Assert.Equal(expected[0][0], m3[0, 0]); Assert.Equal(expected[0][1], m3[0, 1]); Assert.Equal(expected[0][2], m3[0, 2]); Assert.Equal(expected[1][0], m3[1, 0]); Assert.Equal(expected[1][1], m3[1, 1]); Assert.Equal(expected[1][2], m3[1, 2]); Assert.Equal(expected[2][0], m3[2, 0]); Assert.Equal(expected[2][1], m3[2, 1]); Assert.Equal(expected[2][2], m3[2, 2]); //m1.Elements = expected; //Assert.Equal(m1, m3); //Assert.True(m1.Equals(m3 as IMatrixD)); }
public void ElementsTest1() { ColorMatrix m1 = ColorMatrix.Identity; ColorMatrix m2 = new ColorMatrix(0.5, 0.5, 0.5, 1, 0, 0, 0, 0); Assert.Equal(5, m1.RowCount); Assert.Equal(5, m2.ColumnCount); DoubleComponent[][] expected = new DoubleComponent[][] { new DoubleComponent[] {0.5, 0, 0, 0, 0}, new DoubleComponent[] {0, 0.5, 0, 0, 0}, new DoubleComponent[] {0, 0, 0.5, 0, 0}, new DoubleComponent[] {0, 0, 0, 1, 0}, new DoubleComponent[] {0, 0, 0, 0, 1} }; //DoubleComponent[][] actual = m2.Elements; Assert.Equal(expected[0][0], m2[0, 0]); Assert.Equal(expected[0][1], m2[0, 1]); Assert.Equal(expected[0][2], m2[0, 2]); Assert.Equal(expected[1][0], m2[1, 0]); Assert.Equal(expected[1][1], m2[1, 1]); Assert.Equal(expected[1][2], m2[1, 2]); Assert.Equal(expected[2][0], m2[2, 0]); Assert.Equal(expected[2][1], m2[2, 1]); Assert.Equal(expected[2][2], m2[2, 2]); //m1.Elements = expected; m1 = new ColorMatrix(new Matrix(MatrixFormat.RowMajor, expected)); Assert.Equal(m1, m2); Assert.True(m1.Equals(m2 as IMatrix<DoubleComponent>)); }
/// <summary> /// Creates a new non-empty ViewSize3D with the given values. /// </summary> /// <param name="width">Width of the measurement.</param> /// <param name="height">Height of the measurement.</param> /// <param name="depth">Depth of the measurement.</param> public Size3D(DoubleComponent width, DoubleComponent height, DoubleComponent depth) { _width = width; _height = height; _depth = depth; _hasValue = true; }
public Point3D(DoubleComponent x, DoubleComponent y, DoubleComponent z) { _x = x; _y = y; _z = z; _hasValue = true; }
/// <summary> /// Gets or sets an element in the matrix. /// </summary> /// <param name="row">The index of the row of the element.</param> /// <param name="column">The index of the column of the element.</param> /// <returns></returns> DoubleComponent IMatrixD.this[Int32 row, Int32 column] { get { checkIndexes(row, column); if (row == 0) { if (column == 0) { return(_left); } else { return(_top); } } else { if (column == 0) { return(_right); } else { return(_bottom); } } } set { checkIndexes(row, column); if (row == 0) { if (column == 0) { _left = value; } else { _top = value; } } else { if (column == 0) { _right = value; } else { _bottom = value; } } _hasValue = true; } }
/// <summary> /// Creates a new Rectangle2D with the given values for the sides. /// </summary> /// <param name="left">The X value of the left side.</param> /// <param name="top">The Y value of the top side.</param> /// <param name="right">The X value of the right side.</param> /// <param name="bottom">The Y value of the bottom side.</param> public Rectangle2D(Double left, Double top, Double right, Double bottom) { _left = left; _right = right; _top = top; _bottom = bottom; _hasValue = true; }
/// <summary> /// Creates a new Rectangle2D with the upper-left at /// <paramref name="location"/>, and the given <paramref name="size"/>. /// </summary> /// <param name="location">The upper-left point of the Rectangle2D.</param> /// <param name="size">The size of the Rectangle2D.</param> public Rectangle2D(Point2D location, Size2D size) { _left = location.X; _top = location.Y; _right = _left + size.Width; _bottom = _top + size.Height; _hasValue = true; }
public Rectangle3D(Point3D location, Size3D size) { _xMin = location.X; _yMin = location.Y; _zMin = location.Z; _xMax = _xMin.Add(size.Width); _yMax = _yMin.Add(size.Height); _zMax = _zMin.Add(size.Depth); _hasValue = true; }
public void DotProduct() { IVector <DoubleComponent> Test1 = MatrixFactory <DoubleComponent> .CreateVector3D(10, 1, 2); IVector <DoubleComponent> Test2 = MatrixFactory <DoubleComponent> .CreateVector3D(1, 0, 0); DoubleComponent DotResult = Test2.Dot(Test1); Assert.IsTrue(DotResult.Equals(10)); }
public Rectangle3D(Double xMin, Double xMax, Double yMin, Double yMax, Double zMin, Double zMax) { _xMin = xMin; _xMax = xMax; _yMin = yMin; _yMax = yMax; _zMin = zMin; _zMax = zMax; _hasValue = true; }
/// <summary> /// Scales the matrix by the given <paramref name="amount"/> in all orthoganal columns. /// </summary> /// <param name="amount">Amount to scale by.</param> public void Scale(DoubleComponent amount) { if (IsEmpty) { return; } _right = _right.Multiply(amount); _bottom = _bottom.Multiply(amount); }
/// <summary> /// Translates the affine transform by the given amount in each dimension. /// </summary> /// <param name="amount">Amount to translate by.</param> public void Translate(DoubleComponent amount) { if (IsEmpty) { return; } _left = _left.Add(amount); _top = _top.Add(amount); _right = _right.Add(amount); _bottom = _bottom.Add(amount); }
private void recomputeBoundingRegion() { #warning not creating bounding region if (BoundingRegion.RowCount == 0 || BoundingRegion.ColumnCount == 0) { DoubleComponent[][] boxElements = new DoubleComponent[BoundingRegion.RowCount][]; for (Int32 rowIndex = 0; rowIndex < BoundingRegion.RowCount; rowIndex++) { boxElements[rowIndex] = new DoubleComponent[BoundingRegion.ColumnCount]; } } Boolean recorded = false; foreach (TPoint point in Path.Points) { DoubleComponent[] components = point.Components; for (Int32 componentIndex = 0; componentIndex < components.Length; componentIndex++) { for (Int32 rowIndex = 0; rowIndex < BoundingRegion.RowCount; rowIndex++) { if (components[componentIndex].GreaterThan(BoundingRegion[rowIndex, componentIndex])) { #warning What happened here? } BoundingRegion[rowIndex, componentIndex] = components[componentIndex]; } if (!recorded) { recorded = true; } else { if (components[componentIndex].GreaterThan(BoundingRegion[0, componentIndex])) { BoundingRegion[0, componentIndex] = components[componentIndex]; } if (components[componentIndex].GreaterThan(BoundingRegion[1, componentIndex])) { BoundingRegion[1, componentIndex] = components[componentIndex]; } } } } }
public void TransformTest() { IAffineTransformMatrix <DoubleComponent> a = MatrixFactory <DoubleComponent> .NewIdentity(VectorDimension.Two); a.Translate(MatrixFactory <DoubleComponent> .CreateVector2D(10, 20)); DoubleComponent x = 10; DoubleComponent y = 20; DoubleComponent newx = 0; DoubleComponent newy = 0; a.Transform(ref newx, ref newy); Assert.AreEqual((double)x, (double)newx, .001); Assert.AreEqual((double)y, (double)newy, .001); }
public Point2D(Double[] elements) { if (elements == null) { throw new ArgumentNullException("elements"); } if (elements.Length != 2) { throw new ArgumentException("Elements array must have only 2 components."); } _x = elements[0]; _y = elements[1]; _hasValue = true; }
public Point2D(IVectorD vector) { if (vector == null) { throw new ArgumentNullException("vector"); } if (vector.ComponentCount != 2) { throw new ArgumentException("Elements array must have only 2 components."); } _x = vector[0]; _y = vector[1]; _hasValue = true; }
/// <summary> /// Scales the matrix by the given vector <paramref name="scaleVector"/>. /// </summary> /// <param name="scaleVector"> /// A vector with scaling components which /// correspond to the affine transform dimensions. /// </param> public void Scale(IVectorD scaleVector) { if (scaleVector == null) { throw new ArgumentNullException("scaleVector"); } if (scaleVector.ComponentCount != 2) { throw new ArgumentException("Number of components in scale vector must be 2.", "scaleVector"); } if (IsEmpty) { return; } _right = _right.Multiply(scaleVector[0]); _bottom = _bottom.Multiply(scaleVector[1]); }
/// <summary> /// Translates the affine transform by the given translation vector. /// </summary> /// <param name="translateVector"> /// A vector whose components will translate the transform /// in the corresponding dimension. /// </param> public void Translate(IVectorD translateVector) { if (translateVector == null) { throw new ArgumentNullException("translateVector"); } if (translateVector.ComponentCount != 2) { throw new ArgumentException("Number of components in scale vector must be 2.", "translateVector"); } if (IsEmpty) { return; } _left = _left.Add(translateVector[0]); _top = _top.Add(translateVector[1]); _right = _right.Add(translateVector[0]); _bottom = _bottom.Add(translateVector[1]); }
DoubleComponent IVectorD.this[Int32 index] { get { checkIndex(index); return(this[index]); } set { checkIndex(index); if (index == 0) { _width = value; } else { _height = value; } _hasValue = true; } }
public void ElementsTest1() { Rectangle2D r1 = Rectangle2D.Empty; Rectangle2D r2 = Rectangle2D.Zero; Rectangle2D r3 = new Rectangle2D(0, 0, 10, 10); // 2007-09-27 - codekaizen - // The column count of an empty Rectangle2D used to be // 0, indicating that it was empty, but this prevented // operations which wanted to manage the Rectangle2D as // an array of arrays of points from property sizing them. //Assert.Equal(0, (r1 as IMatrixD).ColumnCount); Assert.Equal(2, (r1 as IMatrixD).ColumnCount); Assert.Equal(2, (r2 as IMatrixD).ColumnCount); Assert.Equal(2, (r3 as IMatrixD).ColumnCount); DoubleComponent[][] expected = new DoubleComponent[][] { new DoubleComponent[] { 0, 0 }, new DoubleComponent[] { 10, 10 } }; //DoubleComponent[][] actual = (r3 as IMatrixD).Elements; IMatrixD r3Matrix = r1; Assert.Equal(expected[0][0], r3Matrix[0, 0]); Assert.Equal(expected[0][1], r3Matrix[0, 1]); Assert.Equal(expected[1][0], r3Matrix[1, 0]); Assert.Equal(expected[1][1], r3Matrix[1, 1]); //IMatrixD r1Matrix = r1; //r1Matrix.Elements = expected; //r1 = (Rectangle2D) r1Matrix; //Assert.False(r1.IsEmpty); //Assert.Equal(r1, r3); }
public void InvertTest() { //Affine a = Affine.NewIdentity(); IAffineTransformMatrix <DoubleComponent> a = MatrixFactory <DoubleComponent> .NewIdentity(VectorDimension.Two); a.Translate( MatrixFactory <DoubleComponent> .CreateVector2D( M.New <DoubleComponent>(10), M.New <DoubleComponent>(10))); IAffineTransformMatrix <DoubleComponent> b = MatrixFactory <DoubleComponent> .CreateAffine(a); b = b.Inverse; DoubleComponent x = 100; DoubleComponent y = 100; DoubleComponent newx = x; DoubleComponent newy = y; IVector <DoubleComponent> v1 = MatrixFactory <DoubleComponent> .CreateVector2D( M.New <DoubleComponent>(100), M.New <DoubleComponent>(100)); IVector <DoubleComponent> v2 = a.TransformVector(v1); IVector <DoubleComponent> v3 = b.TransformVector(v2); //a.Transform(ref newx, ref newy); //b.Transform(ref newx, ref newy); Assert.AreEqual((double)v1[0], (double)v3[0], .001); Assert.AreEqual((double)v1[1], (double)v3[1], .001); }
/// <summary> /// Computes whether the <see cref="Matrix2D"/> instance /// is equal to some <paramref name="other"/>. /// </summary> /// <param name="other"> /// The other <see cref="Matrix2D"/> to test for equality. /// </param> /// <returns> /// <see langword="true"/> if they are equal; <see langword="false"/> otherwise. /// </returns> public Boolean Equals(Matrix2D other) { if (ReferenceEquals(other, null)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } Int32 length = _elements.Length; DoubleComponent[] x = _elements; DoubleComponent[] y = other._elements; for (Int32 i = 0; i < length; i += 3) { DoubleComponent x1 = x[i]; DoubleComponent y1 = y[i]; DoubleComponent x2 = x[i + 1]; DoubleComponent y2 = y[i + 1]; DoubleComponent x3 = x[i + 2]; DoubleComponent y3 = y[i + 2]; if (!x1.Equals(y1) || !x2.Equals(y2) || !x3.Equals(y3)) { return(false); } } return(true); }
/// <summary> /// Transforms a point by multiplying it with this matrix. /// </summary> /// <param name="x">X component of the point.</param> /// <param name="y">Y component of the point.</param> /// <returns>A Point2D describing the transformed input.</returns> public Point2D TransformVector(Double x, Double y) { DoubleComponent[] transferPoints = new DoubleComponent[] { x, y, 1 }; MatrixProcessor.Multiply(transferPoints, this); return new Point2D((Double)transferPoints[0], (Double)transferPoints[1]); }
public Point2D(Double x, Double y) { _x = x; _y = y; _hasValue = true; }
public Size2D(Double width, Double height) { _width = width; _height = height; _hasValue = true; }
public static Matrix ScalarMultiply(Matrix matrix, DoubleComponent scalar) { return Instance.Operations.ScalarMultiply(matrix, scalar); }
public static IMatrix <DoubleComponent> ScalarMultiply(IMatrix <DoubleComponent> matrix, DoubleComponent scalar) { return(Instance.Operations.ScalarMultiply(matrix, scalar)); }
public static void Multiply(Matrix multiplier, DoubleComponent[] columnVector) { Instance.Operations.Multiply(multiplier, columnVector); }
public void GetComponents(out DoubleComponent a, out DoubleComponent b, out DoubleComponent c) { GetComponents(out a, out b); c = Double.NaN; }
public void GetComponents(out DoubleComponent a, out DoubleComponent b) { a = _width; b = _height; }
public void GetComponents(out DoubleComponent a, out DoubleComponent b, out DoubleComponent c, out DoubleComponent d) { GetComponents(out a, out b, out c); d = Double.NaN; }
public static Matrix ScalarMultiply(Matrix matrix, DoubleComponent scalar) { return(Instance.Operations.ScalarMultiply(matrix, scalar)); }
public static IMatrix<DoubleComponent> ScalarMultiply(IMatrix<DoubleComponent> matrix, DoubleComponent scalar) { return Instance.Operations.ScalarMultiply(matrix, scalar); }
public void ElementsTest1() { Rectangle2D r1 = Rectangle2D.Empty; Rectangle2D r2 = Rectangle2D.Zero; Rectangle2D r3 = new Rectangle2D(0, 0, 10, 10); // 2007-09-27 - codekaizen - // The column count of an empty Rectangle2D used to be // 0, indicating that it was empty, but this prevented // operations which wanted to manage the Rectangle2D as // an array of arrays of points from property sizing them. //Assert.Equal(0, (r1 as IMatrixD).ColumnCount); Assert.Equal(2, (r1 as IMatrixD).ColumnCount); Assert.Equal(2, (r2 as IMatrixD).ColumnCount); Assert.Equal(2, (r3 as IMatrixD).ColumnCount); DoubleComponent[][] expected = new DoubleComponent[][] { new DoubleComponent[] {0, 0}, new DoubleComponent[] {10, 10} }; //DoubleComponent[][] actual = (r3 as IMatrixD).Elements; IMatrixD r3Matrix = r1; Assert.Equal(expected[0][0], r3Matrix[0, 0]); Assert.Equal(expected[0][1], r3Matrix[0, 1]); Assert.Equal(expected[1][0], r3Matrix[1, 0]); Assert.Equal(expected[1][1], r3Matrix[1, 1]); //IMatrixD r1Matrix = r1; //r1Matrix.Elements = expected; //r1 = (Rectangle2D) r1Matrix; //Assert.False(r1.IsEmpty); //Assert.Equal(r1, r3); }
public static void Multiply(DoubleComponent[] rowVector, Matrix multiplier) { Instance.Operations.Multiply(rowVector, multiplier); }
public void ElementsTest1() { Rectangle2D r1 = Rectangle2D.Empty; Rectangle2D r2 = Rectangle2D.Zero; Rectangle2D r3 = new Rectangle2D(0, 0, 10, 10); Assert.AreEqual(0, (r1 as IMatrixD).ColumnCount); Assert.AreEqual(2, (r2 as IMatrixD).ColumnCount); Assert.AreEqual(2, (r3 as IMatrixD).ColumnCount); DoubleComponent[][] expected = new DoubleComponent[][] { new DoubleComponent[] { 0, 0 }, new DoubleComponent[] { 10, 10 } }; DoubleComponent[][] actual = (r3 as IMatrixD).Elements; Assert.AreEqual(expected[0][0], actual[0][0]); Assert.AreEqual(expected[0][1], actual[0][1]); Assert.AreEqual(expected[1][0], actual[1][0]); Assert.AreEqual(expected[1][1], actual[1][1]); IMatrixD r1Matrix = r1; r1Matrix.Elements = expected; r1 = (Rectangle2D)r1Matrix; Assert.IsFalse(r1.IsEmpty); Assert.AreEqual(r1, r3); }
/// <summary> /// Scales the matrix by the given <paramref name="amount"/> in all orthoganal columns. /// </summary> /// <param name="amount">Amount to scale by.</param> /// <param name="order">Order in which to apply the operation.</param> void ITransformMatrix <DoubleComponent> .Scale(DoubleComponent amount, MatrixOperationOrder order) { throw new NotSupportedException(); }
public void GetComponents(out DoubleComponent a, out DoubleComponent b) { a = _x; b = _y; }