Tile

Struct Tile 

Source
pub struct Tile {
    pub colour: HexColour,
    pub name: String,
    /* private fields */
}
Expand description

A tile contains some number of track segments and cities.

Fields§

§colour: HexColour§name: String

Implementations§

Source§

impl Tile

Source

pub fn new<S: Into<String>>( colour: HexColour, name: S, tracks: Vec<Track>, cities: Vec<City>, hex: &Hex, ) -> Self

Creates a new tile and determines the connectivity between track segments, revenue centres, and hex faces.

Note that hex should be the default hexagon, to ensure that track connectivity is valid and consistent. By making this an argument, a single Hex can be used to construct all required tiles, rather than creating a new Hex for each tile.

Examples found in repository?
examples/custom_tile.rs (lines 22-28)
18fn draw_custom_tile(output_dir: &str) {
19    let output_file = "n18tile_custom_tile_1.png";
20    let output_path = std::path::Path::new(output_dir).join(output_file);
21    let hex = Hex::default();
22    let tile = Tile::new(
23        Red,
24        "Custom1",
25        vec![Track::straight(UpperRight), Track::gentle_l(LowerLeft)],
26        vec![],
27        &hex,
28    )
29    .with_offboard_faces([UpperRight, LowerRight])
30    .label(Label::MapLocation("Custom".to_string()), Top.to_centre(0.1))
31    .label(
32        Label::PhaseRevenueVert(vec![
33            (Yellow, 10, false),
34            (Green, 20, true),
35            (Brown, 30, false),
36            (Grey, 40, false),
37        ]),
38        HexPosition::Centre(Some(Delta::InDir(Direction::W, 0.35))),
39    )
40    .hide_tile_name();
41    println!("Writing {} ...", output_path.display());
42    tile.save_png(&hex, output_path).unwrap();
43}
Source

pub fn with_offboard_faces<T>(self, faces: T) -> Self
where T: IntoIterator<Item = HexFace>,

Identifies the tile as an off-board tile that has faces adjacent to on-board tiles.

Examples found in repository?
examples/custom_tile.rs (line 29)
18fn draw_custom_tile(output_dir: &str) {
19    let output_file = "n18tile_custom_tile_1.png";
20    let output_path = std::path::Path::new(output_dir).join(output_file);
21    let hex = Hex::default();
22    let tile = Tile::new(
23        Red,
24        "Custom1",
25        vec![Track::straight(UpperRight), Track::gentle_l(LowerLeft)],
26        vec![],
27        &hex,
28    )
29    .with_offboard_faces([UpperRight, LowerRight])
30    .label(Label::MapLocation("Custom".to_string()), Top.to_centre(0.1))
31    .label(
32        Label::PhaseRevenueVert(vec![
33            (Yellow, 10, false),
34            (Green, 20, true),
35            (Brown, 30, false),
36            (Grey, 40, false),
37        ]),
38        HexPosition::Centre(Some(Delta::InDir(Direction::W, 0.35))),
39    )
40    .hide_tile_name();
41    println!("Writing {} ...", output_path.display());
42    tile.save_png(&hex, output_path).unwrap();
43}
Source

pub fn offboard_faces(&self) -> Option<Vec<HexFace>>

Returns the edges adjacent to on-board tiles, if this tile is an off-board tile, otherwise returns None.

Source

pub fn hide_tile_name(self) -> Self

Do not display the tile name when drawing the tile.

Examples found in repository?
examples/custom_tile.rs (line 40)
18fn draw_custom_tile(output_dir: &str) {
19    let output_file = "n18tile_custom_tile_1.png";
20    let output_path = std::path::Path::new(output_dir).join(output_file);
21    let hex = Hex::default();
22    let tile = Tile::new(
23        Red,
24        "Custom1",
25        vec![Track::straight(UpperRight), Track::gentle_l(LowerLeft)],
26        vec![],
27        &hex,
28    )
29    .with_offboard_faces([UpperRight, LowerRight])
30    .label(Label::MapLocation("Custom".to_string()), Top.to_centre(0.1))
31    .label(
32        Label::PhaseRevenueVert(vec![
33            (Yellow, 10, false),
34            (Green, 20, true),
35            (Brown, 30, false),
36            (Grey, 40, false),
37        ]),
38        HexPosition::Centre(Some(Delta::InDir(Direction::W, 0.35))),
39    )
40    .hide_tile_name();
41    println!("Writing {} ...", output_path.display());
42    tile.save_png(&hex, output_path).unwrap();
43}
Source

pub fn is_tile_name_visible(&self) -> bool

Returns whether the tile name is displayed when drawing the tile.

Source

pub fn connections(&self, from: &Connection) -> Option<&[Connection]>

Source

pub fn all_connections_from<T>(&self, start: T) -> BTreeSet<Connection>
where T: Into<Connection>,

Returns all connections that can be reached from start.

Source

pub fn connected_faces<T>(&self, start: T) -> BTreeSet<HexFace>
where T: Into<Connection>,

Returns the hexagon faces that are connected to start.

Source

pub fn connected_dits<T>(&self, start: T) -> BTreeSet<usize>
where T: Into<Connection>,

Returns the index of each dit that is connected to start.

Source

pub fn connected_cities<T>(&self, start: T) -> BTreeSet<usize>
where T: Into<Connection>,

Returns the index of each city that is connected to start.

Source

pub fn connected_faces_are<T>(&self, start: T, dests: &[HexFace]) -> bool
where T: Into<Connection>,

Returns true if start is connected to each hexagon face in dests, and is not connected to any hexagon face not included in dests.

Source

pub fn no_connected_faces<T>(&self, start: T) -> bool
where T: Into<Connection>,

Returns true if start is not connected to any other hexagon face.

Source

pub fn connected_dits_are<T>( &self, start: T, dits: &[usize], ) -> Option<Vec<usize>>
where T: Into<Connection>,

Returns the index of each dit connected to start, if start is only connected to each dit in dits (identified by their revenue). Otherwise, returns None.

Source

pub fn connected_cities_are<T>( &self, start: T, cities: &[(usize, usize)], ) -> Option<Vec<usize>>
where T: Into<Connection>,

Returns the index of each city connected to start, if start is only connected to each city in cities (identified by their revenue and number of token spaces, respectively). Otherwise, returns None.

Source

pub fn label<P>(self, label: Label, pos: P) -> Self
where P: Into<HexPosition>,

Examples found in repository?
examples/custom_tile.rs (line 30)
18fn draw_custom_tile(output_dir: &str) {
19    let output_file = "n18tile_custom_tile_1.png";
20    let output_path = std::path::Path::new(output_dir).join(output_file);
21    let hex = Hex::default();
22    let tile = Tile::new(
23        Red,
24        "Custom1",
25        vec![Track::straight(UpperRight), Track::gentle_l(LowerLeft)],
26        vec![],
27        &hex,
28    )
29    .with_offboard_faces([UpperRight, LowerRight])
30    .label(Label::MapLocation("Custom".to_string()), Top.to_centre(0.1))
31    .label(
32        Label::PhaseRevenueVert(vec![
33            (Yellow, 10, false),
34            (Green, 20, true),
35            (Brown, 30, false),
36            (Grey, 40, false),
37        ]),
38        HexPosition::Centre(Some(Delta::InDir(Direction::W, 0.35))),
39    )
40    .hide_tile_name();
41    println!("Writing {} ...", output_path.display());
42    tile.save_png(&hex, output_path).unwrap();
43}
Source

pub fn tracks(&self) -> &[Track]

Source

pub fn dits(&self) -> &[Dit]

Source

pub fn cities(&self) -> &[City]

Source

pub fn labels(&self) -> &[LabelAndPos]

Source

pub fn city(&self, space: &TokenSpace) -> Option<&City>

Returns the city that corresponds to the provided token location.

Source

pub fn revenues(&self) -> &[usize]

Source

pub fn only_draw_offboard_track(&self) -> bool

Returns true if this tile is an off-board tile for which special off-board track segments should be drawn, instead of drawing the regular track segments, dits, and cities.

Source

pub fn define_offboard_track_inner_path( &self, ctx: &Context, hex: &Hex, face: &HexFace, ) -> bool

Defines the inner (foreground) layer of the off-board track segment for the specified tile face, if such a segment should be drawn on this face, and returns true.

If no such segment should be drawn, this has no effect and returns false.

Source

pub fn draw_offboard_segment( &self, ctx: &Context, hex: &Hex, face: &HexFace, ) -> bool

Draws the off-board track segment for the specified tile face, if such a segment should be drawn on this face, and returns true.

If no such segment should be drawn, this has no effect and returns false.

Source

pub fn draw(&self, ctx: &Context, hex: &Hex)

Source

pub fn token_spaces(&self) -> Vec<TokenSpace>

Source

pub fn city_token_spaces(&self, city_ix: usize) -> Vec<TokenSpace>

Source

pub fn token_space_count(&self) -> usize

Source

pub fn dit_count(&self) -> usize

Source

pub fn define_token_space( &self, space: &TokenSpace, hex: &Hex, ctx: &Context, ) -> bool

Source

pub fn can_upgrade_to(&self, other: &Tile) -> bool

Check whether a tile can be upgraded to another tile.

Source

pub fn save_png<P: AsRef<Path>>( &self, hex: &Hex, path: P, ) -> Result<(), Box<dyn Error>>

Saves the tile to a PNG file.

Examples found in repository?
examples/custom_tile.rs (line 42)
18fn draw_custom_tile(output_dir: &str) {
19    let output_file = "n18tile_custom_tile_1.png";
20    let output_path = std::path::Path::new(output_dir).join(output_file);
21    let hex = Hex::default();
22    let tile = Tile::new(
23        Red,
24        "Custom1",
25        vec![Track::straight(UpperRight), Track::gentle_l(LowerLeft)],
26        vec![],
27        &hex,
28    )
29    .with_offboard_faces([UpperRight, LowerRight])
30    .label(Label::MapLocation("Custom".to_string()), Top.to_centre(0.1))
31    .label(
32        Label::PhaseRevenueVert(vec![
33            (Yellow, 10, false),
34            (Green, 20, true),
35            (Brown, 30, false),
36            (Grey, 40, false),
37        ]),
38        HexPosition::Centre(Some(Delta::InDir(Direction::W, 0.35))),
39    )
40    .hide_tile_name();
41    println!("Writing {} ...", output_path.display());
42    tile.save_png(&hex, output_path).unwrap();
43}
Source

pub fn save_svg<P: AsRef<Path>>( &self, hex: &Hex, path: P, ) -> Result<(), Box<dyn Error>>

Saves the tile to an SVG file.

Source

pub fn save_pdf<P: AsRef<Path>>( &self, hex: &Hex, path: P, ) -> Result<(), Box<dyn Error>>

Saves the tile to a PDF file.

Source

pub fn write_png<W: Write>( &self, hex: &Hex, stream: &mut W, ) -> Result<(), Box<dyn Error>>

Writes the tile as a PNG image to the provided stream.

Source

pub fn write_svg<W: Write + 'static>( &self, hex: &Hex, stream: W, ) -> Result<(), Box<dyn Error>>

Writes the tile as an SVG image to the provided stream.

Source

pub fn write_pdf<W: Write + 'static>( &self, hex: &Hex, stream: W, ) -> Result<(), Box<dyn Error>>

Writes the tile as a PDF image to the provided stream.

Trait Implementations§

Source§

impl Clone for Tile

Source§

fn clone(&self) -> Tile

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Tile

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Tile

Source§

fn eq(&self, other: &Tile) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Tile

Auto Trait Implementations§

§

impl Freeze for Tile

§

impl RefUnwindSafe for Tile

§

impl Send for Tile

§

impl Sync for Tile

§

impl Unpin for Tile

§

impl UnwindSafe for Tile

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.