/// <summary> /// Basic collision detection routine for single item placement. /// </summary> /// <param name="room">Room currently being populated.</param> /// <param name="candidate">PlacementPackaged being checked for fidelity.</param> /// <param name="pm"></param> /// <returns></returns> public static bool PlacementIsValid(RoomPackage room, PlacementPackage candidate, ProgramManifest pm) { //Verify placed item does not clash with previously placed items. foreach (PlacementPackage placedItem in room.PlacedItems) { if (Confirm.CurvesIntersect(placedItem.Bounds, candidate.Bounds, true)) { if (Confirm.CurvesIntersect(placedItem.Bounds, candidate.Bounds, false)) { return(false); } CurveIntersections ccx = Intersection.CurveCurve(placedItem.Bounds, candidate.Bounds, 0.1, 0.1); if (ccx.Count(x => x.IsOverlap) > 1) { return(false); } } PointContainment insideCheck = placedItem.Bounds.Contains(candidate.Bounds.GetBoundingBox(Plane.WorldXY).Center); if (insideCheck == PointContainment.Inside || insideCheck == PointContainment.Coincident) { return(false); } } //Verify item is completely within boundary of room. foreach (Curve edgeCurve in room.AllEdgeCurves) { if (Confirm.CurvesIntersect(candidate.Bounds, edgeCurve, false)) { return(false); } /* * if (!Confirm.PointInRegion(room.Region, new CurveBounds(candidate.Bounds).Center)) * { * return false; * } */ } //Verify program area is not larger than total room area. if (room.Region.GetArea() < pm.ProgramPackages[candidate.ProgramIndex].OccupationArea) { return(false); } return(true); }
public static Curve TrimWithClosedCurve(Curve trimRegion, Curve curve) { //TODO: Confirm that persistent error with Curve.Trim is my fault and not Rhino Compute. Seems to always return null, like Offset. bool curvesIntersect = Confirm.CurvesIntersect(trimRegion, curve, false); if (curve.Degree > 1) { //Current stopgap to compensate for Curve.Trim rebuilds from intersection points. Output is incorrect for nonlinear curves. return(curve); } Console.WriteLine("Curves intersect!"); Console.WriteLine(curve.PointAtStart.ToString()); if (!curvesIntersect) { Console.WriteLine("Trim region and curve do not intersect. Returning original curve."); return(curve); } List <Point3d> trimPoints = new List <Point3d>(); Rhino.Geometry.Intersect.CurveIntersections ccx = Rhino.Geometry.Intersect.Intersection.CurveCurve(trimRegion, curve, 0.1, 0.1); if (ccx.Count != 2) { Console.WriteLine("Not exactly two intersection events. Circulation axis placement is invalid. Returning original curve."); return(curve); } for (int i = 0; i < ccx.Count; i++) { trimPoints.Add(ccx[i].PointB); } Curve trimmedCurve = new LineCurve(trimPoints[0], trimPoints[1]); /* * if (trimmedCurve == null) * { * Console.WriteLine("Damn."); * return curve; * } */ return(trimmedCurve); }