library RectData requires optional Table
*   RectData v0.0.0.2
*   By Magtheridon96
*   Requirements (optional)
*   ------------
*       - Table [By Bribe] :
*   API
*   ---
*       struct RectData : array
*           real minX
*           real maxX
*           real minY
*           real maxY
*           real centerX
*           real centerY
*           method toRegion :
*               - This returns the rect itself in the form of a region
*           method destroy :
*               - This destroys an instance of the struct
*           method getLength :
*               - Returns the length of the rect
*           method getWidth :
*               - Returns the width of the rect
*           method create :
*               - Creates a new instance of the struct given a rect
    debug private module Init
        debug private static method onInit takes nothing returns nothing
            debug set = Table.create()
        debug endmethod
    debug endmodule
    struct RectData extends array
        private static integer ic = 0
        private static integer ir = 0
        private thistype rn
        real minX
        real maxX
        real minY
        real maxY
        real centerX
        real centerY
        private region rg
        debug private static Table data
        method destroy takes nothing returns nothing
            call RemoveRegion(.rg)
            set .rg=null
            set .rn=ir
            set ir=this
        method toRegion takes nothing returns region
            return .rg
        method getLength takes nothing returns real
            return .maxX - .minX
        method getWidth takes nothing returns real
            return .maxY - .minY
        static method create takes rect r returns thistype
            local thistype this
            debug local integer i = GetHandleId(r)
            debug if not data.has(i) then
                if 0==ir then
                    set ic=ic+1
                    set this=ic
                    set this=ir
                    set ir=.rn
                set .minX = GetRectMinX(r)
                set .minY = GetRectMinY(r)
                set .maxX = GetRectMaxX(r)
                set .maxY = GetRectMaxY(r)
                set .centerX = (.maxX + .minX) / 2
                set .centerY = (.maxY + .minY) / 2
                set .rg = CreateRegion()
                call RegionAddRect(.rg,r)
                debug set data[i] = this
            debug else
                debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"[Rect Data]: Creating multiple instances of the struct RectData for the same rect.")
                debug return data[i]
            debug endif
            return this
        debug implement Init

This is a snippet that can be used to store rect data so that you dont have to constantly call GetRectCenterX, GetRectMinX, etc.. when registering "Unit enters region" events for a trigger.

Table is an optional requirement and is only used for debugging purposes.

I found it useful for my map, so I thought I'd post it here.

Feel free to comment.

Side Note: Most of it inlines anyways.
Last edited: