예제 #1
0
        /// <summary>
        /// Test to see if the two paths are the same in that:
        /// 1. They have the same polygon count.
        /// 2. There are matching polygons in that:
        ///    a. Same point count.
        ///    b. Same orientation.
        /// </summary>
        public static bool AreSame(ClipExecutionData test, PolygonPath path2)
        {
            if (test.Solution.Count != path2.Count)
            {
                return(false);
            }

            for (var i = 0; i < path2.Count; i++)
            {
                var polygon1 = path2[i];

                // Order to make comparison easier.
                polygon1.OrderBottomLeftFirst();

                for (var j = 0; j < test.Solution.Count; j++)
                {
                    var polygon2 = test.Solution[j];

                    // Vertex counts need to match
                    if (polygon1.Count != polygon2.Count)
                    {
                        continue;
                    }

                    // Orientations need to match
                    if (polygon1.Orientation != polygon2.Orientation)
                    {
                        continue;
                    }

                    // Count the number of points that match in order across the polygons.
                    // Given both polygons are ordered by bottom left, then
                    // points at each index should match if they are the same polygon.
                    var pointMatchCount = polygon1
                                          .Where((point, k) => point == polygon2[k])
                                          .Count();

                    // Did the point match count equal the vertex count?
                    if (pointMatchCount != polygon1.Count)
                    {
                        continue;
                    }

                    // This is a matching polygon so remove from both solutions
                    // and decrement outer loop index.
                    path2.RemoveAt(i--);
                    test.Solution.RemoveAt(j);

                    // break from inner loop to outer loop
                    break;
                }
            }

            return(true);
        }
예제 #2
0
        private static void ReadExecutionData(IDictionary <int, ClipExecutionData> data, IReadOnlyList <string> lines, ref int lineNumber)
        {
            const string matchCaption       = @"^CAPTION:\s*(\d+)\s*\.\s*(.*)\s*?($|^)";
            const string matchClipOperation = @"^CLIPTYPE:\s*(.*)\s*$";
            const string matchFillType      = @"^FILLTYPE:\s*(.*)\s*$";

            var executionData = new ClipExecutionData();

            // Read caption and test number
            var match = Regex.Match(lines[lineNumber++], matchCaption);

            if (!match.Success)
            {
                throw new Exception($"Expecting caption at line {lineNumber}.");
            }

            executionData.TestNumber = int.Parse(match.Groups[1].Value);
            executionData.Caption    = match.Groups[2].Value;

            // Read clip type
            match = Regex.Match(lines[lineNumber++], matchClipOperation);
            if (!match.Success)
            {
                throw new Exception($"Expecting clip operation at line {lineNumber}.");
            }
            executionData.ClipOperation = (ClipOperation)Enum.Parse(typeof(ClipOperation), match.Groups[1].Value, true);

            // Read fill type
            match = Regex.Match(lines[lineNumber++], matchFillType);
            if (!match.Success)
            {
                throw new Exception($"Expecting fill type at line {lineNumber}.");
            }
            executionData.FillType = (PolygonFillType)Enum.Parse(typeof(PolygonFillType), match.Groups[1].Value, true);

            // Read subjects
            executionData.Subjects = ReadPath("SUBJECTS", lines, ref lineNumber);

            // Read clip
            executionData.Clips = ReadPath("CLIPS", lines, ref lineNumber);

            // Read solution
            executionData.Solution = ReadPath("SOLUTION", lines, ref lineNumber);

            data.Add(executionData.TestNumber, executionData);
        }