- Joined
- Jan 9, 2019
- Messages
- 102
JASS:
library RelativePlane requires BoundOffset
//-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
// __________________
// # RelativePlane
// v1.1a, by Overfrost
//
// - connects two BoundOffset
//
// - gives data obtainable from the connection
//
// ______________
// # Requires:
//
// - BoundOffset
// hiveworkshop.com/threads/boundoffset.311587
//
//-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
//! novjass
//
struct RelativePlane extends array
//-------------
// Instancers
//
static method create takes BoundOffset o, BoundOffset t returns thistype
// creates a connection from o as origin to t as target
// locks o and t once
//
method lock takes nothing returns nothing
method unlock takes nothing returns boolean
// unlock replaces destroy, returns true if it destroys
// unlocks both BoundOffset on destroy
//
//---------
// Fields
//
BoundOffset origin
BoundOffset target
// when their instance changes, properly unlock the previous instance
// automatically locks the new instance once
//
//----------
// Methods
//
method refresh takes nothing returns thistype
// calculates data required by some fields
// automatically called on instance creation
// returns this (this instance)
//
method swap takes nothing returns thistype
// swaps the instance of origin and target
// also calls refresh after the swap
// returns this
//
//-------------------
// Requires refresh
//
readonly real length // (x,y,z) distance
readonly real range // (x,y) distance
//
readonly real angle // (x,y) direction
readonly real incline // (floor,z) angle, from xy-plane to z-axis
readonly real decline // (z,floor) angle, from z-axis to xy-plane
//
readonly real slope // inclination slope, = dz/range
//
//! endnovjass
//-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
//
private struct S extends array
implement VectorBase
endstruct
struct RelativePlane extends array
implement AllocFast
//
private integer l
//
private BoundOffset o
private BoundOffset t
//
method refresh takes nothing returns thistype
set S(this).x = t.tx - o.tx
set S(this).y = t.ty - o.ty
set S(this).z = t.tz - o.tz
//
return this
endmethod
static method create takes BoundOffset ao, BoundOffset at returns thistype
local thistype this = allocate()
set l = 0
//
set o = ao
set t = at
call ao.lock()
call at.lock()
//
return refresh()
endmethod
//
method operator length takes nothing returns real
return S(this).r
endmethod
method operator range takes nothing returns real
return S(this).s
endmethod
//
method operator angle takes nothing returns real
return S(this).t
endmethod
method operator decline takes nothing returns real
return S(this).p
endmethod
method operator incline takes nothing returns real
return Atan2(S(this).z, range)
endmethod
//
method operator slope takes nothing returns real
return S(this).z/range
endmethod
//
method operator origin takes nothing returns BoundOffset
return o
endmethod
method operator target takes nothing returns BoundOffset
return t
endmethod
//
method operator origin= takes BoundOffset ao returns nothing
call o.unlock()
//
set o = ao
call ao.lock()
endmethod
method operator target= takes BoundOffset at returns nothing
call t.unlock()
//
set t = at
call at.lock()
endmethod
//
method swap takes nothing returns thistype
local BoundOffset lo = o
set o = t
set t = lo
//
return refresh()
endmethod
//
method lock takes nothing returns nothing
set l = l + 1
endmethod
method unlock takes nothing returns boolean
set l = l - 1
if (l < 0) then
//
call o.unlock()
call t.unlock()
//
call deallocate()
return true
endif
return false
endmethod
endstruct
endlibrary
No longer updated. Only serves as a reference.
Changelog:
- v1.1a:
- Now swap inherently calls refresh after its swaps
- Improved documentation a little
Last edited: