Esempio n. 1
0
        private static double GetOffset([NotNull] Pnt pnt,
                                        [NotNull] SegmentProxy segmentProxy,
                                        out double fraction,
                                        out bool?onRightSide)
        {
            double?offset;

            fraction = SegmentUtils.GetClosestPointFraction(
                segmentProxy, pnt, out offset, out onRightSide, as3D: false);

            double distance2;

            if (fraction < 0)
            {
                distance2   = pnt.Dist2(segmentProxy.GetStart(as3D: false));
                onRightSide = null;
            }
            else if (fraction > 1)
            {
                distance2   = pnt.Dist2(segmentProxy.GetEnd(as3D: false));
                onRightSide = null;
            }
            else
            {
                if (!offset.HasValue)
                {
                    Pnt    s          = segmentProxy.GetStart(as3D: false);
                    Pnt    e          = segmentProxy.GetEnd(as3D: false);
                    double vectorProd = (pnt - s).VectorProduct(s - e);
                    onRightSide = vectorProd < 0;
                    distance2   = pnt.Dist2(segmentProxy.GetPointAt(fraction, as3D: false));
                }
                else
                {
                    distance2 = 0;                     // offset has value and will be used as distance
                }
            }

            double distance = offset ?? Math.Sqrt(distance2);

            return(distance);
        }
Esempio n. 2
0
        private static bool GetNearest([NotNull] Pnt point,
                                       [NotNull] Pnt nearPoint,
                                       ref double minDistance2)
        {
            double distance2 = point.Dist2(nearPoint);

            if (distance2 >= minDistance2)
            {
                return(false);
            }

            minDistance2 = distance2;
            return(true);
        }
        private bool IsCoincident([NotNull] PlaneHelper planeHelper,
                                  [NotNull] Pnt point,
                                  double xyTolerance)
        {
            double near  = Math.Max(xyTolerance, PointCoincidence);
            double near2 = near * near;

            double nearEdge2 = 0;

            if (EdgeCoincidence > 0)
            {
                double nearEdge = Math.Max(xyTolerance, EdgeCoincidence);
                nearEdge2 = nearEdge * nearEdge;
            }

            const bool as3D = true;

            foreach (SegmentProxy segment in planeHelper.GetSegments())
            {
                if (segment.GetStart(as3D).Dist2(point) < near2)
                {
                    return(true);
                }

                if (EdgeCoincidence > 0)
                {
                    double fraction =
                        SegmentUtils.GetClosestPointFraction(segment, point, as3D);
                    if (fraction >= 0 && fraction <= 1)
                    {
                        IPnt edgePoint = segment.GetPointAt(fraction, as3D);

                        if (point.Dist2(edgePoint) < nearEdge2)
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }