public void DetermineSourceBounds_ShouldReturn_ExpectedBoundingBox() { //we expect the result to be the compound spread of all extremities of the provided data CoordinateStructure coordinateStructure1 = new CoordinateStructure(); coordinateStructure1.ListPoints = new List <Point> { new Point(50, 50), new Point(60, 60) }; CoordinateStructure coordinateStructure2 = new CoordinateStructure(); coordinateStructure2.ListPoints = new List <Point> { new Point(150, 150), new Point(160, 160) }; List <CoordinateStructure> listCoordinateStructures = new List <CoordinateStructure> { coordinateStructure1, coordinateStructure2 }; var result = _geometryService.DetermineSourceBounds(listCoordinateStructures); Assert.AreEqual(result.BottomLeft.X, 50); Assert.AreEqual(result.BottomLeft.Y, 50); Assert.AreEqual(result.TopRight.X, 160); Assert.AreEqual(result.TopRight.Y, 160); }
public static int oneStructureParams(int x, int y) { CoordinateStructure c = new CoordinateStructure(); c.x = x; c.y = y; if (c.x > 0 && c.y > 0) { return(1); } else if (c.x < 0 && c.y > 0) { return(2); } else if (c.x < 0 && c.y < 0) { return(3); } else if (c.x > 0 && c.y < 0) { return(4); } else { return(-1); } }
public static int guessCoordinates(CoordinateStructure p1, CoordinateStructure p2) { SegmentStructure s = new SegmentStructure(); s.p1 = p1; s.p2 = p2; if (s.p1.x == 1 && s.p1.y == 2) { if (s.p2.x == 3 && s.p2.y == 4) { return(3); // 1+2 } else { return(-1); // 1-2 } } else { if (s.p2.x == 3 && s.p2.y == 4) { return(1); // -1+2 } else { return(-3); // -1-2 } } }
public static int arrayOfStructuresParams(int[] xs, int[] ys) { if (xs == null || ys == null || xs.Length != ys.Length) { return(0); } CoordinateStructure[] cs = new CoordinateStructure[xs.Length]; for (int i = 0; i < cs.Length; i++) { cs[i] = new CoordinateStructure(); cs[i].x = xs[i]; cs[i].y = ys[i]; } int ret = 0; foreach (CoordinateStructure c in cs) { if ((c.x + c.y) % 2 == 0) { ret++; } else { ret--; } } return(ret); }
public static int twoStructures(CoordinateStructure c1, CoordinateStructure c2) { CoordinateStructure c = new CoordinateStructure(); c.x = c1.x + c2.x; c.y = c1.y + c2.y; if (c.x > 0 && c.y > 0) { return(1); } else if (c.x < 0 && c.y > 0) { return(2); } else if (c.x < 0 && c.y < 0) { return(3); } else if (c.x > 0 && c.y < 0) { return(4); } else { return(-1); } }
public static CoordinateStructure returnStructure( CoordinateStructure c) { c.x = -c.x; c.y = -c.y; return(c); }
/// <summary> /// Move pen through each of the points in the path (sequence) /// </summary> /// <param name="listGCodes"></param> /// <param name="sequence"></param> private static void SequencePath(List <string> listGCodes, CoordinateStructure sequence) { foreach (var step in sequence.ListRescaledPoints) { // using "G01" for "linear interpolation", to draw line between points listGCodes.Add($"{GCodes.LinearInterpolation} x{(int)step.X} y{(int)step.Y} z{Pen.PenDownIndex}\n"); } }
public static int useStructureParams(int x, int y) { CoordinateStructure c = new CoordinateStructure(); c.x = x; c.y = y; return(c.x + c.y); }
/// <summary> /// Lift the pen at the last coordinate (ready to 'rapid reposition to start of next path') /// </summary> /// <param name="listGCodes"></param> /// <param name="sequence"></param> private static void SequenceEnd(List <string> listGCodes, CoordinateStructure sequence) { Point endPoint = new Point { X = (int)(sequence.ListRescaledPoints[sequence.ListRescaledPoints.Count - 1].X), Y = (int)(sequence.ListRescaledPoints[sequence.ListRescaledPoints.Count - 1].Y) }; listGCodes.Add($"{GCodes.RapidReposition} x{endPoint.X} y{endPoint.Y} z{Pen.PenUpIndex}\n"); }
public List <CoordinateStructure> ExtractCoordinates(List <string> listPathNodes) { // an array of arrays (which contain point coordinates, which are constructed from the list of offsets in the SVG List <CoordinateStructure> listCoordinateStructures = new List <CoordinateStructure>(); Console.WriteLine($"Parsing nodes..."); foreach (var pathNode in listPathNodes) { var coordinateStructure = new CoordinateStructure(); var listWords = pathNode.Split(" "); // extract start coordinates int coordStartX = int.Parse(Regex.Replace(listWords[0], "[^0-9.+-]", "")); int coordStartY = int.Parse(Regex.Replace(listWords[1], "[^0-9.+-]", "")); coordinateStructure.ListPoints.Add(new Point(coordStartX, coordStartY)); int i = 2; // don't start at very beginning, skip over the first pair of values as these are always the "starting position" SvgPathVariantEnum currentSvgPathVariantEnum = SvgPathVariantEnum.Unset; while (i < listWords.Length) { //check to see if the "variant" has changed (is this a line or curve, or are we carrying on from the last previously set variant?) var newPathVariant = GetCurrentPathVariant(listWords, i); if (newPathVariant != SvgPathVariantEnum.Unset) { currentSvgPathVariantEnum = newPathVariant; } // depending on the "variant" extract the appropriate coordinates and add this to "coordinateStructure.ListPoints" collection. Point previousPoint = coordinateStructure.ListPoints[coordinateStructure.ListPoints.Count - 1]; Point?nextPoint = ExtractCoordinate(previousPoint, listWords, i, currentSvgPathVariantEnum); if (nextPoint is null) { // skip over, as point was a "MoveTo" command. } else { coordinateStructure.ListPoints.Add((Point)nextPoint); } //depending on the current variant, increment the current index appropriately (either by 2 for a line, or 6 for a curve) i = i + IncrementCurrentPathIndex(currentSvgPathVariantEnum); } listCoordinateStructures.Add(coordinateStructure); } return(listCoordinateStructures); }
public static CoordinateStructure returnStructureParams(int x, int y) { CoordinateStructure c = new CoordinateStructure(); c.x = x; c.y = y; c.x = -c.x; c.y = -c.y; return(c); }
/// <summary> /// Move pen to starting point of new path (sequence) /// </summary> /// <param name="listGCodes"></param> /// <param name="sequence"></param> private static void SequenceStart(List <string> listGCodes, CoordinateStructure sequence) { Point startingPoint = new Point { X = (int)(sequence.ListRescaledPoints[0].X), Y = (int)(sequence.ListRescaledPoints[0].Y) }; // reposition pen to start of sequence, explicitly lift the pen, so it doesn't draw a line during the repositioning [from previous step] listGCodes.Add($"{GCodes.RapidReposition} x{startingPoint.X} y{startingPoint.Y} z{Pen.PenUpIndex}\n"); // lower pen, as we're about to start drawing... listGCodes.Add($"{GCodes.LinearInterpolation} x{startingPoint.X} y{startingPoint.Y} z{Pen.PenDownIndex}\n"); }
public static int withLimit(CoordinateStructure c, int max) { int ret = 0; for (int i = 0; i < max && i < 10; i++) { if ((c.x + c.y) % 2 == 0) { ret++; } else { ret--; } } return(ret); }
public static int twoStructuresParams(int x1, int y1, int x2, int y2) { CoordinateStructure c1 = new CoordinateStructure(); c1.x = x1; c1.y = y1; CoordinateStructure c2 = new CoordinateStructure(); c2.x = x2; c2.y = y2; CoordinateStructure c = new CoordinateStructure(); c.x = c1.x + c2.x; c.y = c1.y + c2.y; if (c.x > 0 && c.y > 0) { return(1); } else if (c.x < 0 && c.y > 0) { return(2); } else if (c.x < 0 && c.y < 0) { return(3); } else if (c.x > 0 && c.y < 0) { return(4); } else { return(-1); } }
public static int oneStructure(CoordinateStructure c) { if (c.x > 0 && c.y > 0) { return(1); } else if (c.x < 0 && c.y > 0) { return(2); } else if (c.x < 0 && c.y < 0) { return(3); } else if (c.x > 0 && c.y < 0) { return(4); } else { return(-1); } }
public static int noLimitParams(int x, int y, int max) { CoordinateStructure c = new CoordinateStructure(); c.x = x; c.y = y; int ret = 0; for (int i = 0; i < max; i++) { if ((c.x + c.y) % 2 == 0) { ret++; } else { ret--; } } return(ret); }
public static int useStructure(CoordinateStructure c) { return(c.x + c.y); }