MRaster lib 21.0.0.0
Image Processing Library
Loading...
Searching...
No Matches
MRpoint2d.hpp
Go to the documentation of this file.
1// -*- Mode:C++; Coding:us-ascii-unix; fill-column:158 -*-
2/*******************************************************************************************************************************************************.H.S.**/
3/**
4 @file MRpoint2d.hpp
5 @author Mitch Richling <https://www.mitchr.me>
6 @brief Internal include file for ramCanvas types.@EOL
7 @copyright
8 @parblock
9 Copyright (c) 1988-2015, Mitchell Jay Richling <https://www.mitchr.me> All rights reserved.
10
11 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
12
13 1. Redistributions of source code must retain the above copyright notice, this list of conditions, and the following disclaimer.
14
15 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions, and the following disclaimer in the documentation
16 and/or other materials provided with the distribution.
17
18 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software
19 without specific prior written permission.
20
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
26 DAMAGE.
27 @endparblock
28*/
29/*******************************************************************************************************************************************************.H.E.**/
30
31#ifndef MJR_INCLUDE_MRpoint2d
32
33#include <iomanip> /* C++ stream formatting C++11 */
34#include <iostream> /* C++ iostream C++11 */
35
36#include <type_traits> /* C++ metaprogramming C++11 */
37#include <complex> /* Complex Numbers C++11 */
38#include <vector> /* STL vector C++11 */
39#include <tuple> /* STL tuples C++11 */
40
41// Put everything in the mjr namespace
42namespace mjr {
43 /** Handy class to hold a point in 2D (integer or real) */
44 template <class coordT>
45 requires (std::is_arithmetic<coordT>::value)
46 class point2d {
47 public:
48 coordT x; //!< X coordinate
49 coordT y; //!< Y coordinate
50
51 /** @name Constructors */
52 //@{
53 /** Default constructor. */
54 point2d() = default;
55 /** Construct from an initializer_list. */
56 point2d(std::initializer_list<coordT> iList) { auto p=iList.begin(); x=*p; y=*(++p); }
57 /** Construct from a point2d object -- copy constructor. */
58 point2d(const point2d &aPoint) { x=aPoint.x; y=aPoint.y; }
59 /** Construct from coordinates. */
60 point2d(coordT newX, coordT newY) { x=newX; y=newY; }
61 /** Construct from a complex number. */
62 point2d(std::complex<coordT> aComplex) { x=aComplex.real(); y=aComplex.imag(); }
63 /** Construct from a tuple. */
64 point2d(std::tuple<coordT, coordT> aTuple) { x=std::get<0>(aTuple); y=std::get<1>(aTuple); }
65 /** Construct from a vector. */
66 point2d(std::vector<coordT> aVector) { x=aVector[0]; y=aVector[1]; }
67 /** Construct from a C-style array. */
68 point2d(coordT* aPtr) { x=aPtr[0]; y=aPtr[1]; }
69
70 /** @name Conversion Operators */
71 //@{
72 /** COnvert to a complex number. */
73 operator std::complex<coordT>() { return std::complex<coordT>(x, y); }
74 //@}
75
76 ~point2d() = default;
77 }; // end point2d
78} // end namespace mjr
79
80#define MJR_INCLUDE_MRpoint2d
81#endif
Handy class to hold a point in 2D (integer or real)
Definition MRpoint2d.hpp:46
point2d(std::complex< coordT > aComplex)
Construct from a complex number.
Definition MRpoint2d.hpp:62
coordT x
X coordinate.
Definition MRpoint2d.hpp:48
point2d(std::initializer_list< coordT > iList)
Construct from an initializer_list.
Definition MRpoint2d.hpp:56
point2d(coordT *aPtr)
Construct from a C-style array.
Definition MRpoint2d.hpp:68
point2d(std::tuple< coordT, coordT > aTuple)
Construct from a tuple.
Definition MRpoint2d.hpp:64
point2d()=default
Default constructor.
point2d(std::vector< coordT > aVector)
Construct from a vector.
Definition MRpoint2d.hpp:66
point2d(const point2d &aPoint)
Construct from a point2d object – copy constructor.
Definition MRpoint2d.hpp:58
point2d(coordT newX, coordT newY)
Construct from coordinates.
Definition MRpoint2d.hpp:60
~point2d()=default
coordT y
Y coordinate.
Definition MRpoint2d.hpp:49