/* -*- C++ -*- * Copyright ©2004 Hugo Mills * * This software is distributed under the terms of the GNU GPL v3 * For more information on the GPL, see the file COPYING or * visit http://www.gnu.org/ * * This software is distributed without warranty */ #include "crossing.h" bool Crossing::operator==(const Crossing& c) const { if(_isc != c._isc) return false; if(_isc) return _pos == c._pos; else { Crossing tmp = c.opp(); return (_pos == c._pos && _d == c._d) || (_pos == tmp._pos && _d == tmp._d); } } std::ostream& operator<<(std::ostream& o, const Crossing& c) { o << c.pos(); if(!c._isc) o << " " << c._d; return o; } Crossing operator+(const Crossing& c, const Diff& d) { if(d.isc()) return Crossing(c._pos.x + d.x(), c._pos.y + d.y()); else return Crossing(c._pos.x + d.x(), c._pos.y + d.y(), d.d()); } const Diff offset_opp[4] = { Diff(-1, 0, 2), Diff(0, -1, 3), Diff(1, 0, 0), Diff(0, 1, 1) }; Crossing Crossing::opp(void) const { if(_isc) return *this; else return *this + offset_opp[_d]; } const Diff endpos_offset[] = { Diff(-1, 0), Diff(0, -1), Diff(1, 0), Diff(0, 1) }; iCoordinate Crossing::end(void) const { if(_isc) return _pos; else { Crossing tmp = _pos + endpos_offset[_d]; return tmp.pos(); } }