MinGfx Toolkit  1.0
A minimal library for writing cross-platform (Windows, OSX, linux) graphics programs.
point2.h
Go to the documentation of this file.
1 /*
2  This file is part of the MinGfx Project.
3 
4  Copyright (c) 2017,2018 Regents of the University of Minnesota.
5  All Rights Reserved.
6 
7  Original Author(s) of this File:
8  Dan Keefe, 2018, University of Minnesota
9 
10  Author(s) of Significant Updates/Modifications to the File:
11  ...
12  */
13 
14 #ifndef SRC_POINT2_H_
15 #define SRC_POINT2_H_
16 
17 #include <iostream>
18 
19 namespace mingfx {
20 
22 #define MINGFX_MATH_EPSILON 1e-8
23 
24 
28 class Point2 {
29 public:
31  Point2();
32 
35  Point2(float x, float y);
36 
38  Point2(float *p);
39 
41  Point2(const Point2& p);
42 
44  virtual ~Point2();
45 
47  bool operator==(const Point2& p) const;
48 
50  bool operator!=(const Point2& p) const;
51 
53  Point2& operator=(const Point2& p);
54 
56  float operator[](const int i) const;
57 
65  float& operator[](const int i);
66 
69  float x() const { return p[0]; }
70 
73  float y() const { return p[1]; }
74 
76  float w() const { return 1.0; }
77 
78 
80  const float * value_ptr() const;
81 
85  Point2 Lerp(const Point2 &b, float alpha) const;
86 
87 
89  static const Point2& Origin();
90 
92  static const Point2& Zero();
93 
95  static const Point2& One();
96 
99  static Point2 Lerp(const Point2 &a, const Point2 &b, float alpha);
100 
101 private:
102  float p[2];
103 };
104 
105 
106 std::ostream & operator<< ( std::ostream &os, const Point2 &p);
107 std::istream & operator>> ( std::istream &is, Point2 &p);
108 
109 
110 } // namespace
111 
112 #endif
A 2D Point with floating point coordinates, used for storing 2D texture coordinates,...
Definition: point2.h:28
const float * value_ptr() const
Returns a const pointer to the raw data array.
static const Point2 & Origin()
(0,0) - a shortcut for a special point that is frequently needed
Point2()
Default point at the origin.
static const Point2 & One()
(1,1) - a shortcut for a special point that is frequently needed
Point2(float *p)
Constructs a point given a pointer to x,y data.
float y() const
Read only access to the y coordinate. Can also use my_point[1]. Use the my_point[1] = 1....
Definition: point2.h:73
float & operator[](const int i)
Returns a reference to the ith coordinate of the point. Use this accessor if you wish to set the coor...
bool operator!=(const Point2 &p) const
Check for "inequality", taking floating point imprecision into account.
static const Point2 & Zero()
(0,0) - a shortcut for a special point that is frequently needed
static Point2 Lerp(const Point2 &a, const Point2 &b, float alpha)
Linear interpolation between two points. Alpha=0.0 returns 'a' and alpha=1.0 returns 'b',...
Point2(float x, float y)
Constructs a point given (x,y,1), where the 1 comes from the use of homogeneous coordinates in comput...
virtual ~Point2()
Point destructor.
Point2 Lerp(const Point2 &b, float alpha) const
Linear interpolation between this point and another. Alpha=0.0 returns this point,...
float x() const
Read only access to the x coordinate. Can also use my_point[0]. Use the my_point[0] = 1....
Definition: point2.h:69
Point2(const Point2 &p)
Copy constructor for point.
float w() const
In homogeneous coordinates, the w coordinate for all points is 1.0.
Definition: point2.h:76
bool operator==(const Point2 &p) const
Check for "equality", taking floating point imprecision into account.
float operator[](const int i) const
Read only access to the ith coordinate of the point.
Point2 & operator=(const Point2 &p)
Assignment operator.
Namespace for the MinGfx Toolkit.
Definition: aabb.h:21
std::ostream & operator<<(std::ostream &os, const Color &c)
std::istream & operator>>(std::istream &is, Color &c)