Changeset View
Changeset View
Standalone View
Standalone View
extern/draco/draco/src/draco/compression/attributes/point_d_vector.h
- This file was moved from extern/draco/dracoenc/src/draco/compression/attributes/point_d_vector.h.
| Show All 13 Lines | |||||
| // | // | ||||
| #ifndef DRACO_COMPRESSION_ATTRIBUTES_POINT_D_VECTOR_H_ | #ifndef DRACO_COMPRESSION_ATTRIBUTES_POINT_D_VECTOR_H_ | ||||
| #define DRACO_COMPRESSION_ATTRIBUTES_POINT_D_VECTOR_H_ | #define DRACO_COMPRESSION_ATTRIBUTES_POINT_D_VECTOR_H_ | ||||
| #include <cstring> | #include <cstring> | ||||
| #include <memory> | #include <memory> | ||||
| #include <vector> | #include <vector> | ||||
| #include "draco/core/macros.h" | #include "draco/core/macros.h" | ||||
| namespace draco { | namespace draco { | ||||
| // The main class of this file is PointDVector providing an interface similar to | // The main class of this file is PointDVector providing an interface similar to | ||||
| // std::vector<PointD> for arbitrary number of dimensions (without a template | // std::vector<PointD> for arbitrary number of dimensions (without a template | ||||
| // argument). PointDVectorIterator is a random access iterator, which allows for | // argument). PointDVectorIterator is a random access iterator, which allows for | ||||
| // compatibility with existing algorithms. PseudoPointD provides for a view on | // compatibility with existing algorithms. PseudoPointD provides for a view on | ||||
| // the individual items in a contiguous block of memory, which is compatible | // the individual items in a contiguous block of memory, which is compatible | ||||
| // with the swap function and is returned by a dereference of | // with the swap function and is returned by a dereference of | ||||
| // PointDVectorIterator. Swap functions provide for compatibility/specialization | // PointDVectorIterator. Swap functions provide for compatibility/specialization | ||||
| // that allows these classes to work with currently utilized STL functions. | // that allows these classes to work with currently utilized STL functions. | ||||
| // This class allows for swap functionality from the RandomIterator | // This class allows for swap functionality from the RandomIterator | ||||
| // It seems problematic to bring this inside PointDVector due to templating. | // It seems problematic to bring this inside PointDVector due to templating. | ||||
| template <typename internal_t> | template <typename internal_t> | ||||
| class PseudoPointD { | class PseudoPointD { | ||||
| public: | public: | ||||
| PseudoPointD(internal_t *mem, internal_t dimension) | PseudoPointD(internal_t *mem, internal_t dimension) | ||||
| : mem_(mem), dimension_(dimension) {} | : mem_(mem), dimension_(dimension) {} | ||||
| // Specifically copies referenced memory | // Specifically copies referenced memory | ||||
| void swap(PseudoPointD &other) noexcept { | void swap(PseudoPointD &other) noexcept { | ||||
| for (internal_t dim = 0; dim < dimension_; dim += 1) | for (internal_t dim = 0; dim < dimension_; dim += 1) { | ||||
| std::swap(mem_[dim], other.mem_[dim]); | std::swap(mem_[dim], other.mem_[dim]); | ||||
| } | } | ||||
| } | |||||
| PseudoPointD(const PseudoPointD &other) | PseudoPointD(const PseudoPointD &other) | ||||
| : mem_(other.mem_), dimension_(other.dimension_) {} | : mem_(other.mem_), dimension_(other.dimension_) {} | ||||
| const internal_t &operator[](const size_t &n) const { | const internal_t &operator[](const size_t &n) const { | ||||
| DRACO_DCHECK_LT(n, dimension_); | DRACO_DCHECK_LT(n, dimension_); | ||||
| return mem_[n]; | return mem_[n]; | ||||
| } | } | ||||
| internal_t &operator[](const size_t &n) { | internal_t &operator[](const size_t &n) { | ||||
| DRACO_DCHECK_LT(n, dimension_); | DRACO_DCHECK_LT(n, dimension_); | ||||
| return mem_[n]; | return mem_[n]; | ||||
| } | } | ||||
| bool operator==(const PseudoPointD &other) const { | bool operator==(const PseudoPointD &other) const { | ||||
| for (auto dim = 0; dim < dimension_; dim += 1) | for (auto dim = 0; dim < dimension_; dim += 1) { | ||||
| if (mem_[dim] != other.mem_[dim]) | if (mem_[dim] != other.mem_[dim]) { | ||||
| return false; | return false; | ||||
| } | |||||
| } | |||||
| return true; | return true; | ||||
| } | } | ||||
| bool operator!=(const PseudoPointD &other) const { | bool operator!=(const PseudoPointD &other) const { | ||||
| return !this->operator==(other); | return !this->operator==(other); | ||||
| } | } | ||||
| private: | private: | ||||
| internal_t *const mem_; | internal_t *const mem_; | ||||
| ▲ Show 20 Lines • Show All 203 Lines • Show Last 20 Lines | |||||