Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / basegfx / source / range / b2dpolyrange.cxx
blob25117cb5dbd11173a84ce3a3304f4329edffb33d
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 <algorithm>
28 #include <vector>
30 namespace basegfx
32 class ImplB2DPolyRange
34 public:
35 ImplB2DPolyRange() :
36 maBounds(),
37 maRanges(),
38 maOrient()
41 bool operator==(const ImplB2DPolyRange& rRHS) const
43 return maRanges == rRHS.maRanges && maOrient == rRHS.maOrient;
46 sal_uInt32 count() const
48 return maRanges.size();
51 B2DPolyRange::ElementType getElement(sal_uInt32 nIndex) const
53 return std::make_tuple(maRanges[nIndex], maOrient[nIndex]);
56 void appendElement(const B2DRange& rRange, B2VectorOrientation eOrient, sal_uInt32 nCount)
58 maRanges.insert(maRanges.end(), nCount, rRange);
59 maOrient.insert(maOrient.end(), nCount, eOrient);
60 maBounds.expand(rRange);
63 void clear()
65 std::vector<B2DRange> aTmpRanges;
66 std::vector<B2VectorOrientation> aTmpOrient;
68 maRanges.swap(aTmpRanges);
69 maOrient.swap(aTmpOrient);
71 maBounds.reset();
74 bool overlaps( const B2DRange& rRange ) const
76 if( !maBounds.overlaps( rRange ) )
77 return false;
79 const std::vector<B2DRange>::const_iterator aEnd( maRanges.end() );
80 return std::any_of( maRanges.begin(),
81 aEnd,
82 [&rRange](const B2DRange& aRange) { return aRange.overlaps(rRange); } );
85 B2DPolyPolygon solveCrossovers() const
87 return tools::solveCrossovers(maRanges,maOrient);
90 private:
91 B2DRange maBounds;
92 std::vector<B2DRange> maRanges;
93 std::vector<B2VectorOrientation> maOrient;
96 B2DPolyRange::B2DPolyRange() :
97 mpImpl()
100 B2DPolyRange::~B2DPolyRange()
103 B2DPolyRange::B2DPolyRange( const B2DPolyRange& rRange ) :
104 mpImpl( rRange.mpImpl )
107 B2DPolyRange& B2DPolyRange::operator=( const B2DPolyRange& rRange )
109 mpImpl = rRange.mpImpl;
110 return *this;
113 bool B2DPolyRange::operator==(const B2DPolyRange& rRange) const
115 if(mpImpl.same_object(rRange.mpImpl))
116 return true;
118 return ((*mpImpl) == (*rRange.mpImpl));
121 bool B2DPolyRange::operator!=(const B2DPolyRange& rRange) const
123 return !(*this == rRange);
126 sal_uInt32 B2DPolyRange::count() const
128 return mpImpl->count();
131 B2DPolyRange::ElementType B2DPolyRange::getElement(sal_uInt32 nIndex) const
133 return mpImpl->getElement(nIndex);
136 void B2DPolyRange::appendElement(const B2DRange& rRange, B2VectorOrientation eOrient, sal_uInt32 nCount)
138 mpImpl->appendElement(rRange, eOrient, nCount );
141 void B2DPolyRange::clear()
143 mpImpl->clear();
146 bool B2DPolyRange::overlaps( const B2DRange& rRange ) const
148 return mpImpl->overlaps(rRange);
151 B2DPolyPolygon B2DPolyRange::solveCrossovers() const
153 return mpImpl->solveCrossovers();
155 } // end of namespace basegfx
157 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */