File indexing completed on 2024-06-16 04:15:51

0001 /*
0002  * SPDX-FileCopyrightText: 2008 Cyrille Berger <cberger@cberger.net>
0003  *
0004  *  SPDX-License-Identifier: LGPL-2.0-or-later
0005  */
0006 
0007 #include "Ruler.h"
0008 
0009 Ruler::Ruler() : p1(QPointF(10, 10)), p2(QPointF(100, 190))
0010 {
0011 }
0012 
0013 Ruler::~Ruler()
0014 {
0015 }
0016 
0017 QPointF Ruler::project(const QPointF& pt)
0018 {
0019     double x1 = p1.x();
0020     double y1 = p1.y();
0021     double x2 = p2.x();
0022     double y2 = p2.y();
0023     double a1 = (y2 - y1) / (x2 - x1);
0024     double b1 = y1 - x1 * a1;
0025     double a2 = (x2 - x1) / (y1 - y2);
0026     double b2 = pt.y() - a2 * pt.x();
0027     double xm = (b2 - b1) / (a1 - a2);
0028     return QPointF(xm, xm * a1 + b1);
0029 }
0030 
0031 const QPointF& Ruler::point1() const
0032 {
0033     return p1;
0034 }
0035 
0036 const QPointF& Ruler::point2() const
0037 {
0038     return p2;
0039 }