Ejemplo n.º 1
0
        /// <summary>
        /// Resolves a compare operation.
        /// </summary>
        /// <param name="kind">The compare kind.</param>
        /// <param name="flags">The compare flags.</param>
        /// <param name="type">The type to compare.</param>
        /// <returns>The resolved compare operation.</returns>
        public static string GetCompareOperation(
            CompareKind kind,
            CompareFlags flags,
            ArithmeticBasicValueType type)
        {
            var unorderedFloatComparison = type.IsFloat() &&
                                           flags.HasFlag(CompareFlags.UnsignedOrUnordered);

            if (unorderedFloatComparison)
            {
                if (CompareUnorderedFloatOperations.TryGetValue(
                        (kind, type),
                        out string operation))
                {
                    return(operation);
                }
            }
            else
            {
                if (CompareOperations.TryGetValue((kind, type), out string operation))
                {
                    return(operation);
                }
            }
            throw new NotSupportedIntrinsicException(kind.ToString());
        }
Ejemplo n.º 2
0
        //--------------------------------------------------------------------------------------------------

        internal static bool CompareShape(TopoDS_Shape shape, string brepFile, CompareFlags flags = CompareFlags.CompareProperties)
        {
            // Get OCC Shape
            Assert.IsNotNull(shape);

            // Save to BREP ASCII
            var bytes = Occt.Helper.BRepExchange.WriteASCII(shape, flags.HasFlag(CompareFlags.SaveTriangulation));

            Assert.IsNotNull(bytes);
            Assert.IsNotEmpty(bytes);

            // Read file to compare
            var referenceBytes = TestData.GetTestData(brepFile + ".brep");

            if (referenceBytes == null)
            {
                TestData.WriteTestResult(bytes, brepFile + "_TestResult.brep");
                Assume.That(false, $"{brepFile}: Reference shape file not found.");
                return(false);
            }

            // Possible additions:  TopTools::Dump

            if (flags.HasFlag(CompareFlags.CompareBytes) && !bytes.SequenceEqual(referenceBytes))
            {
                TestData.WriteTestResult(bytes, brepFile + "_TestResult.brep");
                TestContext.WriteLine($"{brepFile}: Shape not equal to reference");
                return(false);
            }

            if (flags.HasFlag(CompareFlags.CompareText))
            {
                TestData.WriteTestResult(bytes, brepFile + "_TestResult.brep");
                AssertHelper.IsSameText(referenceBytes, bytes, AssertHelper.TextCompareFlags.IgnoreFloatPrecision);
                return(true);
            }

            if (flags.HasFlag(CompareFlags.CompareProperties))
            {
                var shape2 = Occt.Helper.BRepExchange.ReadASCII(referenceBytes);

                // Check transformation
                var trsf1 = shape.Location().Transformation();
                var trsf2 = shape2.Location().Transformation();
                for (int row = 1; row <= 3; row++)
                {
                    for (int col = 1; col <= 4; col++)
                    {
                        if (!trsf2.Value(row, col).IsEqual(trsf1.Value(row, col), 0.00000000001))
                        {
                            TestData.WriteTestResult(bytes, brepFile + "_TestResult.brep");
                            TestContext.WriteLine($"{brepFile}: Transformation is different at {col},{row}");
                            return(false);
                        }
                    }
                }

                string message;
                if (_CompareLinearProperties(shape, shape2, out message) ||
                    _CompareVolumeProperties(shape, shape2, out message) ||
                    _CompareSurfaceProperties(shape, shape2, out message))
                {
                    TestData.WriteTestResult(bytes, brepFile + "_TestResult.brep");
                    TestContext.WriteLine($"{brepFile}: {message}");
                    return(false);
                }
            }

            // Test was ok, delete result file if any left
            TestData.DeleteTestResult(brepFile + "_TestResult.brep");
            return(true);
        }