Skip to content

Commit 7b54d76

Browse files
committed
Add iai
1 parent 1b83689 commit 7b54d76

File tree

6 files changed

+83
-109
lines changed

6 files changed

+83
-109
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
/target
1+
target/
22
.idea/
33
*.iml

Cargo.lock

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tiling/Cargo.toml

+8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ edition = "2018"
88

99
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1010

11+
[dev-dependencies]
12+
iai = "0.1"
13+
14+
[[bench]]
15+
name = "iai"
16+
harness = false
17+
path = "src/iai.rs"
18+
1119
[dependencies]
1220
arrayvec = "0.7"
1321
derive_more = "0.99"

tiling/src/iai.rs

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
use euclid::default::Point2D;
2+
3+
use euclid::default::Box2D;
4+
use iai::black_box;
5+
use penrose_tiling::{compute_area, FiveFold, MatchList};
6+
7+
fn render(bounds: &Box2D<f64>, mut plane: FiveFold) -> MatchList {
8+
compute_area(&mut plane, bounds)
9+
}
10+
11+
fn ace() {
12+
let plane = FiveFold::ace_configuration();
13+
let bounds = Box2D::new(Point2D::new(-8., -4.), Point2D::new(8., 4.));
14+
15+
render(&bounds, black_box(plane));
16+
}
17+
18+
fn deuce() {
19+
let plane = FiveFold::deuce_configuration();
20+
let bounds = Box2D::new(Point2D::new(-40., -20.), Point2D::new(40., 20.));
21+
22+
render(&bounds, black_box(plane));
23+
}
24+
25+
fn sun() {
26+
let plane = FiveFold::sun_configuration();
27+
let bounds = Box2D::new(Point2D::new(-14., -7.), Point2D::new(14., 7.));
28+
29+
render(&bounds, black_box(plane));
30+
}
31+
32+
fn star() {
33+
let plane = FiveFold::star_configuration();
34+
let bounds = Box2D::new(Point2D::new(-40., -20.), Point2D::new(40., 20.));
35+
36+
render(&bounds, black_box(plane));
37+
}
38+
39+
fn jack() {
40+
let plane = FiveFold::jack_configuration();
41+
let bounds = Box2D::new(Point2D::new(-40., -20.), Point2D::new(40., 20.));
42+
43+
render(&bounds, black_box(plane));
44+
}
45+
46+
fn queen() {
47+
let plane = FiveFold::queen_configuration();
48+
let bounds = Box2D::new(Point2D::new(-40., -20.), Point2D::new(40., 20.));
49+
50+
render(&bounds, black_box(plane));
51+
}
52+
53+
fn king() {
54+
let plane = FiveFold::king_configuration();
55+
let bounds = Box2D::new(Point2D::new(-40., -20.), Point2D::new(40., 20.));
56+
57+
render(&bounds, black_box(plane));
58+
}
59+
60+
iai::main!(ace, deuce, sun, star, jack, queen, king);

tiling/src/lib.rs

-108
Original file line numberDiff line numberDiff line change
@@ -63,111 +63,3 @@ pub fn compute_area(plane: &mut FiveFold, bounds: &Box2D<f64>) -> MatchList {
6363

6464
MatchList { kites, darts }
6565
}
66-
67-
#[cfg(test)]
68-
mod test {
69-
use std::io::Write;
70-
71-
use euclid::default::Point2D;
72-
73-
use crate::shape::Shape;
74-
75-
use super::*;
76-
77-
fn show_matches(bounds: &Box2D<f64>, mut plane: FiveFold) {
78-
let matches = compute_area(&mut plane, &bounds);
79-
80-
let y_range = bounds.max.y - bounds.min.y;
81-
let x_range = bounds.max.x - bounds.min.x;
82-
83-
let y_step = y_range / 50f64;
84-
let x_step = x_range / 200f64;
85-
let y_center = (bounds.max.y + bounds.min.y + y_step) / 2f64;
86-
let x_center = (bounds.max.x + bounds.min.x + x_step) / 2f64;
87-
88-
let mut res = String::from("\n");
89-
for y in -25..25 {
90-
for x in -100..100 {
91-
let point =
92-
Point2D::new(x as f64 * x_step + x_center, y as f64 * y_step + y_center);
93-
94-
if matches.kites.iter().any(|kite| kite.contains(point)) {
95-
res += "X";
96-
} else if matches.darts.iter().any(|dart| dart.contains(point)) {
97-
res += ":"
98-
} else {
99-
res += " ";
100-
}
101-
}
102-
res += "\n";
103-
}
104-
res += "\n";
105-
let stdout = std::io::stdout();
106-
let mut lock = stdout.lock();
107-
lock.write_all(res.as_bytes()).unwrap();
108-
lock.flush().unwrap();
109-
}
110-
111-
#[test]
112-
#[ignore]
113-
fn ace() {
114-
let plane = FiveFold::ace_configuration();
115-
let bounds = Box2D::new(Point2D::new(-8., -4.), Point2D::new(8., 4.));
116-
117-
show_matches(&bounds, plane);
118-
}
119-
120-
#[test]
121-
#[ignore]
122-
fn deuce() {
123-
let plane = FiveFold::deuce_configuration();
124-
let bounds = Box2D::new(Point2D::new(-40., -20.), Point2D::new(40., 20.));
125-
126-
show_matches(&bounds, plane);
127-
}
128-
129-
#[test]
130-
#[ignore]
131-
fn sun() {
132-
let plane = FiveFold::sun_configuration();
133-
let bounds = Box2D::new(Point2D::new(-14., -7.), Point2D::new(14., 7.));
134-
135-
show_matches(&bounds, plane);
136-
}
137-
138-
#[test]
139-
#[ignore]
140-
fn star() {
141-
let plane = FiveFold::star_configuration();
142-
let bounds = Box2D::new(Point2D::new(-40., -20.), Point2D::new(40., 20.));
143-
144-
show_matches(&bounds, plane);
145-
}
146-
147-
#[test]
148-
#[ignore]
149-
fn jack() {
150-
let plane = FiveFold::jack_configuration();
151-
let bounds = Box2D::new(Point2D::new(-40., -20.), Point2D::new(40., 20.));
152-
153-
show_matches(&bounds, plane);
154-
}
155-
156-
#[test]
157-
#[ignore]
158-
fn queen() {
159-
let plane = FiveFold::queen_configuration();
160-
let bounds = Box2D::new(Point2D::new(-40., -20.), Point2D::new(40., 20.));
161-
162-
show_matches(&bounds, plane);
163-
}
164-
165-
#[test]
166-
#[ignore]
167-
fn king() {
168-
let plane = FiveFold::king_configuration();
169-
let bounds = Box2D::new(Point2D::new(-40., -20.), Point2D::new(40., 20.));
170-
171-
show_matches(&bounds, plane);
172-
}
173-
}

tiling/src/musical_sequence.rs

+7
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ fn ddist(shorts: BarNumber, longs: BarNumber, distance: f64) -> f64 {
4343
}
4444

4545
impl MusicalSequence {
46+
fn new() -> Self {
47+
MusicalSequence {
48+
upper_y: 1,
49+
..Default::default()
50+
}
51+
}
52+
4653
pub(crate) fn new_with_coords(x: f64, y: f64, r: f64) -> Self {
4754
MusicalSequence {
4855
upper_y: 1,

0 commit comments

Comments
 (0)