Пример #1
0
        public void Test_InterceptRec_Equality_Exact1()
        {
            InterceptRec intercept  = new InterceptRec(1, 2, 3, 4, 5, 6);
            InterceptRec intercept2 = new InterceptRec(1, 2, 3, 4, 5, 6);

            Assert.Equal(intercept, intercept2);
        }
Пример #2
0
        public void Test_InterceptRec_Inequality_InExact()
        {
            InterceptRec intercept  = new InterceptRec(0.999f, 1.999f, 3, 4, 4.999f, 6);
            InterceptRec intercept2 = new InterceptRec(1, 2, 3, 4, 5, 6);

            Assert.False(intercept.Equals(intercept2), "Intercept recs not equal when they should be (1)");
            Assert.False(intercept.Equals(intercept2.OriginX, intercept2.OriginY, intercept2.ProfileItemIndex), "Intercept recs not equal when they should be (2)");
        }
Пример #3
0
        public void Test_InterceptRec_Equality_Exact2()
        {
            InterceptRec intercept  = new InterceptRec(1, 2, 3, 4, 5, 6);
            InterceptRec intercept2 = new InterceptRec(1, 2, 3, 4, 5, 6);

            Assert.Equal(intercept, intercept2);
            Assert.True(intercept.Equals(intercept2), "Intercept recs not equal when they should be (1)");
            Assert.True(intercept.Equals(intercept2.OriginX, intercept2.OriginY, intercept2.ProfileItemIndex), "Intercept recs not equal when they should be (2)");
        }
Пример #4
0
        public void Test_InterceptRec_Compare()
        {
            var intercept1 = new InterceptRec(1, 2, 3, 4, 5, 6);
            var intercept2 = new InterceptRec(1, 2, 3, 4, 5, 6);
            var intercept3 = new InterceptRec(1, 2, 3, 4, 0, 6);

            intercept1.Compare(intercept1, intercept2).Should().Be(0);
            intercept1.Compare(intercept1, intercept3).Should().Be(1);
            intercept3.Compare(intercept3, intercept1).Should().Be(-1);
        }
Пример #5
0
        public void Test_InterceptRec_Creation()
        {
            InterceptRec intercept = new InterceptRec(1, 2, 3, 4, 5, 6);

            Assert.True(intercept.OriginX == 1 &&
                        intercept.OriginY == 2 &&
                        intercept.MidPointX == 3 &&
                        intercept.MidPointY == 4 &&
                        intercept.ProfileItemIndex == 5 &&
                        intercept.InterceptLength == 6);
        }
Пример #6
0
        public void Test_InterceptList_AddPoint2()
        {
            InterceptList list = new InterceptList();

            var newPoint = new InterceptRec(1, 2, 0, 0, 5, 0);

            list.AddPoint(newPoint);

            Assert.True(1 == list.Count, "List count not 1 after addition");
            Assert.True(list.Items[0].Equals(newPoint), "New point and list point not same after addition");
        }
Пример #7
0
        public void Test_InterceptList_MergeInterceptLists_SameItems()
        {
            InterceptList list1 = new InterceptList();
            InterceptList list2 = new InterceptList();

            var newPoint = new InterceptRec(1, 2, 3, 4, 5, 6);

            list1.AddPoint(newPoint);
            list2.AddPoint(newPoint);

            InterceptList mergedList = new InterceptList();

            mergedList.MergeInterceptLists(list1, list2);

            Assert.True(1 == mergedList.Count, $"merged list count != after merge, = {mergedList.Count}");
            Assert.Equal(newPoint, mergedList.Items[0]);
        }
Пример #8
0
        public void Test_InterceptList_MergeInterceptLists_UniqueItems_InOrder()
        {
            InterceptList list1 = new InterceptList();
            InterceptList list2 = new InterceptList();

            var newPoint1 = new InterceptRec(1, 2, 3, 4, 5, 6);
            var newPoint2 = new InterceptRec(2, 3, 4, 5, 6, 7);

            list1.AddPoint(newPoint1);
            list2.AddPoint(newPoint2);

            InterceptList mergedList = new InterceptList();

            mergedList.MergeInterceptLists(list1, list2);

            Assert.True(2 == mergedList.Count, $"merged list count != after merge, = {mergedList.Count}");
            Assert.Equal(newPoint1, mergedList.Items[0]);
            Assert.Equal(newPoint2, mergedList.Items[1]);
        }
Пример #9
0
        public void Test_InterceptList_MergeInterceptLists_SameItems_InExactOutOfOrder()
        {
            InterceptList list1 = new InterceptList();
            InterceptList list2 = new InterceptList();

            var newPoint1 = new InterceptRec(1.99995f, 2.99995f, 3, 4, 5.99995f, 6);
            var newPoint2 = new InterceptRec(2, 3, 4, 5, 6, 7);

            list1.AddPoint(newPoint2);
            list2.AddPoint(newPoint1);

            InterceptList mergedList = new InterceptList();

            mergedList.MergeInterceptLists(list1, list2);

            Assert.True(1 == mergedList.Count, $"merged list count != after merge, = {mergedList.Count}");
            Assert.Equal(newPoint1, mergedList.Items[0]);
            Assert.Equal(newPoint2, mergedList.Items[0]);
        }
Пример #10
0
        /// <summary>
        /// Computes a profile line across the TIN surface between two points
        /// </summary>
        /// <param name="startPoint"></param>
        /// <param name="endPoint"></param>
        /// <param name="startStation"></param>
        /// <returns></returns>
        private List <XYZS> Compute(XYZ startPoint, XYZ endPoint, double startStation)
        {
            // 1. Determine the set of sub grids the profile line cross using the same logic used to
            // compute cell cross by production data profiling

            // ...
            var cellProfileBuilder = new OptimisedTTMCellProfileBuilder(Index.CellSize, true);

            if (!cellProfileBuilder.Build(new [] { startPoint, endPoint }, startStation))
            {
                return(null);
            }

            // 2. Iterate across each sub grid in turn locating all triangles in that sub grid
            // that intersect the line and sorting them according to the distance of the closest
            // intercept from the start of the line

            // Get the resulting vertical and horizontal intercept list
            var VtHzIntercepts = cellProfileBuilder.VtHzIntercepts;

            // Iterate through the intercepts looking for ones that hit a sub grid in the TTM
            // spatial index that contains triangles

            var intercepts = new List <XYZS>();
            var plane      = new Plane();

            // Add an initial intercept if the start point is located within a triangle
            AddEndIntercept(startPoint, intercepts, startStation);

            int prevCellX = int.MinValue, preCellY = int.MinValue;

            for (int interceptIndex = 0; interceptIndex < VtHzIntercepts.Count; interceptIndex++)
            {
                InterceptRec intercept = VtHzIntercepts.Items[interceptIndex];

                if (!Index.CalculateIndexOfCellContainingPosition(intercept.MidPointX, intercept.MidPointY, out int cellX, out int cellY))
                {
                    Log.LogWarning($"No cell address computable for location {intercept.MidPointX}:{intercept.MidPointY}");
                    continue;
                }

                // Make sure we are not repeating a sub grid (can happen as a result of how the initial HZ/Vt intersects are constructed
                if (prevCellX == cellX && preCellY == cellY)
                {
                    // This sub grid has just been processed...
                    continue;
                }

                prevCellX = cellX;
                preCellY  = cellY;

                var subGrid = Index.LocateSubGridContaining(cellX, cellY);

                if (subGrid == null)
                {
                    // No triangles are present in this 'node' sub grid. Move to the next sub grid, the implicit gap will be
                    // picked up when triangle intercepts are aggregated together to form the final profile line
                    continue;
                }

                if (!(subGrid is TriangleArrayReferenceSubGrid referenceSubGrid))
                {
                    Log.LogCritical($"Sub grid is not a TriangleArrayReferenceSubGrid, is is a {subGrid.GetType()}");
                    continue;
                }

                subGrid.GetSubGridCellIndex(cellX, cellY, out byte subGridX, out byte subGridY);

                TriangleArrayReference referenceList = referenceSubGrid.Items[subGridX, subGridY];

                if (referenceList.Count == 0)
                {
                    // There are no triangles in this 'leaf' sub grid
                    continue;
                }

                // Locate all triangles in this sub grid that intersect the profile line
                var endIndex = referenceList.TriangleArrayIndex + referenceList.Count;
                for (int i = referenceList.TriangleArrayIndex; i < endIndex; i++)
                {
                    int      triIndex = Indices[i];
                    Triangle tri      = TTM.Triangles.Items[triIndex];

                    // Does this triangle intersect the line?
                    XYZ v0 = TTM.Vertices.Items[tri.Vertex0];
                    XYZ v1 = TTM.Vertices.Items[tri.Vertex1];
                    XYZ v2 = TTM.Vertices.Items[tri.Vertex2];

                    bool planeInited = false;

                    if (LineIntersection.LinesIntersect(startPoint.X, startPoint.Y, endPoint.X, endPoint.Y, v0.X, v0.Y, v1.X, v1.Y, out double intersectX, out double intersectY, true, out bool linesAreColinear))
                    {
                        // If the lines are co-linear there is nothing more to do. The two vertices need to be added and no more checking is required
                        if (linesAreColinear)
                        {
                            intercepts.Add(new XYZS(v0.X, v0.Y, v0.Z, startStation + MathUtilities.Hypot(startPoint.X - v0.X, startPoint.Y - v0.Y), triIndex));
                            intercepts.Add(new XYZS(v1.X, v1.Y, v1.Z, startStation + MathUtilities.Hypot(startPoint.X - v1.X, startPoint.Y - v1.Y), triIndex));
                            continue;
                        }

                        planeInited = true;
                        plane.Init(v0, v1, v2);

                        // Otherwise, add the intercept location to the list
                        intercepts.Add(new XYZS(intersectX, intersectY, plane.Evaluate(intersectX, intersectY), startStation + MathUtilities.Hypot(startPoint.X - intersectX, startPoint.Y - intersectY), triIndex));
                    }

                    if (LineIntersection.LinesIntersect(startPoint.X, startPoint.Y, endPoint.X, endPoint.Y, v0.X, v0.Y, v2.X, v2.Y, out intersectX, out intersectY, true, out linesAreColinear))
                    {
                        // If the lines are co-linear there is nothing more to do. The two vertices need to be added and no more checking is required
                        if (linesAreColinear)
                        {
                            intercepts.Add(new XYZS(v0.X, v0.Y, v0.Z, startStation + MathUtilities.Hypot(startPoint.X - v0.X, startPoint.Y - v0.Y), triIndex));
                            intercepts.Add(new XYZS(v2.X, v2.Y, v2.Z, startStation + MathUtilities.Hypot(startPoint.X - v2.X, startPoint.Y - v2.Y), triIndex));
                            continue;
                        }

                        if (!planeInited)
                        {
                            planeInited = true;
                            plane.Init(v0, v1, v2);
                        }

                        // Otherwise, add the intercept location to the list
                        intercepts.Add(new XYZS(intersectX, intersectY, plane.Evaluate(intersectX, intersectY), startStation + MathUtilities.Hypot(startPoint.X - intersectX, startPoint.Y - intersectY), triIndex));
                    }

                    if (LineIntersection.LinesIntersect(startPoint.X, startPoint.Y, endPoint.X, endPoint.Y, v1.X, v1.Y, v2.X, v2.Y, out intersectX, out intersectY, true, out linesAreColinear))
                    {
                        // If the lines are co-linear there is nothing more to do. The two vertices need to be added and no more checking is required
                        if (linesAreColinear)
                        {
                            intercepts.Add(new XYZS(v1.X, v1.Y, v1.Z, startStation + MathUtilities.Hypot(startPoint.X - v1.X, startPoint.Y - v1.Y), triIndex));
                            intercepts.Add(new XYZS(v2.X, v2.Y, v2.Z, startStation + MathUtilities.Hypot(startPoint.X - v2.X, startPoint.Y - v2.Y), triIndex));
                            continue;
                        }

                        if (!planeInited)
                        {
                            plane.Init(v0, v1, v2);
                        }

                        // Otherwise, add the intercept location to the list
                        intercepts.Add(new XYZS(intersectX, intersectY, plane.Evaluate(intersectX, intersectY), startStation + MathUtilities.Hypot(startPoint.X - intersectX, startPoint.Y - intersectY), triIndex));
                    }
                }
            }

            // Add an end intercept if the start point is located within a triangle
            AddEndIntercept(endPoint, intercepts, startStation + MathUtilities.Hypot(startPoint.X - endPoint.X, startPoint.Y - endPoint.Y));

            return(intercepts);
        }