Krita Source Code Documentation
Loading...
Searching...
No Matches
Ruler.cc
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2008 Cyrille Berger <cberger@cberger.net>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6
7#include "Ruler.h"
8
9Ruler::Ruler() : p1(QPointF(10, 10)), p2(QPointF(100, 190))
10{
11}
12
14{
15}
16
17QPointF Ruler::project(const QPointF& pt)
18{
19 double x1 = p1.x();
20 double y1 = p1.y();
21 double x2 = p2.x();
22 double y2 = p2.y();
23 double a1 = (y2 - y1) / (x2 - x1);
24 double b1 = y1 - x1 * a1;
25 double a2 = (x2 - x1) / (y1 - y2);
26 double b2 = pt.y() - a2 * pt.x();
27 double xm = (b2 - b1) / (a1 - a2);
28 return QPointF(xm, xm * a1 + b1);
29}
30
31const QPointF& Ruler::point1() const
32{
33 return p1;
34}
35
36const QPointF& Ruler::point2() const
37{
38 return p2;
39}
QPointF p2
QPointF p1
const QPointF & point2() const
Definition Ruler.cc:36
QPointF p2
Definition Ruler.h:28
QPointF p1
Definition Ruler.h:27
const QPointF & point1() const
Definition Ruler.cc:31
Ruler()
Definition Ruler.cc:9
QPointF project(const QPointF &)
Definition Ruler.cc:17
~Ruler()
Definition Ruler.cc:13