I've got a problem that I imagine is due to some mistake on my part, but I've been unsuccessful in identifying the exact cause. I am trying to offset a polyline that is composed of line segments with xyz coordinates. Since the clipper2 library only uses xy coordinates, I'm basically trying to make PointD/PathD objects that have the original polyline's x/y values, inflate them to get the offset x/y values, and then update the original polyline to use those new offset x/y values. However, when I call InflatePaths(), the solution set is empty. The if(solution.isNotEmpty()) block never evaluates to true.
So I tried testing just some arbitrary points and even THIS gives an empty "testSolution":
val testPath = PathD(listOf(PointD(10, 20), PointD(25, 45), PointD(80, 155)))
val testPathsList = PathsD(listOf(testPath))
val testSolution = Clipper.InflatePaths(testPathsList, 5.0, JoinType.Round, EndType.Round)
Log.d("test", "Test solution: ${testSolution}") // Prints out "Test solution: "
private fun offsetPolyline(originalPolyline: ArrayList<Point3D>, offsetDistance: Double, closed:Boolean): ArrayList<Point3D> {
val pathForClipper = PathD()
for (point in originalPolyline) {
// Scale the x/y values for Clipper and add them to a path
pathForClipper.add(PointD(point.x, point.y))
}
// Add the path to a paths object so we can inflate
val paths = PathsD()
paths.add(pathForClipper)
// Use ClipperOffset to offset the path
val solution = Clipper.InflatePaths(paths, offsetDistance, JoinType.Round, if (closed) EndType.Polygon else EndType.Round) // again, consider the scaling
// Convert the resulting path(s) back to ArrayList<Point3D>
val offsetPolyline = ArrayList(originalPolyline)
if (solution.isNotEmpty()) {
for (i in solution[0].indices) { // take the first path, consider others?
offsetPolyline[i].x = solution[0][i].x
offsetPolyline[i].y = solution[0][i].y
}
} else {
Log.d("test", "Solution empty.")
}
return offsetPolyline
}