Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef _BGFX_RANGE_BASICBOX_HXX
30 : : #define _BGFX_RANGE_BASICBOX_HXX
31 : :
32 : : #include <basegfx/range/basicrange.hxx>
33 : : #include <basegfx/basegfxdllapi.h>
34 : :
35 : :
36 : : namespace basegfx
37 : : {
38 : : /** Explicitely different from BasicRange, handling the inside predicates
39 : : differently.
40 : :
41 : : This is modelled after how polygon fill algorithms set pixel -
42 : : typically excluding rightmost and bottommost ones.
43 : : */
44 : : class BasicBox : public BasicRange< sal_Int32, Int32Traits >
45 : : {
46 : : typedef BasicRange< sal_Int32, Int32Traits > Base;
47 : : public:
48 : 6324985 : BasicBox() {}
49 : :
50 : 36019286 : explicit BasicBox( sal_Int32 nValue ) :
51 : 36019286 : Base( nValue )
52 : : {
53 : 36019286 : }
54 : :
55 : 114306033 : bool isEmpty() const
56 : : {
57 : 114306033 : return mnMinimum >= mnMaximum;
58 : : }
59 : :
60 : 10 : double getCenter() const
61 : : {
62 [ + + ]: 10 : if(isEmpty())
63 : : {
64 : 5 : return 0.0;
65 : : }
66 : : else
67 : : {
68 : 10 : return ((mnMaximum + mnMinimum - 1.0) / 2.0);
69 : : }
70 : : }
71 : :
72 : : using Base::isInside;
73 : :
74 : 103280408 : bool isInside(sal_Int32 nValue) const
75 : : {
76 [ + + ]: 103280408 : if(isEmpty())
77 : : {
78 : 17542 : return false;
79 : : }
80 : : else
81 : : {
82 [ + + ][ + + ]: 103280408 : return (nValue >= mnMinimum) && (nValue < mnMaximum);
83 : : }
84 : : }
85 : :
86 : : using Base::overlaps;
87 : :
88 : 10 : bool overlaps(const BasicBox& rBox) const
89 : : {
90 [ - + ]: 10 : if(isEmpty())
91 : : {
92 : 0 : return false;
93 : : }
94 : : else
95 : : {
96 [ - + ]: 10 : if(rBox.isEmpty())
97 : : {
98 : 0 : return false;
99 : : }
100 : : else
101 : : {
102 [ + + ][ + - ]: 10 : return !((rBox.mnMaximum <= mnMinimum) || (rBox.mnMinimum >= mnMaximum));
103 : : }
104 : : }
105 : : }
106 : :
107 : : void grow(sal_Int32 nValue)
108 : : {
109 : : if(!isEmpty())
110 : : {
111 : : bool bLessThanZero(nValue < 0);
112 : :
113 : : if(nValue > 0 || bLessThanZero)
114 : : {
115 : : mnMinimum -= nValue;
116 : : mnMaximum += nValue;
117 : :
118 : : if(bLessThanZero)
119 : : {
120 : : // test if range did collapse
121 : : if(mnMinimum > mnMaximum)
122 : : {
123 : : // if yes, collapse to center
124 : : mnMinimum = mnMaximum = ((mnMaximum + mnMinimum - 1) / 2);
125 : : }
126 : : }
127 : : }
128 : : }
129 : : }
130 : : };
131 : :
132 : : } // end of namespace basegfx
133 : :
134 : : #endif /* _BGFX_RANGE_BASICBOX_HXX */
135 : :
136 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|