I want to create a function to get absolute id of fractal subobject by layer/row and column id. In an fractal object there are repeating subobjects, you can split them into layers. Any object with identifier "W" contains 7x G's, each object identified by G's again contain 7x N's etc.
if layer is ...
...3 (rowId=2) then only strings with "N"...
...2 (rowId=1) then only strings with "G"...
...
are counted.
The raw code:
const rawData = [["W1","W2","W3","W4","W5","W6","W7"],
["G1","G2","G3","G4","G5","G6","G7"],
["N1","N2","N3","N4","N5","N6","N7"],
["T1","T2","T3","T4","T5","T6","T7"]]
const selIds=[0,1,2,4] // selected indices of W1 G2 N3 T5 (range per array element: [0-6])
// to calculate absolute fractal "cell" counter; following input is given by click on subobject
rowId=1 // layer index - 1 (0-6)
colId=2 // element index - 1 (0-6)
I think result can be calculated this way?
result=((7^1*selIds[0])+selIds[1]*7^0)*7^(rowId+1)+3=(0+1)*49+3=52
On click the selIds change with given rowId & colIds to selIds=[0,2,2,4]; letters of rawData are just arbitrary, because in reality they are like identifiers of planets, solar systems, galaxies and so on
My functions so far:
const getCurrentIndex = function(elementIndex, layerIndex) {
let currentIndex = 0
if(layerIndex > 0) {
for(let j = 0; j < layerIndex; j++) {
currentIndex += (selIds[j]) * Math.pow(7, layerIndex-j)
}
}
currentIndex += elementIndex
currentIndex += 1
return currentIndex
}
Examples (layer/row & element/col = absolute id):
W1:G1:N1:T1 = 1
W1:G1:N1 = 1
W4:G5:N6 = 3*7*7 + 4*7 + 6 = 181
W2:G2:N3 = 1*7*7 + 1*7 + 3 = 59
W3:G4:N3 = 2*7*7 + 3*7 + 3 = 122
W4:G4:N4 = 3*7*7 + 3*7 + 4 = 172
W2:G2:N3:T4 = 1*7*7*7 + 1*7*7 + 2*7 + 4 = 410
Column id is the number of the last string element split by :.
W1:G1:N1:T1becomes1111(b7)at first. The "additional rule" says "decrease all digits by 1 except the last digit", that gives0001(b7)which is one in Base-10. All other combinations work in the same way. Is my interpretation correct?[0,2,2,4]becomes0225(b7)because now the last index vanuit has to be increased by 1.parseInt(base7Str, 7).