From 6dae2d2541e572a7d3c0c218eba794b1edeaf988 Mon Sep 17 00:00:00 2001 From: Peter Vaiko Date: Wed, 1 Jan 2025 13:23:06 -0500 Subject: [PATCH 1/4] fix: multi vehicle course with no headland #252 --- scripts/courseGenerator/FieldworkCourseMultiVehicle.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/courseGenerator/FieldworkCourseMultiVehicle.lua b/scripts/courseGenerator/FieldworkCourseMultiVehicle.lua index 5a634db45..71209fd7a 100644 --- a/scripts/courseGenerator/FieldworkCourseMultiVehicle.lua +++ b/scripts/courseGenerator/FieldworkCourseMultiVehicle.lua @@ -232,8 +232,7 @@ function FieldworkCourseMultiVehicle:generateCenter() -- if there are no headlands, or there are, but we start working in the middle, then use the -- designated start location, otherwise the point where the innermost headland ends. if #self.headlands == 0 then - -- the virtual headland the center uses is the combined working width - self.context:setHeadlandWidthForAdjustment(self.context.nVehicles * self.context.workingWidth) + -- the virtual headland the center uses is the single working width, no need for adjusted headland width self.center = CourseGenerator.Center(self.context, self.boundary, nil, self.context.startLocation, self.bigIslands) else -- The center is generated with the combined width of all vehicles and it assumes that the headland From 2df9a21e3d0c95fd741a7494738317d68c285b2c Mon Sep 17 00:00:00 2001 From: Peter Vaiko Date: Wed, 1 Jan 2025 14:34:19 -0500 Subject: [PATCH 2/4] fix: division by zero #252 --- scripts/courseGenerator/FieldworkCourseMultiVehicle.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scripts/courseGenerator/FieldworkCourseMultiVehicle.lua b/scripts/courseGenerator/FieldworkCourseMultiVehicle.lua index 71209fd7a..a4d0f6a03 100644 --- a/scripts/courseGenerator/FieldworkCourseMultiVehicle.lua +++ b/scripts/courseGenerator/FieldworkCourseMultiVehicle.lua @@ -345,7 +345,12 @@ end ---@param polyline Polyline the original path ---@param offsetVector Vector offset vector, the direction and length of the offset (left: y > 0, right: y < 0) local function _generateOffsetSection(polyline, offsetVector) - local offsetUnitVector = offsetVector / offsetVector:length() + local offsetUnitVector + if offsetVector:length() > 0.00001 then + offsetUnitVector = offsetVector / offsetVector:length() + else + offsetUnitVector = offsetVector + end return CourseGenerator.Offset.generate(polyline, offsetUnitVector, offsetVector:length()) end From b3da6ce91fad11a381c50422a2de3e4db6d3dd2d Mon Sep 17 00:00:00 2001 From: Peter Vaiko Date: Wed, 1 Jan 2025 14:35:48 -0500 Subject: [PATCH 3/4] fix: division by zero On a second thought, it is probably better to fix this on the Vector level... #252 --- scripts/courseGenerator/FieldworkCourseMultiVehicle.lua | 7 +------ scripts/geometry/Vector.lua | 2 +- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/scripts/courseGenerator/FieldworkCourseMultiVehicle.lua b/scripts/courseGenerator/FieldworkCourseMultiVehicle.lua index a4d0f6a03..71209fd7a 100644 --- a/scripts/courseGenerator/FieldworkCourseMultiVehicle.lua +++ b/scripts/courseGenerator/FieldworkCourseMultiVehicle.lua @@ -345,12 +345,7 @@ end ---@param polyline Polyline the original path ---@param offsetVector Vector offset vector, the direction and length of the offset (left: y > 0, right: y < 0) local function _generateOffsetSection(polyline, offsetVector) - local offsetUnitVector - if offsetVector:length() > 0.00001 then - offsetUnitVector = offsetVector / offsetVector:length() - else - offsetUnitVector = offsetVector - end + local offsetUnitVector = offsetVector / offsetVector:length() return CourseGenerator.Offset.generate(polyline, offsetUnitVector, offsetVector:length()) end diff --git a/scripts/geometry/Vector.lua b/scripts/geometry/Vector.lua index 0429a9c70..8f5fe96ab 100644 --- a/scripts/geometry/Vector.lua +++ b/scripts/geometry/Vector.lua @@ -130,7 +130,7 @@ end -- meta function to divide Vectors function Vector.__div(a,b) assert(a:is_a(Vector) and type(b) == "number", "div: wrong argument types (expected and )") - return Vector(a.x / b, a.y / b) + return Vector(CpMathUtil.divide(a.x / b), CpMathUtil.divide(a.y / b)) end -- meta function to check if Vectors have the same values From 5a2aaf0c2afe8d879b0153aae6f2e5893540cdc2 Mon Sep 17 00:00:00 2001 From: Peter Vaiko Date: Wed, 1 Jan 2025 14:39:33 -0500 Subject: [PATCH 4/4] fix: division by zero On a second thought, it is probably better to fix this on the Vector level... #252 --- scripts/geometry/Vector.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/geometry/Vector.lua b/scripts/geometry/Vector.lua index 8f5fe96ab..139f7d3da 100644 --- a/scripts/geometry/Vector.lua +++ b/scripts/geometry/Vector.lua @@ -130,7 +130,7 @@ end -- meta function to divide Vectors function Vector.__div(a,b) assert(a:is_a(Vector) and type(b) == "number", "div: wrong argument types (expected and )") - return Vector(CpMathUtil.divide(a.x / b), CpMathUtil.divide(a.y / b)) + return Vector(CpMathUtil.divide(a.x, b), CpMathUtil.divide(a.y, b)) end -- meta function to check if Vectors have the same values