pub struct Card(/* private fields */);Implementations§
Source§impl Card
impl Card
pub fn new(index: usize) -> Card
Sourcepub fn index(self) -> usize
pub fn index(self) -> usize
Maps the card value back to the index from which it was derived.
Examples found in repository?
examples/count.rs (line 213)
209fn build_lookup() {
210 let cards = cards();
211
212 for (&a, &b) in (0..81).collect::<Vec<_>>().pairs() {
213 let c = (cards[a], cards[b]).complete_set().index();
214 unsafe {
215 SETS[a][b] = c;
216 // `complete_set()` is commutative
217 SETS[b][a] = c;
218 }
219 }
220}More examples
examples/simulate.rs (line 211)
207fn build_lookup() {
208 let cards = cards();
209
210 for (&a, &b) in (0..81).collect::<Vec<_>>().pairs() {
211 let c = (cards[a], cards[b]).complete_set().index();
212 unsafe {
213 SETS[a][b] = c;
214 // `complete_set()` is commutative
215 SETS[b][a] = c;
216 }
217 }
218}examples/genpng.rs (line 83)
35fn generate_card_images(path: &str, card_width: i32, border: i32,
36 vertical: bool, scheme: ColorScheme) -> io::Result<()>
37{
38 let card_height = (card_width as f64 / CARD_ASPECT_RATIO).ceil() as i32;
39 let card_rect = Rectangle {
40 // offset by (border, border)
41 x: border as f64,
42 y: border as f64,
43 width: card_width as f64,
44 height: card_height as f64,
45 };
46
47 // add space for the border on each edge
48 let mut ctx_width = card_width + border * 2;
49 let mut ctx_height = card_height + border * 2;
50 if vertical {
51 mem::swap(&mut ctx_width, &mut ctx_height);
52 }
53
54 // create the surface and context
55 let surface = ImageSurface::create(Format::ARgb32, ctx_width, ctx_height)
56 .expect("Could not create surface.");
57 let ctx = Context::new(&surface);
58 if vertical {
59 // adjust the transform to account for the vertical orientation
60 ctx.rotate(FRAC_PI_2);
61 ctx.translate(0.0, -ctx_width as f64);
62 }
63
64 for card in cards() {
65 // completely clear the context to avoid accumulating color on
66 // any edge that antialiases over the transparent background
67 // (e.g. rounded card corners)
68 ctx.save();
69 ctx.set_operator(Operator::Clear);
70 ctx.paint();
71 ctx.restore();
72
73 if border > 0 {
74 ctx.rounded_rect(card_rect, card_corner_radius(card_rect));
75 ctx.set_source_gray(0.0);
76 // half the stroke will be covered by the card
77 ctx.set_line_width(border as f64 * 2.);
78 ctx.stroke();
79 }
80
81 ctx.draw_card(card, card_rect, None, scheme);
82
83 let filename = format!("{}/{}.png", path, card.index());
84 let mut image = File::create(&filename)?;
85
86 surface.write_to_png(&mut image)
87 .unwrap_or_else(|_| println!("Error writing {}", filename));
88 }
89
90 Ok(())
91}Trait Implementations§
Source§impl Ord for Card
impl Ord for Card
Source§impl PartialOrd for Card
impl PartialOrd for Card
impl Copy for Card
impl Eq for Card
impl StructuralPartialEq for Card
Auto Trait Implementations§
impl Freeze for Card
impl RefUnwindSafe for Card
impl Send for Card
impl Sync for Card
impl Unpin for Card
impl UnwindSafe for Card
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more