Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / include / basegfx / polygon / b2dpolypolygon.hxx
blobd3177e3c4c91de0e5942a6a6c67ae9f41d155827
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 #pragma once
22 #include <ostream>
23 #include <vector>
25 #include <sal/types.h>
26 #include <o3tl/cow_wrapper.hxx>
27 #include <basegfx/range/b2drange.hxx>
28 #include <basegfx/basegfxdllapi.h>
29 #include <basegfx/polygon/b2dpolygon.hxx>
31 namespace basegfx
33 class B2DHomMatrix;
34 class ImplB2DPolyPolygon;
36 class BASEGFX_DLLPUBLIC B2DPolyPolygon
38 private:
39 o3tl::cow_wrapper<ImplB2DPolyPolygon, o3tl::ThreadSafeRefCountingPolicy> mpPolyPolygon;
41 public:
42 B2DPolyPolygon();
43 B2DPolyPolygon(const B2DPolyPolygon& rPolyPolygon);
44 B2DPolyPolygon(B2DPolyPolygon&& rPolyPolygon);
45 explicit B2DPolyPolygon(const B2DPolygon& rPolygon);
46 ~B2DPolyPolygon();
48 // assignment operator
49 B2DPolyPolygon& operator=(const B2DPolyPolygon& rPolyPolygon);
50 B2DPolyPolygon& operator=(B2DPolyPolygon&& rPolyPolygon);
52 /// unshare this poly-polygon (and all included polygons) with all internally shared instances
53 void makeUnique();
55 // compare operators
56 bool operator==(const B2DPolyPolygon& rPolyPolygon) const;
57 bool operator!=(const B2DPolyPolygon& rPolyPolygon) const;
59 // polygon interface
60 sal_uInt32 count() const;
62 B2DPolygon const & getB2DPolygon(sal_uInt32 nIndex) const;
63 void setB2DPolygon(sal_uInt32 nIndex, const B2DPolygon& rPolygon);
65 // test for curve
66 bool areControlPointsUsed() const;
68 // insert/append single polygon
69 void insert(sal_uInt32 nIndex, const B2DPolygon& rPolygon, sal_uInt32 nCount = 1);
70 void append(const B2DPolygon& rPolygon, sal_uInt32 nCount = 1);
71 void reserve(sal_uInt32 nCount);
73 /** Default adaptive subdivision access
75 For details refer to B2DPolygon::getDefaultAdaptiveSubdivision()
77 @return
78 The default subdivision of this polygon
80 B2DPolyPolygon getDefaultAdaptiveSubdivision() const;
82 /** Get the B2DRange (Rectangle dimensions) of this B2DPolyPolygon
84 For details refer to B2DPolygon::getB2DRange()
86 @return
87 The outer range of the bezier curve/polygon
89 B2DRange getB2DRange() const;
91 // insert/append multiple polygons
92 void insert(sal_uInt32 nIndex, const B2DPolyPolygon& rPolyPolygon);
93 void append(const B2DPolyPolygon& rPolyPolygon);
95 // remove
96 void remove(sal_uInt32 nIndex, sal_uInt32 nCount = 1);
98 // reset to empty state
99 void clear();
101 // closed state
102 bool isClosed() const;
103 void setClosed(bool bNew);
105 // flip polygon direction
106 void flip();
108 // test if tools::PolyPolygon has double points
109 bool hasDoublePoints() const;
111 // remove double points, at the begin/end and follow-ups, too
112 void removeDoublePoints();
114 // apply transformation given in matrix form to the polygon
115 void transform(const basegfx::B2DHomMatrix& rMatrix);
117 // polygon iterators (same iterator validity conditions as for vector)
118 const B2DPolygon* begin() const;
119 const B2DPolygon* end() const;
120 B2DPolygon* begin();
121 B2DPolygon* end();
123 // exclusive management op's for SystemDependentData at B2DPolygon
124 template<class T>
125 std::shared_ptr<T> getSystemDependentData() const
127 return std::static_pointer_cast<T>(getSystemDependantDataInternal(typeid(T).hash_code()));
130 template<class T, class... Args>
131 std::shared_ptr<T> addOrReplaceSystemDependentData(Args&&... args) const
133 std::shared_ptr<T> r = std::make_shared<T>(std::forward<Args>(args)...);
135 // tdf#129845 only add to buffer if a relevant buffer time is estimated
136 if(r->calculateCombinedHoldCyclesInSeconds() > 0)
138 basegfx::SystemDependentData_SharedPtr r2(r);
139 addOrReplaceSystemDependentDataInternal(r2);
142 return r;
145 private:
146 void addOrReplaceSystemDependentDataInternal(SystemDependentData_SharedPtr& rData) const;
147 SystemDependentData_SharedPtr getSystemDependantDataInternal(size_t hash_code) const;
150 // typedef for a vector of B2DPolyPolygons
151 typedef ::std::vector< B2DPolyPolygon > B2DPolyPolygonVector;
153 template< typename charT, typename traits >
154 inline std::basic_ostream<charT, traits> & operator <<(
155 std::basic_ostream<charT, traits> & stream, const B2DPolyPolygon& poly )
157 stream << "[" << poly.count() << ":";
158 for (sal_uInt32 i = 0; i < poly.count(); i++)
160 if (i > 0)
161 stream << ",";
162 stream << poly.getB2DPolygon(i);
164 stream << "]";
166 return stream;
169 } // end of namespace basegfx
171 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */