Skip to content

Commit

Permalink
Grid: fix spiral start location
Browse files Browse the repository at this point in the history
  • Loading branch information
meee1 committed Feb 18, 2023
1 parent 7b08dbc commit 47490a8
Showing 1 changed file with 42 additions and 3 deletions.
45 changes: 42 additions & 3 deletions ExtLibs/Utilities/Grid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,40 @@ public static List<PointLatLngAlt> CreateRotary(List<PointLatLngAlt> polygon, do
// utm position list
List<utmpos> utmpositions = utmpos.ToList(PointLatLngAlt.ToUTM(utmzone, polygon), utmzone);

// close the loop if its not already
if (utmpositions[0] != utmpositions[utmpositions.Count - 1])
utmpositions.Add(utmpositions[0]); // make a full loop
// get mins/maxs of coverage area
Rect area = getPolyMinMax(utmpositions);

var maxlane = laps;// (Centroid(utmpositions).GetDistance(utmpositions[0]) / distance);

// pick start positon based on initial point rectangle
utmpos startposutm;

switch (startpos)
{
default:
case StartPosition.Home:
startposutm = new utmpos(HomeLocation);
break;
case StartPosition.BottomLeft:
startposutm = new utmpos(area.Left, area.Bottom, utmzone);
break;
case StartPosition.BottomRight:
startposutm = new utmpos(area.Right, area.Bottom, utmzone);
break;
case StartPosition.TopLeft:
startposutm = new utmpos(area.Left, area.Top, utmzone);
break;
case StartPosition.TopRight:
startposutm = new utmpos(area.Right, area.Top, utmzone);
break;
case StartPosition.Point:
startposutm = new utmpos(StartPointLatLngAlt);
break;
}

// find the closes polygon point based from our startpos selection
startposutm = findClosestPoint(startposutm, utmpositions);

ClipperLib.ClipperOffset clipperOffset = new ClipperLib.ClipperOffset();

clipperOffset.AddPath(utmpositions.Select(a => { return new ClipperLib.IntPoint(a.x * 1000.0, a.y * 1000.0); }).ToList(), ClipperLib.JoinType.jtMiter, ClipperLib.EndType.etClosedPolygon);
Expand All @@ -240,7 +268,18 @@ public static List<PointLatLngAlt> CreateRotary(List<PointLatLngAlt> polygon, do
{
ans1 = treeChild.Contour.Select(a => new utmpos(a.X / 1000.0, a.Y / 1000.0, utmzone))
.ToList();
// rotate points so the start point is close to the previous
{
startposutm = findClosestPoint(startposutm, ans1);

var startidx = ans1.IndexOf(startposutm);

var firsthalf = ans1.GetRange(startidx, ans1.Count - startidx);
var secondhalf = ans1.GetRange(0, startidx);

ans1 = firsthalf;
ans1.AddRange(secondhalf);
}
if (lane == 0 && clockwise_laps != 1 && match_spiral_perimeter)
{
ans1.Insert(0, ans1.Last<utmpos>()); // start at the last point of the first calculated lap
Expand Down

0 comments on commit 47490a8

Please sign in to comment.