geometry.cc (1018B)
1 #include "geometry.hh" 2 3 #include <algorithm> 4 5 using namespace winsys; 6 7 void 8 Region::apply_minimum_dim(Dim const& dim) 9 { 10 this->dim.w = std::max(this->dim.w, dim.w); 11 this->dim.h = std::max(this->dim.h, dim.h); 12 } 13 14 void 15 Region::apply_extents(Extents const& extents) 16 { 17 pos.x -= extents.left; 18 pos.y -= extents.top; 19 dim.w += extents.left + extents.right; 20 dim.h += extents.top + extents.bottom; 21 } 22 23 void 24 Region::remove_extents(Extents const& extents) 25 { 26 pos.x += extents.left; 27 pos.y += extents.top; 28 dim.w -= extents.left + extents.right; 29 dim.h -= extents.top + extents.bottom; 30 } 31 32 bool 33 Region::contains(Pos pos) const 34 { 35 return pos.x >= this->pos.x 36 && pos.y >= this->pos.y 37 && pos.x < this->pos.x + this->dim.w 38 && pos.y < this->pos.y + this->dim.h; 39 } 40 41 bool 42 Region::contains(Region const& region) const 43 { 44 return contains(region.pos) 45 && contains(region.pos + region.dim); 46 } 47 48 Pos 49 Region::center() const 50 { 51 return pos + Pos::from_center_of_dim(dim); 52 }