/src/poppler/poppler/PDFRectangle.h
Line | Count | Source |
1 | | //======================================================================== |
2 | | // |
3 | | // PDFRectange.h |
4 | | // |
5 | | // Code originally from Page.cc |
6 | | // |
7 | | // Copyright 1996-2007 Glyph & Cog, LLC |
8 | | // |
9 | | //======================================================================== |
10 | | |
11 | | //======================================================================== |
12 | | // |
13 | | // Modified under the Poppler project - http://poppler.freedesktop.org |
14 | | // |
15 | | // All changes made under the Poppler project to this file are licensed |
16 | | // under GPL version 2 or later |
17 | | // |
18 | | // Copyright (C) 2020 Albert Astals Cid <aacid@kde.org> |
19 | | // Copyright (C) 2025 Stefan BrĂ¼ns <stefan.bruens@rwth-aachen.de> |
20 | | // Copyright (C) 2026 g10 Code GmbH, Author: Sune Stolborg Vuorela <sune@vuorela.dk> |
21 | | // |
22 | | // To see a description of the changes please see the Changelog file that |
23 | | // came with your tarball or type make ChangeLog if you are building from git |
24 | | // |
25 | | //======================================================================== |
26 | | |
27 | | #ifndef PDFRECTANGLE_H |
28 | | #define PDFRECTANGLE_H |
29 | | |
30 | | //------------------------------------------------------------------------ |
31 | | |
32 | | class PDFRectangle |
33 | | { |
34 | | public: |
35 | | double x1 = 0.0; |
36 | | double y1 = 0.0; |
37 | | double x2 = 0.0; |
38 | | double y2 = 0.0; |
39 | | |
40 | 90.1k | constexpr PDFRectangle() = default; |
41 | | constexpr PDFRectangle(double x1A, double y1A, double x2A, double y2A) |
42 | 0 | { |
43 | 0 | x1 = x1A; |
44 | 0 | y1 = y1A; |
45 | 0 | x2 = x2A; |
46 | 0 | y2 = y2A; |
47 | 0 | } |
48 | 0 | constexpr bool isValid() const { return x1 != 0 || y1 != 0 || x2 != 0 || y2 != 0; } |
49 | 0 | constexpr bool isEmpty() const { return x1 == x2 && y1 == y2; } |
50 | 0 | constexpr bool contains(double x, double y) const { return x1 <= x && x <= x2 && y1 <= y && y <= y2; } |
51 | | constexpr void clipTo(const PDFRectangle &rect); |
52 | | |
53 | 3.78k | constexpr bool operator==(const PDFRectangle &rect) const { return x1 == rect.x1 && y1 == rect.y1 && x2 == rect.x2 && y2 == rect.y2; } |
54 | | }; |
55 | | |
56 | | constexpr void PDFRectangle::clipTo(const PDFRectangle &rect) |
57 | 15.1k | { |
58 | 15.1k | if (x1 < rect.x1) { |
59 | 0 | x1 = rect.x1; |
60 | 15.1k | } else if (x1 > rect.x2) { |
61 | 0 | x1 = rect.x2; |
62 | 0 | } |
63 | 15.1k | if (x2 < rect.x1) { |
64 | 0 | x2 = rect.x1; |
65 | 15.1k | } else if (x2 > rect.x2) { |
66 | 0 | x2 = rect.x2; |
67 | 0 | } |
68 | 15.1k | if (y1 < rect.y1) { |
69 | 0 | y1 = rect.y1; |
70 | 15.1k | } else if (y1 > rect.y2) { |
71 | 0 | y1 = rect.y2; |
72 | 0 | } |
73 | 15.1k | if (y2 < rect.y1) { |
74 | 0 | y2 = rect.y1; |
75 | 15.1k | } else if (y2 > rect.y2) { |
76 | 0 | y2 = rect.y2; |
77 | 0 | } |
78 | 15.1k | } |
79 | | |
80 | | #endif |