Commit 5aa165ba authored by Dan Sheppard's avatar Dan Sheppard
Browse files

Add zoom to bumper array.

parent 6a74bb55
use std::fmt;
use composit::Zoom;
use types::{ Dot, Direction, LEFT, RIGHT, UP, DOWN };
use types::{ Dot, Direction, LEFT, RIGHT, UP, DOWN, IN, OUT, AxisSense };
pub struct Position {
pos: Dot<f64,f64>,
......@@ -55,35 +55,38 @@ impl Position {
self.pos.1 = self.pos.1.round();
}
pub fn get_edge(&self, which: &Direction) -> f64 {
pub fn middle_to_edge(&self, which: &Direction) -> f64 {
let bp = self.get_screen_in_bp();
match *which {
LEFT => self.pos.0 - bp/2. + self.px_to_bp(self.min_x_bumper),
RIGHT => self.pos.0 + bp/2. - self.px_to_bp(self.max_x_bumper),
UP => self.pos.1 - self.screen_size.1 as f64/2.,
DOWN => self.pos.1 + self.screen_size.1 as f64/2.
LEFT => - bp/2. + self.px_to_bp(self.min_x_bumper),
RIGHT => bp/2. - self.px_to_bp(self.max_x_bumper),
UP => - self.screen_size.1 as f64/2.,
DOWN => self.screen_size.1 as f64/2.,
IN|OUT => 0.
}
}
pub fn get_limit_of_middle(&self, which: &Direction) -> f64 {
let hw_bp = self.zoom.get_screen_in_bp()/2.;
let hh_px = self.screen_size.1 as f64/2.;
pub fn get_edge(&self, which: &Direction) -> f64 {
let delta = self.middle_to_edge(which);
match *which {
LEFT => self.min_x + hw_bp - self.px_to_bp(self.min_x_bumper),
RIGHT => self.max_x - hw_bp + self.px_to_bp(self.min_x_bumper),
UP => hh_px,
DOWN => self.max_y as f64 - hh_px
LEFT|RIGHT => self.pos.0 + delta,
UP|DOWN => self.pos.1 + delta,
IN|OUT => self.zoom.get_zoom()
}
}
pub fn get_limit_of_middle(&self, which: &Direction) -> f64 {
self.get_limit_of_edge(which) - self.middle_to_edge(which)
}
pub fn get_limit_of_edge(&self, which: &Direction) -> f64 {
let hw_bp = self.zoom.get_screen_in_bp()/2.;
let hh_px = self.screen_size.1 as f64/2.;
match *which {
LEFT => self.min_x,
RIGHT => self.max_x,
DOWN => self.max_y as f64,
UP => 0.,
DOWN => self.max_y as f64
IN => self.zoom.get_limit(&AxisSense::Pos),
OUT => self.zoom.get_limit(&AxisSense::Neg),
}
}
......@@ -96,12 +99,11 @@ impl Position {
}
fn set_limit_min_zoom(&mut self) {
let max_bp = /* maximum "displayed" bp is ... */
self.max_x-self.min_x+1. /* ... available bp on stick ... */
+ (self.min_x_bumper+self.max_x_bumper) /* ... plus x bumpers (in px) ... */
/ self.screen_size.0 as f64 /* ... px->screen ... */
* self.zoom.get_screen_in_bp() /* ... screen->bp... */
;
let max_bp =
self.get_limit_of_edge(&RIGHT) - self.get_limit_of_edge(&LEFT)
+ 1.
+ self.px_to_bp(self.min_x_bumper)
+ self.px_to_bp(self.max_x_bumper);
self.zoom.set_max_bp(max_bp);
}
......@@ -109,8 +111,8 @@ impl Position {
match *which {
LEFT => self.min_x = val,
RIGHT => self.max_x = val,
UP => (),
DOWN => self.max_y = val as i32
DOWN => self.max_y = val as i32,
_ => (),
}
self.set_limit_min_zoom();
self.check_own_limits();
......
......@@ -3,7 +3,10 @@ use std::collections::HashMap;
use composit::{ Leaf, Position, Wrapping };
use controller::output::Report;
use program::UniformValue;
use types::{CPixel, cpixel, Move, Dot, Direction, LEFT, RIGHT, UP, DOWN };
use types::{
CPixel, cpixel, Move, Dot, Direction,
LEFT, RIGHT, UP, DOWN, IN, OUT
};
// XXX TODO avoid big-minus-big type calculations which accumulate error
......@@ -38,6 +41,8 @@ impl Stage {
report.set_status_bool("bumper-right",self.bumped(&RIGHT));
report.set_status_bool("bumper-top",self.bumped(&UP));
report.set_status_bool("bumper-bottom",self.bumped(&DOWN));
report.set_status_bool("bumper-in",self.bumped(&IN));
report.set_status_bool("bumper-out",self.bumped(&OUT));
}
pub fn set_wrapping(&mut self, w: &Wrapping) {
......
use std::fmt;
use types::AxisSense;
#[derive(Clone,Copy)]
pub struct Zoom {
zoom: f64,
......@@ -21,20 +23,19 @@ impl Zoom {
self.max_bp = bp;
}
fn check_min_limit(&self, val: f64) -> f64 {
if val < -self.max_bp.log10() {
return -self.max_bp.log10();
} else {
return val;
pub fn get_limit(&self, min_max: &AxisSense) -> f64 {
match *min_max {
AxisSense::Neg => -self.max_bp.log10(),
AxisSense::Pos => -MAX_LIMIT_BP.log10()
}
}
fn check_min_limit(&self, val: f64) -> f64 {
val.max(self.get_limit(&AxisSense::Neg))
}
fn check_max_limit(&self, val: f64) -> f64 {
if val > -MAX_LIMIT_BP.log10() {
return -MAX_LIMIT_BP.log10();
} else {
return val;
}
val.min(self.get_limit(&AxisSense::Pos))
}
pub fn set_zoom(&mut self, val: f64) {
......
......@@ -29,6 +29,7 @@ fn exe_move_event(app: &App, v: Move<f64,f64>) {
let v = match v.direction().0 {
Axis::Horiz => v.convert(Units::Bases,s),
Axis::Vert => v.convert(Units::Pixels,s),
Axis::Zoom => v // TODO invalid pre-unification
};
s.inc_pos(&v);
s.get_pos_middle()
......
......@@ -64,6 +64,8 @@ lazy_static! {
StatusJigsaw::Atom("bumper-right".to_string(),StatusJigsawType::Boolean),
StatusJigsaw::Atom("bumper-bottom".to_string(),StatusJigsawType::Boolean),
StatusJigsaw::Atom("bumper-left".to_string(),StatusJigsawType::Boolean),
StatusJigsaw::Atom("bumper-out".to_string(),StatusJigsawType::Boolean),
StatusJigsaw::Atom("bumper-in".to_string(),StatusJigsawType::Boolean),
}),Some(500.))
};
}
......
......@@ -51,7 +51,8 @@ impl<T: Clone + Copy + Mul<f64,Output=T> + Div<f64,Output=T> + Debug> Distance<T
let dims = stage.get_size();
let (size,zoom) = match axis {
Axis::Horiz => (dims.0 as f64,stage.get_screen_in_bp() as f64),
Axis::Vert => (dims.1 as f64,1.0)
Axis::Vert => (dims.1 as f64,1.0),
Axis::Zoom => (1.,1.), // TODO
};
let quant = match source {
Units::Pixels => match target {
......
......@@ -6,7 +6,7 @@ use program::Input;
use types::{ Dot, area, Rect };
#[derive(Clone,Copy,Debug,PartialEq,Eq)]
pub enum Axis { Horiz, Vert }
pub enum Axis { Horiz, Vert, Zoom }
#[derive(Clone,Copy,Debug,PartialEq,Eq)]
pub enum AxisSense { Pos, Neg }
......@@ -69,6 +69,8 @@ pub const LEFT : Direction = Direction(Axis::Horiz,AxisSense::Neg);
pub const RIGHT : Direction = Direction(Axis::Horiz,AxisSense::Pos);
pub const UP : Direction = Direction(Axis::Vert,AxisSense::Neg);
pub const DOWN : Direction = Direction(Axis::Vert,AxisSense::Pos);
pub const OUT : Direction = Direction(Axis::Zoom,AxisSense::Neg);
pub const IN : Direction = Direction(Axis::Zoom,AxisSense::Pos);
#[derive(Clone,Copy,Debug)]
pub struct Corner(pub AxisSense, pub AxisSense);
......
......@@ -7,7 +7,7 @@ pub use types::corners::{
Anchors, Axis, AxisSense, Anchored, Corner, Edge, Anchor,
cedge, Direction,
LEFT, RIGHT, UP, DOWN,
LEFT, RIGHT, UP, DOWN, IN, OUT,
TOPLEFT, BOTTOMLEFT, TOPRIGHT, BOTTOMRIGHT,
A_TOPLEFT, A_TOP, A_TOPRIGHT,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment