Dirac
22710180
- Reaction score
- 147
Because i do, and i find it to be a very good replacement to the ugly Location native
The join method would be used to constantly have useful data of both locations at any time without repeating the same calculations
If you don't know what the "slope" variable is for, it's the relation between the difference of the height of two locs and the distance between them.
The join method would be used to constantly have useful data of both locations at any time without repeating the same calculations
If you don't know what the "slope" variable is for, it's the relation between the difference of the height of two locs and the distance between them.
JASS:
library Loc /* v1.0.0
Replacement of the Location native.
***********************************************************************
*
* struct Loc
*
* readonly real x
* readonly real y
* readonly real z
* - These 3 read-only variables are the Loc's coordinates
*
* static method create takes real x, real y, real z returns Loc
* - Creates a new Loc with the given coordinates.
* method destroy takes nothing returns nothing
* - Deallocates the Loc.
*
* method move takes real x, real y, real z returns nothing
* - Assigns the Loc new coordinates.
*
* static method join takes Loc v1, Loc v2 returns nothing
* - Joins two Locs together.
* method disjoint takes nothing returns nothing
* - Breaks the joint of the given Loc.
*
* readonly real angle
* readonly real distance
* readonly real slope
* - These 3 read-only members store the relation between
* - two joined Locs. Updates everytime a Loc is moved.
*
**********************************************************************/
struct Loc extends array
private static integer ic = 0
private static integer array next
readonly static location point = Location(0,0)
readonly real x
readonly real y
readonly real z
readonly real angle
readonly real distance
readonly real slope
private static method refresh takes Loc v1, Loc v2 returns nothing
local real a = Atan2(v2.y-v1.y,v2.x-v1.x)
local real d = SquareRoot((v1.x-v2.x)*(v1.x-v2.x)+(v1.y-v2.y)*(v1.y-v2.y))
local real s = (v2.z-v1.z)/d
set v1.angle = a
set v2.angle = a+bj_PI
set v1.distance = d
set v2.distance = d
set v1.slope = s
set v2.slope = -s
endmethod
static method join takes Loc v1, Loc v2 returns nothing
call refresh(v1,v2)
set next[v1]=v2
set next[v2]=v1
endmethod
method disjoint takes nothing returns nothing
set next[next[this]]=next[this]
set next[this]=this
endmethod
method move takes real sx, real sy, real sz returns nothing
call MoveLocation(point,sx,sy)
set x=sx
set y=sy
set z=sz+GetLocationZ(point)
if this!=next[this] then
call refresh(this,next[this])
endif
endmethod
static method create takes real sx, real sy, real sz returns thistype
local thistype this
if next[0]==0 then
set ic = ic+1
set this = ic
else
set this = next[0]
set next[0] = next[next[0]]
endif
set next[this]=this
call this.move(sx,sy,sz)
return this
endmethod
method destroy takes nothing returns nothing
call this.disjoint()
set next[this]=next[0]
set next[0]=this
endmethod
endstruct
endlibrary