use crate::engine::{Point, common::BitMatrix};
use super::{Direction, Value, util::opposite};
pub trait BitMatrixCursorTrait {
fn testAt(&self, p: Point) -> Value;
fn blackAt(&self, pos: Point) -> bool {
self.testAt(pos).isBlack()
}
fn isIn(&self, p: Point) -> bool; fn isInSelf(&self) -> bool; fn isBlack(&self) -> bool;
fn front(&self) -> &Point; fn back(&self) -> Point; fn left(&self) -> Point; fn right(&self) -> Point; fn direction(&self, dir: Direction) -> Point {
self.right() * Into::<i32>::into(dir)
}
fn turnBack(&mut self); fn turnLeft(&mut self); fn turnRight(&mut self); fn turn(&mut self, dir: Direction);
fn edgeAt_point(&self, d: Point) -> Value;
fn edgeAtFront(&self) -> Value {
self.edgeAt_point(*self.front())
}
fn edgeAtBack(&self) -> Value {
self.edgeAt_point(self.back())
}
fn edgeAtLeft(&self) -> Value {
self.edgeAt_point(self.left())
}
fn edgeAtRight(&self) -> Value {
self.edgeAt_point(self.right())
}
fn edgeAt_direction(&self, dir: Direction) -> Value {
self.edgeAt_point(self.direction(dir))
}
fn setDirection(&mut self, dir: Point);
fn step(&mut self, s: Option<f32>) -> bool;
fn turnedBack(&self) -> Self;
fn stepToEdge(&mut self, nth: Option<i32>, range: Option<i32>, backup: Option<bool>) -> i32;
fn stepAlongEdge(&mut self, dir: Direction, skipCorner: Option<bool>) -> bool
{
let skipCorner = skipCorner.unwrap_or_default();
if !self.edgeAt_direction(dir).isValid() {
self.turn(dir);
} else if self.edgeAtFront().isValid() {
self.turn(opposite(dir));
if self.edgeAtFront().isValid() {
self.turn(opposite(dir));
if self.edgeAtFront().isValid() {
return false;
}
}
}
let mut ret = self.step(None);
if ret && skipCorner && !self.edgeAt_direction(dir).isValid() {
self.turn(dir);
ret = self.step(None);
}
ret
}
fn p(&self) -> Point;
fn d(&self) -> Point;
fn img(&self) -> &BitMatrix;
}