number range
merci son auteur
- Code : Tout sélectionner
Public Class NumberRange
' A range of numerics.
' Please read the Gnu General Public License before use:
' http://www.gnu.org/licenses/gpl.txt
' @author Johan Känngård, http://dev.kanngard.net/
' @version 0.8a
lo As Variant
hi As Variant
Public Sub new(lo As Variant, hi As Variant)
' Creates a new NumberRange from lo to hi.
If Not ( Isscalar(lo) And Isscalar(hi) ) Then Error 2000, "Not scalars"
If Not Typename(lo) = Typename(hi) Then Error 2000, "Not same type"
If Not ( Isnumeric(lo) And Isnumeric(hi) ) Then Error 2000, "Not numerics"
Me.lo = lo
Me.hi = hi
End Sub
Public Function getMinimum() As Variant
' Returns the minimum number in this range.
getMinimum = lo
End Function
Public Function getMaximum() As Variant
' Returns the maximum number in this range.
getMaximum = hi
End Function
Public Function includesNumber(o As Variant) As Variant
' Tests whether the specified number occurs within this range.
includesNumber = (o => lo And o =< hi)
End Function
Public Function includesRange(r As NumberRange) As Variant
' Tests whether the specified range occurs entirely within this range.
includesRange = includesNumber(r.getMinimum()) _
And includesNumber(r.getMaximum())
End Function
Public Function overlaps(r As NumberRange) As Variant
' Tests whether the specified range overlaps with this range.
overlaps = includesNumber(r.getMinimum()) Or includesNumber(r.getMaximum())
End Function
Public Function toString() As String
' Returns the string representation of this range.
toString = getMinimum() & " to " & getMaximum()
End Function
End Class