node editor: dragging!
[zinnia.git] / src / geom.h
blobcbbb0e00bf1d511da6370eae9bde92b8776323eb
1 #pragma once
3 #define IMGUI_DEFINE_MATH_OPERATORS
4 #include <imgui.h>
5 #include <imgui_internal.h>
6 #include <sstream>
8 class Rect {
9 public:
10 Rect(ImVec2 pos, ImVec2 size) : pos(pos), size(size) {}
11 Rect(float x, float y, float w, float h) : pos(x, y), size(w, h) {}
13 ImVec2 pos;
14 ImVec2 size;
16 float top() const { return pos.y; }
17 float left() const { return pos.x; }
18 float bottom() const { return pos.y + size.y; }
19 float right() const { return pos.x + size.x; }
21 bool intersects(const Rect &other) {
22 return this->left() < other.right() &&
23 this->right() > other.left() &&
24 this->top() < other.bottom() &&
25 this->bottom() > other.top();
29 std::ostream &operator<<(std::ostream &os, const ImVec2 &vec);
30 std::ostream &operator<<(std::ostream &os, const Rect &rect);