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_f.h
Go to the documentation of this file.
1 #pragma once
5 #include <cstdint>
6 #include <ostream>
7 #include <string>
8 #include <xtd/object.h>
9 #include <xtd/ustring.h>
10 #include "../drawing_export.h"
11 
13 namespace xtd {
15  namespace drawing {
17  class size;
19 
26  class drawing_export_ point_f : public object {
27  public:
29 
31  static const point_f empty;
33 
35 
37  point_f() = default;
38  point_f(float x, float y) : x_(x), y_(y) {}
40 
42  point_f(const point_f&) = default;
43  point_f& operator=(const point_f&) = default;
44  bool operator==(const point_f& value) const {return x_ == value.x_ && y_ == value.y_;}
45  bool operator!=(const point_f& value) const {return !operator==(value);}
47 
49 
51  bool is_empty() const {return *this == point_f::empty;}
52 
53  float x() const {return x_;}
54 
55  void x(float x) {x_ = x;}
56 
57  float y() const {return y_;}
58 
59  void y(float y) {y_ = y;}
61 
63 
65  void offset(const point_f& pt) {offset(pt.x_, pt.y_);}
66 
67  void offset(float dx, float dy) {
68  x_ += dx;
69  y_ += dy;
70  }
71 
72  xtd::ustring to_string() const noexcept override {return "{x=" + std::to_string(x_) + ", y=" + std::to_string(y_) + "}";}
74 
76  friend std::ostream& operator<<(std::ostream& os, const xtd::drawing::point_f& point) noexcept {
77  return os << point.to_string();
78  }
80 
81  private:
82  float x_ = 0;
83  float y_ = 0;
84  };
85  }
86 }
xtd::ustring to_string() const noexcept override
Returns a std::string that represents the current object.
Definition: point_f.h:72
Represents an ordered pair of integer x- and y-coordinates that defines a point in a two-dimensional ...
Definition: point.h:48
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:50
std::string to_string(const date_time &value, const std::string &fmt, const std::locale &loc)
Convert a specified value into a string with specified format and locale.
Definition: date_time.h:1110
Represents an ordered pair of floating-point x- and y-coordinates that defines a point in a two-dimen...
Definition: point_f.h:26
Contains xtd::ustring class.
Contains xtd::object class.
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes...
Definition: object.h:30
size_t size
Represents a size of any object in bytes.
Definition: types.h:171