Sha256: 9f94152daf624d4370a7c5857ce1f9f3c239d353babb4384ccce32dfeb36c739

Contents?: true

Size: 1.36 KB

Versions: 6

Compression:

Stored size: 1.36 KB

Contents

package org.sunflow.core.bucket;

import org.sunflow.core.BucketOrder;

public class SpiralBucketOrder implements BucketOrder {

    @Override
    public int[] getBucketSequence(int nbw, int nbh) {
        int[] coords = new int[2 * nbw * nbh];
        for (int i = 0; i < nbw * nbh; i++) {
            int bx, by;
            int center = (Math.min(nbw, nbh) - 1) / 2;
            int nx = nbw;
            int ny = nbh;
            while (i < (nx * ny)) {
                nx--;
                ny--;
            }
            int nxny = nx * ny;
            int minnxny = Math.min(nx, ny);
            if ((minnxny & 1) == 1) {
                if (i <= (nxny + ny)) {
                    bx = nx - minnxny / 2;
                    by = -minnxny / 2 + i - nxny;
                } else {
                    bx = nx - minnxny / 2 - (i - (nxny + ny));
                    by = ny - minnxny / 2;
                }
            } else {
                if (i <= (nxny + ny)) {
                    bx = -minnxny / 2;
                    by = ny - minnxny / 2 - (i - nxny);
                } else {
                    bx = -minnxny / 2 + (i - (nxny + ny));
                    by = -minnxny / 2;
                }
            }
            coords[2 * i + 0] = bx + center;
            coords[2 * i + 1] = by + center;
        }
        return coords;
    }
}

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
joonsrenderer-1.3.1-java src/main/java/org/sunflow/core/bucket/SpiralBucketOrder.java
joonsrenderer-1.2.0-java src/main/java/org/sunflow/core/bucket/SpiralBucketOrder.java
joonsrenderer-1.1.3-java src/main/java/org/sunflow/core/bucket/SpiralBucketOrder.java
joonsrenderer-1.1.2-java src/main/java/org/sunflow/core/bucket/SpiralBucketOrder.java
joonsrenderer-1.1.1-java src/main/java/org/sunflow/core/bucket/SpiralBucketOrder.java
joonsrenderer-1.1-java src/main/java/org/sunflow/core/bucket/SpiralBucketOrder.java