NXPCUP-libary
Library for car's control board on NXPCUP competition based on the Mbed framework.
Image.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <algorithm>
4 #include <array>
5 #include <numeric>
6 
7 namespace nxpcup {
8 
12 template <typename T, std::size_t N>
13 struct Image {
14  static constexpr std::size_t size = N;
15 
16  std::array<T, size> data;
17 
18  T& operator[](std::size_t i) { return data[i]; }
19 
20  const T& operator[](std::size_t i) const { return data[i]; }
21 
22  const T* begin() const { return data.begin(); }
23 
24  const T* end() const { return data.end(); }
25 
26  T* begin() { return data.begin(); }
27 
28  T* end() { return data.end(); }
29 
35  Image difference() const
36  {
37  std::array<T, size> res;
38  res[0] = 0;
39  for (std::size_t i = 1; i < data.size(); i++) {
40  res[i] = abs(data[i] - data[i - 1]);
41  }
42  return Image{ res };
43  }
44 };
45 
46 } // namespace nxpcup
const T * begin() const
Definition: Image.h:22
T * begin()
Definition: Image.h:26
Definition: BorderDetector.h:6
T abs(const T &v)
Definition: util.h:17
Image difference() const
Definition: Image.h:35
std::array< T, size > data
Definition: Image.h:16
T * end()
Definition: Image.h:28
const T * end() const
Definition: Image.h:24
T & operator[](std::size_t i)
Definition: Image.h:18
Definition: Image.h:13
const T & operator[](std::size_t i) const
Definition: Image.h:20
static constexpr std::size_t size
Definition: Image.h:14