From 2ac18802b58d671c10538e78d50a620baad9a188 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Wed, 7 Dec 2022 21:23:42 +0100 Subject: advanced transform --- evc/src/debug.rs | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) (limited to 'evc/src/debug.rs') diff --git a/evc/src/debug.rs b/evc/src/debug.rs index 06dd507..99723b8 100644 --- a/evc/src/debug.rs +++ b/evc/src/debug.rs @@ -1,4 +1,11 @@ -use crate::{frame::Frame, helpers::pixel::Pixel, helpers::vector::Vec2, view::View}; +use crate::{ + block::Block, + format::ser::map_scalar8, + frame::Frame, + helpers::vector::Vec2, + helpers::{matrix::Mat2, pixel::Pixel}, + view::View, +}; impl View<&mut Frame> { pub fn draw_box(&mut self, color: Pixel) { @@ -54,3 +61,47 @@ impl Pixel { b: 255, }; } + +pub fn draw_debug(block: &Block, mut target: View<&mut Frame>) { + match &block { + Block::Literal(_) => { + target.draw_box(Pixel::GREEN); + } + Block::Split(box [a, b]) => { + let [at, bt] = target.split_mut_unsafe(); + draw_debug(a, at); + draw_debug(b, bt); + } + Block::Reference { translation } => { + target.draw_box(Pixel::BLUE); + target.frame.draw_line( + target.center().into(), + (target.center() + *translation).into(), + Pixel::RED, + ) + } + Block::AdvancedReference(r) => { + let mat = Mat2 { + a: map_scalar8(r.transform.a), + b: map_scalar8(r.transform.b), + c: map_scalar8(r.transform.c), + d: map_scalar8(r.transform.d), + }; + let translation = Vec2 { + x: map_scalar8(r.translation.x), + y: map_scalar8(r.translation.y), + }; + let tl = mat.transform(translation) + target.offset.into(); + let tr = + mat.transform(translation + target.size.x_only().into()) + target.offset.into(); + let bl = + mat.transform(translation + target.size.y_only().into()) + target.offset.into(); + let br = mat.transform(translation + target.size.into()) + target.offset.into(); + target.frame.draw_line(tl, tr, Pixel::MAGENTA); + target.frame.draw_line(tr, br, Pixel::MAGENTA); + target.frame.draw_line(bl, br, Pixel::MAGENTA); + target.frame.draw_line(tl, bl, Pixel::MAGENTA); + target.draw_box(Pixel::CYAN); + } + } +} -- cgit v1.2.3-70-g09d2