def smoothed_path(path, maxjointsize=3, tightness=1.99, ignore_unfixable_kinks=False):
    """returns a path with no non-differentiable joints."""
    if len(path) == 1:
        return path

    assert path.iscontinuous()

    sharp_kinks = []
    new_path = [path[0]]
    for idx in range(len(path)):
        if idx == len(path)-1:
            if not path.isclosed():
                continue
            else:
                seg1 = new_path[0]
        else:
            seg1 = path[idx + 1]
        seg0 = new_path[-1]

        try:
            unit_tangent0 = seg0.unit_tangent(1)
            unit_tangent1 = seg1.unit_tangent(0)
            flag = False
        except ValueError:
            flag = True  # unit tangent not well-defined

        if not flag and isclose(unit_tangent0, unit_tangent1):  # joint is already smooth
            if idx != len(path)-1:
                new_path.append(seg1)
            continue
        else:
            kink_idx = (idx + 1) % len(path)  # kink at start of this seg
            if not flag and isclose(-unit_tangent0, unit_tangent1):
                # joint is sharp 180 deg (must be fixed manually)
                new_path.append(seg1)
                sharp_kinks.append(kink_idx)
            else:  # joint is not smooth, let's  smooth it.
                args = (seg0, seg1, maxjointsize, tightness)
                new_seg0, elbow_segs, new_seg1 = smoothed_joint(*args)
                new_path[-1] = new_seg0
                new_path += elbow_segs
                if idx == len(path) - 1:
                    new_path[0] = new_seg1
                else:
                    new_path.append(new_seg1)

    # If unfixable kinks were found, let the user know
    if sharp_kinks and not ignore_unfixable_kinks:
        _report_unfixable_kinks(path, sharp_kinks)

    return Path(*new_path)
def smoothed_path ( path , maxjointsize = 3 , tightness = 1.99 , ignore_unfixable_kinks = False ) : if len ( path ) == 1 : return path assert path . iscontinuous ( ) sharp_kinks = [ ] new_path = [ path [ 0 ] ] for idx in range ( len ( path ) ) : if idx == len ( path ) - 1 : if not path . isclosed ( ) : continue else : seg1 = new_path [ 0 ] else : seg1 = path [ idx + 1 ] seg0 = new_path [ - 1 ] try : unit_tangent0 = seg0 . unit_tangent ( 1 ) unit_tangent1 = seg1 . unit_tangent ( 0 ) flag = False except ValueError : flag = True if not flag and isclose ( unit_tangent0 , unit_tangent1 ) : if idx != len ( path ) - 1 : new_path . append ( seg1 ) continue else : kink_idx = ( idx + 1 ) % len ( path ) if not flag and isclose ( - unit_tangent0 , unit_tangent1 ) : new_path . append ( seg1 ) sharp_kinks . append ( kink_idx ) else : args = ( seg0 , seg1 , maxjointsize , tightness ) new_seg0 , elbow_segs , new_seg1 = smoothed_joint ( * args ) new_path [ - 1 ] = new_seg0 new_path += elbow_segs if idx == len ( path ) - 1 : new_path [ 0 ] = new_seg1 else : new_path . append ( new_seg1 ) if sharp_kinks and not ignore_unfixable_kinks : _report_unfixable_kinks ( path , sharp_kinks ) return Path ( * new_path )
returns a path with no non-differentiable joints.