Skip to content

Commit

Permalink
Make Rectangle fields public
Browse files Browse the repository at this point in the history
  • Loading branch information
dharkness committed Aug 25, 2023
1 parent 6631cec commit 7524413
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 39 deletions.
36 changes: 6 additions & 30 deletions src/layout/cells/rectangle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ use super::{Cell, CellSet};
/// A rectangle of four cells.
#[derive(Clone, Copy, Eq, PartialEq)]
pub struct Rectangle {
top_left: Cell,
top_right: Cell,
bottom_left: Cell,
bottom_right: Cell,
cells: CellSet,
block_count: usize,
pub top_left: Cell,
pub top_right: Cell,
pub bottom_left: Cell,
pub bottom_right: Cell,
pub cells: CellSet,
pub block_count: usize,
}

impl Rectangle {
Expand Down Expand Up @@ -43,30 +43,6 @@ impl Rectangle {
pub fn from(c1: Cell, c2: Cell, c3: Cell, c4: Cell) -> Rectangle {
Rectangle::new(c1.min(c2).min(c3).min(c4), c1.max(c2).max(c3).max(c4))
}

pub const fn top_left(&self) -> Cell {
self.top_left
}

pub const fn top_right(&self) -> Cell {
self.top_right
}

pub const fn bottom_left(&self) -> Cell {
self.bottom_left
}

pub const fn bottom_right(&self) -> Cell {
self.bottom_right
}

pub const fn cells(&self) -> CellSet {
self.cells
}

pub const fn block_count(&self) -> usize {
self.block_count
}
}

impl Hash for Rectangle {
Expand Down
10 changes: 5 additions & 5 deletions src/solvers/avoidable_rectangles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ pub fn find_avoidable_rectangles(board: &Board) -> Option<Effects> {
.combinations(3)
.map(Rectangle::try_from)
.filter_map(Result::ok)
.filter(|r| r.block_count() == 2)
.filter(|r| r.block_count == 2)
{
let top_left = rectangle.top_left();
let top_right = rectangle.top_right();
let bottom_left = rectangle.bottom_left();
let bottom_right = rectangle.bottom_right();
let top_left = rectangle.top_left;
let top_right = rectangle.top_right;
let bottom_left = rectangle.bottom_left;
let bottom_right = rectangle.bottom_right;

let top_left_value = board.value(top_left);
let top_right_value = board.value(top_right);
Expand Down
8 changes: 4 additions & 4 deletions src/solvers/unique_rectangles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ fn check_type_one(
return;
}

let fourth = (rectangle.cells() - corners).as_single().unwrap();
let fourth = (rectangle.cells - corners).as_single().unwrap();
let candidates = board.candidates(fourth);
if !candidates.has_all(pair) {
return;
Expand Down Expand Up @@ -204,7 +204,7 @@ impl Candidate {
let roof_right_extras = board.candidates(roof_right) - pair;

let rectangle = Rectangle::from(floor_left, floor_right, roof_left, roof_right);
if rectangle.block_count() != 2 {
if rectangle.block_count != 2 {
return Err(());
}

Expand Down Expand Up @@ -244,11 +244,11 @@ impl Candidate {

let floor = CellSet::from_iter([floor1, floor2]);
let rectangle = Rectangle::try_from(floor)?;
if rectangle.block_count() != 2 {
if rectangle.block_count != 2 {
return Err(());
}

let roof = rectangle.cells() - floor;
let roof = rectangle.cells - floor;
let roof_pair = roof.as_pair().unwrap();

// the floor and roof are formed by the diagonals;
Expand Down

0 comments on commit 7524413

Please sign in to comment.