Skip to content

Commit bdd1751

Browse files
committed
fern_sim: Updated.
1 parent 002cb75 commit bdd1751

File tree

12 files changed

+69
-27
lines changed

12 files changed

+69
-27
lines changed

fern_sim/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[package]
22
name = "fern_sim"
33
version = "0.1.0"
4+
edition = "2018"
45
authors = ["You <[email protected]>"]
56
license = "MIT"
67
homepage = "https://fernsim.example.com/"

fern_sim/src/cells.rs

Lines changed: 0 additions & 12 deletions
This file was deleted.

fern_sim/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
//! Simulate the growth of ferns, from the level of
22
//! individual cells on up.
33
4-
pub mod cells;
4+
#![warn(rust_2018_idioms)]
5+
#![allow(elided_lifetimes_in_paths)]
6+
57
pub mod plant_structures;
68
pub mod simulation;
79
pub mod spores;

fern_sim/src/plant_structures/leaves.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
//! Simulation of individual leaves (for the formation of leaves, see `stem`).
33
44
pub struct Leaf {
5-
x: bool
5+
pub x: bool
66
}

fern_sim/src/plant_structures/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,17 @@ impl Fern {
4343
self.stems.iter().all(|s| !s.furled)
4444
}
4545
}
46+
47+
/// Create and return a [`VascularPath`] which represents the path of
48+
/// nutrients from the given [`Root`][r] to the given [`Leaf`](leaves::Leaf).
49+
///
50+
/// [r]: roots::Root
51+
pub fn trace_path(leaf: &leaves::Leaf, root: &roots::Root) -> VascularPath {
52+
VascularPath { from: leaf.x, to: root.x }
53+
}
54+
55+
#[doc(alias = "route")]
56+
pub struct VascularPath {
57+
pub from: bool,
58+
pub to: bool,
59+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![allow(dead_code)]
22

33
pub struct Root {
4-
x: bool
4+
pub x: bool
55
}
66

77
pub type RootSet = Vec<Root>;

fern_sim/src/plant_structures/stems.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
//! the feathery leaf structure that's the most immediately recognizable
44
//! property of ferns.
55
6+
// in plant_structures/stems.rs
7+
pub mod xylem;
8+
pub mod phloem;
9+
610
pub struct Stem {
711
pub furled: bool
812
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//! Structures for distributing the products of photosynthesis.
2+
3+
/// Tissue for translocating sucrose and other photosynthesis products.
4+
pub struct Phloem {
5+
pub flow_rate: f32,
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//! Structures for bringing nutrients from roots up to other parts of the plant.
2+
3+
/// Vascular tissue for transporting water and nutrients from the roots.
4+
pub struct Xylem {
5+
pub flow_rate: f32,
6+
}

fern_sim/src/simulation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
use std::fs::File;
66
use std::time::Duration;
7-
use plant_structures::{Fern, FernType};
7+
use crate::plant_structures::{Fern, FernType};
88

99
/// The simulated universe.
1010
pub struct Terrarium {

fern_sim/src/spores.rs

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,46 @@
22

33
//! Fern reproduction.
44
5-
use cells::Cell;
5+
use cells::{Cell, Gene};
66

77
/// A cell made by an adult fern. It disperses on the wind as part of
88
/// the fern life cycle. A spore grows into a prothallus -- a whole
9-
/// separate organism, up to 5mm across -- which produces a zygote,
10-
/// which becomes a new fern. (Plant sex is complicated.)
9+
/// separate organism, up to 5mm across -- which produces the zygote
10+
/// that grows into a new fern. (Plant sex is complicated.)
1111
pub struct Spore {
12-
x: bool
13-
}
14-
15-
/// A compartment, usually on the bottom of a leaf, where spores form.
16-
pub struct Sporangium {
17-
x: bool
12+
size: f64
1813
}
1914

2015
/// Simulate the production of a spore by meiosis.
2116
pub fn produce_spore(factory: &mut Sporangium) -> Spore {
22-
Spore { x: false }
17+
Spore { size: 1.0 }
18+
}
19+
20+
/// Extract the genes in a particular spore.
21+
pub(crate) fn genes(spore: &Spore) -> Vec<Gene> {
22+
todo!()
2323
}
2424

2525
/// Mix genes to prepare for meiosis (part of interphase).
2626
fn recombine(parent: &mut Cell) {
27+
todo!()
2728
}
2829

30+
pub struct Sporangium;
31+
32+
mod cells {
33+
//! The simulation of biological cells, which is as low-level as we go.
34+
35+
pub struct Cell {
36+
x: f64,
37+
y: f64
38+
}
39+
40+
impl Cell {
41+
pub fn distance_from_origin(&self) -> f64 {
42+
f64::hypot(self.x, self.y)
43+
}
44+
}
45+
46+
pub struct Gene;
47+
}

fern_sim/tests/unfurl.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// tests/unfurl.rs - Fiddleheads unfurl in sunlight
22

3-
extern crate fern_sim;
3+
#![warn(rust_2018_idioms)]
4+
#![allow(elided_lifetimes_in_paths)]
5+
46
use fern_sim::Terrarium;
57
use std::time::Duration;
68

0 commit comments

Comments
 (0)