I am with you Wave! Let's make this mod.
I am Making the start...
Here what I have done this morning
Type HaLine2d
Field x1# , y1# , x2# , y2#
Function create:HALine2d(_x1# = 0 , _y1 = 0 , _x2# = 10 , _y2# = 0)
Local FLine:HALine2d = New HALine2d
FLine.x1 = _x1
FLine.y1 = _y1
FLine.x2 = _X2
FLine.y2 = _y2
Return FLine
End Function
Function createParallel:HALine2d(Line1:HALine2d , _x , _y , _Length)
Local Line2:HALine2d = New HALine2d
Line2.x1 = _x
Line2.y1 = _y
Line2.x2 = Line2.x1 + ( Cos(Line1.getAngle() ) * _Length)
Line2.y2 = Line2.y1 - ( Sin(Line1.getAngle() ) * _Length)
Return Line2
End Function
Function createVertical:HALine2d(Line1:HALine2d , _x , _y , _Length)
Local Line2:HALine2d = New HALine2d
Line2.x1 = _x
Line2.y1 = _y
Line2.x2 = Line2.x1 + ( Cos(Line1.getAngle() + 90) * _Length)
Line2.y2 = Line2.y1 - ( Sin(Line1.getAngle() + 90) * _Length)
Return Line2
End Function
Method Draw()
DrawLine x1 , y1 , x2 , y2
End Method
Method GetLength:Float()
Return Sqr( (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1) )
End Method
Method getAngle:Float()
Return ATan2(y1 - y2 , x2 - x1)
End Method
Method extendLine(Ex:Float , dir:Byte = 1)
Local an:Float = self.getAngle()
If Dir = True
x2 = x2 + (Cos(an) * Ex)
y2 = y2 - (Sin(an) * Ex)
End If
If Dir = False
x1 = x1 - (Cos(an) * Ex)
y1 = y1 + (Sin(an) * Ex)
End If
End Method
Method reverse()
Local xr# = x1
Local yr# = y1
x1 = x2
y1 = y2
x2 = xr
y2 = yr
End Method
Method setLength(L:Float , dir:Byte = 1)
Local an:Float = self.getAngle()
If dir = True
x2 = x1 + (Cos(an) * L)
y2 = y1 - (Sin(an) * L)
End If
If dir = False
x1 = x2 - (Cos(an) * L)
y1 = y2 + (Sin(an) * L)
End If
End Method
Method setAngle(an:Float , tr:Byte = 1)
Local L:Float = self.getLength()
If tr = True
x2 = x1 + ( Cos(an) * L)
y2 = y1 - ( Sin(an) * L)
End If
If tr = False
x1 = x2 + ( Cos(an) * L)
y1 = y2 - ( Sin(an) * L)
End If
End Method
Method MoveTo(_x , _y , tr:Byte = 1)
Local an# = getAngle()
Local L# = getLength()
If tr = True
x1 = _x
y1 = _y
x2 = x1 + (Cos(an) * L)
y2 = y1 - (Sin(an) * L)
End If
If tr = False
x2 = _x
y2 = _y
x1 = x2 - (Cos(an) * L)
y1 = y2 + (Sin(an) * L)
End If
End Method
Method CollideLine(_Line:HALine2d)
Local L1d:Float
Local L2d:Float
Local L1x#,L1y#,L2x#,L2y#
L1x = x2-x1
L1y = y2-y1
L2x = _Line.x2-_Line.x1
L2y = _Line.y2-_Line.y1
L1d = ( _Line.y1 - y1 + (L2y/L2x)*( x1 - _Line.x1 )) / ( L1y - L2y*L1x/L2x )
If L1d >=0 And L1d <=1
L2d = ( x1 + L1x*L1d - _Line.x1 ) / L2x
If L2d >=0 And L2d <=1
Return True
EndIf
EndIf
Return False
End Method
Method GetCollideLinePoint(xi# Var , yi# Var , _Line:HALine2d)
Local L1d:Float
Local L2d:Float
Local L1x#,L1y#,L2x#,L2y#
L1x = x2-x1
L1y = y2-y1
L2x = _Line.x2-_Line.x1
L2y = _Line.y2-_Line.y1
L1d = ( _Line.y1 - y1 + (L2y/L2x)*( x1 - _Line.x1 )) / ( L1y - L2y*L1x/L2x )
If L1d >=0 And L1d <=1
L2d = ( x1 + L1x*L1d - _Line.x1 ) / L2x
If L2d >=0 And L2d <=1
xi = x1 + L1d*L1x
yi = y1 + L1d*L1y
Return True
EndIf
EndIf
Return False
End Method
End Type