public static bool GetCenterForOutsideCells(ShuffleBlock block, List <Cell> cells, out Point3d outsideCenter) { if (block == null) { outsideCenter = new Point3d(); return(false); } var boundingBox = block.GetBoundingBox();/* * boundingBox[BBOX_MIN] = new Cell(0, 0, Guid.Empty, new Dictionary<Guid, int>(), new Point3d(0, 0, 0)); * boundingBox[BBOX_MAX] = new Cell(60, 60, Guid.Empty, new Dictionary<Guid, int>(), new Point3d(60, 60, 0)); */ Debug.Print("boundingBox: " + boundingBox[BBOX_MIN] + "." + boundingBox[BBOX_MAX] + "\n"); var sumPoint = AddCellsInBoundingBox(boundingBox); var totalCells = CountCellsInBoundingBox(boundingBox); var sumInsidePoint = new Point3d(0, 0, 0); var totalCellsInside = 0; foreach (Cell cell in cells) { if (IsCellInBoundingBox(cell, boundingBox)) { totalCellsInside++; sumInsidePoint += cell.point; } } Debug.Print("sumInsidePoint: " + sumInsidePoint + "\n"); int totalCellsOutside = totalCells - totalCellsInside; Debug.Print("total cells: " + totalCells + "\n"); Debug.Print("total inside cells: " + totalCellsInside + "\n"); if (totalCellsOutside < 100) { outsideCenter = new Point3d(); return(false); } Point3d outsidePoint = (Point3d)(sumPoint - sumInsidePoint); outsideCenter = outsidePoint / totalCellsOutside; Debug.Print("outside center: " + outsideCenter + "\n"); return(true); }
public ShuffleBlock(ShuffleBlock oldShuffleBlock) { //all properties get set the same as in the oldShuffleBlock this.m_centerPoint = oldShuffleBlock.centerPoint; }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { List <Curve> objGeometry = new List <Curve>(); Point3d objectCorner1 = new Point3d(); Point3d objectCorner2 = new Point3d(); List <Curve> clearGeometry = new List <Curve>(); Point3d clearanceCorner1 = new Point3d(); Point3d clearanceCorner2 = new Point3d(); Point3d centerPoint = new Point3d(); int priority = -1; if (!DA.GetDataList(0, objGeometry)) { return; } if (!DA.GetData(1, ref objectCorner1)) { return; } if (!DA.GetData(2, ref objectCorner2)) { return; } if (!DA.GetDataList(3, clearGeometry)) { return; } if (!DA.GetData(4, ref clearanceCorner1)) { return; } if (!DA.GetData(5, ref clearanceCorner2)) { return; } if (!DA.GetData(6, ref centerPoint)) { return; } if (!DA.GetData(7, ref priority)) { return; } Dictionary <string, int> cornerOffsets = new Dictionary <string, int>(); int centerX = Convert.ToInt16(centerPoint.X); int centerY = Convert.ToInt16(centerPoint.Y); int clearanceCorner1X = Convert.ToInt16(clearanceCorner1.X); int clearanceCorner1Y = Convert.ToInt16(clearanceCorner1.Y); int clearanceCorner2X = Convert.ToInt16(clearanceCorner2.X); int clearanceCorner2Y = Convert.ToInt16(clearanceCorner2.Y); int objectCorner1X = Convert.ToInt16(objectCorner1.X); int objectCorner1Y = Convert.ToInt16(objectCorner1.Y); int objectCorner2X = Convert.ToInt16(objectCorner2.X); int objectCorner2Y = Convert.ToInt16(objectCorner2.Y); cornerOffsets.Add("toBoundingBottomLeftX", clearanceCorner1X - centerX); cornerOffsets.Add("toBoundingBottomLeftY", clearanceCorner1Y - centerY); cornerOffsets.Add("toBoundinTopRightX", clearanceCorner2X - centerX); cornerOffsets.Add("toBoundinTopRightY", clearanceCorner2Y - centerY); cornerOffsets.Add("toObjectBottomLeftX", objectCorner1X - centerX); cornerOffsets.Add("toObjectBottomLeftY", objectCorner1Y - centerY); cornerOffsets.Add("toObjectinTopRightX", objectCorner2X - centerX); cornerOffsets.Add("toObjectinTopRightY", objectCorner2Y - centerY); ShuffleBlock myBlock = new ShuffleBlock(centerPoint, cornerOffsets, priority, objGeometry, clearGeometry); DA.SetData(0, myBlock); }