1 // Copyright (C) 2012-2019 The VPaint Developers.
2 // See the COPYRIGHT file at the top-level directory of this distribution
3 // and at https://github.com/dalboris/vpaint/blob/master/COPYRIGHT
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 
17 #ifndef GEOMETRYUTILS_H
18 #define GEOMETRYUTILS_H
19 
20 #include <QPointF>
21 #include <cmath>
22 #include <Eigen/Core>
23 
24 class GeometryUtils
25 {
26 public:
length(QPointF p)27     static double length(QPointF p){return sqrt(p.x()*p.x()+p.y()*p.y());}
dot(QPointF p,QPointF q)28     static double dot(QPointF p, QPointF q){return p.x()*q.x()+p.y()*q.y();}
det(QPointF p,QPointF q)29     static double det(QPointF p, QPointF q){return p.x()*q.y()-p.y()*q.x();}
30     // return a value in [0..4[ bijective with [0..2Pi[
31     static double angleLike(QPointF u, QPointF v);
32     // same with v=(1,0), assumes u is unitary
33     static double angleLike(const Eigen::Vector2d & u);
34     static double angleLike(const Eigen::Vector2d & u, const Eigen::Vector2d & v);
35     static bool segmentIntersects(QPointF a, QPointF b, QPointF c, QPointF d);
36 
37 };
38 
39 
40 #endif
41