Skip to content

Commit

Permalink
eckit::geometry
Browse files Browse the repository at this point in the history
  • Loading branch information
pmaciel committed Aug 11, 2023
1 parent eb3d84f commit e89f813
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 151 deletions.
2 changes: 0 additions & 2 deletions src/eckit/geometry/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ list( APPEND eckit_geometry_srcs
iterator/Reduced.h
iterator/Regular.cc
iterator/Regular.h
iterator/Unstructured.cc
iterator/Unstructured.h
polygon/LonLatPolygon.cc
polygon/LonLatPolygon.h
polygon/Polygon.cc
Expand Down
27 changes: 25 additions & 2 deletions src/eckit/geometry/Grid.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,31 @@ class Grid {
public:
// -- Types

using iterator = std::unique_ptr<Iterator>;
using const_iterator = std::unique_ptr<const Iterator>;
struct Iterator final : std::unique_ptr<geometry::Iterator> {
explicit Iterator(geometry::Iterator* it) :
unique_ptr(it) { ASSERT(operator bool()); }

Iterator(const Iterator&) = delete;
Iterator(Iterator&&) = delete;

~Iterator() = default;

void operator=(const Iterator&) = delete;
void operator=(Iterator&&) = delete;

bool operator!=(const Iterator& other) { return get()->operator!=(*(other.get())); }
bool operator++() { return get()->operator++(); }
bool operator--() { return get()->operator--(); }

explicit operator bool() { return get()->operator bool(); }
Point& operator*() { return get()->operator*(); }

size_t size() const { return get()->size(); }
size_t index() const { return get()->index(); }
};

using iterator = Iterator;
using const_iterator = const Iterator;

// -- Exceptions
// None
Expand Down
6 changes: 4 additions & 2 deletions src/eckit/geometry/Iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ class Iterator {

virtual bool operator!=(const Iterator&) = 0;
virtual bool operator++() = 0;
virtual explicit operator bool() = 0;
virtual const Point& operator*() const = 0;
virtual bool operator--() = 0;

virtual explicit operator bool() = 0;
virtual Point& operator*() = 0;

// -- Methods

Expand Down
39 changes: 25 additions & 14 deletions src/eckit/geometry/iterator/Reduced.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

#include "eckit/geometry/iterator/Reduced.h"

#include <ostream>

#include "eckit/exception/Exceptions.h"


Expand All @@ -34,17 +32,6 @@ Reduced::Reduced(const std::vector<double>& latitudes,
}


void Reduced::print(std::ostream& out) const {
out << "Reduced[N=" << N_ << /*",bbox=" << bbox_ <<*/ ",Ni=" << Ni_ << ",Nj=" << Nj_
<< ",i=" << i_ << ",j=" << j_ << ",k=" << k_ << ",count=" << count_ << "]";
}


size_t Reduced::index() const {
return count_;
}


size_t Reduced::resetToRow(size_t j) {
ASSERT(j < latitudes_.size());
lat_ = latitudes_[j];
Expand All @@ -71,6 +58,11 @@ size_t Reduced::resetToRow(size_t j) {
}


bool Reduced::operator!=(const Iterator&) {
NOTIMP;
}


bool Reduced::operator++() {
while (Ni_ == 0 && j_ < Nj_) {
Ni_ = resetToRow(k_ + j_++);
Expand Down Expand Up @@ -99,8 +91,27 @@ bool Reduced::operator++() {
}


bool Reduced::operator--() {
NOTIMP;
}


Reduced::operator bool() {
NOTIMP;
}


Point& Reduced::operator*() {
NOTIMP;
}


size_t Reduced::size() const {
return 0;
NOTIMP;
}

size_t Reduced::index() const {
return count_;
}


Expand Down
9 changes: 7 additions & 2 deletions src/eckit/geometry/iterator/Reduced.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,19 @@ class Reduced final : public Iterator {

// -- Methods

void print(std::ostream&) const;
size_t index() const;
size_t resetToRow(size_t);

// -- Overridden methods

bool operator!=(const Iterator&) override;
bool operator++() override;
bool operator--() override;

explicit operator bool() override;
Point& operator*() override;

size_t size() const override;
size_t index() const override;

// -- Class members
// None
Expand Down
35 changes: 22 additions & 13 deletions src/eckit/geometry/iterator/Regular.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

#include "eckit/geometry/iterator/Regular.h"

#include <ostream>

#include "eckit/exception/Exceptions.h"


Expand Down Expand Up @@ -62,16 +60,8 @@ Regular::Regular(size_t ni, size_t nj, double north, double west, double we, dou
}


Regular::~Regular() {
auto count = count_ + (i_ > 0 || j_ > 0 ? 1 : 0);
ASSERT(count == ni_ * nj_);
}


void Regular::print(std::ostream& out) const {
out << "Regular[ni=" << ni_ << ",nj=" << nj_ << ",north=" << north_ << ",west=" << west_
<< ",we=" << we_ << ",ns=" << ns_ << ",i=" << i_ << ",j=" << j_ << ",count=" << count_
<< "]";
bool Regular::operator!=(const Iterator&) {
NOTIMP;
}


Expand Down Expand Up @@ -106,8 +96,27 @@ bool Regular::operator++() {
}


bool Regular::operator--() {
NOTIMP;
}


Regular::operator bool() {
NOTIMP;
}


Point& Regular::operator*() {
NOTIMP;
}


size_t Regular::size() const {
return 0;
NOTIMP;
}

size_t Regular::index() const {
NOTIMP;
}


Expand Down
13 changes: 9 additions & 4 deletions src/eckit/geometry/iterator/Regular.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ class Regular final : public Iterator {
Regular(size_t ni, size_t nj, double north, double west, double we, double ns);

// -- Destructor

~Regular() override;
// None

// -- Convertors
// None
Expand Down Expand Up @@ -75,13 +74,19 @@ class Regular final : public Iterator {
Point p_;

// -- Methods

void print(std::ostream&) const;
// None

// -- Overridden methods

bool operator!=(const Iterator&) override;
bool operator++() override;
bool operator--() override;

explicit operator bool() override;
Point& operator*() override;

size_t size() const override;
size_t index() const override;

// -- Class members
// None
Expand Down
34 changes: 0 additions & 34 deletions src/eckit/geometry/iterator/Unstructured.cc

This file was deleted.

77 changes: 0 additions & 77 deletions src/eckit/geometry/iterator/Unstructured.h

This file was deleted.

2 changes: 1 addition & 1 deletion src/tools/eckit-grid.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class EckitGrid final : public EckitTool {

auto it = grid->begin();

std::cout << **it << std::endl;
std::cout << *it << std::endl;

// (*it).print(out) << std::endl;
// static_cast<std::ostream&>(out) << "first: " << q << std::endl;
Expand Down

0 comments on commit e89f813

Please sign in to comment.