Commit 6a74bb55 authored by Dan Sheppard's avatar Dan Sheppard
Browse files

Bumper event reporting for up/down/left/right.

(But not in/out).
parent 03fcfc06
......@@ -65,6 +65,28 @@ impl Position {
}
}
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.;
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
}
}
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,
UP => 0.,
DOWN => self.max_y as f64
}
}
pub fn get_middle(&self) -> Dot<f64,f64> {
Dot(self.pos.0,self.pos.1)
}
......@@ -79,7 +101,7 @@ impl Position {
+ (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... */
;
;
self.zoom.set_max_bp(max_bp);
}
......@@ -104,50 +126,12 @@ impl Position {
self.check_own_limits();
}
fn limit_min_y(&self, pos: &mut Dot<f64,f64>) {
let min_dy = (self.screen_size.1 as f64/2.).max(0.);
pos.1 = pos.1.max(min_dy);
}
fn limit_max_y(&self, pos: &mut Dot<f64,f64>) {
let max_dy = (self.max_y as f64 - self.screen_size.1 as f64/2.).max(0.);
pos.1 = pos.1.min(max_dy);
}
fn limit_min_x(&self, pos: &mut Dot<f64,f64>) {
let min_dx = /* minimum x-coordinate in bp for centre is ... */
/* ... specified min (in bp, wrt left edge) ... */
self.min_x
/* ... moved to centre ... */
+ self.zoom.get_screen_in_bp()/2.
/* ... minus left bumper (in px) ... */
- self.min_x_bumper
/ self.screen_size.0 as f64 /* ... px->screen ... */
* self.zoom.get_screen_in_bp() /* ... screen->bp */
;
pos.0 = pos.0.max(min_dx);
}
fn limit_max_x(&self, pos: &mut Dot<f64,f64>) {
let max_dx = /* maximum x-coordinate in bp for centre is ... */
/* ... specified max (in bp, wrt right edge) ... */
self.max_x
/* ... moved to centre ... */
- self.zoom.get_screen_in_bp()/2.
/* ... plus right bumper (in px) ... */
+ self.max_x_bumper
/ self.screen_size.0 as f64 /* ... px->screen ... */
* self.zoom.get_screen_in_bp() /* ... screen->bp */
;
pos.0 = pos.0.min(max_dx);
}
fn check_limits(&self, pos: &mut Dot<f64,f64>) {
/* minima always "win" when in conflict => max fn's called first */
self.limit_max_x(pos);
self.limit_min_x(pos);
self.limit_max_y(pos);
self.limit_min_y(pos);
pos.0 = pos.0.min(self.get_limit_of_middle(&RIGHT));
pos.0 = pos.0.max(self.get_limit_of_middle(&LEFT));
pos.1 = pos.1.min(self.get_limit_of_middle(&DOWN));
pos.1 = pos.1.max(self.get_limit_of_middle(&UP));
}
fn check_own_limits(&mut self) {
......
......@@ -3,7 +3,7 @@ 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 };
use types::{CPixel, cpixel, Move, Dot, Direction, LEFT, RIGHT, UP, DOWN };
// XXX TODO avoid big-minus-big type calculations which accumulate error
......@@ -26,9 +26,18 @@ impl Stage {
}
}
fn bumped(&self, direction: &Direction) -> bool {
self.pos.get_edge(direction).floor() == self.pos.get_limit_of_edge(direction).floor()
}
pub fn update_report(&self, report: &Report) {
report.set_status("start",&self.pos.get_edge(&LEFT).floor().to_string());
report.set_status("end",&self.pos.get_edge(&RIGHT).ceil().to_string());
let (left,right) = (self.pos.get_edge(&LEFT),self.pos.get_edge(&RIGHT));
report.set_status("start",&left.floor().to_string());
report.set_status("end",&right.ceil().to_string());
report.set_status_bool("bumper-left",self.bumped(&LEFT));
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));
}
pub fn set_wrapping(&mut self, w: &Wrapping) {
......
......@@ -58,6 +58,12 @@ lazy_static! {
StatusJigsaw::Atom("stick".to_string(),StatusJigsawType::String),
StatusJigsaw::Atom("start".to_string(),StatusJigsawType::Number),
StatusJigsaw::Atom("end".to_string(),StatusJigsawType::Number),
}),Some(500.)),
("bumper",StatusJigsaw::Array(vec!{
StatusJigsaw::Atom("bumper-top".to_string(),StatusJigsawType::Boolean),
StatusJigsaw::Atom("bumper-right".to_string(),StatusJigsawType::Boolean),
StatusJigsaw::Atom("bumper-bottom".to_string(),StatusJigsawType::Boolean),
StatusJigsaw::Atom("bumper-left".to_string(),StatusJigsawType::Boolean),
}),Some(500.))
};
}
......@@ -203,6 +209,10 @@ impl Report {
let mut imp = self.0.lock().unwrap();
imp.set_status(key,value);
}
pub fn set_status_bool(&self, key: &str, value: bool) {
self.set_status(key,&value.to_string());
}
pub fn set_interval(&mut self, key: &str, interval: Option<f64>) {
let mut imp = self.0.lock().unwrap();
......
......@@ -4,7 +4,7 @@ use serde_json::Value as JSONValue;
use stdweb::web::html_element::SelectElement;
use stdweb::traits::IEvent;
use stdweb::unstable::TryInto;
use stdweb::web::{ Element, IEventTarget, HtmlElement, INode };
use stdweb::web::{ Element, IEventTarget, HtmlElement };
use stdweb::web::event::{ ChangeEvent, ClickEvent };
use controller::input::EggDetector;
......
......@@ -54,6 +54,7 @@ const AE : Anchor = Anchor(Some(AxisSense::Neg));
pub const A_TOP : Anchors = Dot(AM,AS);
pub const A_TOPLEFT : Anchors = Dot(AS,AS);
pub const A_TOPRIGHT : Anchors = Dot(AE,AS);
#[allow(unused)]
pub const A_BOTTOM : Anchors = Dot(AM,AE);
pub const A_BOTTOMLEFT : Anchors = Dot(AS,AE);
pub const A_BOTTOMRIGHT: Anchors = Dot(AE,AE);
......@@ -61,7 +62,7 @@ pub const A_LEFT : Anchors = Dot(AS,AM);
pub const A_RIGHT : Anchors = Dot(AE,AM);
pub const A_MIDDLE : Anchors = Dot(AM,AM);
#[derive(PartialEq,Eq)]
#[derive(PartialEq,Eq,Debug)]
pub struct Direction(pub Axis,pub AxisSense);
pub const LEFT : Direction = Direction(Axis::Horiz,AxisSense::Neg);
......
......@@ -686,6 +686,9 @@ Module.STDWEB_PRIVATE.acquire_tmp = function( dummy ) {
"__cargo_web_snippet_6cc57df24f1e7383b7c0590707297e15f860dc19": function($0, $1, $2, $3, $4, $5, $6, $7) {
$1 = Module.STDWEB_PRIVATE.to_js($1);$2 = Module.STDWEB_PRIVATE.to_js($2);$3 = Module.STDWEB_PRIVATE.to_js($3);$4 = Module.STDWEB_PRIVATE.to_js($4);$5 = Module.STDWEB_PRIVATE.to_js($5);$6 = Module.STDWEB_PRIVATE.to_js($6);$7 = Module.STDWEB_PRIVATE.to_js($7);Module.STDWEB_PRIVATE.from_js($0, (function(){var id=($1).createImageData(($2),($3));id.data.set(($4));($5).putImageData(id,($6),($7));})());
},
"__cargo_web_snippet_6dc4f8ae7f6f817eb79d86191e298d65cc5ab23b": function($0, $1) {
$1 = Module.STDWEB_PRIVATE.to_js($1);Module.STDWEB_PRIVATE.from_js($0, (function(){return($1).innerHTML;})());
},
"__cargo_web_snippet_6fcce0aae651e2d748e085ff1f800f87625ff8c8": function($0) {
Module.STDWEB_PRIVATE.from_js($0, (function(){return document;})());
},
......
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