[docs]defseams_align(slicer,align_with="next_path"):"""Aligns the seams (start- and endpoint) of a print. Parameters ---------- slicer: :class:`compas_slicer.slicers.BaseSlicer` An instance of one of the compas_slicer.slicers classes. align_with: str or :class:`compas.geometry.Point` Direction to orient the seams in. next_path = orients the seam to the next path origin = orients the seam to the origin (0,0,0) x_axis = orients the seam to the x_axis y_axis = orients the seam to the y_axis Point(x,y,z) = orients the seam according to the given point Returns ------- None """# TODO: Implement random seamslogger.info("Aligning seams to: %s"%align_with)fori,layerinenumerate(slicer.layers):forj,pathinenumerate(layer.paths):ifalign_with=="next_path":pt_to_align_with=None# make sure aligning point is cleared# determines the correct point to align the current path withiflen(layer.paths)==1andi==0:# if ONE PATH and FIRST LAYER# >>> align with second layerpt_to_align_with=slicer.layers[i+1].paths[0].points[0]iflen(layer.paths)==1andi!=0:last_path_index=len(slicer.layers[i-1].paths)-1# if ONE PATH and NOT FIRST LAYER# >>> align with previous layerpt_to_align_with=slicer.layers[i-1].paths[last_path_index].points[-1]iflen(layer.paths)!=1andi==0andj==0:# if MULTIPLE PATHS and FIRST LAYER and FIRST PATH# >>> align with second path of first layerpt_to_align_with=slicer.layers[i].paths[i+1].points[-1]iflen(layer.paths)!=1andj!=0:# if MULTIPLE PATHS and NOT FIRST PATH# >>> align with previous pathpt_to_align_with=slicer.layers[i].paths[j-1].points[-1]iflen(layer.paths)!=1andi!=0andj==0:# if MULTIPLE PATHS and NOT FIRST LAYER and FIRST PATH# >>> align with first path of previous layerlast_path_index=len(slicer.layers[i-1].paths)-1pt_to_align_with=slicer.layers[i-1].paths[last_path_index].points[-1]elifalign_with=="origin":pt_to_align_with=Point(0,0,0)elifalign_with=="x_axis":pt_to_align_with=Point(2**32,0,0)elifalign_with=="y_axis":pt_to_align_with=Point(0,2**32,0)elifisinstance(align_with,Point):pt_to_align_with=align_withelse:raiseNameError("Unknown align_with : "+str(align_with))# CLOSED PATHSifpath.is_closed:# get the points of the current layer and pathpath_to_change=layer.paths[j].points# check if start- and end-points are the same pointifpath_to_change[0]==path_to_change[-1]:first_last_point_the_same=True# if they are, remove the last pointpath_to_change.pop(-1)else:first_last_point_the_same=False# computes distance between pt_to_align_with and the current path pointsdistance_current_pt_align_pt=[distance_point_point(pt_to_align_with,pt)forptinpath_to_change]# gets the index of the closest point by looking for the minimumnew_start_index=distance_current_pt_align_pt.index(min(distance_current_pt_align_pt))# shifts the list by the distance determinedshift_list=path_to_change[new_start_index:]+path_to_change[:new_start_index]iffirst_last_point_the_same:shift_list=shift_list+[shift_list[0]]layer.paths[j].points=shift_listelse:# OPEN PATHSpath_to_change=layer.paths[j].points# get the distance between the align point and the start/end pointstart=path_to_change[0]end=path_to_change[-1]d_start=distance_point_point(start,pt_to_align_with)d_end=distance_point_point(end,pt_to_align_with)# if closer to end point > reverse listifd_start>d_end:layer.paths[j].points.reverse()