Use ranges properly
This commit is contained in:
+17
-11
@@ -66,7 +66,7 @@ impl Board {
|
||||
pub fn update_square(&mut self, point: &Point, value: CellValue) {
|
||||
let row_bounds = point.row_bounds();
|
||||
let col_bounds = point.col_bounds();
|
||||
for c in self.cells.slice_mut(s![row_bounds.0..row_bounds.1, col_bounds.0..col_bounds.1]) {
|
||||
for c in self.cells.slice_mut(s![row_bounds, col_bounds]) {
|
||||
c.remove_candidate(value);
|
||||
}
|
||||
}
|
||||
@@ -82,6 +82,12 @@ impl Board {
|
||||
pub fn col_range(&self) -> std::ops::Range<usize> {
|
||||
0..REGION_SIZE
|
||||
}
|
||||
|
||||
pub fn square_iter(&self, point: &Point) -> ndarray::ArrayBase<ViewRepr<&Cell>, Dim<[usize; 2]>> {
|
||||
let row_bounds = point.row_bounds();
|
||||
let col_bounds = point.col_bounds();
|
||||
self.cells.slice(s![row_bounds, col_bounds])
|
||||
}
|
||||
|
||||
pub fn row_iter(&self, row: usize) -> ndarray::ArrayBase<ViewRepr<&Cell>, Dim<[usize; 1]>> {
|
||||
self.cells.slice(s![row, ..])
|
||||
@@ -109,17 +115,17 @@ impl Point {
|
||||
[self.row, self.col]
|
||||
}
|
||||
|
||||
fn _bounds(val: usize) -> (usize, usize) {
|
||||
fn _bounds(val: usize) -> std::ops::Range<usize> {
|
||||
let mut start = val / (SUB_REGION_SIZE as usize);
|
||||
start *= SUB_REGION_SIZE;
|
||||
(start, start + SUB_REGION_SIZE)
|
||||
std::ops::Range {start, end: start + SUB_REGION_SIZE}
|
||||
}
|
||||
|
||||
fn row_bounds(&self) -> (usize, usize) {
|
||||
fn row_bounds(&self) -> std::ops::Range<usize> {
|
||||
Self::_bounds(self.row)
|
||||
}
|
||||
|
||||
fn col_bounds(&self) -> (usize, usize) {
|
||||
fn col_bounds(&self) -> std::ops::Range<usize> {
|
||||
Self::_bounds(self.col)
|
||||
}
|
||||
}
|
||||
@@ -133,14 +139,14 @@ mod test {
|
||||
#[test]
|
||||
fn bounds_are_correct() {
|
||||
let origin = Point{ row: 0, col: 0};
|
||||
assert_eq!(origin.row_bounds(), (0, 3));
|
||||
assert_eq!(origin.col_bounds(), (0, 3));
|
||||
assert_eq!(origin.row_bounds(), 0..3);
|
||||
assert_eq!(origin.col_bounds(), 0..3);
|
||||
let one = Point{ row: 1, col: 1};
|
||||
assert_eq!(one.row_bounds(), (0, 3));
|
||||
assert_eq!(one.col_bounds(), (0, 3));
|
||||
assert_eq!(one.row_bounds(), 0..3);
|
||||
assert_eq!(one.col_bounds(), 0..3);
|
||||
let five = Point{ row: 5, col: 7};
|
||||
assert_eq!(five.row_bounds(), (3, 6));
|
||||
assert_eq!(five.col_bounds(), (6, 9));
|
||||
assert_eq!(five.row_bounds(), 3..6);
|
||||
assert_eq!(five.col_bounds(), 6..9);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -17,9 +17,15 @@ pub fn widget(cell: &Cell) -> iced::Element<Message> {
|
||||
|
||||
button(text(display))
|
||||
.style(|theme: &Theme, status| {
|
||||
// Get the current theme's palette
|
||||
let palette = theme.palette();
|
||||
|
||||
// Create a default border, since we need to set off the cells
|
||||
// TODO: Figure out how to get this out of the theme?
|
||||
let mut border = Border::default().color(LIGHT_GRAY);
|
||||
border.width = 1.0;
|
||||
|
||||
// Return a style based on the status
|
||||
match status {
|
||||
button::Status::Active => {
|
||||
button::Style{
|
||||
|
||||
Reference in New Issue
Block a user