Beispiel #1
0
        public static bool IsPointOnHatchByRay(this Hatch hatch, Point3d pt, Tolerance tolerance, Database db)
        {
            var hId = hatch.Id;

            try
            {
                if (hatch.Id.IsNull)
                {
                    using var t = db.TransactionManager.StartTransaction();
                    var cs     = db.CurrentSpaceId.GetObjectT <BlockTableRecord>(OpenMode.ForWrite);
                    var hClone = (Hatch)hatch.Clone();
                    hId = cs.AppendEntity(hClone);
                    t.AddNewlyCreatedDBObject(hClone, true);
                    t.Commit();
                }

                using var r   = hId.CreateRegionFromHatch();
                using var ray = new Ray { BasePoint = pt, UnitDir = new Vector3d(0.235, 0.7458, 0) };
                var pts = new Point3dCollection();
                ray.IntersectWith(r, Intersect.OnBothOperands, new Plane(), pts, IntPtr.Zero, IntPtr.Zero);
                return(pts.Count > 0 && (pts.Count.IsOdd() || pts.Cast <Point3d>().Any(p => p.IsEqualTo(pt))));
            }
            finally
            {
                if (!hId.IsNull)
                {
#pragma warning disable 618
                    using var h = hId.Open(OpenMode.ForWrite, false, true) as Hatch;
#pragma warning restore 618
                    h?.Erase();
                }
            }
        }