private static void AssertAreEqual(Vector3D expected, Vector3D actual, string message = null, params object[] args) { if (!Vector3D.AreEqual(expected, actual)) { Assert.AreEqual(expected, actual, message, args); } }
public void TestMultiplyVector() { const float a11 = 1.1f; const float a12 = 2.1f; const float a13 = 3.1f; const float a21 = 1.2f; const float a31 = 1.3f; const float a22 = 2.2f; const float a32 = 2.3f; const float a23 = 3.2f; const float a33 = 3.3f; const float b1 = 0.1f; const float b2 = 0.2f; const float b3 = 0.3f; var m = new Matrix3D(new[, ] { { a11, a12, a13 }, { a21, a22, a23 }, { a31, a32, a33 } }); var v = new Vector3D(b1, b2, b3); var r1 = new Vector3D(a11 * b1 + a12 * b2 + a13 * b3, a21 * b1 + a22 * b2 + a23 * b3, a31 * b1 + a32 * b2 + a33 * b3); Assert.IsTrue(Vector3D.AreEqual(m * v, r1)); var r2 = new Vector3D(b1 * a11 + b2 * a21 + b3 * a31, b1 * a12 + b2 * a22 + b3 * a32, b1 * a13 + b2 * a23 + b3 * a33); Assert.IsTrue(Vector3D.AreEqual(v * m, r2)); }
public void TestCross() { Vector3D v1 = new Vector3D(2.2F, -6.1F, 7.4F); Vector3D v2 = new Vector3D(-3.8F, 3.7F, 4.1F); Vector3D result = new Vector3D(-52.39F, -37.14F, -15.04F); Assert.IsTrue(Vector3D.AreEqual(v1.Cross(v2), result)); }
private static void AssertVolumeSlice(VolumeSlice actualSlice, int expectedRows, int expectedColumns, Vector3D expectedPositionPatient, Vector3D expectedRowOrientationPatient, Vector3D expectedColumnOrientationPatient, float expectedRowSpacing, float expectedColumnSpacing, float expectedSliceThickness, float?expectedSpacingBetweenSlices, string message = null, params object[] args) { const float tolerance = 1e-5f; var msg = !string.IsNullOrEmpty(message) ? "{0} (" + string.Format(message, args) + ")" : "{0}"; Assert.AreEqual(expectedRows, actualSlice.Rows, msg, "Rows"); Assert.AreEqual(expectedColumns, actualSlice.Columns, msg, "Columns"); var imagePositionPatient = ImagePositionPatient.FromString(actualSlice.ImagePositionPatient); Assert.IsNotNull(imagePositionPatient, "ImagePositionPatient"); var actualPositionPatient = new Vector3D((float)imagePositionPatient.X, (float)imagePositionPatient.Y, (float)imagePositionPatient.Z); if (!Vector3D.AreEqual(expectedPositionPatient, actualPositionPatient, tolerance)) { Assert.AreEqual(expectedPositionPatient, actualPositionPatient, msg, "ImagePositionPatient"); } var imageOrientationPatient = ImageOrientationPatient.FromString(actualSlice.ImageOrientationPatient); Assert.IsNotNull(imageOrientationPatient, "ImageOrientationPatient"); var actualRowOrientationPatient = new Vector3D((float)imageOrientationPatient.RowX, (float)imageOrientationPatient.RowY, (float)imageOrientationPatient.RowZ); var actualColumnOrientationPatient = new Vector3D((float)imageOrientationPatient.ColumnX, (float)imageOrientationPatient.ColumnY, (float)imageOrientationPatient.ColumnZ); if (!Vector3D.AreEqual(expectedRowOrientationPatient, actualRowOrientationPatient, tolerance)) { Assert.AreEqual(expectedRowOrientationPatient, actualRowOrientationPatient, msg, "ImageOrientationPatient.Row"); } if (!Vector3D.AreEqual(expectedColumnOrientationPatient, actualColumnOrientationPatient, tolerance)) { Assert.AreEqual(expectedColumnOrientationPatient, actualColumnOrientationPatient, msg, "ImageOrientationPatient.Column"); } var actualPixelSpacing = PixelSpacing.FromString(actualSlice.PixelSpacing); Assert.IsNotNull(actualPixelSpacing, "PixelSpacing"); Assert.AreEqual(expectedRowSpacing, actualPixelSpacing.Row, tolerance, msg, "PixelSpacing.Row"); Assert.AreEqual(expectedColumnSpacing, actualPixelSpacing.Column, tolerance, msg, "PixelSpacing.Column"); Assert.AreEqual(expectedSliceThickness, float.Parse(actualSlice.SliceThickness), tolerance, msg, "SliceThickness"); if (expectedSpacingBetweenSlices.HasValue) { Assert.AreEqual(expectedSpacingBetweenSlices.Value, float.Parse(actualSlice.SpacingBetweenSlices), tolerance, msg, "SpacingBetweenSlices"); } else { Assert.IsEmpty(actualSlice.SpacingBetweenSlices, msg, "SpacingBetweenSlices"); } }
public void TestDivide() { Vector3D result = new Vector3D(2.2F, -6.1F, 7.4F); Vector3D v1 = new Vector3D(6.82F, -18.91F, 22.94f); v1 = 3.1F / v1; Assert.IsTrue(Vector3D.AreEqual(v1, result)); }
public void TestSubtract() { Vector3D v1 = new Vector3D(2.2F, 6.1F, 7.4F); Vector3D v2 = new Vector3D(3.8F, 3.7F, 4.1F); Vector3D result = new Vector3D(-1.6F, 2.4F, 3.3F); Assert.IsTrue(Vector3D.AreEqual(v1 - v2, result)); v1 = new Vector3D(2.2F, -6.1F, 7.4F); v2 = new Vector3D(-3.8F, 3.7F, -4.1F); result = new Vector3D(6F, -9.8F, 11.5F); Assert.IsTrue(Vector3D.AreEqual(v1 - v2, result)); }
private bool GetTextBoxAdjustmentParameters(out PointF startPoint, out PointF endPoint, out float lengthOfLineThroughTextBox) { startPoint = _topParent.Points[0]; endPoint = _topParent.Points[1]; lengthOfLineThroughTextBox = 0; Vector3D lineDirection = new Vector3D(endPoint.X - startPoint.X, endPoint.Y - startPoint.Y, 0F); if (Vector3D.AreEqual(lineDirection, Vector3D.Null)) { return(false); } Vector3D lineUnit = lineDirection.Normalize(); Vector3D xUnit = new Vector3D(1F, 0, 0); Vector3D yUnit = new Vector3D(0, 1F, 0); float cosThetaX = Math.Abs(xUnit.Dot(lineUnit)); float cosThetaY = Math.Abs(yUnit.Dot(lineUnit)); float textWidth = _textGraphic.BoundingBox.Width; float textHeight = _textGraphic.BoundingBox.Height; if (cosThetaX >= cosThetaY) { // the distance along the line to where we want the outside right edge of the text to be. lengthOfLineThroughTextBox = cosThetaX * textWidth; if (lineDirection.X < 0) { startPoint = _topParent.Points[1]; endPoint = _topParent.Points[0]; } } else { // the distance along the line to where we want the outside bottom edge of the text to be. lengthOfLineThroughTextBox = cosThetaY * textHeight; if (lineDirection.Y < 0) { startPoint = _topParent.Points[1]; endPoint = _topParent.Points[0]; } } return(true); }
public void TestLinePlaneIntersection() { Vector3D planeNormal = new Vector3D(1, 1, 1); Vector3D pointInPlane = new Vector3D(1, 1, 1); Vector3D point1 = new Vector3D(0.5F, 0.5F, 0.5F); Vector3D point2 = new Vector3D(1.5F, 1.5F, 1.5F); Vector3D expected = new Vector3D(1, 1, 1); Vector3D intersection = Vector3D.GetLinePlaneIntersection(planeNormal, pointInPlane, point1, point2, true); // line segment intersects plane Assert.IsTrue(Vector3D.AreEqual(expected, intersection), "line-plane intersection is not what is expected!"); // infinite line intersects plane point2 = -point2; intersection = Vector3D.GetLinePlaneIntersection(planeNormal, pointInPlane, point1, point2, false); Assert.IsTrue(Vector3D.AreEqual(expected, intersection), "line-plane intersection is not what is expected!"); // line segment does not intersect plane intersection = Vector3D.GetLinePlaneIntersection(planeNormal, pointInPlane, point1, point2, true); Assert.AreEqual(intersection, null, "line-plane intersection is not what is expected!"); // line is in plane (no intersection) point1 = new Vector3D(1, 0, 0); point2 = new Vector3D(0, 0, 1); intersection = Vector3D.GetLinePlaneIntersection(planeNormal, pointInPlane, point1, point2, true); Assert.AreEqual(intersection, null, "line-plane intersection is not what is expected!"); // line is in plane (no intersection) intersection = Vector3D.GetLinePlaneIntersection(planeNormal, pointInPlane, point1, point2, false); Assert.AreEqual(intersection, null, "line-plane intersection is not what is expected!"); // intersection at infinity (sort of) point1 = new Vector3D(1, 0, 0); point2 = new Vector3D(0, 0, 0.99999991F); intersection = Vector3D.GetLinePlaneIntersection(planeNormal, pointInPlane, point1, point2, true); Assert.AreEqual(intersection, null, "line-plane intersection is not what is expected!"); // intersection at infinity (sort of), line segment does not intersect intersection = Vector3D.GetLinePlaneIntersection(planeNormal, pointInPlane, point1, point2, false); Assert.AreNotEqual(intersection, null, "line-plane intersection is not what is expected!"); }