@name line_mindist
@inputs 
@outputs Distance 
@persist [PointA PointB]:vector
@trigger none

if (first()) {
    
    function number minDist( LineA:vector , LineB:vector , Point:vector ) {
        local LineA = LineA:setZ(0)
        local LineB = LineB:setZ(0)
        local Point = Point:setZ(0)
    
        local Length2 = LineA:distance2(LineB)
        
        # Case: LineA == LineB
        if (Length2 == 0) { return Point:distance(LineA) }
        
        local Dot = (Point - LineA):dot(LineB - LineA) / Length2
        
        # Case: Beyond LineA
        if (Dot < 0) { return Point:distance(LineA) }
    
        # Case: Beyond LineB
        if (Dot > 1) { return Point:distance(LineB) }
    
        # Case: On Segment
        return Point:distance(LineA + Dot*(LineB - LineA))
    }
    
    
    PointA = entity():pos()
    PointB = entity():pos() + vec(200, 0, 0):rotate(0, 45, 0)
    
    holoCreate(1, PointA)
    holoCreate(2, PointB)

}

Distance = minDist( PointA, PointB, entity():pos() )

interval(60)
