Created a function for the conversion of coordinates from algebra space to screen space. Typo.
This commit is contained in:
20
src/lib.rs
20
src/lib.rs
@@ -84,10 +84,15 @@ fn point_to_cga(x: f64, y: f64) -> CGA {
|
||||
0.5*mag_sqr*n_vec + ux*x_vec + uy*y_vec - 0.5*n_bar
|
||||
}
|
||||
|
||||
fn point_to_screen_space(x: f64, y: f64) -> (f64, f64) {
|
||||
let screen_x = x*RADIUS + CENTER_X;
|
||||
let screen_y = y*RADIUS + CENTER_Y;
|
||||
(screen_x, screen_y)
|
||||
}
|
||||
|
||||
fn draw_point(context: &CanvasRenderingContext2d, point: &CGA) {
|
||||
//Naively assume we are given a valid point
|
||||
let x = point[1]*RADIUS + CENTER_X;
|
||||
let y = point[2]*RADIUS + CENTER_Y;
|
||||
let (x,y) = point_to_screen_space(point[E1], point[E2]);
|
||||
|
||||
context.begin_path();
|
||||
context.set_fill_style_str(RED);
|
||||
@@ -125,8 +130,10 @@ fn draw_line(context: &CanvasRenderingContext2d, line: &CGA) {
|
||||
let p1y = py + ty * 1000.;
|
||||
let p2x = px - tx * 1000.;
|
||||
let p2y = py - ty * 1000.;
|
||||
context.move_to(p1x*RADIUS + CENTER_X, p1y*RADIUS + CENTER_Y);
|
||||
context.line_to(p2x*RADIUS + CENTER_X, p2y*RADIUS + CENTER_Y);
|
||||
let (canvas_x1, canvas_y1) = point_to_screen_space(p1x, p1y);
|
||||
let (canvas_x2, canvas_y2) = point_to_screen_space(p2x, p2y);
|
||||
context.move_to(canvas_x1, canvas_y1);
|
||||
context.line_to(canvas_x2, canvas_y2);
|
||||
|
||||
}
|
||||
} else {
|
||||
@@ -139,12 +146,11 @@ fn draw_line(context: &CanvasRenderingContext2d, line: &CGA) {
|
||||
//draw_point(context, &point_to_cga(c_x, c_y));
|
||||
|
||||
//Convert into Canvas Space
|
||||
let canvas_cx = c_x*RADIUS + CENTER_X;
|
||||
let canvas_cy = c_y*RADIUS + CENTER_Y;
|
||||
let (canvas_x, canvas_y) = point_to_screen_space(c_x, c_y);
|
||||
let canvas_r = r*RADIUS;
|
||||
|
||||
//Draw
|
||||
context.arc(canvas_cx, canvas_cy, canvas_r, 0., TWO_PI).unwrap();
|
||||
context.arc(canvas_x, canvas_y, canvas_r, 0., TWO_PI).unwrap();
|
||||
}
|
||||
context.stroke();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user