Пример #1
0
// worker methods
bool Pattern::operator==(const Pattern & obj) const {
	bool match = true;
	if (&obj == 0) {
		std::cout << "Pattern::operator ==: obj is null" << std::endl;
		return false;
	}

	match = match && (this->getPattern() == obj.getPattern());
	if (match == false) {
		std::cout << "Pattern::equals: vector mismatch" << std::endl;
		return false;
	}
	return true;
}
Пример #2
0
double Pattern::compare(const Pattern & obj) const {

	const std::vector<bool> this_pat = this->getPattern();
	const std::vector<bool> obj_pat = obj.getPattern();
	int this_sz = this_pat.size();
	int obj_sz = obj_pat.size();

#ifdef PATTERN_DEBUG // DEBUG
	std::cout << "Pattern::compare: this: ";
	common::Misc::print(std::cout, this_pat);
	std::cout << std::endl;
	std::cout << "Pattern::compare: obj: ";
	common::Misc::print(std::cout, obj_pat);
	std::cout << std::endl;
#endif // DEBUG
	if (this_sz == 0) {
		std::cout << "Pattern::compare: this zero pattern mismatch" << std::endl;
		return 0;
	} else {
		if (obj_sz == 0) {
			std::cout << "Pattern::compare: obj zero pattern mismatch" << std::endl;
			return 0;
		}
	}
	if (this_sz != obj_sz) {

		std::cout << "Pattern::compare: size mismatch " << std::endl;
		return 0;
	}
	double fraction = static_cast<double>(1) / static_cast<double>(this_sz);
	double match = 0;

	std::vector<bool>::const_iterator it_this_vec = this_pat.begin();
	const std::vector<bool>::const_iterator it_this_vec_end = this_pat.end();
	std::vector<bool>::const_iterator it_obj_vec = obj_pat.begin();
	const std::vector<bool>::const_iterator it_obj_vec_end = obj_pat.end();

	while (it_this_vec != it_this_vec_end && it_obj_vec != it_obj_vec_end) {
		if (*it_this_vec == *it_obj_vec) {
			match += fraction;
		}
		++it_this_vec;
		++it_obj_vec;
	}
#ifdef PATTERN_DEBUG // DEBUG
	std::cout << "Pattern::compare: match: " << match << std::endl;
#endif // DEBUG
	return match;

}
Пример #3
0
	void pastePattern(int x, int y, bool isReverse, Pattern const & pattern)
	{
		if ((0 <= x) && ((x + pattern.getWidth()) < CELL_LENGTH_1) && (0 <= y) && ((y + pattern.getHeight()) < CELL_LENGTH_0))
		{
			int i = 0;
			for (auto const & row : *pattern.getPattern())
			{
				int j = 0;
				for (auto const e : row)
				{
					if (isReverse)
					{
						(*cell)[y + j][x + i] = !e;
					}
					else
					{
						(*cell)[y + j][x + i] = e;
					}
					++j;
				}
				++i;
			}
		}
	}