- Joined
- Sep 14, 2012
- Messages
- 3,413
Oh okay.
I fear that someone do this.
I think I'll fix those static to members.
I fear that someone do this.
I think I'll fix those static to members.
Oh okay.
I fear that someone do this.
I think I'll fix those static to members.
// Constructor for a complex number from polar coordinates
static method createPolar takes real abs, real phase returns thistype
// Setter for absolute value of the complex number
method operator abs= takes real value returns nothing
// Setter for phase value of the complex number
method operator arg= takes real value returns nothing
call
here:debug BJDebugMsg("thistype Error : Divide by 0!! Crashing thread")
But what to do if the user create a cartesian one and uses such method ?
It would be a mess.
1. Convert the cartesian to polar form
2. Set its absolute value/phase appropriate
3. Convert it back to cartesian and store those values
Updated.
Didn't make the polar functions yet.
debug BJDebugMsg("thistype Error : Divide by 0!! Crashing thread")
method add takes thistype z returns thistype
local thistype c = thistype.allocate()
set c.re = this.re + z.re
set c.im = this.im + z.im
return c
endmethod
method add takes thistype z returns thistype
return thistype.create(this.re + z.re, this.im + z.im)
endmethod
method exp takes nothing returns thistype
return Complex.create(Pow(e, this.re)*Cos(this.im), Pow(e, this.re)*Sin(this.im))
endmethod
thistype
here would be preferable over Complex
, to keep it consistent with the rest of the library.Yeah I just made this before seeing the post ^^'
I'll update soon.
Done.
debug BJDebugMsg("thistype Error : Divide by 0!! Crashing thread"
local Complex c = Complex.create(-9, 0)
call BJDebugMsg(c.sqrt().toString())
method toString takes nothing returns string
local string s
if (this.im > 0) then
set s = R2S(this.re)+"+"+R2S(this.im)+"i"
else
set s = R2S(this.re)+" "+R2S(this.im)+"i"
endif
return s
endmethod
method toString takes nothing returns string
if (this.im > 0) then
return R2S(this.re)+"+"+R2S(this.im)+"i"
endif
return R2S(this.re)+R2S(this.im)+"i" // No space required here
endmethod
div
method could also be shortened a bit by this). Also you should remove the space in the string for negative imaginary parts (see comment in the code above) such that both complex values look equal. Otherwise you have this:1.0-2.0i // good
1.0 +2.0i // additional space if im > 0, inconsistent
toStringPolar
method would be nice toothis.im==0
to this.im == 0
since you used spaces that way everywhere else to keep the coding consistent (same in div
method).method operator== takes thistype z returns boolean
I didn't remember it is possible to override == in vJASS.
thistype
interchangeable with integer
instead of performing an explicit cast. So using an overloaded operator== might lead to difficult-to-find bugs.operator<
, then operator>
is defined automaticallyoperator==
, then operator!=
is defined automatically<=
and >=
are never defined and you also have no way of defining these. So using them, will instead use the corresponding integer operators:struct Test
integer value
static method create takes integer val returns thistype
local thistype this = thistype.allocate()
set this.value = val
return this
endmethod
method operator< takes thistype other returns boolean
return value < other.value
endmethod
method operator== takes thistype other returns boolean
return value == other.value
endmethod
endstruct
function foo takes nothing returns nothing
Test t1 = Test.create(1)
Test t2 = Test.create(2)
if t1 == t2 then // calls Test.operator==
endif
if t1 > t2 then // calls Test.operator>
endif
if t1 >= t2 then // calls integer.operator>= !!!
endif
endfunction
Trying to sort C is pointless.
But yeah I agreee about the common point about comparaison operators.
operator==
to a method like equals
is better due to the incomplete implementation of operator overloading in vJass... I also seems that those operators don't work correctly when used in combination with modules, so... Maybe its best not to use them at all.local Complex c1 = Complex.create(-81, 81)
local Complex c2 = Complex.create(-9, 0)
call BJDebugMsg(c1.div(c2).toString())
this.im >= 0
instead of this.im > 0
, because zero is also displayed without sign, so we need to add the plus to the string as well.Updated
elitism at its prime?
So how would manderbrot usable in wc3 in any sensible way anyway?