示例#1
0
        private static bool CutLineCircle2D([NotNull] SegmentProxy segmentProxy,
                                            [NotNull] Pnt center, double r2,
                                            out double tMin, out double tMax)
        {
            const bool as3D = false;

            var p0s = (Pnt2D)segmentProxy.GetStart(as3D);
            var p0e = (Pnt2D)segmentProxy.GetEnd(as3D);
            Pnt l0  = p0e - p0s;

            return(CutLineCircle(p0s, l0, center, r2, out tMin, out tMax));
        }
示例#2
0
        public static double GetClosestPointFraction([NotNull] SegmentProxy segmentProxy,
                                                     [NotNull] Pnt nearPoint,
                                                     out double?offset,
                                                     out bool?onRightSide,
                                                     bool as3D)
        {
            if (segmentProxy.IsLinear)
            {
                Pnt p0s = segmentProxy.GetStart(as3D);
                Pnt p0e = segmentProxy.GetEnd(as3D);
                Pnt l0  = p0e - p0s;
                offset      = null;
                onRightSide = null;
                return(GetAlongFraction(nearPoint - p0s, l0));
            }

            const bool forceCreation = true;
            IPolyline  segmentLine   = segmentProxy.GetPolyline(forceCreation);

            IPoint near = new PointClass();

            near.PutCoords(nearPoint.X, nearPoint.Y);

            IPoint onPoint = new PointClass();

            double     fraction    = 0;
            double     offsetValue = 0;
            var        rightSide   = false;
            const bool asRatio     = true;

            segmentLine.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, near,
                                              asRatio, onPoint, ref fraction,
                                              ref offsetValue, ref rightSide);

            offset      = offsetValue;
            onRightSide = rightSide;
            return(fraction);
        }
示例#3
0
        private static bool GetCoincident([NotNull] SegmentProxy segment,
                                          [NotNull] SegmentProxy hull,
                                          bool is3D,
                                          out NearSegment hullStartNear,
                                          out NearSegment hullEndNear)
        {
            hullStartNear = NearSegment.NotNear;           // TODO
            hullEndNear   = NearSegment.NotNear;           // TODO

            IPolyline segLine  = segment.GetPolyline(false);
            IPolyline hullLine = hull.GetPolyline(false);

            if (!((IRelationalOperator)segLine).Equals(hullLine))
            {
                return(false);
            }

            var coincident = true;

            Pnt segmentStart = segment.GetStart(is3D);
            Pnt segmentEnd   = segment.GetEnd(is3D);

            Pnt hullStart = hull.GetStart(is3D);
            Pnt hullEnd   = hull.GetEnd(is3D);

            double distFromSegFromHull;
            {
                double dx = segmentStart.X - hullStart.X;
                double dy = segmentStart.Y - hullStart.Y;
                distFromSegFromHull = dx * dx + dy * dy;
            }
            double distFromSegToHull;
            {
                double dx = segmentStart.X - hullEnd.X;
                double dy = segmentStart.Y - hullEnd.Y;
                distFromSegToHull = dx * dx + dy * dy;
            }

            bool isInverse = (distFromSegFromHull > distFromSegToHull);
            Pnt  hullMatchSegFrom;
            Pnt  hullMatchSegTo;

            if (!isInverse)
            {
                hullMatchSegFrom = hullStart;
                hullMatchSegTo   = hullEnd;
            }
            else
            {
                hullMatchSegFrom = hullEnd;
                hullMatchSegTo   = hullStart;
            }

            if (is3D)
            {
                double            zPrecision       = 0;
                ISpatialReference spatialReference = segment.SpatialReference;

                if (spatialReference != null && spatialReference.HasZPrecision())
                {
                    double falseZ;
                    double zUnits;
                    spatialReference.GetZFalseOriginAndUnits(out falseZ, out zUnits);
                    zPrecision = 1 / zUnits;
                }

                if (Math.Abs(hullMatchSegFrom[2] - segmentStart[2]) > zPrecision ||
                    Math.Abs(hullMatchSegTo[2] - segmentStart[2]) > zPrecision)
                {
                    coincident = false;
                }
            }

            if (coincident)
            {
                if (!isInverse)
                {
                    hullStartNear = NearSegment.NearStart;
                    hullEndNear   = NearSegment.NearEnd;
                }
                else
                {
                    hullStartNear = NearSegment.NearEnd;
                    hullEndNear   = NearSegment.NearStart;
                }
            }

            return(coincident);
        }