AliceVision
Photogrammetric Computer Vision Framework
Point2d.hpp
1 // This file is part of the AliceVision project.
2 // Copyright (c) 2017 AliceVision contributors.
3 // This Source Code Form is subject to the terms of the Mozilla Public License,
4 // v. 2.0. If a copy of the MPL was not distributed with this file,
5 // You can obtain one at https://mozilla.org/MPL/2.0/.
6 
7 #pragma once
8 
9 #include <cmath>
10 #include <ostream>
11 
12 namespace aliceVision {
13 
14 class Point2d
15 {
16  public:
17  union
18  {
19  struct
20  {
21  double x, y;
22  };
23  double m[2];
24  };
25 
26  inline Point2d()
27  {
28  x = 0.0;
29  y = 0.0;
30  }
31 
32  inline Point2d(const double _x, const double _y)
33  {
34  x = _x;
35  y = _y;
36  }
37 
38  inline Point2d(const int _x, const int _y)
39  {
40  x = (double)_x;
41  y = (double)_y;
42  }
43 
44  inline Point2d& operator=(const Point2d& param)
45  {
46  x = param.x;
47  y = param.y;
48  return *this;
49  }
50 
51  inline Point2d operator-(const Point2d& _p) const { return Point2d(x - _p.x, y - _p.y); }
52 
53  inline Point2d operator+(const Point2d& _p) const { return Point2d(x + _p.x, y + _p.y); }
54 
55  inline Point2d operator*(const double d) const { return Point2d(x * d, y * d); }
56 
57  inline Point2d operator+(const double d) const { return Point2d(x + d, y + d); }
58 
59  inline Point2d operator/(const double d) const { return Point2d(x / d, y / d); }
60 
61  inline Point2d normalize() const
62  {
63  double d = std::sqrt(x * x + y * y);
64  return Point2d(x / d, y / d);
65  }
66 
67  inline double size() const { return std::sqrt(x * x + y * y); }
68 
69  friend double dot(const Point2d& p1, const Point2d& p2);
70 };
71 
72 inline double dot(const Point2d& p1, const Point2d& p2) { return p1.x * p2.x + p1.y * p2.y; }
73 
74 inline std::ostream& operator<<(std::ostream& stream, const Point2d& p)
75 {
76  stream << p.x << "," << p.y;
77  return stream;
78 }
79 
80 } // namespace aliceVision
aliceVision
Definition: checkerDetector.cpp:32
aliceVision::Point2d
Definition: Point2d.hpp:14