chore: run cargo fmt
This commit is contained in:
parent
5d6ab1fa71
commit
63c13e1739
@ -1,9 +1,9 @@
|
||||
use crate::components::BackgroundProps;
|
||||
use crate::components::Background;
|
||||
use crate::routes::whymdc::*;
|
||||
use crate::routes::home::*;
|
||||
use crate::routes::empty::*;
|
||||
use crate::components::BackgroundProps;
|
||||
use crate::routes::blog::*;
|
||||
use crate::routes::empty::*;
|
||||
use crate::routes::home::*;
|
||||
use crate::routes::whymdc::*;
|
||||
use leptos::*;
|
||||
use leptos_meta::*;
|
||||
use leptos_router::*;
|
||||
@ -44,4 +44,3 @@ pub fn App(cx: Scope) -> impl IntoView {
|
||||
</Router>
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -40,7 +40,11 @@ pub fn Background(cx: Scope, class: &'static str) -> impl IntoView {
|
||||
context_to_render.move_to(n.position.x.into(), n.position.y.into());
|
||||
context_to_render.line_to(child.position.x.into(), child.position.y.into());
|
||||
};
|
||||
let mut sc = SpaceColonization::new(width.try_into().unwrap(), height.try_into().unwrap(), render_node_fn);
|
||||
let mut sc = SpaceColonization::new(
|
||||
width.try_into().unwrap(),
|
||||
height.try_into().unwrap(),
|
||||
render_node_fn,
|
||||
);
|
||||
let nodes = Rc::new(RefCell::new(Vec::new()));
|
||||
nodes.borrow_mut().push(Node::new(Point::new((
|
||||
(window_width / 3) as i32,
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
mod codeblock;
|
||||
mod code;
|
||||
mod background;
|
||||
pub use codeblock::*;
|
||||
pub use code::*;
|
||||
mod code;
|
||||
mod codeblock;
|
||||
pub use background::*;
|
||||
pub use code::*;
|
||||
pub use codeblock::*;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
mod space_colonization;
|
||||
pub mod app;
|
||||
mod components;
|
||||
mod routes;
|
||||
mod space_colonization;
|
||||
use cfg_if::cfg_if;
|
||||
|
||||
cfg_if! {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
use crate::components::*;
|
||||
use leptos::*;
|
||||
use leptos_meta::*;
|
||||
use crate::components::*;
|
||||
|
||||
#[component]
|
||||
pub fn Blog(cx: Scope) -> impl IntoView {
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
pub mod whymdc;
|
||||
pub mod home;
|
||||
pub mod blog;
|
||||
pub mod empty;
|
||||
pub mod home;
|
||||
pub mod whymdc;
|
||||
|
||||
@ -31,5 +31,3 @@ pub fn SubsectionTitle(cx: Scope, dark: bool, children: Children) -> impl IntoVi
|
||||
<h5 class={class}>{children(cx)}</h5>
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -394,7 +394,7 @@ pub fn WhyMicroDatacenters(cx: Scope) -> impl IntoView {
|
||||
</p>
|
||||
<p class="text-justify mt-2 text-neutral-400 text-xs ml-72 mr-72">
|
||||
"https://www.pewresearch.org/internet/2019/11/15/americans-and-privacy-concerned-confused-and-feeling-lack-of-control-over-their-personal-information/?fbcli
|
||||
d=IwAR3wuxdHW8VE30FMaqZ6Iuj9Cs86bRSvmij1e_zDjM6Bwo4l71n5EKcLxqY"
|
||||
d=IwAR3wuxdHW8VE30FMaqZ6Iuj9Cs86bRSvmij1e_zDjM6Bwo4l71n5EKcLxqY"
|
||||
</p>
|
||||
</div>
|
||||
|
||||
|
||||
@ -46,20 +46,20 @@ impl Point {
|
||||
|
||||
impl Ord for Point {
|
||||
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
|
||||
if self.x > other.x {
|
||||
return std::cmp::Ordering::Greater;
|
||||
}
|
||||
if self.x < other.x {
|
||||
return std::cmp::Ordering::Less;
|
||||
}
|
||||
if self.y > other.y {
|
||||
return std::cmp::Ordering::Greater;
|
||||
}
|
||||
if self.y < other.y {
|
||||
return std::cmp::Ordering::Less;
|
||||
}
|
||||
if self.x > other.x {
|
||||
return std::cmp::Ordering::Greater;
|
||||
}
|
||||
if self.x < other.x {
|
||||
return std::cmp::Ordering::Less;
|
||||
}
|
||||
if self.y > other.y {
|
||||
return std::cmp::Ordering::Greater;
|
||||
}
|
||||
if self.y < other.y {
|
||||
return std::cmp::Ordering::Less;
|
||||
}
|
||||
|
||||
std::cmp::Ordering::Equal
|
||||
std::cmp::Ordering::Equal
|
||||
}
|
||||
}
|
||||
|
||||
@ -69,169 +69,135 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn distance_to_itself_is_zero() {
|
||||
let p = Point {
|
||||
x: 1,
|
||||
y: 1,
|
||||
};
|
||||
let p = Point { x: 1, y: 1 };
|
||||
assert_eq!(p.distance(&p), 0.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn distance_same_x_is_y() {
|
||||
let p1 = Point {
|
||||
x: 1,
|
||||
y: 1,
|
||||
};
|
||||
let p1 = Point { x: 1, y: 1 };
|
||||
|
||||
let p2 = Point {
|
||||
x: 1,
|
||||
y: 5,
|
||||
};
|
||||
let p2 = Point { x: 1, y: 5 };
|
||||
|
||||
assert_eq!(p1.distance(&p2), 4.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn distance_same_y_is_x() {
|
||||
let p1 = Point::new((1,1));
|
||||
let p2 = Point::new((5,1));
|
||||
let p1 = Point::new((1, 1));
|
||||
let p2 = Point::new((5, 1));
|
||||
|
||||
assert_eq!(p1.distance(&p2), 4.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn distance_3_4_5() {
|
||||
let p1 = Point::new((0,0));
|
||||
let p2 = Point::new((3,4));
|
||||
let p1 = Point::new((0, 0));
|
||||
let p2 = Point::new((3, 4));
|
||||
|
||||
assert_eq!(p1.distance(&p2), 5.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn distance_is_always_positive() {
|
||||
let p1 = Point::new((10,10));
|
||||
let p2 = Point::new((5,10));
|
||||
let p1 = Point::new((10, 10));
|
||||
let p2 = Point::new((5, 10));
|
||||
|
||||
assert_eq!(p1.distance(&p2), 5.0);
|
||||
|
||||
let p1 = Point::new((10,10));
|
||||
let p2 = Point::new((10,5));
|
||||
let p1 = Point::new((10, 10));
|
||||
let p2 = Point::new((10, 5));
|
||||
|
||||
assert_eq!(p1.distance(&p2), 5.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn distance_quadrant3() {
|
||||
let p1 = Point {
|
||||
x: 3,
|
||||
y: 4,
|
||||
};
|
||||
let p1 = Point { x: 3, y: 4 };
|
||||
|
||||
let p2 = Point {
|
||||
x: 0,
|
||||
y: 0,
|
||||
};
|
||||
let p2 = Point { x: 0, y: 0 };
|
||||
|
||||
assert_eq!(p1.distance(&p2), 5.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn distance_quadrant2() {
|
||||
let p1 = Point {
|
||||
x: 3,
|
||||
y: 4,
|
||||
};
|
||||
let p1 = Point { x: 3, y: 4 };
|
||||
|
||||
let p2 = Point {
|
||||
x: 0,
|
||||
y: 100,
|
||||
};
|
||||
let p2 = Point { x: 0, y: 100 };
|
||||
|
||||
assert_eq!(p1.distance(&p2) as f32, 96.04687);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn distance_quadrant2_fast() {
|
||||
let p1 = Point {
|
||||
x: 3,
|
||||
y: 4,
|
||||
};
|
||||
let p1 = Point { x: 3, y: 4 };
|
||||
|
||||
let p2 = Point {
|
||||
x: 3,
|
||||
y: 50,
|
||||
};
|
||||
let p2 = Point { x: 3, y: 50 };
|
||||
|
||||
assert_eq!(p1.distance(&p2), 46.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn distance_quadrant4() {
|
||||
let p1 = Point {
|
||||
x: 3,
|
||||
y: 4,
|
||||
};
|
||||
let p1 = Point { x: 3, y: 4 };
|
||||
|
||||
let p2 = Point {
|
||||
x: 50,
|
||||
y: -50,
|
||||
};
|
||||
let p2 = Point { x: 50, y: -50 };
|
||||
|
||||
assert_eq!(p1.distance(&p2) as f32, 71.5891);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn movement_does_nothing_when_right_length() {
|
||||
let root = Point::new((0,0));
|
||||
let node = Point::new((0,1));
|
||||
let root = Point::new((0, 0));
|
||||
let node = Point::new((0, 1));
|
||||
assert_eq!(root.movement(node.clone(), 1), node);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn movement_does_not_overlap() {
|
||||
let root = Point::new((0,1));
|
||||
let node = Point::new((0,0));
|
||||
let root = Point::new((0, 1));
|
||||
let node = Point::new((0, 0));
|
||||
assert_eq!(root.movement(node.clone(), 2), Point::new((0, -1)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn movement_adjusts_to_asked_length() {
|
||||
let root = Point::new((0,0));
|
||||
let node = Point::new((0,1));
|
||||
assert_eq!(root.movement(node, 10), Point::new((0,10)));
|
||||
let root = Point::new((0, 0));
|
||||
let node = Point::new((0, 1));
|
||||
assert_eq!(root.movement(node, 10), Point::new((0, 10)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn movement_works_away_from_origin() {
|
||||
let root = Point::new((10,10));
|
||||
let node = Point::new((10,11));
|
||||
assert_eq!(root.movement(node, 10), Point::new((10,20)));
|
||||
let root = Point::new((10, 10));
|
||||
let node = Point::new((10, 11));
|
||||
assert_eq!(root.movement(node, 10), Point::new((10, 20)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn movement_works_in_two_dimension() {
|
||||
let root = Point::new((10,10));
|
||||
let node = Point::new((40,50));
|
||||
assert_eq!(root.movement(node, 50), Point::new((40,50)));
|
||||
let root = Point::new((10, 10));
|
||||
let node = Point::new((40, 50));
|
||||
assert_eq!(root.movement(node, 50), Point::new((40, 50)));
|
||||
|
||||
let root = Point::new((10,10));
|
||||
let node = Point::new((40,50));
|
||||
assert_eq!(root.movement(node, 5), Point::new((13,14)));
|
||||
let root = Point::new((10, 10));
|
||||
let node = Point::new((40, 50));
|
||||
assert_eq!(root.movement(node, 5), Point::new((13, 14)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn movement_works_in_all_directions() {
|
||||
let root = Point::new((40,50));
|
||||
let node = Point::new((10,10));
|
||||
assert_eq!(root.movement(node, 5), Point::new((37,46)));
|
||||
let root = Point::new((40, 50));
|
||||
let node = Point::new((10, 10));
|
||||
assert_eq!(root.movement(node, 5), Point::new((37, 46)));
|
||||
|
||||
let root = Point::new((50,10));
|
||||
let node = Point::new((10,10));
|
||||
assert_eq!(root.movement(node, 5), Point::new((45,10)));
|
||||
let root = Point::new((50, 10));
|
||||
let node = Point::new((10, 10));
|
||||
assert_eq!(root.movement(node, 5), Point::new((45, 10)));
|
||||
|
||||
let root = Point::new((10,50));
|
||||
let node = Point::new((10,10));
|
||||
assert_eq!(root.movement(node, 5), Point::new((10,45)));
|
||||
let root = Point::new((10, 50));
|
||||
let node = Point::new((10, 10));
|
||||
assert_eq!(root.movement(node, 5), Point::new((10, 45)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -311,7 +311,7 @@ mod test {
|
||||
let mut attractors = Vec::new();
|
||||
attractors.push(Attractor::new(Point::new((10, 0))));
|
||||
|
||||
let mut sc = SpaceColonization::new_for_tests(100, 100, attractors, |_, _|{});
|
||||
let mut sc = SpaceColonization::new_for_tests(100, 100, attractors, |_, _| {});
|
||||
|
||||
assert_eq!(sc.attractors.len(), 1);
|
||||
assert!(sc.attractors.iter().find(|a| a.dead == true).is_none());
|
||||
@ -357,7 +357,7 @@ mod test {
|
||||
dead: true,
|
||||
});
|
||||
|
||||
let mut sc = SpaceColonization::new_for_tests(100, 100, attractors, |_, _|{});
|
||||
let mut sc = SpaceColonization::new_for_tests(100, 100, attractors, |_, _| {});
|
||||
|
||||
assert_eq!(sc.attractors.len(), 1);
|
||||
assert!(sc.attractors.iter().find(|a| a.dead == true).is_some());
|
||||
|
||||
@ -154,8 +154,10 @@ mod test {
|
||||
assert_eq!(
|
||||
index.get_surrounding_elements(&Point::new((50, 50))).sort(),
|
||||
vec![
|
||||
&4040, &4545, &5040, &6040, &4050, &5050, &6050, &5050, &5151, &6060, &4060, &5060, &6060,
|
||||
].sort()
|
||||
&4040, &4545, &5040, &6040, &4050, &5050, &6050, &5050, &5151, &6060, &4060, &5060,
|
||||
&6060,
|
||||
]
|
||||
.sort()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user