fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / basegfx / source / range / b2dpolyrange.cxx
blob90a24d876b126cfdc74652d94c275e31e0de3c82
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <basegfx/range/b2dpolyrange.hxx>
22 #include <basegfx/range/b2drange.hxx>
23 #include <basegfx/range/b2drangeclipper.hxx>
24 #include <basegfx/tuple/b2dtuple.hxx>
25 #include <basegfx/polygon/b2dpolypolygon.hxx>
27 #include <boost/bind.hpp>
28 #include <boost/tuple/tuple.hpp>
29 #include <algorithm>
30 #include <vector>
32 namespace basegfx
34 class ImplB2DPolyRange
36 void updateBounds()
38 maBounds.reset();
39 std::for_each(maRanges.begin(),
40 maRanges.end(),
41 boost::bind(
42 (void (B2DRange::*)(const B2DRange&))(
43 &B2DRange::expand),
44 boost::ref(maBounds),
45 _1));
48 public:
49 ImplB2DPolyRange() :
50 maBounds(),
51 maRanges(),
52 maOrient()
55 explicit ImplB2DPolyRange( const B2DRange& rRange, B2VectorOrientation eOrient ) :
56 maBounds( rRange ),
57 maRanges( 1, rRange ),
58 maOrient( 1, eOrient )
61 bool operator==(const ImplB2DPolyRange& rRHS) const
63 return maRanges == rRHS.maRanges && maOrient == rRHS.maOrient;
66 sal_uInt32 count() const
68 return maRanges.size();
71 B2DPolyRange::ElementType getElement(sal_uInt32 nIndex) const
73 return boost::make_tuple(maRanges[nIndex],
74 maOrient[nIndex]);
77 void appendElement(const B2DRange& rRange, B2VectorOrientation eOrient, sal_uInt32 nCount)
79 maRanges.insert(maRanges.end(), nCount, rRange);
80 maOrient.insert(maOrient.end(), nCount, eOrient);
81 maBounds.expand(rRange);
84 void clear()
86 std::vector<B2DRange> aTmpRanges;
87 std::vector<B2VectorOrientation> aTmpOrient;
89 maRanges.swap(aTmpRanges);
90 maOrient.swap(aTmpOrient);
92 maBounds.reset();
95 bool overlaps( const B2DRange& rRange ) const
97 if( !maBounds.overlaps( rRange ) )
98 return false;
100 const std::vector<B2DRange>::const_iterator aEnd( maRanges.end() );
101 return std::find_if( maRanges.begin(),
102 aEnd,
103 boost::bind<bool>( boost::mem_fn( &B2DRange::overlaps ),
105 boost::cref(rRange) ) ) != aEnd;
108 B2DPolyPolygon solveCrossovers() const
110 return tools::solveCrossovers(maRanges,maOrient);
113 private:
114 B2DRange maBounds;
115 std::vector<B2DRange> maRanges;
116 std::vector<B2VectorOrientation> maOrient;
119 B2DPolyRange::B2DPolyRange() :
120 mpImpl()
123 B2DPolyRange::~B2DPolyRange()
126 B2DPolyRange::B2DPolyRange( const B2DPolyRange& rRange ) :
127 mpImpl( rRange.mpImpl )
130 B2DPolyRange& B2DPolyRange::operator=( const B2DPolyRange& rRange )
132 mpImpl = rRange.mpImpl;
133 return *this;
136 bool B2DPolyRange::operator==(const B2DPolyRange& rRange) const
138 if(mpImpl.same_object(rRange.mpImpl))
139 return true;
141 return ((*mpImpl) == (*rRange.mpImpl));
144 bool B2DPolyRange::operator!=(const B2DPolyRange& rRange) const
146 return !(*this == rRange);
149 sal_uInt32 B2DPolyRange::count() const
151 return mpImpl->count();
154 B2DPolyRange::ElementType B2DPolyRange::getElement(sal_uInt32 nIndex) const
156 return mpImpl->getElement(nIndex);
159 void B2DPolyRange::appendElement(const B2DRange& rRange, B2VectorOrientation eOrient, sal_uInt32 nCount)
161 mpImpl->appendElement(rRange, eOrient, nCount );
164 void B2DPolyRange::clear()
166 mpImpl->clear();
169 bool B2DPolyRange::overlaps( const B2DRange& rRange ) const
171 return mpImpl->overlaps(rRange);
174 B2DPolyPolygon B2DPolyRange::solveCrossovers() const
176 return mpImpl->solveCrossovers();
178 } // end of namespace basegfx
180 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */