summaryrefslogtreecommitdiff
path: root/drawinglayer/source/primitive3d/polygontubeprimitive3d.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'drawinglayer/source/primitive3d/polygontubeprimitive3d.cxx')
-rw-r--r--drawinglayer/source/primitive3d/polygontubeprimitive3d.cxx114
1 files changed, 47 insertions, 67 deletions
diff --git a/drawinglayer/source/primitive3d/polygontubeprimitive3d.cxx b/drawinglayer/source/primitive3d/polygontubeprimitive3d.cxx
index ff00b91050f6..672c78463a7d 100644
--- a/drawinglayer/source/primitive3d/polygontubeprimitive3d.cxx
+++ b/drawinglayer/source/primitive3d/polygontubeprimitive3d.cxx
@@ -25,8 +25,7 @@
#include <basegfx/polygon/b3dpolypolygontools.hxx>
#include <drawinglayer/primitive3d/transformprimitive3d.hxx>
#include <drawinglayer/primitive3d/drawinglayer_primitivetypes3d.hxx>
-#include <rtl/instance.hxx>
-
+#include <mutex>
namespace drawinglayer::primitive3d
{
@@ -39,7 +38,7 @@ namespace drawinglayer::primitive3d
Primitive3DContainer m_aLineTubeList;
sal_uInt32 m_nLineTubeSegments;
attribute::MaterialAttribute3D m_aLineMaterial;
- ::osl::Mutex m_aMutex;
+ std::mutex m_aMutex;
public:
TubeBuffer()
: m_nLineTubeSegments(0)
@@ -54,7 +53,7 @@ namespace drawinglayer::primitive3d
const attribute::MaterialAttribute3D& rMaterial)
{
// may exclusively change cached data, use mutex
- ::osl::MutexGuard aGuard(m_aMutex);
+ std::unique_lock aGuard(m_aMutex);
if (nSegments != m_nLineTubeSegments || !(rMaterial == m_aLineMaterial))
{
@@ -70,7 +69,7 @@ namespace drawinglayer::primitive3d
basegfx::B3DPoint aLastLeft(0.0, 1.0, 0.0);
basegfx::B3DPoint aLastRight(1.0, 1.0, 0.0);
basegfx::B3DHomMatrix aRot;
- aRot.rotate(F_2PI / static_cast<double>(m_nLineTubeSegments), 0.0, 0.0);
+ aRot.rotate(2 * M_PI / static_cast<double>(m_nLineTubeSegments), 0.0, 0.0);
m_aLineTubeList.resize(m_nLineTubeSegments);
for(sal_uInt32 a = 0; a < m_nLineTubeSegments; ++a)
@@ -93,9 +92,8 @@ namespace drawinglayer::primitive3d
aNewPolygon.setClosed(true);
- const basegfx::B3DPolyPolygon aNewPolyPolygon(aNewPolygon);
- const Primitive3DReference xRef(new PolyPolygonMaterialPrimitive3D(aNewPolyPolygon, m_aLineMaterial, false));
- m_aLineTubeList[a] = xRef;
+ basegfx::B3DPolyPolygon aNewPolyPolygon(aNewPolygon);
+ m_aLineTubeList[a] = new PolyPolygonMaterialPrimitive3D(std::move(aNewPolyPolygon), m_aLineMaterial, false);
aLastLeft = aNextLeft;
aLastRight = aNextRight;
@@ -105,16 +103,13 @@ namespace drawinglayer::primitive3d
}
};
- struct theTubeBuffer :
- public rtl::Static< TubeBuffer, theTubeBuffer > {};
-
Primitive3DContainer getLineTubeSegments(
sal_uInt32 nSegments,
const attribute::MaterialAttribute3D& rMaterial)
{
// static data for buffered tube primitives
- TubeBuffer &rTheBuffer = theTubeBuffer::get();
- return rTheBuffer.getLineTubeSegments(nSegments, rMaterial);
+ static TubeBuffer theTubeBuffer;
+ return theTubeBuffer.getLineTubeSegments(nSegments, rMaterial);
}
class CapBuffer
@@ -124,7 +119,7 @@ namespace drawinglayer::primitive3d
Primitive3DContainer m_aLineCapList;
sal_uInt32 m_nLineCapSegments;
attribute::MaterialAttribute3D m_aLineMaterial;
- ::osl::Mutex m_aMutex;
+ std::mutex m_aMutex;
public:
CapBuffer()
: m_nLineCapSegments(0)
@@ -138,7 +133,7 @@ namespace drawinglayer::primitive3d
const attribute::MaterialAttribute3D& rMaterial)
{
// may exclusively change cached data, use mutex
- ::osl::MutexGuard aGuard(m_aMutex);
+ std::unique_lock aGuard(m_aMutex);
if (nSegments != m_nLineCapSegments || !(rMaterial == m_aLineMaterial))
{
@@ -152,7 +147,7 @@ namespace drawinglayer::primitive3d
const basegfx::B3DPoint aNull(0.0, 0.0, 0.0);
basegfx::B3DPoint aLast(0.0, 1.0, 0.0);
basegfx::B3DHomMatrix aRot;
- aRot.rotate(F_2PI / static_cast<double>(m_nLineCapSegments), 0.0, 0.0);
+ aRot.rotate(2 * M_PI / static_cast<double>(m_nLineCapSegments), 0.0, 0.0);
m_aLineCapList.resize(m_nLineCapSegments);
for(sal_uInt32 a = 0; a < m_nLineCapSegments; ++a)
@@ -171,9 +166,8 @@ namespace drawinglayer::primitive3d
aNewPolygon.setClosed(true);
- const basegfx::B3DPolyPolygon aNewPolyPolygon(aNewPolygon);
- const Primitive3DReference xRef(new PolyPolygonMaterialPrimitive3D(aNewPolyPolygon, m_aLineMaterial, false));
- m_aLineCapList[a] = xRef;
+ basegfx::B3DPolyPolygon aNewPolyPolygon(aNewPolygon);
+ m_aLineCapList[a] = new PolyPolygonMaterialPrimitive3D(std::move(aNewPolyPolygon), m_aLineMaterial, false);
aLast = aNext;
}
@@ -183,16 +177,13 @@ namespace drawinglayer::primitive3d
}
};
- struct theCapBuffer :
- public rtl::Static< CapBuffer, theCapBuffer > {};
-
Primitive3DContainer getLineCapSegments(
sal_uInt32 nSegments,
const attribute::MaterialAttribute3D& rMaterial)
{
// static data for buffered cap primitives
- CapBuffer &rTheBuffer = theCapBuffer::get();
- return rTheBuffer.getLineCapSegments(nSegments, rMaterial);
+ static CapBuffer theCapBuffer;
+ return theCapBuffer.getLineCapSegments(nSegments, rMaterial);
}
class CapRoundBuffer
@@ -202,7 +193,7 @@ namespace drawinglayer::primitive3d
Primitive3DContainer m_aLineCapRoundList;
sal_uInt32 m_nLineCapRoundSegments;
attribute::MaterialAttribute3D m_aLineMaterial;
- ::osl::Mutex m_aMutex;
+ std::mutex m_aMutex;
public:
CapRoundBuffer()
: m_nLineCapRoundSegments(0)
@@ -216,7 +207,7 @@ namespace drawinglayer::primitive3d
const attribute::MaterialAttribute3D& rMaterial)
{
// may exclusively change cached data, use mutex
- ::osl::MutexGuard aGuard(m_aMutex);
+ std::unique_lock aGuard(m_aMutex);
if (nSegments != m_nLineCapRoundSegments || !(rMaterial == m_aLineMaterial))
{
@@ -241,8 +232,8 @@ namespace drawinglayer::primitive3d
nSegments,
nVerSeg,
true,
- F_PI2, 0.0,
- 0.0, F_2PI));
+ M_PI_2, 0.0,
+ 0.0, 2 * M_PI));
const sal_uInt32 nCount(aSphere.count());
if (nCount)
@@ -251,7 +242,7 @@ namespace drawinglayer::primitive3d
// forget to transform normals, too
basegfx::B3DHomMatrix aSphereTrans;
- aSphereTrans.rotate(0.0, 0.0, F_PI2);
+ aSphereTrans.rotate(0.0, 0.0, M_PI_2);
aSphere.transform(aSphereTrans);
aSphere.transformNormals(aSphereTrans);
@@ -261,12 +252,12 @@ namespace drawinglayer::primitive3d
for (sal_uInt32 a = 0; a < nCount; ++a)
{
const basegfx::B3DPolygon& aPartPolygon(aSphere.getB3DPolygon(a));
- const basegfx::B3DPolyPolygon aPartPolyPolygon(aPartPolygon);
+ basegfx::B3DPolyPolygon aPartPolyPolygon(aPartPolygon);
// need to create one primitive per Polygon since the primitive
// is for planar PolyPolygons which is definitely not the case here
m_aLineCapRoundList[a] = new PolyPolygonMaterialPrimitive3D(
- aPartPolyPolygon,
+ std::move(aPartPolyPolygon),
rMaterial,
false);
}
@@ -278,17 +269,13 @@ namespace drawinglayer::primitive3d
};
- struct theCapRoundBuffer :
- public rtl::Static< CapRoundBuffer, theCapRoundBuffer > {};
-
-
Primitive3DContainer getLineCapRoundSegments(
sal_uInt32 nSegments,
const attribute::MaterialAttribute3D& rMaterial)
{
// static data for buffered cap primitives
- CapRoundBuffer &rTheBuffer = theCapRoundBuffer::get();
- return rTheBuffer.getLineCapRoundSegments(nSegments, rMaterial);
+ static CapRoundBuffer theCapRoundBuffer;
+ return theCapRoundBuffer.getLineCapRoundSegments(nSegments, rMaterial);
}
Primitive3DContainer getLineJoinSegments(
@@ -307,18 +294,18 @@ namespace drawinglayer::primitive3d
if(basegfx::B2DLineJoin::Round == aLineJoin)
{
// calculate new horizontal segments
- const sal_uInt32 nHorSeg(basegfx::fround((fAngle / F_2PI) * static_cast<double>(nSegments)));
+ const sal_uInt32 nHorSeg(basegfx::fround((fAngle / (2 * M_PI)) * static_cast<double>(nSegments)));
if(nHorSeg)
{
// create half-sphere
- const basegfx::B3DPolyPolygon aSphere(basegfx::utils::createUnitSphereFillPolyPolygon(nHorSeg, nVerSeg, true, F_PI2, -F_PI2, 0.0, fAngle));
+ const basegfx::B3DPolyPolygon aSphere(basegfx::utils::createUnitSphereFillPolyPolygon(nHorSeg, nVerSeg, true, M_PI_2, -M_PI_2, 0.0, fAngle));
for(sal_uInt32 a(0); a < aSphere.count(); a++)
{
const basegfx::B3DPolygon& aPartPolygon(aSphere.getB3DPolygon(a));
- const basegfx::B3DPolyPolygon aPartPolyPolygon(aPartPolygon);
- aResultVector.push_back(new PolyPolygonMaterialPrimitive3D(aPartPolyPolygon, rMaterial, false));
+ basegfx::B3DPolyPolygon aPartPolyPolygon(aPartPolygon);
+ aResultVector.push_back(new PolyPolygonMaterialPrimitive3D(std::move(aPartPolyPolygon), rMaterial, false));
}
}
else
@@ -342,13 +329,13 @@ namespace drawinglayer::primitive3d
}
}
- const double fInc(F_PI / static_cast<double>(nVerSeg));
+ const double fInc(M_PI / static_cast<double>(nVerSeg));
const double fSin(sin(-fAngle));
const double fCos(cos(-fAngle));
const bool bMiter(basegfx::B2DLineJoin::Miter == aLineJoin);
const double fMiterSin(bMiter ? sin(-(fAngle/2.0)) : 0.0);
const double fMiterCos(bMiter ? cos(-(fAngle/2.0)) : 0.0);
- double fPos(-F_PI2);
+ double fPos(-M_PI_2);
basegfx::B3DPoint aPointOnXY, aPointRotY, aNextPointOnXY, aNextPointRotY;
basegfx::B3DPoint aCurrMiter, aNextMiter;
basegfx::B3DPolygon aNewPolygon, aMiterPolygon;
@@ -464,8 +451,8 @@ namespace drawinglayer::primitive3d
// create primitive
if(aNewPolygon.count())
{
- const basegfx::B3DPolyPolygon aNewPolyPolygon(aNewPolygon);
- aResultVector.push_back(new PolyPolygonMaterialPrimitive3D(aNewPolyPolygon, rMaterial, false));
+ basegfx::B3DPolyPolygon aNewPolyPolygon(aNewPolygon);
+ aResultVector.push_back(new PolyPolygonMaterialPrimitive3D(std::move(aNewPolyPolygon), rMaterial, false));
}
if(bMiter && aMiterPolygon.count())
@@ -477,8 +464,8 @@ namespace drawinglayer::primitive3d
}
// create primitive
- const basegfx::B3DPolyPolygon aMiterPolyPolygon(aMiterPolygon);
- aResultVector.push_back(new PolyPolygonMaterialPrimitive3D(aMiterPolyPolygon, rMaterial, false));
+ basegfx::B3DPolyPolygon aMiterPolyPolygon(aMiterPolygon);
+ aResultVector.push_back(new PolyPolygonMaterialPrimitive3D(std::move(aMiterPolyPolygon), rMaterial, false));
}
// prepare next step
@@ -498,10 +485,7 @@ namespace drawinglayer::primitive3d
Primitive3DContainer aRetval(aResultVector.size());
- for(size_t a(0); a < aResultVector.size(); a++)
- {
- aRetval[a] = Primitive3DReference(aResultVector[a]);
- }
+ std::transform(aResultVector.cbegin(), aResultVector.cend(), aRetval.begin(), [](auto &rResult){return Primitive3DReference(rResult);});
return aRetval;
}
@@ -533,7 +517,7 @@ using namespace com::sun::star;
if(nPointCount)
{
- if(basegfx::fTools::more(getRadius(), 0.0))
+ if(getRadius() > 0.0)
{
const attribute::MaterialAttribute3D aMaterial(getBColor());
static const sal_uInt32 nSegments(8); // default for 3d line segments, for more quality just raise this value (in even steps)
@@ -550,7 +534,7 @@ using namespace com::sun::star;
const basegfx::B3DVector aForw(aNext - aCurr);
const double fForwLen(aForw.getLength());
- if(basegfx::fTools::more(fForwLen, 0.0))
+ if(fForwLen > 0.0)
{
// find out if linecap is active
const bool bFirst(!a);
@@ -612,7 +596,7 @@ using namespace com::sun::star;
aSequence = getLineCapSegments(nSegments, aMaterial);
}
- aResultVector.push_back(new TransformPrimitive3D(aCapTrans, aSequence));
+ aResultVector.push_back(new TransformPrimitive3D(std::move(aCapTrans), aSequence));
}
else
{
@@ -622,7 +606,7 @@ using namespace com::sun::star;
if(!basegfx::fTools::equalZero(fCross))
{
// line connect non-parallel, aBack, aForw, use getLineJoin()
- const double fAngle(acos(aBack.scalar(aForw) / (fForwLen * aBack.getLength()))); // 0.0 .. F_PI2
+ const double fAngle(acos(aBack.scalar(aForw) / (fForwLen * aBack.getLength()))); // 0.0 .. M_PI_2
Primitive3DContainer aNewList(
getLineJoinSegments(
nSegments,
@@ -640,8 +624,8 @@ using namespace com::sun::star;
// create trans by rotating unit sphere with angle 90 degrees around Y, then 180-fRot in X.
// Also apply usual scaling and translation
basegfx::B3DHomMatrix aSphereTrans;
- aSphereTrans.rotate(0.0, F_PI2, 0.0);
- aSphereTrans.rotate(F_PI - fRotInYZ, 0.0, 0.0);
+ aSphereTrans.rotate(0.0, M_PI_2, 0.0);
+ aSphereTrans.rotate(M_PI - fRotInYZ, 0.0, 0.0);
aSphereTrans *= aRotVector;
aSphereTrans.scale(getRadius(), getRadius(), getRadius());
aSphereTrans.translate(aCurr.getX(), aCurr.getY(), aCurr.getZ());
@@ -649,7 +633,7 @@ using namespace com::sun::star;
// line start edge, build transformed primitiveVector3D
aResultVector.push_back(
new TransformPrimitive3D(
- aSphereTrans,
+ std::move(aSphereTrans),
aNewList));
}
}
@@ -657,7 +641,7 @@ using namespace com::sun::star;
// create line segments, build transformed primitiveVector3D
aResultVector.push_back(
new TransformPrimitive3D(
- aTubeTrans,
+ std::move(aTubeTrans),
getLineTubeSegments(nSegments, aMaterial)));
if(bNoLineJoin || (!bClosed && bLast))
@@ -666,7 +650,7 @@ using namespace com::sun::star;
basegfx::B3DHomMatrix aBackCapTrans;
// Mirror (line end) and radius scale
- aBackCapTrans.rotate(0.0, F_PI, 0.0);
+ aBackCapTrans.rotate(0.0, M_PI, 0.0);
aBackCapTrans.scale(getRadius(), getRadius(), getRadius());
if(bLineCapSquare && bLast)
@@ -700,7 +684,7 @@ using namespace com::sun::star;
aResultVector.push_back(
new TransformPrimitive3D(
- aBackCapTrans,
+ std::move(aBackCapTrans),
aSequence));
}
}
@@ -720,10 +704,7 @@ using namespace com::sun::star;
// prepare return value
Primitive3DContainer aRetval(aResultVector.size());
- for(size_t a(0); a < aResultVector.size(); a++)
- {
- aRetval[a] = Primitive3DReference(aResultVector[a]);
- }
+ std::transform(aResultVector.cbegin(), aResultVector.cend(), aRetval.begin(), [](auto &rResult){return Primitive3DReference(rResult);});
return aRetval;
}
@@ -736,7 +717,6 @@ using namespace com::sun::star;
double fDegreeStepWidth,
double fMiterMinimumAngle)
: PolygonHairlinePrimitive3D(rPolygon, rBColor),
- maLast3DDecomposition(),
mfRadius(fRadius),
mfDegreeStepWidth(fDegreeStepWidth),
mfMiterMinimumAngle(fMiterMinimumAngle),
@@ -763,7 +743,7 @@ using namespace com::sun::star;
Primitive3DContainer PolygonTubePrimitive3D::get3DDecomposition(const geometry::ViewInformation3D& rViewInformation) const
{
- ::osl::MutexGuard aGuard( m_aMutex );
+ std::unique_lock aGuard( m_aMutex );
if(getLast3DDecomposition().empty())
{