1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef _BGFX_RANGE_B2DPOLYRANGE_HXX 25 #define _BGFX_RANGE_B2DPOLYRANGE_HXX 26 27 #include <o3tl/cow_wrapper.hxx> 28 #include <boost/tuple/tuple.hpp> 29 #include <basegfx/vector/b2enums.hxx> 30 #include <basegfx/basegfxdllapi.h> 31 32 namespace basegfx 33 { 34 class B2DTuple; 35 class B2DRange; 36 class B2DPolyPolygon; 37 class ImplB2DPolyRange; 38 39 /** Multiple ranges in one object. 40 41 This class combines multiple ranges in one object, providing a 42 total, enclosing range for it. 43 44 You can use this class e.g. when updating views containing 45 rectangular objects. Add each modified object to a 46 B2DMultiRange, then test each viewable object against 47 intersection with the multi range. 48 49 Similar in spirit to the poly-polygon vs. polygon relationship. 50 51 Note that comparable to polygons, a poly-range can also 52 contain 'holes' - this is encoded via polygon orientation at 53 the poly-polygon, and via explicit flags for the poly-range. 54 */ 55 class BASEGFX_DLLPUBLIC B2DPolyRange 56 { 57 public: 58 typedef boost::tuple<B2DRange,B2VectorOrientation> ElementType ; 59 60 B2DPolyRange(); 61 ~B2DPolyRange(); 62 63 /** Create a multi range with exactly one containing range 64 */ 65 explicit B2DPolyRange( const ElementType& rElement ); 66 B2DPolyRange( const B2DRange& rRange, B2VectorOrientation eOrient ); 67 B2DPolyRange( const B2DPolyRange& ); 68 B2DPolyRange& operator=( const B2DPolyRange& ); 69 70 /// unshare this poly-range with all internally shared instances 71 void makeUnique(); 72 73 bool operator==(const B2DPolyRange&) const; 74 bool operator!=(const B2DPolyRange&) const; 75 76 /// Number of included ranges 77 sal_uInt32 count() const; 78 79 ElementType getElement(sal_uInt32 nIndex) const; 80 void setElement(sal_uInt32 nIndex, const ElementType& rElement ); 81 void setElement(sal_uInt32 nIndex, const B2DRange& rRange, B2VectorOrientation eOrient ); 82 83 // insert/append a single range 84 void insertElement(sal_uInt32 nIndex, const ElementType& rElement, sal_uInt32 nCount = 1); 85 void insertElement(sal_uInt32 nIndex, const B2DRange& rRange, B2VectorOrientation eOrient, sal_uInt32 nCount = 1); 86 void appendElement(const ElementType& rElement, sal_uInt32 nCount = 1); 87 void appendElement(const B2DRange& rRange, B2VectorOrientation eOrient, sal_uInt32 nCount = 1); 88 89 // insert/append multiple ranges 90 void insertPolyRange(sal_uInt32 nIndex, const B2DPolyRange&); 91 void appendPolyRange(const B2DPolyRange&); 92 93 void remove(sal_uInt32 nIndex, sal_uInt32 nCount = 1); 94 void clear(); 95 96 // flip range orientations - converts holes to solids, and vice versa 97 void flip(); 98 99 /** Get overall range 100 101 @return 102 The union range of all contained ranges 103 */ 104 B2DRange getBounds() const; 105 106 /** Test whether given tuple is inside one or more of the 107 included ranges. Does *not* use overall range, but checks 108 individually. 109 */ 110 bool isInside( const B2DTuple& rTuple ) const; 111 112 /** Test whether given range is inside one or more of the 113 included ranges. Does *not* use overall range, but checks 114 individually. 115 */ 116 bool isInside( const B2DRange& rRange ) const; 117 118 /** Test whether given range overlaps one or more of the 119 included ranges. Does *not* use overall range, but checks 120 individually. 121 */ 122 bool overlaps( const B2DRange& rRange ) const; 123 124 /** Request a poly-polygon with solved cross-overs 125 */ 126 B2DPolyPolygon solveCrossovers() const; 127 128 // element iterators (same iterator validity conditions as for vector) 129 const B2DRange* begin() const; 130 const B2DRange* end() const; 131 B2DRange* begin(); 132 B2DRange* end(); 133 134 private: 135 o3tl::cow_wrapper< ImplB2DPolyRange > mpImpl; 136 }; 137 } 138 139 #endif /* _BGFX_RANGE_B2DPOLYRANGE_HXX */ 140