Attribute VB_Name = "mMath" Option Explicit ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Operações matemáticas gerais ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Converte um vetor de três bytes num número (big-endian & unsigned) ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Function Get3ByteNumber(vtbtInput) As Long ' Converte e soma Get3ByteNumber = vtbtInput(0) * 65536 + _ vtbtInput(1) * 256 + _ vtbtInput(2) End Function ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Converte um vetor de quatro bytes num número (little-endian & unsigned) ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Function Get4ByteNumber(vtbtInput) As Long ' Converte e soma Get4ByteNumber = vtbtInput(3) * 16777216 + _ vtbtInput(2) * 65536 + _ vtbtInput(1) * 256 + _ vtbtInput(0) End Function ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Retorna se um número possui outro ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Function Has(Number, Base) As Boolean ' Verifica se possui e retorna Has = ((Number And Base) > 0) End Function ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Gera hex de 2 caracteres ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Function HexTwo(itNumber) As String Dim stAux As String ' Seta valor hex stAux = Hex(itNumber) ' Se não tiver tamanho 2 While (Len(stAux) < 2) ' Adiciona um caracter 0 antes stAux = "0" + stAux Wend ' Retorna HexTwo = stAux End Function ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Gera hex de 4 caracteres ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Function HexFour(itNumber) As String Dim stAux As String ' Seta valor hex stAux = Hex(itNumber) ' Se não tiver tamanho 4 While (Len(stAux) < 4) ' Adiciona um caracter 0 antes stAux = "0" + stAux Wend ' Retorna HexFour = stAux End Function ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Retorna valor hex em número (para byte/integer) ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Function dHexTwo(stInput As String) As Byte ' Verifica se a string possui um tamanho válido If (Len(stInput) = 2) Then ' Decodifica dHexTwo = c_Bitwise.ShiftLeft(HexValue(Mid(stInput, 1, 1)), 4) + _ HexValue(Mid(stInput, 2, 1)) End If End Function Function dHexFour(stInput As String) As Integer ' Verifica se a string possui um tamanho válido If (Len(stInput) = 4) Then ' Decodifica dHexFour = c_Bitwise.ShiftLeft(HexValue(Mid(stInput, 1, 1)), 12) + _ c_Bitwise.ShiftLeft(HexValue(Mid(stInput, 2, 1)), 8) + _ c_Bitwise.ShiftLeft(HexValue(Mid(stInput, 3, 1)), 4) + _ HexValue(Mid(stInput, 4, 1)) End If End Function ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Valor hexa ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Private Function HexValue(stHex As String) As Byte ' Verifica qual o caracter Select Case stHex ' Se for numérico Case 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ' Retorna próprio valor numérico HexValue = CByte(stHex) ' Outros valores Case "A", "a" HexValue = 10 Case "B", "b" HexValue = 11 Case "C", "c" HexValue = 12 Case "D", "d" HexValue = 13 Case "E", "e" HexValue = 14 Case "F", "f" HexValue = 15 End Select End Function ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Porta lógica NOR ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 'Sub Nor(Number, Base) ' ' ' Seta ' Number = Number Or (Not Base) 'End Sub ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' "Desmarca" um número em outro ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Sub Nand(Number, Base) ' Seta Number = Number And (Not Base) End Sub ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Se uma reta planar está próxima de outra ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Public Function lineClose(lnLine1a As Long, lnLine1b As Long, lnLine2a As Long, lnLine2b As Long) As Boolean ' Ordem 1----1 2----2 If (lnLine2a > lnLine1a) Then ' Se o inicial de 2 estiver anterior ao final de 1 lineClose = ((lnLine2a - lnLine1b) <= LN_LINE_CLOSE) ' Ordem 2----2 1---1 Else ' Se o inicial de 1 estiver anterior ao final de 2 lineClose = ((lnLine1a - lnLine2b) <= LN_LINE_CLOSE) End If End Function ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Dado dois retângulos, verificar se são próximos (attachment) ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Public Function rectClose(rtPos1 As RECT, rtPos2 As RECT) As Boolean ' Se bottom/top estão próximos If lineClose(rtPos1.Left, rtPos1.Right, rtPos2.Left, rtPos2.Right) Then ' Se left/rigth estão próximos rectClose = lineClose(rtPos1.Top, rtPos1.Bottom, rtPos2.Top, rtPos2.Bottom) Else ' Retorna que não são próximos rectClose = False End If End Function