00001 /* 00002 This file is part of geometria. 00003 00004 geometria is free software; you can redistribute it and/or modify 00005 it under the terms of the GNU General Public License as published 00006 by the Free Software Foundation; either version 2 of the License, 00007 or (at your option) any later version. 00008 00009 geometria is distributed in the hope that it will be useful, but 00010 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 00011 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 00012 License for more details. 00013 00014 You should have received a copy of the GNU General Public 00015 License along with geometria; if not, write to the Free Software 00016 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 00017 00018 (c) Philipp Moritz, 2006 00019 */ 00020 00021 #include "line_join_algorithm.hpp" 00022 00023 #include <cmath> 00024 00025 line_join_algorithm::line_join_algorithm(boost::shared_ptr<geo_point> p, boost::shared_ptr<geo_point> q) 00026 : m_p(p), m_q(q) 00027 { 00028 m_p->register_observer(this); 00029 m_q->register_observer(this); 00030 } 00031 00032 line_join_algorithm::~line_join_algorithm() 00033 { 00034 m_p->unregister_observer(this); 00035 m_q->unregister_observer(this); 00036 } 00037 00038 line line_join_algorithm::calculate() 00039 { 00040 point p = m_p->get_point(); 00041 point q = m_q->get_point(); 00042 //y = m*x + t 00043 //m = delta_y/delta_x 00044 //t = y - m*x 00045 double delta_x = p.get_x() - q.get_x(); 00046 double delta_y = p.get_y() - q.get_y(); 00047 00048 double m = delta_y/delta_x; 00049 00050 double t = p.get_y() - m*p.get_x(); 00051 return line(m, t); 00052 }