summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIsaac Clayton2022-01-22 16:25:44 +0100
committerIsaac Clayton2022-01-22 16:25:44 +0100
commit804f22d05a18ae1baadf4d90371a1baca3bd9098 (patch)
treebdedf448c438695d370efae8750857513df76dc7 /src
parent995a8539056e087af6f088ad24db8f89219d626a (diff)
Taking a break
Diffstat (limited to 'src')
-rw-r--r--src/main.rs11
-rw-r--r--src/quad.rs36
2 files changed, 30 insertions, 17 deletions
diff --git a/src/main.rs b/src/main.rs
index e30aa12..14595c7 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -13,11 +13,20 @@ fn main() {
base.push(i);
}
- let quad: quad::Node<u8, u8> = quad::Node::new_from_square(
+ let mut quad: quad::Node<u8, u8> = quad::Node::new_from_square(
&mut ctx, base,
);
println!("{:#?}", quad);
+ // TODO: this does not work correctly
+ // for x in -2..2 {
+ // for y in -2..2 {
+ // let (nquad, color) = quad.sample_color(&mut ctx, x, y);
+ // quad = nquad;
+ // println!("{}", color[0]);
+ // }
+ // }
+
// render::graphics();
}
diff --git a/src/quad.rs b/src/quad.rs
index 0ce8b58..2b275e5 100644
--- a/src/quad.rs
+++ b/src/quad.rs
@@ -32,30 +32,34 @@ pub struct Node<A: Embed, B: Embed> {
}
impl<A: Embed, B: Embed> Node<A, B> {
+ // TODO: this function does not work correctly
pub fn sample_color<S, N: Approx<A, B, S>>(
self,
ctx: &mut Ctx<A, B, S, N>,
x: isize,
y: isize,
) -> (Self, [u8; 4]) {
- // self = ctx.expand(self);
- // if let Quad::Base(b) = self.data {
- // return (self, ctx.color_base(&b));
- // }
-
- let child_size = 1 << (self.depth - 1);
- let nx = (x + child_size) % child_size;
- let ny = (y + child_size) % child_size;
-
- match (x >= 0, y >= 0) {
- (true, true) => {
- let x = x;
+ let mut expanded = ctx.expand(self);
+ match expanded.data {
+ Quad::Base(a) => (expanded, ctx.color_base(a)),
+ Quad::Node(ref mut n) => {
+ let depth = expanded.depth;
+ let half = 1 << (depth - 1);
+ let (c, nx, ny) = match (x >= 0, y >= 0) {
+ (true , true) => (1, x - half, y - half),
+ (true , false) => (3, x - half, y + half),
+ (false , true) => (0, x + half, y - half),
+ (false , false) => (2, x + half, y + half),
+ };
+
+ let oc = std::mem::replace(&mut n[c], Self::new_empty(ctx));
+ let (nc, color) = oc.sample_color(ctx, nx, ny);
+ n[c] = nc;
+
+ (expanded, color)
},
- _ => { unreachable!(); }
+ Quad::Cached => unreachable!("Expanded this node!"),
}
-
- // self
- todo!()
}
/// Creates a new tree with a single empty base node