LibreOffice Module basegfx (master) 1
b2dpolyrange.cxx
Go to the documentation of this file.
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
21
25
26#include <algorithm>
27#include <vector>
28
29namespace basegfx
30{
32 {
33 public:
35 {}
36
37 bool operator==(const ImplB2DPolyRange& rRHS) const
38 {
39 return maRanges == rRHS.maRanges && maOrient == rRHS.maOrient;
40 }
41
42 sal_uInt32 count() const
43 {
44 return maRanges.size();
45 }
46
47 B2DPolyRange::ElementType getElement(sal_uInt32 nIndex) const
48 {
49 return std::make_tuple(maRanges[nIndex], maOrient[nIndex]);
50 }
51
52 void appendElement(const B2DRange& rRange, B2VectorOrientation eOrient)
53 {
54 maRanges.push_back(rRange);
55 maOrient.push_back(eOrient);
56 maBounds.expand(rRange);
57 }
58
59 void clear()
60 {
61 std::vector<B2DRange>().swap(maRanges);
62 std::vector<B2VectorOrientation>().swap(maOrient);
63
65 }
66
67 bool overlaps( const B2DRange& rRange ) const
68 {
69 if( !maBounds.overlaps( rRange ) )
70 return false;
71
72 const std::vector<B2DRange>::const_iterator aEnd( maRanges.end() );
73 return std::any_of( maRanges.begin(),
74 aEnd,
75 [&rRange](const B2DRange& aRange) { return aRange.overlaps(rRange); } );
76 }
77
79 {
81 }
82
83 void transform(const basegfx::B2DHomMatrix& rTranslate)
84 {
85 maBounds.transform(rTranslate);
86 for (auto &a : maRanges)
87 a.transform(rTranslate);
88 }
89
90 private:
92 std::vector<B2DRange> maRanges;
93 std::vector<B2VectorOrientation> maOrient;
94 };
95
97
99
100 B2DPolyRange::B2DPolyRange( const B2DPolyRange& ) = default;
101
103
104 bool B2DPolyRange::operator==(const B2DPolyRange& rRange) const
105 {
106 if(mpImpl.same_object(rRange.mpImpl))
107 return true;
108
109 return ((*mpImpl) == (*rRange.mpImpl));
110 }
111
112 bool B2DPolyRange::operator!=(const B2DPolyRange& rRange) const
113 {
114 return !(*this == rRange);
115 }
116
117 sal_uInt32 B2DPolyRange::count() const
118 {
119 return mpImpl->count();
120 }
121
123 {
124 return mpImpl->getElement(nIndex);
125 }
126
128 {
129 mpImpl->appendElement(rRange, eOrient);
130 }
131
133 {
134 mpImpl->clear();
135 }
136
137 bool B2DPolyRange::overlaps( const B2DRange& rRange ) const
138 {
139 return mpImpl->overlaps(rRange);
140 }
141
143 {
144 mpImpl->transform(rTranslate);
145 }
146
148 {
149 return mpImpl->solveCrossovers();
150 }
151} // end of namespace basegfx
152
153/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Multiple ranges in one object.
std::tuple< B2DRange, B2VectorOrientation > ElementType
ElementType getElement(sal_uInt32 nIndex) const
B2DPolyRange & operator=(const B2DPolyRange &)
sal_uInt32 count() const
Number of included ranges.
B2DPolyPolygon solveCrossovers() const
Request a poly-polygon with solved cross-overs.
void appendElement(const B2DRange &rRange, B2VectorOrientation eOrient)
bool operator==(const B2DPolyRange &) const
o3tl::cow_wrapper< ImplB2DPolyRange > mpImpl
bool operator!=(const B2DPolyRange &) const
bool overlaps(const B2DRange &rRange) const
Test whether given range overlaps one or more of the included ranges.
void transform(const B2DHomMatrix &rTranslate)
A two-dimensional interval over doubles.
Definition: b2drange.hxx:54
BASEGFX_DLLPUBLIC void transform(const B2DHomMatrix &rMatrix)
Transform Range by given transformation matrix.
Definition: b2drange.cxx:38
std::vector< B2VectorOrientation > maOrient
sal_uInt32 count() const
bool operator==(const ImplB2DPolyRange &rRHS) const
bool overlaps(const B2DRange &rRange) const
std::vector< B2DRange > maRanges
B2DPolyRange::ElementType getElement(sal_uInt32 nIndex) const
void transform(const basegfx::B2DHomMatrix &rTranslate)
void appendElement(const B2DRange &rRange, B2VectorOrientation eOrient)
B2DPolyPolygon solveCrossovers() const
void expand(const Tuple2D< TYPE > &rTuple)
add point to the set, expanding as necessary
Definition: Range2D.hxx:142
void reset()
reset the object to empty state again, clearing all values
Definition: Range2D.hxx:72
bool overlaps(const Range2D &rRange) const
yields true if rRange at least partly inside set
Definition: Range2D.hxx:130
sal_Int32 nIndex
uno_Any a
B2DPolyPolygon solveCrossovers(const B2DPolyPolygon &rCandidate, size_t *pPointLimit)
Solve all crossovers (aka self-intersections) in a polyPolygon.
B2VectorOrientation
Descriptor for the mathematical orientations of two 2D Vectors.
Definition: b2enums.hxx:27