diff --git a/include/ge211_forward.hxx b/include/ge211_forward.hxx index 12c72aa..78d97ff 100644 --- a/include/ge211_forward.hxx +++ b/include/ge211_forward.hxx @@ -80,6 +80,7 @@ namespace geometry { template struct Basic_dimensions; template struct Basic_position; template struct Basic_rectangle; +class Origin_type; using Dimensions = Basic_dimensions; using Position = Basic_position; diff --git a/include/ge211_geometry.hxx b/include/ge211_geometry.hxx index 3490352..b4d25b4 100644 --- a/include/ge211_geometry.hxx +++ b/include/ge211_geometry.hxx @@ -14,6 +14,13 @@ namespace ge211 { /// Geometric objects and their operations. namespace geometry { +/// The type of the special value `the_origin`. +/// +/// This type exists only so that we can overload the +/// Basic_position constructor to construct the origin. See +/// geometry::the_origin for examples. +class Origin_type { }; + /// Represents the dimensions of an object, or more generally, /// the displacement between two Basic_position%s. Note that /// much of the library uses geometry::Dimensions, which is a @@ -242,11 +249,18 @@ struct Basic_position : x{x}, y{y} { } + /// Constructs the origin when given geometry::the_origin. + Basic_position(Origin_type) + NOEXCEPT_(detail::is_nothrow_convertible()) + : Basic_position(0, 0) + { } + /// Constructs a position from a Basic_dimensions, which gives the /// displacement of the position from the origin. - explicit Basic_position(Dimensions dims) - NOEXCEPT_(detail::is_nothrow_convertible()) - : Basic_position{dims.width, dims.height} + explicit + Basic_position(Dimensions dims) + NOEXCEPT_(detail::is_nothrow_convertible()) + : Basic_position(dims.width, dims.height) { } /// Converts a Basic_position to another coordinate type. @@ -811,6 +825,21 @@ bool operator==(const Transform&, const Transform&) NOEXCEPT; /// Disequality for transforms. bool operator!=(const Transform&, const Transform&) NOEXCEPT; +/// Gets implicitly converted to `Basic_position(0, 0)` +/// for any coordinate type `T`. +/// +/// Examples: +/// +/// ``` +/// ge211::Basic_position p0 = the_origin; +/// ``` +/// +/// ``` +/// return Rectangle::from_top_left(the_origin, {w, h}); +/// ``` +//; +constexpr Origin_type the_origin; + } // end namespace geometry. } // end namespace ge211