xtd - Reference Guide  0.1.1
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
point.h
Go to the documentation of this file.
1 #pragma once
5 #include <cstdint>
6 #include <ostream>
7 #include <xtd/object.h>
8 #include <xtd/ustring.h>
9 #include "../drawing_export.h"
10 #include "point_f.h"
11 
13 namespace xtd {
15  namespace drawing {
17  class size;
19 
48  class drawing_export_ point : public object {
49  public:
51  static const point empty;
52 
55  point() = default;
56 
79  explicit point(int32_t dw) : x_(dw & 0x0000FFFF), y_((dw & 0xFFFF0000)>>16) {}
80 
103  point(int32_t x, int32_t y) : x_(x), y_(y) {}
104 
126  point (const size& sz);
127 
129  point(const point&) = default;
130  point& operator=(const point&) = default;
131  operator point_f() const {return point_f(static_cast<float>(x_), static_cast<float>(y_));}
133 
136  bool is_empty() const {return *this == point::empty;}
137 
159  int32_t x() const {return x_;}
160 
182  void x(int32_t x) {x_ = x;}
183 
205  int32_t y() const {return y_;}
206 
228  void y(int32_t y) {y_ = y;}
229 
244  static point add(const point& pt, const size& sz);
246  static point add(const point& pt1, const point& pt2);
248 
252  static point ceiling(const point_f& value);
253 
257  void offset(int dx, int dy) {
258  x_ += dx;
259  y_ += dy;
260  }
261 
275  void offset(const point& p) {offset(p.x_, p.y_);}
276 
280  static point round(const point_f& value);
281 
287  static point subtract(const point& pt, const size& sz);
289  static point subtract(const point& pt1, const point& pt2);
291 
294  xtd::ustring to_string() const noexcept override {return ustring::format("{{x={}, y={}}}", x_, y_);}
295 
299  static point truncate(const point_f& value);
300 
302  bool operator==(const point& value) const {return x_ == value.x_ && y_ == value.y_;}
303  bool operator!=(const point& value) const {return !operator==(value);}
304 
305  friend std::ostream& operator<<(std::ostream& os, const xtd::drawing::point& point) noexcept {
306  return os << point.to_string();
307  }
308 
309  point operator+(const size& sz) const;
310  point operator+(const point& pt) const;
311  point& operator+=(const size& sz);
312  point& operator+=(const point& pt);
313  point operator-(const size& sz) const;
314  point operator-(const point& pt) const;
315  point& operator-=(const size& sz);
316  point& operator-=(const point& pt);
318 
319  private:
320  int32_t x_ = 0;
321  int32_t y_ = 0;
322  };
323  }
324 
325  template<>
326  inline drawing::point parse<drawing::point>(const std::string& str) {
327  auto values = xtd::ustring(str).replace("}", "").replace(" y=", "").replace("{x=", "").split({','});
328  return {xtd::parse<int32_t>(values[0]), xtd::parse<int32_t>(values[1])};
329  }
330 }
Represents an ordered pair of floating-point x- and y-coordinates that defines a point in a two-dimen...
Definition: point_f.h:26
Represents an ordered pair of integer x- and y-coordinates that defines a point in a two-dimensional ...
Definition: point.h:48
static point ceiling(const point_f &value)
Converts the specified point_f to a point by rounding the values of the point_f to the next higher in...
bool is_empty() const
Gets a value indicating whether this point is empty.
Definition: point.h:136
static point subtract(const point &pt, const size &sz)
Returns the result of subtracting specified Size from the specified point.
xtd::ustring to_string() const noexcept override
Converts this point to a human-readable string.
Definition: point.h:294
static point truncate(const point_f &value)
Converts the specified point_f to a point by truncating the values of the point_f.
point()=default
Initializes a new instance of the point class.
void offset(int dx, int dy)
Translates this point by the specified amount.
Definition: point.h:257
static point round(const point_f &value)
Converts the specified point_f to a point object by rounding the point_f values to the nearest intege...
point(int32_t dw)
Initializes a new instance of the point class using coordinates specified by an integer value.
Definition: point.h:79
void x(int32_t x)
Sets the x-coordinate of this point.
Definition: point.h:182
static const point empty
Represents a point that has x and y values set to zero.
Definition: point.h:51
int32_t y() const
Gets the y-coordinate of this point.
Definition: point.h:205
point(int32_t x, int32_t y)
Initializes a new instance of the point class with the specified coordinates.
Definition: point.h:103
void offset(const point &p)
Translates this point by the specified point.
Definition: point.h:275
static point add(const point &pt, const size &sz)
Adds the specified size to the specified point.
point(const size &sz)
Initializes a new instance of the point class from a size.
int32_t x() const
Gets the x-coordinate of this point.
Definition: point.h:159
void y(int32_t y)
Sets the y-coordinate of this point.
Definition: point.h:228
Stores an ordered pair of integers, which specify a height and width.
Definition: size.h:25
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition: object.h:26
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:48
ustring replace(value_type old_char, value_type new_char) const noexcept
Replaces all occurrences of a specified char_t in this string with another specified char_t.
std::vector< ustring > split(const std::vector< value_type > &separators, size_t count, string_split_options options) const noexcept
Splits this string into a maximum number of substrings based on the characters in an array.
static ustring format(const ustring &fmt, args_t &&... args)
Writes the text representation of the specified arguments list, to string using the specified format ...
Definition: ustring.h:689
#define drawing_export_
Define shared library export.
Definition: drawing_export.h:13
size_t size
Represents a size of any object in bytes.
Definition: types.h:171
@ add
The Add key.
@ y
The Y key.
@ p
The P key.
@ subtract
The Subtract key.
@ x
The X key.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition: system_report.h:17
Contains xtd::object class.
Contains xtd::drawing::point_f class.
Contains xtd::ustring class.