# Path: drawingDimensioning/linearDimension.py
# def linearDimension_parallels_hide_non_parallel(elementParms, elementViewObject):
#     x1,y1,x2,y2 = [ elementParms[k] for k in [ 'x1', 'y1', 'x2', 'y2' ] ]
#     d = numpy.array([ x2 - x1, y2 - y1] )
#     d_ref = d / numpy.linalg.norm(d)
#     p = numpy.array([ x1, y1] )
#     def hideFun( gi ):
#         if isinstance(gi,selectionOverlay.LineSelectionGraphicsItem):
#             if gi.elementParms != elementParms:
#                 x1,y1,x2,y2 = [ gi.elementParms[k] for k in [ 'x1', 'y1', 'x2', 'y2' ] ]
#                 d = numpy.array([ x2 - x1, y2 - y1] )
#                 d = d / numpy.linalg.norm(d)
#                 if abs(numpy.dot(d_ref,d)) > 1.0 - 10**-9: #then parallel
#                     d_rotated = rotate2D(d, numpy.pi/2)
#                     offset =  numpy.array([ x1, y1] ) - p
#                     if abs(numpy.dot(d_rotated, offset)) > 10**-6: #then not colinear
#                         return False
#         elif isinstance(gi,selectionOverlay.PointSelectionGraphicsItem):
#             return False
#         return True 
#     selectionOverlay.hideSelectionGraphicsItems(hideFun)


from drawingDimensioning.command import *
from .linearDimension import linearDimension_parallels_hide_non_parallel

d = DimensioningCommand( add_viewScale_KW = True )

def _centerLineSVG( x1, y1, x2, y2, len_dot, len_dash, len_gap, start_with_half_dot=False):
    start = numpy.array( [x1, y1] )
    end = numpy.array( [x2, y2] )
    d = directionVector(start, end)
    dCode = ''
    pos = start
    step = len_dot*0.5 if start_with_half_dot else len_dot
    while norm(pos - start) + 10**-6 < norm(end - start):
        dCode = dCode + 'M %f,%f' %  (pos[0], pos[1])
        pos = pos + d*step
        if norm(pos - start) > norm(end - start):
            pos = end
        dCode = dCode + ' L %f,%f ' % (pos[0], pos[1])
        pos = pos + d*len_gap
        step = len_dash if step < len_dash else len_dot
    if dCode != '':
        return '<path d="%s"/>' % dCode
    else:
        return ''

def _centerLinesSVG( center, topLeft, bottomRight, viewScale, centerLine_len_dot, centerLine_len_dash, centerLine_len_gap, strokeWidth, lineColor, doVertical, doHorizontal ):
    XML_body = []

# Path: drawingDimensioning/linearDimension.py
# def linearDimension_parallels_hide_non_parallel(elementParms, elementViewObject):
#     x1,y1,x2,y2 = [ elementParms[k] for k in [ 'x1', 'y1', 'x2', 'y2' ] ]
#     d = numpy.array([ x2 - x1, y2 - y1] )
#     d_ref = d / numpy.linalg.norm(d)
#     p = numpy.array([ x1, y1] )
#     def hideFun( gi ):
#         if isinstance(gi,selectionOverlay.LineSelectionGraphicsItem):
#             if gi.elementParms != elementParms:
#                 x1,y1,x2,y2 = [ gi.elementParms[k] for k in [ 'x1', 'y1', 'x2', 'y2' ] ]
#                 d = numpy.array([ x2 - x1, y2 - y1] )
#                 d = d / numpy.linalg.norm(d)
#                 if abs(numpy.dot(d_ref,d)) > 1.0 - 10**-9: #then parallel
#                     d_rotated = rotate2D(d, numpy.pi/2)
#                     offset =  numpy.array([ x1, y1] ) - p
#                     if abs(numpy.dot(d_rotated, offset)) > 10**-6: #then not colinear
#                         return False
#         elif isinstance(gi,selectionOverlay.PointSelectionGraphicsItem):
#             return False
#         return True 
#     selectionOverlay.hideSelectionGraphicsItems(hideFun)


# Path: drawingDimensioning/centerLines.py
from drawingDimensioning.command import *
from .linearDimension import linearDimension_parallels_hide_non_parallel


d = DimensioningCommand( add_viewScale_KW = True )

def _centerLineSVG( x1, y1, x2, y2, len_dot, len_dash, len_gap, start_with_half_dot=False):
    start = numpy.array( [x1, y1] )
    end = numpy.array( [x2, y2] )
    d = directionVector(start, end)
    dCode = ''
    pos = start
    step = len_dot*0.5 if start_with_half_dot else len_dot
    while norm(pos - start) + 10**-6 < norm(end - start):
        dCode = dCode + 'M %f,%f' %  (pos[0], pos[1])
        pos = pos + d*step
        if norm(pos - start) > norm(end - start):
            pos = end
        dCode = dCode + ' L %f,%f ' % (pos[0], pos[1])
        pos = pos + d*len_gap
        step = len_dash if step < len_dash else len_dot
    if dCode != '':
        return '<path d="%s"/>' % dCode
    else:
        return ''

def _centerLinesSVG( center, topLeft, bottomRight, viewScale, centerLine_len_dot, centerLine_len_dash, centerLine_len_gap, strokeWidth, lineColor, doVertical, doHorizontal ):
    XML_body = []

    center = numpy.array( center ) / viewScale