code format
This commit is contained in:
@@ -11,8 +11,7 @@ BlockViewWavetrace::BlockViewWavetrace(int width, int height) {
|
||||
void BlockViewWavetrace::resize(int width, int height) {
|
||||
wid = width;
|
||||
hei = height;
|
||||
if (field.size() != wid)
|
||||
field.resize(wid);
|
||||
if (field.size() != wid) field.resize(wid);
|
||||
for (int i = 0; i < wid; ++i) {
|
||||
if (field[i].size() != hei) {
|
||||
field[i].resize(hei);
|
||||
@@ -41,8 +40,7 @@ void BlockViewWavetrace::fill(const QRect & rect, short val) {
|
||||
|
||||
void BlockViewWavetrace::fill(int px, int py, short val) {
|
||||
short p = field[px][py].value;
|
||||
if ((val == HorizontalBus && p == VerticalBus ) ||
|
||||
(val == VerticalBus && p == HorizontalBus))
|
||||
if ((val == HorizontalBus && p == VerticalBus) || (val == VerticalBus && p == HorizontalBus))
|
||||
field[px][py].value = Blocked;
|
||||
else
|
||||
field[px][py].value = val;
|
||||
@@ -54,14 +52,13 @@ bool BlockViewWavetrace::trace(const QPoint & start, const QPoint & finish) {
|
||||
st = start;
|
||||
fn = finish;
|
||||
if (dir_ == NoTrace) return true;
|
||||
//qDebug() << "trace" << start << finish;
|
||||
// qDebug() << "trace" << start << finish;
|
||||
short cl = 0;
|
||||
QRect frect(0, 0, wid - 1, hei - 1);
|
||||
QVector<QPoint> cpnts, npnts;
|
||||
fill(st, cl);
|
||||
cpnts.push_back(st);
|
||||
if (field[fn.x()][fn.y()].value == (short)Blocked)
|
||||
return false;
|
||||
if (field[fn.x()][fn.y()].value == (short)Blocked) return false;
|
||||
auto checkAndFill = [this, &npnts, &frect](int x, int y, short acc_dir, short c) {
|
||||
if (!frect.contains(x, y)) return;
|
||||
short p = field[x][y].value;
|
||||
@@ -73,18 +70,16 @@ bool BlockViewWavetrace::trace(const QPoint & start, const QPoint & finish) {
|
||||
while (cpnts.size() > 0) {
|
||||
npnts.clear();
|
||||
cl++;
|
||||
if (cl >= max_steps)
|
||||
return false;
|
||||
if (cl >= max_steps) return false;
|
||||
for (int i = 0; i < cpnts.size(); ++i) {
|
||||
if (cpnts[i] == fn)
|
||||
return true;
|
||||
checkAndFill(cpnts[i].x() - 1, cpnts[i].y() , (short)VerticalBus , cl);
|
||||
checkAndFill(cpnts[i].x() + 1, cpnts[i].y() , (short)VerticalBus , cl);
|
||||
checkAndFill(cpnts[i].x() , cpnts[i].y() - 1, (short)HorizontalBus, cl);
|
||||
checkAndFill(cpnts[i].x() , cpnts[i].y() + 1, (short)HorizontalBus, cl);
|
||||
if (cpnts[i] == fn) return true;
|
||||
checkAndFill(cpnts[i].x() - 1, cpnts[i].y(), (short)VerticalBus, cl);
|
||||
checkAndFill(cpnts[i].x() + 1, cpnts[i].y(), (short)VerticalBus, cl);
|
||||
checkAndFill(cpnts[i].x(), cpnts[i].y() - 1, (short)HorizontalBus, cl);
|
||||
checkAndFill(cpnts[i].x(), cpnts[i].y() + 1, (short)HorizontalBus, cl);
|
||||
}
|
||||
cpnts = npnts;
|
||||
//qDebug() << cl << ": " << cpnts.size();
|
||||
// qDebug() << cl << ": " << cpnts.size();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -99,25 +94,22 @@ void BlockViewWavetrace::gatherPath() {
|
||||
}
|
||||
int pa = -1, ca = -1;
|
||||
bool first = true;
|
||||
short cl = field[fn.x()][fn.y()].value;
|
||||
short cl = field[fn.x()][fn.y()].value;
|
||||
QRect frect(0, 0, wid, hei);
|
||||
QPoint cpnt = fn;
|
||||
auto checkAndStep = [this, &cpnt, &first, &frect] (int dir, short c, int & ca_, int pa_)->bool {
|
||||
QPoint cpnt = fn;
|
||||
auto checkAndStep = [this, &cpnt, &first, &frect](int dir, short c, int & ca_, int pa_) -> bool {
|
||||
int cx = cpnt.x() + dps[dir].x();
|
||||
int cy = cpnt.y() + dps[dir].y();
|
||||
if (frect.contains(cx, cy)) {
|
||||
const Cell & cell(field[cx][cy]);
|
||||
if (cell.value == c) {
|
||||
if (cell.direction == HorizontalBus || cell.direction == VerticalBus) {
|
||||
if (dps[dir].x() == 0 && cell.direction == VerticalBus)
|
||||
return false;
|
||||
if (dps[dir].y() == 0 && cell.direction == HorizontalBus)
|
||||
return false;
|
||||
if (dps[dir].x() == 0 && cell.direction == VerticalBus) return false;
|
||||
if (dps[dir].y() == 0 && cell.direction == HorizontalBus) return false;
|
||||
}
|
||||
ca_ = QLineF(QPointF(cx, cy), cpnt).angle();
|
||||
if (ca_ != pa_ && !first)
|
||||
path_.push_front(cpnt);
|
||||
cpnt = QPoint(cx, cy);
|
||||
if (ca_ != pa_ && !first) path_.push_front(cpnt);
|
||||
cpnt = QPoint(cx, cy);
|
||||
first = false;
|
||||
return true;
|
||||
}
|
||||
@@ -132,7 +124,6 @@ void BlockViewWavetrace::gatherPath() {
|
||||
if (checkAndStep(1, cl, ca, pa)) continue;
|
||||
if (checkAndStep(2, cl, ca, pa)) continue;
|
||||
if (checkAndStep(3, cl, ca, pa)) continue;
|
||||
|
||||
}
|
||||
path_.push_front(st);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user