Exemplo n.º 1
0
        public void Test_XYZTests_GetPointOffset()
        {
            XYZ bottom = new XYZ(0, 0, 0);
            XYZ top    = new XYZ(0, 10, 0);
            XYZ left   = new XYZ(-5, 5, 0);
            XYZ right1 = new XYZ(0, 5, 0);
            XYZ right2 = new XYZ(5, 5, 0);

            Assert.Equal(0.0, XYZ.GetPointOffset(bottom, top, right1));
            Assert.Equal(5.0, XYZ.GetPointOffset(bottom, top, right2));
            Assert.Equal(XYZ.GetPointOffset(bottom, top, left), -5.0);
        }
Exemplo n.º 2
0
        public static void VectoriseSmoothPolylineTolerance(NFFLineworkSmoothedPolyLineEntity SmoothPolyline,
                                                            double ATolerance,
                                                            Action <double, double, DecompositionVertexLocation> DecompCallback)
        {
// ATolerance is defined as a maximum deviation from the point being inserted to a line
//  between the two points at each end of the interval being inserted into.
            double Alpha, Beta;
            double AlphaPlusBeta;
            double TwoAlphaPlusBeta;
            double lx, ly;
            NFFLineworkSmoothedPolyLineVertexEntity StartPt, EndPt;
            XYZ StartPos, EndPos;

            XYZ GetPosition(double Ordinate)
            {
                double o2    = Ordinate * Ordinate;
                double Cubic = AlphaPlusBeta * o2 * Ordinate - TwoAlphaPlusBeta * o2 + Alpha * Ordinate;

                var Result = new XYZ(StartPt.X + lx * Ordinate, StartPt.Y + ly * Ordinate, Consts.NullDouble);

                if (Cubic != 0.0)
                {
                    Result.X -= ly * Cubic;
                    Result.Y += lx * Cubic;
                }

                return(Result);
            }

            void InsertIntoInterval(double IntStart, double IntEnd, XYZ startPos, XYZ endPos)
            {
                double HalfInterval = (IntStart + IntEnd) / 2;
                var    pos          = GetPosition(HalfInterval);

                if (Math.Abs(XYZ.GetPointOffset(startPos, endPos, pos)) > ATolerance)
                {
                    // Process the interval before the point to insert
                    InsertIntoInterval(IntStart, HalfInterval, startPos, pos);

                    // Insert the point that divides this interval
                    DecompCallback(pos.X, pos.Y, DecompositionVertexLocation.Intermediate);

                    // Process the interval after before the point to insert
                    InsertIntoInterval(HalfInterval, IntEnd, pos, endPos);
                }
            }

            //  if SmoothPolyline.Vertices.Count < 2 then
            //    Exit;

            StartPt = SmoothPolyline.Vertices.First();
            EndPt   = SmoothPolyline.Vertices.Last();

//  lx = EndPt.X - StartPt.X;
//  ly = EndPt.Y - StartPt.Y;

            // Add the start point of the smooth polyline
            DecompCallback(StartPt.X, StartPt.Y, DecompositionVertexLocation.First);

            for (int I = 0; I < SmoothPolyline.Vertices.Count - 1; I++)
            {
                EndPt = SmoothPolyline.Vertices[I + 1];

                lx = EndPt.X - StartPt.X;
                ly = EndPt.Y - StartPt.Y;

                // Cache these, for speed.
                Alpha = EndPt.Alpha;
                Beta  = EndPt.Beta;

                // zero co-efficients means a straight line
                if (Alpha != 0 && Beta != 0)
                {
                    AlphaPlusBeta    = Alpha + Beta;
                    TwoAlphaPlusBeta = AlphaPlusBeta + Alpha;

                    StartPos = new XYZ(StartPt.X, StartPt.Y, StartPt.Z);
                    EndPos   = new XYZ(EndPt.X, EndPt.Y, EndPt.Z);

                    InsertIntoInterval(0, 1, StartPos, EndPos);
                }

                if (I < SmoothPolyline.Vertices.Count - 1)
                {
                    DecompCallback(EndPt.X, EndPt.Y, DecompositionVertexLocation.Intermediate);
                }

                StartPt = EndPt;
            }

            // Add the end point of the segment to the polyline vertices
            DecompCallback(EndPt.X, EndPt.Y, DecompositionVertexLocation.Last);
        }