LibreOffice Module basegfx (master) 1
b2ibox.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#pragma once
21
22#include <ostream>
23
26
27namespace basegfx
28{
55 class B2IBox
56 {
57 public:
58 typedef sal_Int32 ValueType;
60
61 B2IBox() {}
62
64 explicit B2IBox(const B2ITuple& rTuple)
65 : maRangeX(rTuple.getX()),
66 maRangeY(rTuple.getY())
67 {
68 }
69
71 B2IBox(sal_Int32 x1,
72 sal_Int32 y1,
73 sal_Int32 x2,
74 sal_Int32 y2) :
75 maRangeX(x1),
76 maRangeY(y1)
77 {
78 maRangeX.expand(x2);
79 maRangeY.expand(y2);
80 }
81
83 B2IBox(const B2ITuple& rTuple1,
84 const B2ITuple& rTuple2) :
85 maRangeX(rTuple1.getX()),
86 maRangeY(rTuple1.getY())
87 {
88 expand( rTuple2 );
89 }
90
96 bool isEmpty() const
97 {
98 return maRangeX.isEmpty() || maRangeY.isEmpty();
99 }
100
101 bool operator==( const B2IBox& rBox ) const
102 {
103 return (maRangeX == rBox.maRangeX
104 && maRangeY == rBox.maRangeY);
105 }
106
107 bool operator!=( const B2IBox& rBox ) const
108 {
109 return (maRangeX != rBox.maRangeX
110 || maRangeY != rBox.maRangeY);
111 }
112
114 sal_Int32 getMinX() const
115 {
116 return maRangeX.getMinimum();
117 }
118
120 sal_Int32 getMinY() const
121 {
122 return maRangeY.getMinimum();
123 }
124
126 sal_Int32 getMaxX() const
127 {
128 return maRangeX.getMaximum();
129 }
130
132 sal_Int32 getMaxY() const
133 {
134 return maRangeY.getMaximum();
135 }
136
138 sal_Int64 getWidth() const
139 {
140 return maRangeX.getRange();
141 }
142
144 sal_Int64 getHeight() const
145 {
146 return maRangeY.getRange();
147 }
148
150 bool isInside(const B2ITuple& rTuple) const
151 {
152 return (
153 maRangeX.isInside(rTuple.getX())
154 && maRangeY.isInside(rTuple.getY())
155 );
156 }
157
159 void expand(const B2ITuple& rTuple)
160 {
161 maRangeX.expand(rTuple.getX());
162 maRangeY.expand(rTuple.getY());
163 }
164
166 void intersect(const B2IBox& rBox)
167 {
170 }
171
172 private:
175 };
176
177} // end of namespace basegfx
178
179template< typename charT, typename traits >
180inline std::basic_ostream<charT, traits> & operator <<(
181 std::basic_ostream<charT, traits> & stream, const basegfx::B2IBox& box )
182{
183 if (box.isEmpty())
184 return stream << "EMPTY";
185 else
186 return stream << box.getWidth() << 'x' << box.getHeight()
187 << "@(" << box.getMinX() << "," << box.getMinY() << ")";
188}
189
190/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::basic_ostream< charT, traits > & operator<<(std::basic_ostream< charT, traits > &stream, const basegfx::B2IBox &box)
Definition: b2ibox.hxx:180
A two-dimensional interval over integers.
Definition: b2ibox.hxx:56
sal_Int32 getMaxX() const
get upper bound of the set. returns arbitrary values for empty sets.
Definition: b2ibox.hxx:126
sal_Int32 getMinX() const
get lower bound of the set. returns arbitrary values for empty sets.
Definition: b2ibox.hxx:114
void expand(const B2ITuple &rTuple)
add point to the set, expanding as necessary
Definition: b2ibox.hxx:159
bool isEmpty() const
Check if the interval set is empty.
Definition: b2ibox.hxx:96
BasicBox maRangeX
Definition: b2ibox.hxx:173
Int32Traits TraitsType
Definition: b2ibox.hxx:59
BasicBox maRangeY
Definition: b2ibox.hxx:174
sal_Int64 getHeight() const
return difference between upper and lower Y value. returns 0 for empty sets.
Definition: b2ibox.hxx:144
void intersect(const B2IBox &rBox)
calc set intersection
Definition: b2ibox.hxx:166
B2IBox(sal_Int32 x1, sal_Int32 y1, sal_Int32 x2, sal_Int32 y2)
Create proper interval between the two given points.
Definition: b2ibox.hxx:71
bool isInside(const B2ITuple &rTuple) const
yields true if point is contained in set
Definition: b2ibox.hxx:150
B2IBox(const B2ITuple &rTuple1, const B2ITuple &rTuple2)
Create proper interval between the two given points.
Definition: b2ibox.hxx:83
bool operator==(const B2IBox &rBox) const
Definition: b2ibox.hxx:101
sal_Int32 ValueType
Definition: b2ibox.hxx:58
B2IBox(const B2ITuple &rTuple)
Create degenerate interval that's still empty.
Definition: b2ibox.hxx:64
sal_Int32 getMaxY() const
get upper bound of the set. returns arbitrary values for empty sets.
Definition: b2ibox.hxx:132
bool operator!=(const B2IBox &rBox) const
Definition: b2ibox.hxx:107
sal_Int32 getMinY() const
get lower bound of the set. returns arbitrary values for empty sets.
Definition: b2ibox.hxx:120
sal_Int64 getWidth() const
return difference between upper and lower X value. returns 0 for empty sets.
Definition: b2ibox.hxx:138
Base class for all Points/Vectors with two sal_Int32 values.
Definition: b2ituple.hxx:37
Explicitly different from BasicRange, handling the inside predicates differently.
Definition: basicbox.hxx:34
bool isInside(sal_Int32 nValue) const
Definition: basicbox.hxx:51
bool isEmpty() const
Definition: basicbox.hxx:44
void intersect(const BasicRange &rRange)
Definition: basicrange.hxx:205
T getMaximum() const
Definition: basicrange.hxx:63
T getMinimum() const
Definition: basicrange.hxx:62
void expand(T nValue)
Definition: basicrange.hxx:152
Traits::DifferenceType getRange() const
Definition: basicrange.hxx:276
TYPE getX() const
Get X-Coordinate of 2D Tuple.
Definition: Tuple2D.hxx:63
TYPE getY() const
Get Y-Coordinate of 2D Tuple.
Definition: Tuple2D.hxx:66
Reference< XOutputStream > stream