Rename Point -> Vec2 to distinguish it clearly from any 3d object
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use ansi_term::Color::RGB;
|
||||
use crate::geom::Point;
|
||||
use crate::geom::Vec2;
|
||||
use crate::{flt::{Flt, Real}, Material as _};
|
||||
use crate::mat;
|
||||
use crate::sim::{Cell, GenericSim};
|
||||
@@ -48,7 +48,7 @@ fn scale_unsigned_to_u8(x: Flt, typ: Flt) -> u8 {
|
||||
}
|
||||
|
||||
/// Scale a vector to have magnitude between [0, 1).
|
||||
fn scale_vector(x: Point, typical_mag: Flt) -> Point {
|
||||
fn scale_vector(x: Vec2, typical_mag: Flt) -> Vec2 {
|
||||
let new_mag = scale_unsigned(x.mag(), typical_mag);
|
||||
x.with_mag(new_mag)
|
||||
}
|
||||
@@ -112,7 +112,7 @@ impl<'a> RenderSteps<'a> {
|
||||
self.render_vector_field(Rgb([0xff, 0xff, 0xff]), 1.0e-9, |cell| cell.b().xy());
|
||||
}
|
||||
|
||||
fn render_vector_field<F: Fn(&Cell<mat::Static>) -> Point>(&mut self, color: Rgb<u8>, typical: Flt, measure: F) {
|
||||
fn render_vector_field<F: Fn(&Cell<mat::Static>) -> Vec2>(&mut self, color: Rgb<u8>, typical: Flt, measure: F) {
|
||||
let w = self.im.width();
|
||||
let h = self.im.height();
|
||||
let vec_spacing = 10;
|
||||
@@ -123,7 +123,7 @@ impl<'a> RenderSteps<'a> {
|
||||
let norm_vec = scale_vector(vec, typical);
|
||||
let alpha = 0.7*scale_unsigned(vec.mag_sq(), typical * 5.0);
|
||||
let vec = norm_vec * (vec_spacing as Flt);
|
||||
let center = Point::new(x as _, y as _) + Point::new(vec_spacing as _, vec_spacing as _)*0.5;
|
||||
let center = Vec2::new(x as _, y as _) + Vec2::new(vec_spacing as _, vec_spacing as _)*0.5;
|
||||
self.im.draw_field_arrow(center, vec, color, alpha as f32);
|
||||
}
|
||||
}
|
||||
@@ -169,8 +169,8 @@ impl<'a> RenderSteps<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
fn field_vector<F: Fn(&Cell<mat::Static>) -> Point>(&self, xidx: u32, yidx: u32, size: u32, measure: &F) -> Point {
|
||||
let mut field = Point::default();
|
||||
fn field_vector<F: Fn(&Cell<mat::Static>) -> Vec2>(&self, xidx: u32, yidx: u32, size: u32, measure: &F) -> Vec2 {
|
||||
let mut field = Vec2::default();
|
||||
let w = self.im.width();
|
||||
let h = self.im.height();
|
||||
let xstart = xidx.min(w);
|
||||
@@ -186,7 +186,7 @@ impl<'a> RenderSteps<'a> {
|
||||
let yw = yend - ystart;
|
||||
if xw == 0 || yw == 0 {
|
||||
// avoid division by zero
|
||||
Point::new(0.0, 0.0)
|
||||
Vec2::new(0.0, 0.0)
|
||||
} else {
|
||||
field * (1.0 / ((xw*yw) as Flt))
|
||||
}
|
||||
@@ -194,11 +194,11 @@ impl<'a> RenderSteps<'a> {
|
||||
}
|
||||
|
||||
trait ImageRenderExt {
|
||||
fn draw_field_arrow(&mut self, center: Point, rel: Point, color: Rgb<u8>, alpha: f32);
|
||||
fn draw_field_arrow(&mut self, center: Vec2, rel: Vec2, color: Rgb<u8>, alpha: f32);
|
||||
}
|
||||
|
||||
impl ImageRenderExt for RgbImage {
|
||||
fn draw_field_arrow(&mut self, center: Point, rel: Point, color: Rgb<u8>, alpha: f32) {
|
||||
fn draw_field_arrow(&mut self, center: Vec2, rel: Vec2, color: Rgb<u8>, alpha: f32) {
|
||||
let start = (center - rel * 0.5).round();
|
||||
let end = (center + rel * 0.5).round();
|
||||
let i_start = (start.x() as _, start.y() as _);
|
||||
|
Reference in New Issue
Block a user