Line data Source code
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 : #ifndef INCLUDED_BASEGFX_RANGE_BASICBOX_HXX
21 : #define INCLUDED_BASEGFX_RANGE_BASICBOX_HXX
22 :
23 : #include <basegfx/range/basicrange.hxx>
24 : #include <basegfx/basegfxdllapi.h>
25 :
26 :
27 : namespace basegfx
28 : {
29 : /** Explicitely different from BasicRange, handling the inside predicates
30 : differently.
31 :
32 : This is modelled after how polygon fill algorithms set pixel -
33 : typically excluding rightmost and bottommost ones.
34 : */
35 : class BasicBox : public BasicRange< sal_Int32, Int32Traits >
36 : {
37 : typedef BasicRange< sal_Int32, Int32Traits > Base;
38 : public:
39 2269924 : BasicBox() {}
40 :
41 22518282 : explicit BasicBox( sal_Int32 nValue ) :
42 22518282 : Base( nValue )
43 : {
44 22518282 : }
45 :
46 3675264266 : bool isEmpty() const
47 : {
48 3675264266 : return mnMinimum >= mnMaximum;
49 : }
50 :
51 : double getCenter() const
52 : {
53 : if(isEmpty())
54 : {
55 : return 0.0;
56 : }
57 : else
58 : {
59 : return ((mnMaximum + mnMinimum - 1.0) / 2.0);
60 : }
61 : }
62 :
63 : using Base::isInside;
64 :
65 3666608694 : bool isInside(sal_Int32 nValue) const
66 : {
67 3666608694 : if(isEmpty())
68 : {
69 2 : return false;
70 : }
71 : else
72 : {
73 3666608692 : return (nValue >= mnMinimum) && (nValue < mnMaximum);
74 : }
75 : }
76 :
77 : using Base::overlaps;
78 :
79 : bool overlaps(const BasicBox& rBox) const
80 : {
81 : if(isEmpty())
82 : {
83 : return false;
84 : }
85 : else
86 : {
87 : if(rBox.isEmpty())
88 : {
89 : return false;
90 : }
91 : else
92 : {
93 : return !((rBox.mnMaximum <= mnMinimum) || (rBox.mnMinimum >= mnMaximum));
94 : }
95 : }
96 : }
97 :
98 : void grow(sal_Int32 nValue)
99 : {
100 : if(!isEmpty())
101 : {
102 : bool bLessThanZero(nValue < 0);
103 :
104 : if(nValue > 0 || bLessThanZero)
105 : {
106 : mnMinimum -= nValue;
107 : mnMaximum += nValue;
108 :
109 : if(bLessThanZero)
110 : {
111 : // test if range did collapse
112 : if(mnMinimum > mnMaximum)
113 : {
114 : // if yes, collapse to center
115 : mnMinimum = mnMaximum = ((mnMaximum + mnMinimum - 1) / 2);
116 : }
117 : }
118 : }
119 : }
120 : }
121 : };
122 :
123 : } // end of namespace basegfx
124 :
125 : #endif // INCLUDED_BASEGFX_RANGE_BASICBOX_HXX
126 :
127 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|