protected BorderVerifier getToughBorderVerifier(DirectionBase direction, Machine machine) { ColoBox boundingBox = new ColoBox("", 1); boundingBox.AddPoint(531.67, 415); boundingBox.AddPoint(531.67, 474.61); boundingBox.AddPoint(507.86, 497.33); boundingBox.AddPoint(465.8, 497.33); boundingBox.AddPoint(463.07, 494.76); boundingBox.AddPoint(459.83, 491.71); boundingBox.AddPoint(456, 488.1); boundingBox.AddPoint(456, 473.67); boundingBox.AddPoint(473.67, 473.67); boundingBox.AddPoint(473.67, 445.67); boundingBox.AddPoint(456, 445.67); boundingBox.AddPoint(456, 415); boundingBox.AddPoint(410, 415); boundingBox.AddPoint(410, 335); boundingBox.AddPoint(483, 335); boundingBox.AddPoint(483, 352.67); boundingBox.AddPoint(532, 352.67); boundingBox.AddPoint(532, 335); boundingBox.AddPoint(595.33, 335); boundingBox.AddPoint(595.33, 415); boundingBox.AddPoint(531.67, 415); List <ColoBox> staticBoxes = new List <ColoBox>(); staticBoxes.Add(boundingBox); machine.boundingBox = boundingBox; BorderVerifier verifier = new BorderVerifier(staticBoxes, machine); return(verifier); }
public override double GetYPointTouchesBorder(ColoBox currentBoxReference, Type type, Border b) { double lowY, highY; if (b is TiltBorder) { double yOut; Utility.BorderEndpoints(b, LocationMachine.InitParam.Tolerance, currentBoxReference.MaxY, out lowY, out highY, out yOut); if (type == typeof(FirstBorderPositive)) { if (yOut >= lowY && yOut <= highY) { return(yOut); } //even though it makes sense to return the maxY for a positive border when we move L2R, if the maxY is not within the border vertical values, we will have to return the //minY return(currentBoxReference.MinY); } else { //First Border is negative if (currentBoxReference.MinY >= lowY && currentBoxReference.MinY <= highY) { return(currentBoxReference.MinY); } return(currentBoxReference.MaxY); } } //for a vertical border, it doesn't matter minY or maxY return(currentBoxReference.MinY); }
private bool nextSpaceValid(ColoBox boxToPlace) { if (verticalX.FindCollision(boxToPlace)) { return(false); } if (horizontalY.FindCollision(boxToPlace)) { return(false); } if (tilted.FindCollision(boxToPlace)) { isMeetingTiltedWall = true; return(false); } //we found a local wall, keep looking inside the bounding box to find potential space before the exterior wall (in case this is not exterior) if (boxToPlace.MaxX < boundingBox.MaxX && isMeetingTiltedWall) { locationMachine.IsSteppedOutBoundingBox = true; return(false); } //when we hit the exterior region of the bounding box of the main space if (locationMachine.direction.IsHittingExteriorBorder(boxToPlace, locationMachine))// boxToPlace.MaxX > locationMachine.LastVerticalLine ) { if (locationMachine.IsSteppedOutBoundingBox) { locationMachine.IsSteppedOutBoundingBox = false; } locationMachine.RowNumber++; locationMachine.ROWSTARTS.SetCurrent(); isMeetingTiltedWall = false; return(false); } ////This is a special case that we are trying to locate a new row starting at the "ORIGIN" coordinates of the next row ////sometimes the wall on certain location doesn't start on the ORIGIN of the bounding box. so we need to verify that //if (locationMachine.OnRowStart) //{ // //first find vertical lines that have y-coordinates which include at least one box horizontal line // if (verticalX.BorderNotAlignWithBoundingBox(boxToPlace)) // { // return false; // } //} if (locationMachine.CurrentlyOutsideTheBox) { return(false); } return(true); }
internal BorderCollection(ColoBox boundingBox, ColoEngine.Model.LocationStatemachine.Machine machine) { this.boundingBox = boundingBox; borders = new List <Border>(); transformed_borders = new List <Border>(); this.locationMachine = machine; }
private bool IsHorizontalCollide(ColoBox boxToPlace) { double minX = boxToPlace.MinX; double maxX = boxToPlace.MaxX; double minY = boxToPlace.MinY; double maxY = boxToPlace.MaxY; double minCrossX = this.GetXIntersect(minY); double maxCrossX = this.GetXIntersect(maxY); bool minCross = false; bool maxCross = false; if (minX < minCrossX && minCrossX < maxX) { //double minCrossY = this.getIntersect(minCrossX); if (getSmaller("Y") < minY && minY < getBigger("Y")) { minCross = true; } } if (minY < maxCrossX && maxCrossX < maxY) { if (getSmaller("Y") < maxY && maxY < getBigger("Y")) { maxCross = true; } } return(minCross || maxCross); }
internal override bool FindCollision(ColoBox boxToPlace) { selectBorderCollection(boxToPlace.IsRotating); //bool isVerticalsCrossLine = false; //bool isHorizontalsCrossLine = false; //double lineX1,lineX2,lineY1,lineY2; if (boxToPlace.IsRotating) { lborders = transformed_borders; } else { lborders = borders; } foreach (var b in lborders) { LinearLine line = new LinearLine(b); if (line.FindCollision(boxToPlace)) { //calculatedNextLocation = new Vector2 { X = boxToPlace.MinX + boxToPlace.Width, Y = boxToPlace.MinY }; return(true); } //else // calculatedNextLocation = null; } return(false);// isHorizontalsCrossLine; }
protected TiltBorder getBorder(DirectionBase direction, Type type) { ColoBox box = new ColoBox("", 1); Point p1 = new Point(); Point p2 = new Point(); if (type == typeof(FirstBorderPositive)) { p1.X = 160.21; p2.X = 310; } else { p1.X = 310; p2.X = 160.21; } p1.Y = -530.45; p2.Y = -390; RawBorder rb = new RawBorder(p1, p2); TiltBorder tb = new TiltBorder(rb, box); direction.LocationMachine = new Machine(new InitParams { Tolerance = 0.5 }, null); return(tb); }
protected PathSection getPathSection(bool IsL2R, bool isTough = false) { InitParams init = new InitParams(); ColoBox box = new ColoBox("", 1); Machine machine = new Machine(init, box); PathSection pathSection = new PathSection(machine); DirectionBase direction = null; if (IsL2R) { direction = new DirectionL2R(machine); } else { direction = new DirectionR2L(machine); } LayoutManager layoutManager = new LayoutManager(init); layoutManager.LocationMachine = machine; machine.direction = direction; machine.direction.LayoutManager = layoutManager; if (isTough) { machine.BorderVerifier = getToughBorderVerifier(direction, machine); } else { machine.BorderVerifier = getBorderVerifier(direction, machine); } return(pathSection); }
protected Point CalculateNextLinearLocation(Border vx, ColoBox boxToPlace) { double x = locationMachine.direction.CalculateNextLinearLocation(vx, boxToPlace, locationMachine.InitParam.SpaceAfterObstacle); return(new Point { X = x, Y = boxToPlace.MinY /* to keep the box on the same baseline of the current row*/ }); }
internal override bool BoxInOutsidePaTh(Point pathSection, ColoBox boxToPlace) { double minX = pathSection.X; if (minX > pathSection.Y) { minX = pathSection.Y; } return(boxToPlace.MinX < minX); }
internal override bool IsHittingExteriorBorder(ColoBox boxToPlace) { double valueToComp = LocationMachine.LastVerticalLine; if (valueToComp == 0) { valueToComp = LocationMachine.boundingBox.MaxX; } return(boxToPlace.MaxX > valueToComp);// locationMachine.LastVerticalLine; }
public void LookAhead_BeginingL2RMeet2AngledLines() { //arrange PathSection pathSection = getPathSection(true); double maxY = -517.92;//-529.92; ColoBox currentBoxReference = getBox(maxY); //act pathSection.SetRelativeLocation(currentBoxReference); Assert.AreEqual(pathSection.UpperPathSections.Count, 1); Assert.AreEqual(pathSection.LowerPathSections.Count, 1); }
//Adding points that render a tilted line internal void AddTiltedBorder(ColoBox boxBelongsTo, Point fromX, Point fromY) { TiltBorder border = new TiltBorder(); border.BoxWhichBelongTo = boxBelongsTo; border.Endpoints.Add(new BorderNumberPair { coordinate1 = fromX.X, coordinate2 = fromX.Y }); border.Endpoints.Add(new BorderNumberPair { coordinate1 = fromY.X, coordinate2 = fromY.Y }); borders.Add(border); }
internal override void GetOrder(ColoBox boxToPlace, Point section, out RelativeLocation first, out RelativeLocation second) { if (boxToPlace.MinX <= section.X) //&& boxToPlace.MaxX <= section.Y) { first = RelativeLocation.Outside; second = RelativeLocation.Inside; } else { first = RelativeLocation.Inside; second = RelativeLocation.Outside; } }
public ActionResult GetUniverse(InitParams init) { string fileName = getFileName(init);// System.Web.HttpContext.Current.Server.MapPath(string.Format(@"..\api\{0}.dxf", init.FileName)); createOptimizer(fileName, init); //this stage means that we already have the bool isCandidate = true; ColoBox universe = null; //if (init.Stage == 1) //{ // ProjectClass project = getProject(); // universe = new ColoBox(); // universe.Layer = init.StaticLayers.Where(l => l.IsUniverse).First ().Name; // foreach (Point p in project.UniverseNodes) // { // universe.AddPoint(p.X, p.Y); // } // optimizer.AddUniverse(universe); // isCandidate = false; //} optimizer.SetBoundingBox(isCandidate); //saving the bounding box into the project if (init.Stage == 0) { ProjectClass project = getProject(); project.BoundingBox = optimizer.getBoudingBox(); saveProject(project); } if (universe != null) { var pc = universe.PointsCollection; } //string[] points = optimizer.GetObstaclesPointsAsUniverseCandidate(); //ProjectClass prj = getProject(); //prj.Floor = points; //saveProject(prj); return(new JsonResult { JsonRequestBehavior = JsonRequestBehavior.AllowGet, Data = new { obstaclePointArr = optimizer.GetObstaclesPointsAsUniverseCandidate(), factor = optimizer.Factor } }); }
public Border(RawBorder b, ColoBox box) { BoxWhichBelongTo = box; Endpoints = new List <BorderNumberPair>(); BorderNumberPair bnp = new BorderNumberPair(); BorderType = b.BorderType; Endpoints.Add(bnp); switch (b.BorderType) { case Orientation.Horizontal: Coordinate = b.Point1.Y; bnp.coordinate1 = b.Point1.X; if (b.Point2.X < b.Point1.X) { bnp.coordinate1 = b.Point2.X; bnp.coordinate2 = b.Point1.X; } else { bnp.coordinate2 = b.Point2.X; } break; case Orientation.Vertical: Coordinate = b.Point1.X; bnp.coordinate1 = b.Point1.Y; if (b.Point2.Y < b.Point1.Y) { bnp.coordinate1 = b.Point2.Y; bnp.coordinate2 = b.Point1.Y; } else { bnp.coordinate2 = b.Point2.Y; } break; default: Coordinate = 0; bnp.coordinate1 = b.Point1.X; bnp.coordinate2 = b.Point1.Y; bnp = new BorderNumberPair(); bnp.coordinate1 = b.Point2.X; bnp.coordinate2 = b.Point2.Y; Endpoints.Add(bnp); break; } }
public void Y_TouchesBorderL2R_in_Limits_Negative() { //arrange DirectionL2R direction = new DirectionL2R(); double maxY = -400.92; ColoBox currentBoxReference = getBox(maxY); TiltBorder b = getBorder(direction, typeof(FirstBorderNegative)); //act double result = direction.GetYPointTouchesBorder(currentBoxReference, typeof(FirstBorderNegative), b); //assert Assert.AreEqual(result, -420.92); }
public void Y_TouchesBorderR2L_below_Limits_Positive() { //arrange DirectionR2L direction = new DirectionR2L(); double maxY = -520.92; ColoBox currentBoxReference = getBox(maxY); TiltBorder b = getBorder(direction, typeof(FirstBorderPositive)); //act double result = direction.GetYPointTouchesBorder(currentBoxReference, typeof(FirstBorderPositive), b); //assert Assert.AreEqual(result, maxY); }
//finds collision between a box and the fixed border of the drawing internal virtual bool FindCollision(ColoBox boxToPlace) { selectBorderCollection(boxToPlace.IsRotating); double min_x, max_x, min_y, max_y; min_x = boxToPlace.MinX; max_x = boxToPlace.MaxX; min_y = boxToPlace.MinY; max_y = boxToPlace.MaxY; foreach (var vx in lborders) { //indicates if the borders that the box is touching is part of the origin. in that case we are not render that as a collision. bool isTouchingOriginLines = locationMachine.direction.IsTouchingOriginLines(vx); if (vx.Coordinate >= min_x && vx.Coordinate <= max_x && !isTouchingOriginLines) { if (vx.IntersecWith(min_y, max_y)) { //we found a wall in the a box which is not the bounding box we return the next if (vx.BoxWhichBelongTo != boundingBox) { locationMachine.OverrideStartPlace = CalculateNextLinearLocation(vx, boxToPlace); return(true); } //stepping out of the boundingbox localy if (vx.BoxWhichBelongTo == boundingBox && min_x < boundingBox.MaxX) { if (!locationMachine.CurrentlyOutsideTheBox) { locationMachine.OUTSIDEBOUNDINGBOX.SetCurrent(); } else { locationMachine.INSIDEBOUNDINGBOX.SetCurrent(); } } //Found that a verticalX line intersect return(true); } } } return(false); }
internal Machine(double coldAisleWidth, double spaceAfterObstacle, ColoBox boundingBox) { INSIDEBOUNDINGBOX = new State_InsideBounding(this); OUTSIDEBOUNDINGBOX = new State_OutsideBounding(this); ROWSTARTS = new State_RowStart(this); HITOBSTACLE = new State_HitObstacle(this); currentState = ROWSTARTS; RowNumber = 0; this.coldAisleWidth = coldAisleWidth; this.SpaceAfterObstacle = spaceAfterObstacle; this.boundingBox = boundingBox; this.direction = direction; IsSteppedOutBoundingBox = false; }
public void SetRelativeLocation(ColoBox boxToPlace) { if (UpperPathSections == null || LowerPathSections == null) { machine.CurrentBoxToPlace = boxToPlace; UpperPathSections = createPathDictionary(boxToPlace, boxToPlace.MaxY); LowerPathSections = createPathDictionary(boxToPlace, boxToPlace.MinY); //making sure that if an inside renders as outside we might be able to convert from outside to inside if (UpperPathSections.Count != LowerPathSections.Count) { reverseOrder(); } } }
/// <summary> /// This method is looking to find out if the box is currently inside or outside the main shape /// </summary> /// <param name="boxToPlace"></param> /// <returns></returns> internal Point?UpdateMachineState(ColoBox boxToPlace) { //The state "RowStarts" prepare the pathSections down stream of the current row so we can compare if the box is inside or outside the bounding box SetRelativeLocation(boxToPlace); Point?ret = null; foreach (KeyValuePair <Point, string> el in pathSections) { if (boxToPlace.MaxX >= el.Key.X && boxToPlace.MaxX <= el.Key.Y) { ret = setInsideOutsideState(el.Value, machine.direction.getNextLocationAfterOutside(el.Key), boxToPlace.MinY); } } return(ret); }
internal override bool FindCollision(ColoBox boxToPlace) { foreach (var b in borders) { LinearLine line = new LinearLine(b); if (line.FindCollision(boxToPlace)) { //calculatedNextLocation = new Vector2 { X = boxToPlace.MinX + boxToPlace.Width, Y = boxToPlace.MinY }; return(true); } //else // calculatedNextLocation = null; } return(false);// isHorizontalsCrossLine; }
public override bool IsBoxOutside(ColoBox boxToPlace, LookAheadPath.PathSection pathSection) { bool upperCheck = false; bool lowerCheck = false; if (IsBoxOutsideCollection(boxToPlace, pathSection.UpperPathSections)) { upperCheck = true; } if (IsBoxOutsideCollection(boxToPlace, pathSection.LowerPathSections)) { lowerCheck = true; } return(upperCheck || lowerCheck);// true; }
public void IsBoxOutside_inside_TouchR2L() { ColoBox box = getBox(-375); box.MoveOriginTo(new Point { X = 410, Y = 335 }); PathSection pathSectionR2L = getPathSection(false, true); pathSectionR2L.SetRelativeLocation(box); //act bool isBoxR2LOutside = pathSectionR2L.machine.direction.IsBoxOutside(box, pathSectionR2L); //assert Assert.AreEqual(isBoxR2LOutside, false); }
public void GetFirstBorderCoordinatExtremeR2L() { //arrange PathSection pathSectionR2L = getPathSection(false); ColoBox box = getBox(-9); box.MoveOriginTo(new Point { X = 153, Y = -28 }); pathSectionR2L.machine.CurrentBoxReference = box; //act double resultR2L = pathSectionR2L.machine.direction.GetFirstBorderCoordinate(); //assert Assert.AreEqual(resultR2L, double.MinValue); }
protected ColoBox getBox(double maxY, bool isTough = false) { int height = 20; if (isTough) { height = 15; } ColoBox box = new ColoBox(); box.AddPoint(826.18, maxY - height); box.AddPoint(826.18, maxY); box.AddPoint(845.38, maxY - height); box.AddPoint(845.38, maxY); return(box); }
internal void Move2NextLocation(Point nextLocation, ColoBox boxToPlace) { bool isValid = false; Point calcNextLocation = nextLocation; //isInsideBoundingBox = true; locationMachine.CurrentBoxToPlace = boxToPlace; //reseting the flag indicates we are hitting a tilted wall isMeetingTiltedWall = false; int i = 0; while (!isValid) { boxToPlace.MoveOriginTo(calcNextLocation); //if we are in a situation that we are placing outside the bounding box (and there is more space to place inside) //we need to verify if we crossed back into the internal side of the bounding box. if we did, switch the stateMachine to indicate //that state (inside the box) if (locationMachine.CurrentlyOutsideTheBox) { if (locationMachine.LocationWithinBoundingBox) { locationMachine.INSIDEBOUNDINGBOX.SetCurrent(); } } ++i; if (i == 7) { } if (nextSpaceValid(boxToPlace)) { locationMachine.NextState(); //if we are out of the bounding box, the break should not hit until we either step out of the outer bounding box or until //we got back in if (!locationMachine.IsSteppedOutBoundingBox) { break; } } calcNextLocation = locationMachine.NextLocation; } }
public void IsBoxOutside_Outside_CrazyColoR2L() { //arrange ColoBox box = getBox(-375); box.MoveOriginTo(new Point { X = 692, Y = -395 }); PathSection pathSectionR2L = getPathSection(false); pathSectionR2L.SetRelativeLocation(box); //act bool isBoxR2LOutside = pathSectionR2L.machine.direction.IsBoxOutside(box, pathSectionR2L); //assert Assert.AreEqual(isBoxR2LOutside, true); }
public void _1_UpdatemachineStateL2RBoxEndupOutside2() { //arrange PathSection pathSection = getPathSection(true, true); ColoBox currentBoxReference = getBox(0, true); currentBoxReference.MoveOriginTo(new Point { X = 456, Y = 459 }); pathSection.machine.CurrentBoxToPlace = currentBoxReference; //act Point?res = pathSection.UpdateMachineState(currentBoxReference); //assert Assert.AreEqual(pathSection.UpperPathSections[0].RelativeLocation.Value, RelativeLocation.Outside); Assert.AreEqual(pathSection.UpperPathSections[1].RelativeLocation.Value, RelativeLocation.Inside); }