Points&Forces (core)
Software tools facilitating the task of surveying architecture
a_point2.h
Go to the documentation of this file.
1 /*
2 Copyright 2010-2019 Pierre SMARS (smars@yuntech.edu.tw)
3 This program is free software: you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation, either version 2 of the License, or
6 (at your option) any later version.
7 
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12 
13 You should have received a copy of the GNU General Public License
14 along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16 #ifndef _A_POINT2_H_
17 #define _A_POINT2_H_
18 
19 #include <iostream>
20 #include <stdlib.h>
21 #include "a_geom_base.h"
22 
30 class a_point2;
31 
32 a_point2 operator+(const a_point2& a, const a_point2& b);
33 a_point2 operator-(const a_point2& a, const a_point2& b);
34 double operator*(const a_point2& a, const a_point2& b);
35 a_point2 operator*(const double v, const a_point2& a);
36 a_point2 operator*(const a_point2& a, double v);
37 a_point2 operator/(const a_point2& a, double v);
38 
39 class a_point2 : public a_geom_base
40 {
41 public:
42  a_point2() : x_(0), y_(0) {};
43  a_point2(double x, double y) : x_(x), y_(y) {}
44  a_point2(const float x[2]) : x_(x[0]), y_(x[1]) {}
45  a_point2(const double x[2]) : x_(x[0]), y_(x[1]) {}
46  a_point2(const a_point2& p) {x_ = p.x_; y_ = p.y_;}
47 
48  virtual const std::string classname() { return "a_point2";}
49  static const std::string help();
50 
51  //: get coordinates
52  inline double x() const { return x_; }
53  inline double y() const { return y_; }
54  inline double operator[](const int i) const {if (i==0) return x_; if (i==1) return y_; exit(1); return x_;}
55 
56  //: set coordinates
57  inline void x(double v) { x_ = v; }
58  inline void y(double v) { y_ = v; }
59  inline void set(double x, double y) {x_ = x; y_ = y;}
60  inline void set(double x[2]) {x_ = x[0]; y_ = x[1];}
61  inline void set(float x[2]) {x_ = x[0]; y_ = x[1];}
62  inline a_point2& translate(double x, double y) {x_ += x; y_ += y; return *this;}
63  a_point2& rotate(const double angle);
64  inline double& operator[](const int i) {if (i==0) return x_; if (i==1) return y_; exit(1); return x_;}
65 
66  bool operator==(const a_point2& p);
67  a_point2& operator=(const a_point2& p);
69  a_point2& operator+=(const a_point2&);
70  a_point2& operator-=(const a_point2&);
71  double operator*=(const a_point2&);
72  a_point2& operator*=(double v);
73  a_point2& operator/=(double v);
74 
76  double sumsq() const;
77  double norm() const;
78  inline double dist(const a_point2& p) const {return (p-*this).norm();}
80 
81  //: input/output
82  virtual void read(std::istream &i);
83  virtual void write(std::ostream &o) const;
84 
85 protected:
86  double x_;
87  double y_;
88 };
89 
90 inline double dist(const a_point2& a, const a_point2& b) {return (a-b).norm();}
91 double angle(const a_point2& a, const a_point2& b);
92 inline a_point2 average(const a_point2& a, const a_point2& b, double f = 0.5) {return (a+f*(b-a));}
93 a_point2 average_rot(const a_point2& a, const a_point2& b, double f = 0.5);
94 
95 #endif
double angle(const a_point2 &a, const a_point2 &b)
Definition: a_point2.cxx:160
a_point2 average_rot(const a_point2 &a, const a_point2 &b, double f=0.5)
Definition: a_point2.cxx:167
a_point2 operator+(const a_point2 &a, const a_point2 &b)
Definition: a_point2.cxx:106
double operator*(const a_point2 &a, const a_point2 &b)
Definition: a_point2.cxx:118
a_point2 operator/(const a_point2 &a, double v)
Definition: a_point2.cxx:136
a_point2 operator-(const a_point2 &a, const a_point2 &b)
Definition: a_point2.cxx:112
double dist(const a_point2 &a, const a_point2 &b)
Definition: a_point2.h:90
a_point2 average(const a_point2 &a, const a_point2 &b, double f=0.5)
Definition: a_point2.h:92
a_point2 & translate(double x, double y)
Definition: a_point2.h:62
double y() const
Definition: a_point2.h:53
double operator[](const int i) const
Definition: a_point2.h:54
a_point2 & operator-=(const a_point2 &)
Definition: a_point2.cxx:42
static const std::string help()
Definition: a_point2.cxx:22
void set(float x[2])
Definition: a_point2.h:61
double norm() const
Definition: a_point2.cxx:85
a_point2 & normalise()
Definition: a_point2.cxx:90
a_point2 & operator+=(const a_point2 &)
Definition: a_point2.cxx:35
double operator*=(const a_point2 &)
Definition: a_point2.cxx:49
void y(double v)
Definition: a_point2.h:58
a_point2(const double x[2])
Definition: a_point2.h:45
a_point2 & operator=(const a_point2 &p)
Definition: a_point2.cxx:59
virtual void write(std::ostream &o) const
Definition: a_point2.cxx:154
virtual const std::string classname()
Definition: a_point2.h:48
double dist(const a_point2 &p) const
Definition: a_point2.h:78
void set(double x[2])
Definition: a_point2.h:60
double sumsq() const
Definition: a_point2.cxx:80
a_point2 & operator/=(const a_point2 &)
virtual void read(std::istream &i)
Definition: a_point2.cxx:148
a_point2 & operator-()
Definition: a_point2.cxx:28
a_point2(const a_point2 &p)
Definition: a_point2.h:46
a_point2 & rotate(const double angle)
Definition: a_point2.cxx:97
double x_
Definition: a_point2.h:86
a_point2(const float x[2])
Definition: a_point2.h:44
bool operator==(const a_point2 &p)
Definition: a_point2.cxx:54
void set(double x, double y)
Definition: a_point2.h:59
a_point2(double x, double y)
Definition: a_point2.h:43
double & operator[](const int i)
Definition: a_point2.h:64
double x() const
Definition: a_point2.h:52
a_point2()
Definition: a_point2.h:42
double y_
Definition: a_point2.h:87
a_point2 & operator/=(double v)
Definition: a_point2.cxx:73
void x(double v)
Definition: a_point2.h:57