Commit 276c4a8c authored by Dan Sheppard's avatar Dan Sheppard
Browse files

Remove unnecessary abstraction.

parent d58d0505
......@@ -24,5 +24,5 @@ webgl_generator = "*"
cargo-web="*"
regex = "*"
[profile.release]
lto = true
#[profile.release]
#lto = true
......@@ -18,7 +18,7 @@ impl DrawnResponse {
let specs = self.sr.get_shapes(&self.part);
shapes.reserve(specs.len());
for spec in specs {
shapes.push(DrawnShape::new(spec.create()));
shapes.push(DrawnShape::new(spec.to_shape()));
}
self.shapes = Some(shapes);
}
......
......@@ -15,8 +15,8 @@ pub struct MousePhysicsImpl {
#[derive(Clone)]
pub struct MousePhysics(Arc<Mutex<MousePhysicsImpl>>);
const LETHARGY : f64 = 2500.;
const BOING : f64 = 4.00;
const LETHARGY : f64 = 3500.;
const BOING : f64 = 1.00;
const EPS : f64 = 0.01;
const MUL: i32 = 20;
const MAXPERIOD : f64 = 100.;
......
......@@ -12,20 +12,18 @@ pub struct BoxSpec {
pub colspec: ColourSpec
}
pub struct PinBox {
offset: RLeaf,
colspec: ColourSpec,
width: i32,
geom: ProgramType
}
const DELTA_X: &[f32] = &[0.,1.,0.,1.,0.,-1.,0.,-1.];
const DELTA_Y: &[i32] = &[0, 1, 0,-1, 0, -1, 0, 1];
const END_X: &[f32] = &[0.,0.,0.,0.,1.,1.,1.,1.];
const END_Y: &[i32] = &[0, 0, 1, 1, 1, 1, 0, 0];
impl PinBox {
impl BoxSpec {
pub fn create(self) -> Box<Shape> {
let g = despot(PTGeom::Pin,PTMethod::Strip,&self.colspec);
Box::new(self)
}
fn origins(&self) -> Vec<CLeaf> {
let mut v = Vec::<CLeaf>::new();
let near = self.offset.offset();
......@@ -46,7 +44,7 @@ impl PinBox {
}
}
impl Shape for PinBox {
impl Shape for BoxSpec {
fn into_objects(&self, geom: &mut ProgramAttribs, _art: Option<Artwork>, e: &mut PrintEdition) {
let group = self.colspec.to_group(geom,e);
let b = vertices_hollowpoly(geom,4,group);
......@@ -61,18 +59,7 @@ impl Shape for PinBox {
}
}
fn get_geometry(&self) -> ProgramType { self.geom }
}
impl BoxSpec {
pub fn create(&self) -> Box<Shape> {
let g = despot(PTGeom::Pin,PTMethod::Strip,&self.colspec);
Box::new(PinBox {
geom: g,
offset: self.offset,
colspec: self.colspec.clone(),
width: self.width
})
fn get_geometry(&self) -> ProgramType {
despot(PTGeom::Pin,PTMethod::Strip,&self.colspec)
}
}
......@@ -37,8 +37,15 @@ pub struct PinPolySpec {
colspec: ColourSpec
}
impl PinPolySpec {
pub fn create(&self) -> Box<Shape> {
const CIRC_TOL : f32 = 1.; // max px undercut
fn circle_points(r: f32) -> u16 {
// 2*sqrt(pi*r) via 2nd order cos approx to max pixel undercut
(3.54 * (r/CIRC_TOL).sqrt()) as u16
}
impl Shape for PinPolySpec {
fn into_objects(&self, geom_a: &mut ProgramAttribs, _art: Option<Artwork>, e: &mut PrintEdition) {
/* Convert circles to polygons */
let (points, offset) = match self.ms {
MathsShape::Circle => (circle_points(self.size),0.),
......@@ -49,16 +56,25 @@ impl PinPolySpec {
Some(width) => (PTMethod::Strip,width,true),
None => (PTMethod::Triangle,0.,false)
};
/* Do it! */
let geom = despot(self.pt,mt,&self.colspec);
Box::new(PinPoly {
let ppd = PinPolyDraw {
origin: self.origin,
size: self.size,
colspec: self.colspec.clone(),
geom: geom,
anchor: self.anchor,
points, offset, width, hollow,
})
points, offset, width, hollow
};
ppd.draw(geom_a, _art, e);
}
fn get_geometry(&self) -> ProgramType {
let mt = if self.width.is_some() {
PTMethod::Strip
} else {
PTMethod::Triangle
};
despot(self.pt,mt,&self.colspec)
}
}
......@@ -66,7 +82,7 @@ impl PinPolySpec {
* PinPoly
*/
pub struct PinPoly {
struct PinPolyDraw {
origin: PolyPosition<f32>,
anchor: Anchors,
size: f32,
......@@ -78,7 +94,7 @@ pub struct PinPoly {
geom: ProgramType
}
impl PinPoly {
impl PinPolyDraw {
fn add(&self, b: DataBatch, geom: &mut ProgramAttribs,
v: Vec<CFraction>, nump: u16) {
let bbox = self.bounding_box(&v);
......@@ -159,10 +175,8 @@ impl PinPoly {
for p in pts { b.add(*p); }
b.get().unwrap()
}
}
impl Shape for PinPoly {
fn into_objects(&self, geom: &mut ProgramAttribs, _art: Option<Artwork>, e: &mut PrintEdition) {
fn draw(&self, geom: &mut ProgramAttribs, _art: Option<Artwork>, e: &mut PrintEdition) {
let group = self.colspec.to_group(geom,e);
if self.hollow {
let b = vertices_hollowpoly(geom,self.points,group);
......@@ -178,13 +192,6 @@ impl Shape for PinPoly {
fn get_geometry(&self) -> ProgramType { self.geom }
}
const CIRC_TOL : f32 = 1.; // max px undercut
fn circle_points(r: f32) -> u16 {
// 2*sqrt(pi*r) via 2nd order cos approx to max pixel undercut
(3.54 * (r/CIRC_TOL).sqrt()) as u16
}
pub fn pin_mathsshape(origin: &Dot<f32,i32>,
anchor: Anchors,
size: f32, width: Option<f32>, ms: MathsShape,
......
......@@ -15,7 +15,7 @@ use shape::util::{
};
use print::PrintEdition;
use drawing::{ Artwork };
use super::boxshape::{ BoxSpec, PinBox };
use super::boxshape::{ BoxSpec };
#[derive(Clone,Copy,Debug)]
enum RectPosition<T: Clone+Copy+Debug> {
......@@ -33,24 +33,7 @@ pub struct RectSpec {
colspec: ColourSpec
}
impl RectSpec {
pub fn create(&self) -> Box<Shape> {
let g = despot(self.pt,PTMethod::Triangle,&self.colspec);
Box::new(PinRect {
offset: self.offset,
colspec: self.colspec.clone(),
geom: g
})
}
}
pub struct PinRect {
offset: RectPosition<i32>,
colspec: ColourSpec,
geom: ProgramType
}
impl Shape for PinRect {
impl Shape for RectSpec {
fn into_objects(&self, geom: &mut ProgramAttribs, _art: Option<Artwork>, e: &mut PrintEdition) {
let group = self.colspec.to_group(geom,e);
let b = vertices_rect(geom,group);
......@@ -82,7 +65,9 @@ impl Shape for PinRect {
}
}
fn get_geometry(&self) -> ProgramType { self.geom }
fn get_geometry(&self) -> ProgramType {
despot(self.pt,PTMethod::Triangle,&self.colspec)
}
}
/* new, cleaner API */
......
......@@ -14,14 +14,14 @@ pub enum ShapeSpec {
}
impl ShapeSpec {
pub fn create(self) -> Box<Shape> {
pub fn to_shape(self) -> Box<Shape> {
match self {
ShapeSpec::PinPoly(pp) => pp.create(),
ShapeSpec::PinRect(pr) => pr.create(),
ShapeSpec::PinTexture(pt) => pt.create(),
ShapeSpec::StretchTexture(st) => st.create(),
ShapeSpec::Wiggle(w) => w.create(),
ShapeSpec::PinBox(pb) => pb.create(),
ShapeSpec::PinPoly(pp) => Box::new(pp),
ShapeSpec::PinRect(pr) => Box::new(pr),
ShapeSpec::PinTexture(pt) => Box::new(pt),
ShapeSpec::StretchTexture(st) => Box::new(st),
ShapeSpec::Wiggle(w) => Box::new(w),
ShapeSpec::PinBox(pb) => Box::new(pb),
}
}
}
}
......@@ -20,8 +20,8 @@ impl StretchWiggle {
StretchWiggle { points, group, y }
}
pub fn create(&self) -> Box<Shape> {
Box::new(self.clone())
pub fn create(self) -> Box<Shape> {
Box::new(self)
}
}
......
......@@ -824,6 +824,9 @@ Module.STDWEB_PRIVATE.acquire_tmp = function( dummy ) {
"__cargo_web_snippet_a152e8d0e8fac5476f30c1d19e4ab217dbcba73d": function($0, $1, $2) {
$1 = Module.STDWEB_PRIVATE.to_js($1);$2 = Module.STDWEB_PRIVATE.to_js($2);Module.STDWEB_PRIVATE.from_js($0, (function(){try{return{value:function(){return($1).querySelector(($2));}(),success:true};}catch(error){return{error:error,success:false};}})());
},
"__cargo_web_snippet_a1bde086ce8713d0a17c518ea35c6b6a7c47d99b": function($0, $1, $2, $3, $4) {
$0 = Module.STDWEB_PRIVATE.to_js($0);$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);($0).fillText(($1),($2),($3),($4));
},
"__cargo_web_snippet_a22b013cdfad43b048086eb38b7d14366fb7d483": function($0, $1) {
$1 = Module.STDWEB_PRIVATE.to_js($1);Module.STDWEB_PRIVATE.from_js($0, (function(){return($1).readyState;})());
},
......
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