private static List <XYZ> GetSeatVectors(SeatBatch batch, XYZ nextPt, SeatInfo seat) { var leftBottomPt = nextPt; var rightBottomPt = new XYZ(nextPt.X + batch.Width, nextPt.Y, nextPt.Z); var leftTopPt = new XYZ(nextPt.X, nextPt.Y + batch.Length, nextPt.Z); var rightTopPt = new XYZ(nextPt.X + batch.Width, nextPt.Y + batch.Length, nextPt.Z); if (!seat.IsRotation) { return new List <XYZ> { leftBottomPt, rightBottomPt, leftTopPt, rightTopPt } } ; // If you don't understand it, you should draw picture. leftBottomPt = new XYZ(nextPt.X - batch.Width, nextPt.Y, nextPt.Z); rightBottomPt = nextPt; leftTopPt = new XYZ(nextPt.X - batch.Width, nextPt.Y + batch.Length, nextPt.Z); rightTopPt = new XYZ(nextPt.X, nextPt.Y + batch.Length, nextPt.Z); return(new List <XYZ> { leftBottomPt, rightBottomPt, leftTopPt, rightTopPt }); }
private static List <SeatInfo> GetSeatInfosOnBatch(SeatBatch batch, ref XYZ nextPt, bool alignBottom) { var results = new List <SeatInfo>(); var canPut = true; var sum = 0; var f1 = Request.AlignLeft; while (batch.UsableNumber > 0 && canPut) { sum++; // In order to not be an infinite loop. if (sum > 1000) { MessageBox.Show("The loop is endless, please contact the program's developer!"); break; } var f2 = RowNum % 2 == 0; // The seat aligns left and double num or aligns right and single num, should be retated. var seat = new SeatInfo(nextPt, batch, RowNum, f1 && f2 || !f1 && !f2); var pts = GetSeatVectors(batch, nextPt, seat); if (pts.All(CanPut)) { results.Add(seat); batch.UsableNumber -= 1; } nextPt = GetNextPt(batch, nextPt, ref canPut, alignBottom); } return(results); }
private static XYZ ReviseYValue(XYZ nextPt, SeatBatch batch, bool alignBottom) { var line = Line.CreateBound(new XYZ(nextPt.X, -10000000, nextPt.Z), new XYZ(nextPt.X, 10000000, nextPt.Z)); var roomInsPts = line.GetPlaneInsPointList(RoomEdges); var boxInsPts = line.GetPlaneInsPointList(PickEdges); var roomInsMinY = roomInsPts.Min(m => m.Y); var boxInsMinY = boxInsPts.Min(m => m.Y); var roomInsMaxY = roomInsPts.Max(m => m.Y); var boxInsMaxY = boxInsPts.Max(m => m.Y); // Revises the next point y min value. var pt1 = new XYZ(nextPt.X, Math.Max(roomInsMinY, boxInsMinY) + 0.05, nextPt.Z); var pt2 = new XYZ(nextPt.X, Math.Min(roomInsMaxY, boxInsMaxY) - batch.Length - 0.05, nextPt.Z); return(alignBottom ? pt1 : pt2); }
private static XYZ CalcNewRowPosition(XYZ nextPt, SeatBatch batch, bool alignBottom) { var pt1 = new XYZ(nextPt.X + Request.RowWidth, InsBox.Min.Y + 0.05, nextPt.Z); var pt2 = new XYZ(nextPt.X - Request.RowWidth, InsBox.Min.Y + 0.05, nextPt.Z); var pt3 = new XYZ(nextPt.X, InsBox.Min.Y + 0.05, nextPt.Z); // If seat don't align bottom, the seat y value must redure on new row var pt4 = new XYZ(nextPt.X + Request.RowWidth, InsBox.Max.Y - batch.Length - 0.05, nextPt.Z); var pt5 = new XYZ(nextPt.X - Request.RowWidth, InsBox.Max.Y - batch.Length - 0.05, nextPt.Z); var pt6 = new XYZ(nextPt.X, InsBox.Max.Y - batch.Length - 0.05, nextPt.Z); var f1 = RowNum % 2 == 0; var f2 = Request.AlignLeft; var result = alignBottom ? (f1 ? (f2 ? pt1 : pt2) : pt3) : (f1 ? (f2 ? pt4 : pt5) : pt6); return(result); }
private static XYZ GetNextPt(SeatBatch batch, XYZ nextPt, ref bool canPut, bool alignBottom) { // The next seat location should set the location's y axis plus seat length. var pt1 = new XYZ(nextPt.X, nextPt.Y + batch.Length, nextPt.Z); var pt2 = new XYZ(nextPt.X, nextPt.Y - batch.Length, nextPt.Z); nextPt = alignBottom ? pt1 : pt2; var f1 = nextPt.Y > InsBox.Max.Y || InsBox.Max.Y - nextPt.Y < batch.Length; // If seat aligns bottom, then goes to next row util the next point y is less than ins box min y. var f2 = nextPt.Y < InsBox.Min.Y && nextPt.Y - InsBox.Min.Y < batch.Length; // The next point don't need newline. if (alignBottom ? !f1 : !f2) { return(nextPt); } RowNum++; nextPt = CalcNewRowPosition(nextPt, batch, alignBottom); // To not multi calc. canPut = Request.AlignLeft ? !(nextPt.X > InsBox.Max.X) : !(nextPt.X < InsBox.Min.X); // It's an invalid point, must return. // Because boxInsPts count is 0, throw new exception. if (!canPut) { return(nextPt); } if (RowNum % 2 == 1) { nextPt = ReviseYValue(nextPt, batch, alignBottom); } return(nextPt); }