JumpyNET Posted September 30, 2009 Posted September 30, 2009 Hey guys! I do not have the correct words to look for a solution. So I'll try to explain what I want. Is it possible to achieve something like this: Dim angle1 as Angle = Math.Pi*3 '=Math.Pi Dim angle2 as Angle = Math.Pi*3/2 Dim angle3 as Angle = angle1 + angle2 debug.print(angle3) 'Would print 1.57 which is Math.Pi/2 Angle would be a custom class or type or whatever is the right word/solution and inside that "class" definition would be defined that these types can be added(+) and Angle is allways between [0...Math.Pi*2[. Quote
Administrators PlausiblyDamp Posted September 30, 2009 Administrators Posted September 30, 2009 You would want to look at operator overloading for this kind of thing. Something like the following might get you started - the general idea is there it would just need validation adding and the correct maths implemented :D Public Structure Angle Private _Angle As Decimal Public Shared Operator +(ByVal angle1 As Angle, ByVal angle2 As Angle) As Angle Dim a As Angle a._Angle = angle1._Angle + angle2._Angle Return a End Operator Public Shared Widening Operator CType(ByVal d As Decimal) As Angle Dim a As Angle 'validate the angle here a._Angle = d Return a End Operator Public Shared Widening Operator CType(ByVal a As Angle) As Decimal Return a._Angle End Operator End Structure Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.