Fix clippy errors

This commit is contained in:
2020-09-04 16:49:24 -07:00
parent a48481db0d
commit 8e71e02ac1
7 changed files with 23 additions and 33 deletions

View File

@@ -1,4 +1,4 @@
use coremem::{consts, mat, SimState};
use coremem::{mat, SimState};
use coremem::render::{self, Renderer as _};
use std::{thread, time};

View File

@@ -1,4 +1,4 @@
use coremem::{consts, mat, SimState};
use coremem::{mat, SimState};
use coremem::render::{self, Renderer as _};
use std::{thread, time};

View File

@@ -170,11 +170,6 @@ impl Line {
(real(start_x) + delta_x).into()
}
pub fn move_toward_y(&self, start_x: f64, target_y: f64) -> f64 {
let x = self.move_toward_y(start_x, target_y);
self.clamp_x(x)
}
pub fn shifted(&self, p: Point) -> Line {
Line {
from: self.from + p,

View File

@@ -22,6 +22,7 @@ pub use sim::*;
// mu_0 = vacuum permeability = 1.25663706212(19)×106 H/m
// c_0 = speed of light in vacuum = 299792458
#[allow(non_snake_case)]
pub mod consts {
/// Speed of light in a vacuum; m/s.
/// Also equal to 1/sqrt(epsilon_0 mu_0)

View File

@@ -205,7 +205,7 @@ impl Default for GenericMaterial {
}
}
#[cfg(test)]
mod test {
use super::*;
fn mh_curve_for_test() -> MHCurve {
@@ -243,7 +243,6 @@ mod test {
#[test]
fn mh_curve_move_from_inner_to_inner() {
let curve = mh_curve_for_test();
assert_step_toward_symmetric(0.0, 0.0, 5.0, Ok((5.0, 0.0)));
assert_step_toward_symmetric(0.0, 5.0, 10.0, Ok((5.0, 5.0)));
@@ -256,7 +255,6 @@ mod test {
#[test]
fn mh_curve_magnetize_along_edge() {
let curve = mh_curve_for_test();
// start of segment NOOP
assert_step_toward_symmetric(10.0, 0.0, 10.0, Ok((10.0, 0.0)));
// start of segment to middle of segment
@@ -271,7 +269,6 @@ mod test {
#[test]
fn mh_curve_demagnetize_along_edge() {
let curve = mh_curve_for_test();
// start of segment NOOP
assert_step_toward_symmetric(30.0, 150.0, 180.0, Ok((30.0, 150.0)));
// start of segment to middle of segment
@@ -286,7 +283,6 @@ mod test {
#[test]
fn mh_curve_magnetize_across_edges() {
let curve = mh_curve_for_test();
// Rising from start to middle
assert_move_to_symmetric(10.0, 0.0, 132.0, (22.0, 110.0));
// Rising from start to saturation
@@ -303,7 +299,6 @@ mod test {
#[test]
fn mh_curve_demagnetize_across_edges() {
let curve = mh_curve_for_test();
// Falling from saturation to start
assert_move_to_symmetric(30.0, 150.0, 120.0, (0.0, 120.0));
// Falling from post-saturation to post-saturation

View File

@@ -1,12 +1,28 @@
use ansi_term::Color::RGB;
use crate::{consts, Material as _, SimState};
use crate::{Material as _, SimState};
use image::{RgbImage, Rgb};
use std::convert::TryInto as _;
use std::fmt::Write as _;
use std::fs::File;
use std::path::PathBuf;
use y4m;
// fn clamp(v: f32, range: f32) -> f32 {
// v.min(range).max(-range)
// }
// fn curl(x: f64, y: f64) -> f64 {
// let c = x * y;
// if c >= 0.0 {
// c.sqrt()
// } else {
// -(-c).sqrt()
// }
// }
fn norm_color(v: f64) -> u8 {
(v * 64.0 + 128.0).max(0.0).min(255.0) as u8
}
fn simstate_to_image(state: &SimState) -> RgbImage {
let w = state.width().try_into().unwrap();
let h = state.height().try_into().unwrap();
@@ -57,23 +73,6 @@ impl Renderer for NumericTermRenderer {
pub struct ColorTermRenderer;
fn clamp(v: f32, range: f32) -> f32 {
v.min(range).max(-range)
}
fn norm_color(v: f64) -> u8 {
(v * 64.0 + 128.0).max(0.0).min(255.0) as u8
}
fn curl(x: f64, y: f64) -> f64 {
let c = x * y;
if c >= 0.0 {
c.sqrt()
} else {
-(-c).sqrt()
}
}
impl Renderer for ColorTermRenderer {
fn render(&mut self, state: &SimState) {
let square = "";

View File

@@ -191,7 +191,7 @@ impl<M: Material> Cell<M> {
// Then $E_n$ (i.e. the y value of $E$ after this step) is trivially solved
// ```
use consts::real::{C, C2, EPS0, HALF, ONE, TWO};
use consts::real::{EPS0, ONE, TWO};
let sigma: R64 = self.mat.conductivity().into();