public void Y_TouchesBorderL2R_above_Limits_Positive() { //arrange DirectionL2R direction = new DirectionL2R(); double maxY = -380.92; ColoBox currentBoxReference = getBox(maxY); TiltBorder b = getBorder(direction, typeof(FirstBorderPositive)); //act double result = direction.GetYPointTouchesBorder(currentBoxReference, typeof(FirstBorderPositive), b); //assert Assert.AreEqual(result, -400.92); }
public void Y_TouchesBorderR2L_below_Limits_Negative() { //arrange DirectionR2L direction = new DirectionR2L(); double maxY = -520.92; ColoBox currentBoxReference = getBox(maxY); TiltBorder b = getBorder(direction, typeof(FirstBorderNegative)); //act double result = direction.GetYPointTouchesBorder(currentBoxReference, typeof(FirstBorderNegative), b); //assert Assert.AreEqual(result, maxY); }
public IEnumerable <TiltBorder> GetAngledBordersInPath(ColoBox boxToPlace, double y) { //1. collect all the angled borders in the path //3. create virtual borders as vertical in the correct position so we can consider that point as the valid next point to place a given box //4. order the borders (sort) HashSet <string> foundPositive = new HashSet <string>(); HashSet <string> foundNegative = new HashSet <string>(); List <TiltBorder> retVal = new List <TiltBorder>(); List <TiltBorder> bordersWithinPath = new List <TiltBorder>(); foreach (TiltBorder b in BorderVerifier.Tilted) { if (b.BoxWhichBelongTo != boundingBox) { continue; } LinearLine line = new LinearLine(b); double lowY, highY; double rY = Math.Round(y); double yOut; Utility.BorderEndpoints(b, InitParam.Tolerance, y, out lowY, out highY, out yOut); string pKey = string.Format("{0}p", yOut); string nKey = string.Format("{0}n", yOut); if (b.BorderType == Orientation.Positive) { if (yOut >= lowY && yOut <= highY) //&& ! foundNegative.Contains(nKey)) { foundPositive.Add(pKey); //minY is applicaple for both path (upper and lower) b.BoxTouchingBox = line.GetXIntersect(y); bordersWithinPath.Add(b); } } if (b.BorderType == Orientation.Negative)// && !foundPositive.Contains(pKey)) { if (yOut >= lowY && yOut <= highY) { foundNegative.Add(nKey); //minY is applicaple for both path (upper and lower) b.BoxTouchingBox = line.GetXIntersect(y); bordersWithinPath.Add(b); } } } bordersWithinPath.Sort(); foreach (TiltBorder b in bordersWithinPath) { TiltBorder nb = new TiltBorder { Coordinate = b.BoxTouchingBox }; retVal.Add(nb); } return(retVal); }
private List <Point> createPathDictionary(ColoBox boxToPlace, double y) { List <Border> borderInPath = new List <Border>(); double lowY, highY; foreach (Border b in machine.BorderVerifier.VerticalX) { if (b.BoxWhichBelongTo != machine.boundingBox) { continue; } //make sure that we sorted out and have the lower point of the border as "lowY" and the upper as "highY" Utility.BorderEndpoints(b, machine.InitParam.Tolerance, y, out lowY, out highY, out y); //setting up the tolerance correction before comparing if (y >= lowY && y <= highY) { if (!borderInPath.Contains(b)) { borderInPath.Add(b); } } } borderInPath.AddRange(machine.GetAngledBordersInPath(boxToPlace, y)); if (borderInPath.Count == 3) { } borderInPath = setDistinctBorders(borderInPath); List <Point> pathSections = new List <Point>(); RelativeLocation first = RelativeLocation.Inside; RelativeLocation second = RelativeLocation.Outside; bool isOrderSet = false; for (int i = 0; i < borderInPath.Count - 1; ++i) { Point p; TiltBorder tb = getTiltedBorder(borderInPath[i]); //(TiltBorder)borderInPath[i]; TiltBorder tb2 = getTiltedBorder(borderInPath[i + 1]); //(TiltBorder)borderInPath[i + 1]; p = new Point { X = tb.Coordinate, Y = tb2.Coordinate }; p = this.machine.direction.setPathCoordinatesOrder(p); //if (!isOrderSet) //{ // isOrderSet = true; // machine.direction.GetOrder(boxToPlace,p,out first, out second); //} if (i % 2 == 0) // { //pathSections.Add(p, "Inside"); p.RelativeLocation = first; pathSections.Add(p); } else { //pathSections.Add(p, "Outside"); p.RelativeLocation = second; pathSections.Add(p); } } //at this point, if we found that on section is shorter than a box width, just merge that section //double boxWidth = boxToPlace.Width; //List<Point> newPathSection = null; //for (int i = 0; i < pathSections.Count - 1; ++i) //{ // if (Math.Abs(pathSections[i].X - pathSections[i].Y) > boxWidth) // { // if (newPathSection == null) // newPathSection = new List<Point>(); // newPathSection.Add(new Point { X = pathSections[i].X, Y = pathSections[i + 1].Y , RelativeLocation = RelativeLocation.Inside }); // } //} //if (newPathSection != null) // return newPathSection; //before we create path section return(pathSections); }