Skip to content

Commit

Permalink
eckit::geometry
Browse files Browse the repository at this point in the history
  • Loading branch information
pmaciel committed Aug 14, 2023
1 parent 6947eb1 commit dfb0415
Show file tree
Hide file tree
Showing 10 changed files with 275 additions and 56 deletions.
10 changes: 6 additions & 4 deletions src/eckit/geometry/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,12 @@ list( APPEND eckit_geometry_srcs
grid/RegularLL.h
grid/UnstructuredGrid.cc
grid/UnstructuredGrid.h
iterator/Reduced.cc
iterator/Reduced.h
iterator/Regular.cc
iterator/Regular.h
iterator/ListI.cc
iterator/ListI.h
iterator/ListIListJ.cc
iterator/ListIListJ.h
iterator/ReducedIListJ.cc
iterator/ReducedIListJ.h
polygon/LonLatPolygon.cc
polygon/LonLatPolygon.h
polygon/Polygon.cc
Expand Down
27 changes: 26 additions & 1 deletion src/eckit/geometry/Grid.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,32 @@ Grid::Grid(const area::BoundingBox& bbox) :


const area::BoundingBox& Grid::boundingBox() const {
return bbox_;
throw NotImplemented("Grid::boundingBox", Here());
}


size_t Grid::size() const {
throw NotImplemented("Grid::size", Here());
}


bool Grid::includesNorthPole() const {
throw NotImplemented("Grid::includesNorthPole", Here());
}


bool Grid::includesSouthPole() const {
throw NotImplemented("Grid::includesSouthPole", Here());
}


bool Grid::isPeriodicWestEast() const {
throw NotImplemented("Grid::isPeriodicWestEast", Here());
}


const std::vector<Point>& Grid::to_points() const {
throw NotImplemented("Grid::to_points", Here());
}


Expand Down
13 changes: 8 additions & 5 deletions src/eckit/geometry/Grid.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@ class Grid {
void operator=(const Iterator&) = delete;
void operator=(Iterator&&) = delete;

bool operator==(const Iterator& other) { return get()->operator==(*(other.get())); }
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*(); }
const Point& operator*() { return get()->operator*(); }

size_t size() const { return get()->size(); }
size_t index() const { return get()->index(); }
Expand Down Expand Up @@ -96,11 +97,13 @@ class Grid {

virtual const area::BoundingBox& boundingBox() const;

virtual size_t size() const = 0;
virtual size_t size() const;

virtual bool includesNorthPole() const = 0;
virtual bool includesSouthPole() const = 0;
virtual bool isPeriodicWestEast() const = 0;
virtual bool includesNorthPole() const;
virtual bool includesSouthPole() const;
virtual bool isPeriodicWestEast() const;

virtual const std::vector<Point>& to_points() const;

// -- Overridden methods
// None
Expand Down
13 changes: 10 additions & 3 deletions src/eckit/geometry/Iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
#include "eckit/geometry/Point.h"


namespace eckit::geometry {
class Grid;
}


namespace eckit::geometry {


Expand Down Expand Up @@ -43,12 +48,14 @@ class Iterator {
void operator=(const Iterator&) = delete;
void operator=(Iterator&&) = delete;

virtual bool operator!=(const Iterator&) = 0;
bool operator!=(const Iterator& other) { return !operator==(other); }

virtual bool operator==(const Iterator&) = 0;
virtual bool operator++() = 0;
virtual bool operator--() = 0;

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

// -- Methods

Expand All @@ -67,7 +74,7 @@ class Iterator {
protected:
// -- Constructors

Iterator() = default;
Iterator(const Grid&) {}

// -- Members
// None
Expand Down
72 changes: 72 additions & 0 deletions src/eckit/geometry/iterator/ListI.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* (C) Copyright 1996- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities
* granted to it by virtue of its status as an intergovernmental organisation nor
* does it submit to any jurisdiction.
*/


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

#include <type_traits>

#include "eckit/geometry/Grid.h"


namespace eckit::geometry::iterator {


ListI::ListI(const Grid& grid) :
Iterator(grid),
points_(grid.to_points()),
index_(0) {
}


bool ListI::operator==(const Iterator& other) {
const auto* another = dynamic_cast<const ListI*>(&other);
return another != nullptr && points_.data() == another->points_.data() && index_ == another->index_;
}


bool ListI::operator++() {
++index_;
return operator bool();
}


bool ListI::operator--() {
if (index_ == 0) {
return false;
}
index_--;
return operator bool();
}


ListI::operator bool() {
return index_ < points_.size();
}


const Point& ListI::operator*() {
ASSERT(operator bool());
return points_[index_];
}


size_t ListI::size() const {
return points_.size();
}


size_t ListI::index() const {
return index_;
}


} // namespace eckit::geometry::iterator
86 changes: 86 additions & 0 deletions src/eckit/geometry/iterator/ListI.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* (C) Copyright 1996- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities
* granted to it by virtue of its status as an intergovernmental organisation nor
* does it submit to any jurisdiction.
*/


#pragma once

#include "eckit/geometry/Iterator.h"


namespace eckit::geometry::iterator {


class ListI final : public Iterator {
public:
// -- Types
// None

// -- Exceptions
// None

// -- Constructors

explicit ListI(const Grid&);

// -- Destructor
// None

// -- Convertors
// None

// -- Operators
// None

// -- Methods
// None

// -- Overridden methods
// None

// -- Class members
// None

// -- Class methods
// None

private:
// -- Members

const std::vector<Point>& points_;
size_t index_;

// -- Methods
// None

// -- Overridden methods

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

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

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

// -- Class members
// None

// -- Class methods
// None

// -- Friends
// None
};


} // namespace eckit::geometry::iterator
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,40 @@
*/


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

#include "eckit/exception/Exceptions.h"


namespace eckit::geometry::iterator {


Regular::Regular(size_t ni, size_t nj, double north, double west, double we, double ns) :
ni_(ni), nj_(nj), north_(north), west_(west), we_(we), ns_(ns), i_(0), j_(0), lat_(north_), lon_(west_), count_(0), first_(true), p_(PointLonLat{0, 0}) {
ListIListJ::ListIListJ(const Grid& grid) :
Iterator(grid),
ni_(0), // size_t ni
nj_(0), // size_t nj
north_(0), // double north
west_(0), // double west
we_(0), // double we
ns_(0), // double ns
i_(0),
j_(0),
lat_(north_),
lon_(west_),
count_(0),
first_(true),
p_(PointLonLat{0, 0}) {
latValue_ = lat_;
lonValue_ = lon_;
}


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


bool Regular::operator++() {
bool ListIListJ::operator++() {
if (j_ < nj_) {
if (i_ < ni_) {
p_ = PointLonLat{lonValue_, latValue_};
Expand Down Expand Up @@ -61,26 +74,27 @@ bool Regular::operator++() {
}


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


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


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


size_t Regular::size() const {
size_t ListIListJ::size() const {
NOTIMP;
}

size_t Regular::index() const {

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

Expand Down
Loading

0 comments on commit dfb0415

Please sign in to comment.