def isPointAddedAroundClosest(layerInfillWidth, paths, pixelTable, removedEndpointPoint, width):
 closestDistanceSquared = 9.999999999876543e+17
 closestPathIndex = None
 for pathIndex in xrange(len(paths)):
  path = paths[pathIndex]
  for pointIndex in xrange(len(path)):
   point = path[pointIndex]
   distanceSquared = abs((point - removedEndpointPoint))
   if (distanceSquared < closestDistanceSquared):
    closestDistanceSquared = distanceSquared
    closestPathIndex = pathIndex
 if (closestPathIndex == None):
  return
 if (closestDistanceSquared < ((0.8 * layerInfillWidth) * layerInfillWidth)):
  return
 closestPath = paths[closestPathIndex]
 closestPointIndex = getWithLeastLength(closestPath, removedEndpointPoint)
 if isAddedPointOnPathFree(closestPath, pixelTable, removedEndpointPoint, closestPointIndex, width):
  addPointOnPath(closestPath, closestPathIndex, pixelTable, removedEndpointPoint, closestPointIndex, width)
  return True
 return isSidePointAdded(pixelTable, closestPath, closestPathIndex, closestPointIndex, layerInfillWidth, removedEndpointPoint, width)

def isPointAddedAroundClosest ( layerInfillWidth , paths , pixelTable , removedEndpointPoint , width ) : closestDistanceSquared = 9.999999999876543e+17 closestPathIndex = None for pathIndex in xrange ( len ( paths ) ) : path = paths [ pathIndex ] for pointIndex in xrange ( len ( path ) ) : point = path [ pointIndex ] distanceSquared = abs ( ( point - removedEndpointPoint ) ) if ( distanceSquared < closestDistanceSquared ) : closestDistanceSquared = distanceSquared closestPathIndex = pathIndex if ( closestPathIndex == None ) : return if ( closestDistanceSquared < ( ( 0.8 * layerInfillWidth ) * layerInfillWidth ) ) : return closestPath = paths [ closestPathIndex ] closestPointIndex = getWithLeastLength ( closestPath , removedEndpointPoint ) if isAddedPointOnPathFree ( closestPath , pixelTable , removedEndpointPoint , closestPointIndex , width ) : addPointOnPath ( closestPath , closestPathIndex , pixelTable , removedEndpointPoint , closestPointIndex , width ) return True return isSidePointAdded ( pixelTable , closestPath , closestPathIndex , closestPointIndex , layerInfillWidth , removedEndpointPoint , width )
add the closest removed endpoint to the path .