Author Topic: Adding emtpy rows and columns to a two dimensional array with DIMPUSH  (Read 5270 times)

Offline Marmor

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 925
  • 96A285CC
    • View Profile
    • my youtube channel
its time for transfer (arrayx[],arrayy[],start,len) to kill the basic overhead  :noggin:

Offline S.O.P.M.

  • Prof. Inline
  • *****
  • Posts: 529
    • View Profile
Now I've written a new shifting procedure that uses less code and hopyfully will work for any given array but if it will run with similar speed that's the next question. At first I copied element by element inside two loops. Now I copy the whole array to another array with ArrCop[] = Arr[] and then paste the copy to the original with the given x and y offset. Still clearing the remaining elements with a new loop would be stupid. The following code is untested, please take a look on it and tell me what do you think it's the best way to do the task by using basic only. To remember, I need to shift the contents of any array with a single procedure to any extension - using basic code only, as less as possible and fast.

Code: (glbasic) [Select]
FUNCTION ShiftArray: Arr%[], XExt%, YExt%

LOCAL ArrCop%[]
LOCAL ACX%, ACY%
LOCAL AX%, AY%
LOCAL W%, H%

IF XExt < 0
    ACX = ABS(XExt)
ELSE
    AX = XExt
ENDIF
IF YExt < 0
    ACY = ABS(YExt)
ELSE
    AY = YExt
ENDIF
W = BOUNDS(Arr[], 0)
H = BOUNDS(Arr[], 1)
ArrCop[] = Arr[]
FOR i = AX TO H - AY - 1
    FOR j = AY TO W - AX - 1
        Arr[AX + j][AY + i] = ArrCop[ACX + j][ACY + i]
    NEXT
NEXT

ENDFUNCTION

Zeroization is still not in there. XExt and YExt are the given movements, positive values shift right, negative ones left. ACX and ACY are the start coordinates where the copy will read, AX and AY the coordinates to start writing on the origin array. Would like to replace the first two IF-ENDIF's by formulas to set the right values but can't figure out how. Finally want to build the zeroization inside the double loop not using another one for that.
« Last Edit: 2015-Jan-21 by S.O.P.M. »
Notebook PC Samsung E372 Core i5 @ 2,6 GHz; 4 GB RAM; Win 7 Home Premium

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1645
  • Particle Hawk
    • View Profile
My lib uses arrays is a few ways, maybe you can use some of this code, or use the lib itself.
You can see in the image here, a function list for controlling arrays.
In your case here, you would be looking at the pop del and shift functions.

Feel free to use the whole library, its all compatible to each object type...some depend on each other.
By type i mean; strings, lists, files, time, and terminals.
You can get it from my download page.

http://silver.binhoster.com/downloads.html

PS. i will be updating that library again this year i hope. Im thinking about the 3d particle engine as part of the lib too.
« Last Edit: 2015-Mar-13 by Hemlos »
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Offline S.O.P.M.

  • Prof. Inline
  • *****
  • Posts: 529
    • View Profile
Seems to be some fantastic and useful work, many thanks. That's fine  :)
Notebook PC Samsung E372 Core i5 @ 2,6 GHz; 4 GB RAM; Win 7 Home Premium