Debian Codegraph @

src/atlas/domain/detail/RectangularDomain.h

raw
1 /*
2 * (C) Copyright 2013 ECMWF.
3 *
4 * This software is licensed under the terms of the Apache Licence Version 2.0
5 * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6 * In applying this licence, ECMWF does not waive the privileges and immunities
7 * granted to it by virtue of its status as an intergovernmental organisation
8 * nor does it submit to any jurisdiction.
9 */
10
11 #pragma once
12
13 #include <array>
14 #include <iosfwd>
15
16 #include "atlas/domain/detail/Domain.h"
17
18 namespace atlas {
19 namespace domain {
20
21 class RectangularDomain : public Domain {
22 public:
23 using Interval = std::array<double, 2>;
24
25 public:
26 static bool is_global(const Interval& x, const Interval& y, const std::string& units = "degrees");
27 static bool is_zonal_band(const Interval& x, const std::string& units = "degrees");
28
29 public:
30 // constructor
31 RectangularDomain(const eckit::Parametrisation&);
32 RectangularDomain(const Interval& x, const Interval& y, const std::string& units);
33
34 static std::string static_type() { return "rectangular"; }
35 virtual std::string type() const override { return static_type(); }
36
37 /// Checks if the point is contained in the domain
38 virtual bool contains(double x, double y) const override;
39
40 /// Checks if the x-value is contained in the domain
41 bool contains_x(double x) const { return (xmin_tol_ <= x && x <= xmax_tol_); }
42
43 /// Checks if the y-value is contained in the domain
44 bool contains_y(double y) const { return (ymin_tol_ <= y && y <= ymax_tol_); }
45
46 /// Check if grid includes the North pole
47 virtual bool containsNorthPole() const override;
48
49 /// Check if grid includes the South pole
50 virtual bool containsSouthPole() const override;
51
52 virtual bool global() const override { return global_; }
53 bool zonal_band() const { return is_zonal_band({xmin_, xmax_}, units_); }
54
55 virtual bool empty() const override {
56 // deepcode ignore FloatingPointEquals: We want exact comparison
57 return (xmin_ == xmax_) or (ymin_ == ymax_);
58 }
59
60 virtual Spec spec() const override;
61
62 virtual void print(std::ostream&) const override;
63
64 virtual void hash(eckit::Hash&) const override;
65
66 virtual std::string units() const override { return units_; }
67
68 double xmin() const { return xmin_; }
69 double xmax() const { return xmax_; }
70 double ymin() const { return ymin_; }
71 double ymax() const { return ymax_; }
72
73 private:
74 double xmin_, xmax_, ymin_, ymax_;
75 double xmin_tol_, xmax_tol_, ymin_tol_, ymax_tol_;
76 bool global_;
77 std::string units_;
78 bool unit_degrees_;
79 };
80
81 class RectangularLonLatDomain : public RectangularDomain {
82 public:
83 RectangularLonLatDomain(const eckit::Parametrisation& config): RectangularDomain(config) {}
84 RectangularLonLatDomain(const Interval& x, const Interval& y): RectangularDomain(x, y, "degrees") {}
85 double north() const { return ymax(); }
86 double south() const { return ymin(); }
87 double west() const { return xmin(); }
88 double east() const { return xmax(); }
89 };
90
91 } // namespace domain
92 } // namespace atlas