Mass++ Common Libraries v2.7.5
 All Classes Namespaces Files Functions Variables Enumerations Macros
PointArray.cpp
Go to the documentation of this file.
1 
12 #include "stdafx.h"
13 #include "PointArray.h"
14 
15 
16 using namespace kome::core;
17 
18 
19 #include <crtdbg.h>
20 #ifdef _DEBUG
21  #define new new( _NORMAL_BLOCK, __FILE__, __LINE__ )
22  #define malloc( s ) _malloc_dbg( s, _NORMAL_BLOCK, __FILE__, __LINE__ )
23 #endif // _DEBUG
24 
25 
26 
27 // constructor
29 }
30 
31 // destructor
33 }
34 
35 // sort by x
36 void PointArray::sortByX( const bool desc ) {
37  // check the array size
38  if( m_points.size() <= 1 ) {
39  return;
40  }
41 
42  // sort
43  std::sort(
44  m_points.begin(),
45  m_points.end(),
47  );
48 }
49 
50 // sort by y
51 void PointArray::sortByY( const bool desc ) {
52  // check the array size
53  if( m_points.size() <= 1 ) {
54  return;
55  }
56 
57  // sort
58  std::sort(
59  m_points.begin(),
60  m_points.end(),
62  );
63 }
64 
65 // on clear points
67  m_points.clear();
68 }
69 
70 // on add point
71 void PointArray::onAddPoint( const double x, const double y ) {
72  Point< double > pt( x, y );
73  m_points.push_back( pt );
74 }
75 
76 // on insert point
77 void PointArray::onInsertPoint( const unsigned int index, const double x, const double y ) {
78  // check the parameter
79  if( index >= m_points.size() ) {
80  onAddPoint( x, y );
81  return;
82  }
83 
84  // position
85  std::vector< Point< double > >::iterator it = m_points.begin() + index;
86 
87  // insert
88  Point< double > pt( x, y );
89  m_points.insert( it, pt );
90 }
91 
92 // delete point
93 void PointArray::onDeletePoint( const unsigned int index ) {
94  // check the parameter
95  if( index >= m_points.size() ) {
96  return;
97  }
98 
99  // delete
100  std::vector< Point< double > >::iterator it = m_points.begin() + index;
101  m_points.erase( it );
102 }
103 
104 // on get length
105 unsigned int PointArray::onGetLength() {
106  return m_points.size();
107 }
108 
109 // on get x
110 double PointArray::onGetX( const unsigned int index ) {
111  return m_points[ index ].px;
112 }
113 
114 // on get y
115 double PointArray::onGetY( const unsigned int index ) {
116  return m_points[ index ].py;
117 }
118 
119 // on reserve
120 void PointArray::onReserve( const unsigned int num ) {
121  if( num > 0 ) {
122  m_points.reserve( num );
123  }
124 }
virtual double onGetY(const unsigned int index)
This method is called by getY method. (override method)
Definition: PointArray.cpp:115
virtual double onGetX(const unsigned int index)
This method is called by getX method. (override method)
Definition: PointArray.cpp:110
virtual void onDeletePoint(const unsigned int index)
This method is called by deletePoint method. (override method)
Definition: PointArray.cpp:93
void sortByY(const bool desc)
sorts peaks by y
Definition: PointArray.cpp:51
virtual void onInsertPoint(const unsigned int index, const double x, const double y)
This method is called by insertPoint method. (override method)
Definition: PointArray.cpp:77
void sortByX(const bool desc)
sorts peaks by x
Definition: PointArray.cpp:36
virtual void onClearPoints()
This method is called by clearPoints method. (override method)
Definition: PointArray.cpp:66
std::vector< Point< double > > m_points
Definition: PointArray.h:45
virtual void onAddPoint(const double x, const double y)
This method is called by addPoint method. (override method)
Definition: PointArray.cpp:71
virtual void onReserve(const unsigned int num)
This method is called by reserve method. (override method)
Definition: PointArray.cpp:120
interfaces of PointArray class
PointArray()
constructor
Definition: PointArray.cpp:28
virtual ~PointArray()
destructor
Definition: PointArray.cpp:32
2 dimensional point information management class
Definition: Point.h:21
virtual unsigned int onGetLength()
this method is called by getLength method (override method)
Definition: PointArray.cpp:105