struct Region {
crop: char,
plots: HashSet<(usize, usize)>,
perimeter: HashSet<((usize, usize), Side)>,
}
Expand description
A region that is a set of orthogonally adjacent plots in a Garden
with the same crop. It stores the plots and
number of units in the perimeter for use by Garden::total_fencing_cost
.
Fields§
§crop: char
§plots: HashSet<(usize, usize)>
§perimeter: HashSet<((usize, usize), Side)>
Implementations§
source§impl Region
impl Region
sourcefn contains(&self, plot: &Option<(usize, usize)>) -> bool
fn contains(&self, plot: &Option<(usize, usize)>) -> bool
Helper for checking if plot is in the grid. Takes an Option
to match Delta::apply_to
sourcefn check_for_corner(&self, plot: &(usize, usize), side: &Side) -> bool
fn check_for_corner(&self, plot: &(usize, usize), side: &Side) -> bool
Given an edge on one side of a plot. Calculate if following that edge clockwise is a corner
+---+
| A |
+---+ - +
| B | C |
+---+---+
There are only three cases:
- Straight - no corner: The examples above are
- Following the Side::right of the shape from
A
toC
. - Following the Side::bottom of the shape from
C
toB
.
- Following the Side::right of the shape from
- Convex corner, e.g. Side::top B going to A
- Concave corner which follow the Side::left and Side::top of A, Side::bottom and Side::left of B, and the Side::right of C.
If the block straight-ahead is not set it’s a concave corner. If it is set and the one ahead and to the Side::left is also set it’s concave.
sourcefn count_edges(&self) -> usize
fn count_edges(&self) -> usize
For all the edges in the perimeter, check if they are followed by a corner
Trait Implementations§
impl Eq for Region
impl StructuralPartialEq for Region
Auto Trait Implementations§
impl Freeze for Region
impl RefUnwindSafe for Region
impl Send for Region
impl Sync for Region
impl Unpin for Region
impl UnwindSafe for Region
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
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.