xtd - Reference Guide  0.2.0
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 }
static const point empty
Represents a point that has x and y values set to zero.
Definition: point.h:51
void y(int32_t y)
Sets the y-coordinate of this point.
Definition: point.h:228
void offset(const point &p)
Translates this point by the specified point.
Definition: point.h:275
int32_t x() const
Gets the x-coordinate of this point.
Definition: point.h:159
Represents an ordered pair of integer x- and y-coordinates that defines a point in a two-dimensional ...
Definition: point.h:48
Stores an ordered pair of integers, which specify a height and width.
Definition: size.h:25
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
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...
Contains xtd::drawing::point_f class.
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:48
bool is_empty() const
Gets a value indicating whether this point is empty.
Definition: point.h:136
Represents an ordered pair of floating-point x- and y-coordinates that defines a point in a two-dimen...
Definition: point_f.h:26
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...
point(int32_t x, int32_t y)
Initializes a new instance of the point class with the specified coordinates.
Definition: point.h:103
void x(int32_t x)
Sets the x-coordinate of this point.
Definition: point.h:182
Contains xtd::ustring class.
void offset(int dx, int dy)
Translates this point by the specified amount.
Definition: point.h:257
point(int32_t dw)
Initializes a new instance of the point class using coordinates specified by an integer value...
Definition: point.h:79
int32_t y() const
Gets the y-coordinate of this point.
Definition: point.h:205
Contains xtd::object class.
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes...
Definition: object.h:26
xtd::ustring to_string() const noexcept override
Converts this point to a human-readable string.
Definition: point.h:294
Specifies a printer&#39;s point (1/72 inch) as the unit of measure.
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
size_t size
Represents a size of any object in bytes.
Definition: types.h:171
The Subtract key.