CosmosCamel / NoPixels-CW

CosmWasm contract for NoPixels
Apache License 2.0
0 stars 2 forks source link

Fix Chunking / Hilbert Curve #1

Closed siriustaikun closed 1 year ago

siriustaikun commented 2 years ago

Easy

Instead of saving pixels to a nested vecs, just add more indices to your keys and normalize the pixel structure. Then use start and end bounds to look up individual chunks.

 CHUNKS.save(deps.storage, (chunk_x, chunk_y, y, x), &PixelInfo { 
     color, 
     painter: Some(info.sender.clone()), 
 })?; 

Hard

Space filling curves enable one to convey two dimensional space via one dimensional points. Thus, it is a very efficient way to achieve the same functionality currently offered by chunking, but with a simple stream of integers rather than coordinates. Then you can simply paginate through a list of pixels that are already chunked, without the chunks. This also enables you to easily look up any given pixel's color.

 CHUNKS.save(deps.storage, hilbert, &PixelInfo { 
     color, 
     painter: Some(info.sender.clone()), 
 })?; 

rust hilbert curve library https://docs.rs/fast_hilbert/latest/fast_hilbert/index.html

resources: https://en.wikipedia.org/wiki/Space-filling_curve, https://www.youtube.com/watch?v=3s7h2MHQtxc

Other

Not sure why the painter is being saved. It is expensive to store and load, and this information could be queried from an archive node. Some queries were running out of gas in my experience.

CosmosCamel commented 1 year ago

will look into pixel store rewrite for v3