App

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

Geometry.cpp
Go to the documentation of this file.
1
6 #include "Geometry.hpp"
7
8 namespace app {
9
10 int Rect::moveTo(Point ntl) {
11 int dx = ntl.x - tl.x;
12 int dy = ntl.y - tl.y;
13 tl = ntl;
14 br.x += dx;
15 br.y += dy;
16 return 0;
17 }
18
19 Rect Rect::makeCopyAt(const Point ntl) const{
20 int dx = ntl.x - tl.x;
21 int dy = ntl.y - tl.y;
22 return Rect(ntl, Point (br.x + dx, br.y + dy));
23 }
24
25 Rect Rect::makeCopyAt(const Rect &src, Point ntl) {
26 int dx = ntl.x - src.tl.x;
27 int dy = ntl.y - src.tl.y;
28 return Rect(ntl, Point (src.br.x + dx, src.br.y + dy));
29 }
30
31 int Rect::resizeBy(Vect dtl, Vect dbr) {
32 tl.x += dtl.getdx();
33 tl.y += dtl.getdy();
34 br.x += dbr.getdx();
35 br.y += dbr.getdy();
36 return 0;
37 }
38
39 Rect Rect::makeResizedCopy(const Rect &src, Vect dtl, Vect dbr) {
40 return Rect(src.tl.x + dtl.getdx(), src.tl.y + dtl.getdy(), src.br.x + dbr.getdx(), src.br.y + dbr.getdy());
41 }
42
43 Rect Rect::getIntersection(const Rect &rct1, const Rect &rct2) {
44 // tato validace nutná - jinak se může vrátit platný rect, ale nesmysl
45 if ( !(rct1.isValid() && rct2.isValid()) ) { return Rect(0, 0, 0, 0); }
46 int t, l, b, r;
47 t = (rct1.tl.y > rct2.tl.y) ? rct1.tl.y : rct2.tl.y;
48 l = (rct1.tl.x > rct2.tl.x) ? rct1.tl.x : rct2.tl.x;
49 b = (rct1.br.y < rct2.br.y) ? rct1.br.y : rct2.br.y;
50 r = (rct1.br.x < rct2.br.x) ? rct1.br.x : rct2.br.x;
51 Rect res = Rect(Point(l, t), Point(r, b));
52 return res;
53 }
54
55 int Rect::getDifference(const Rect &other, Vect &dtl, Vect &dbr) const {
56 dtl.from = tl;
57 dtl.to = other.tl;
58 dbr.from = br;
59 dbr.to = other.br;
60 return 0;
61 }
62
63 }