File indexing completed on 2024-12-08 05:08:33
0001 /*************************************************************************** 0002 * Copyright (C) 2003-2006 by David Saxton * 0003 * david@bluehaze.org * 0004 * * 0005 * This program is free software; you can redistribute it and/or modify * 0006 * it under the terms of the GNU General Public License as published by * 0007 * the Free Software Foundation; either version 2 of the License, or * 0008 * (at your option) any later version. * 0009 ***************************************************************************/ 0010 0011 #include "cells.h" 0012 #include "utils.h" 0013 0014 // BEGIN class Cells 0015 Cells::Cells(const QRect &canvasRect) 0016 { 0017 init(canvasRect); 0018 } 0019 0020 Cells::~Cells() 0021 { 0022 unsigned w = unsigned(m_cellsRect.width()); 0023 for (uint i = 0; i < w; i++) 0024 delete[] m_cells[i]; 0025 delete[] m_cells; 0026 } 0027 0028 Cells::Cells(const Cells &c) 0029 { 0030 init(QRect(c.cellsRect().topLeft() * 8, c.cellsRect().size() * 8)); 0031 0032 unsigned w = unsigned(m_cellsRect.width()); 0033 unsigned h = unsigned(m_cellsRect.height()); 0034 0035 for (uint i = 0; i < w; i++) { 0036 for (uint j = 0; j < h; j++) { 0037 m_cells[i][j] = c.cell(i, j); 0038 } 0039 } 0040 } 0041 0042 void Cells::init(const QRect &canvasRect) 0043 { 0044 m_cellsRect = QRect(roundDown(canvasRect.topLeft(), 8), canvasRect.size() / 8); 0045 m_cellsRect = m_cellsRect.normalized(); 0046 0047 unsigned w = unsigned(m_cellsRect.width()); 0048 unsigned h = unsigned(m_cellsRect.height()); 0049 0050 typedef Cell *cellptr; 0051 m_cells = new cellptr[w]; 0052 for (uint i = 0; i < w; ++i) { 0053 m_cells[i] = new Cell[h]; 0054 } 0055 } 0056 0057 void Cells::reset() 0058 { 0059 unsigned w = unsigned(m_cellsRect.width()); 0060 unsigned h = unsigned(m_cellsRect.height()); 0061 0062 for (uint i = 0; i < w; i++) { 0063 for (uint j = 0; j < h; j++) 0064 m_cells[i][j].reset(); 0065 } 0066 } 0067 // END class Cells 0068 0069 // BEGIN class Point 0070 Point::Point() 0071 { 0072 x = y = prevX = prevY = startCellPos; 0073 } 0074 // END class Point 0075 0076 // BEGIN class Cell 0077 Cell::Cell() 0078 { 0079 addedToLabels = false; 0080 permanent = false; 0081 CIpenalty = 0; 0082 numCon = 0; 0083 Cpenalty = 0; 0084 bestScore = 0xffff; // Nice large value 0085 } 0086 0087 void Cell::reset() 0088 { 0089 addedToLabels = false; 0090 permanent = false; 0091 bestScore = 0xffff; // Nice large value 0092 } 0093 // END class Cell