Example #1
0
        // This method helps to get correct "boundary box" for the regions which
        // created through the splines. Written by Alexander Rivilis.
        public static void GetVisualBoundary(this Db.Region region, double delta,
                                             ref Gm.Point2d minPoint, ref Gm.Point2d maxPoint)
        {
            using (Gm.BoundBlock3d boundBlk = new Gm.BoundBlock3d())
            {
                using (Br.Brep brep = new Br.Brep(region))
                {
                    foreach (Br.Edge edge in brep.Edges)
                    {
                        using (Gm.Curve3d curve = edge.Curve)
                        {
                            Gm.ExternalCurve3d curve3d = curve as Gm.ExternalCurve3d;

                            if (curve3d != null && curve3d.IsNurbCurve)
                            {
                                using (Gm.NurbCurve3d nurbCurve = curve3d.NativeCurve
                                                                  as Gm.NurbCurve3d)
                                {
                                    Gm.Interval interval = nurbCurve.GetInterval();
                                    for (double par = interval.LowerBound; par <=
                                         interval.UpperBound; par += (delta * 2.0))
                                    {
                                        Gm.Point3d p = nurbCurve.EvaluatePoint(par);
                                        if (!boundBlk.IsBox)
                                        {
                                            boundBlk.Set(p, p);
                                        }
                                        else
                                        {
                                            boundBlk.Extend(p);
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if (!boundBlk.IsBox)
                                {
                                    boundBlk.Set(edge.BoundBlock.GetMinimumPoint(),
                                                 edge.BoundBlock.GetMaximumPoint());
                                }
                                else
                                {
                                    boundBlk.Extend(edge.BoundBlock.GetMinimumPoint());
                                    boundBlk.Extend(edge.BoundBlock.GetMaximumPoint());
                                }
                            }
                        }
                    }
                }
                boundBlk.Swell(delta);

                minPoint = new Gm.Point2d(boundBlk.GetMinimumPoint().X,
                                          boundBlk.GetMinimumPoint().Y);
                maxPoint = new Gm.Point2d(boundBlk.GetMaximumPoint().X,
                                          boundBlk.GetMaximumPoint().Y);
            }
        }
Example #2
0
        // Region extensions

        ///<summary>
        /// Returns whether a Region contains a Point3d.
        ///</summary>
        ///<param name="pt">A points to test against the Region.</param>
        ///<returns>A Boolean indicating whether the Region contains
        /// the point.</returns>
        public static bool ContainsPoint(this _AcDb.Region reg, _AcGe.Point3d pt)
        {
            using (var brep = new _AcBr.Brep(reg))
            {
                var pc = new _AcBr.PointContainment();
                using (var brepEnt = brep.GetPointContainment(pt, out pc))
                {
                    return(pc != _AcBr.PointContainment.Outside);
                }
            }
        }
Example #3
0
 ///<summary>
 /// Returns whether a Region contains a set of Point3ds.
 ///</summary>
 ///<param name="pts">An array of points to test against the Region.</param>
 ///<returns>A Boolean indicating whether the Region contains
 /// all the points.</returns>
 public static bool ContainsPoints(this _AcDb.Region reg, _AcGe.Point3d[] pts)
 {
     using (var brep = new _AcBr.Brep(reg))
     {
         foreach (var pt in pts)
         {
             var pc = new _AcBr.PointContainment();
             using (var brepEnt = brep.GetPointContainment(pt, out pc))
             {
                 if (pc == _AcBr.PointContainment.Outside)
                 {
                     return(false);
                 }
             }
         }
     }
     return(true);
 }