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 
20 #include <drawinglayer/primitive3d/sdrprimitive3d.hxx>
21 #include <basegfx/polygon/b3dpolypolygontools.hxx>
22 #include <drawinglayer/attribute/sdrlineattribute.hxx>
23 
24 
25 using namespace com::sun::star;
26 
27 
28 namespace drawinglayer::primitive3d
29 {
getStandard3DRange() const30         basegfx::B3DRange SdrPrimitive3D::getStandard3DRange() const
31         {
32             basegfx::B3DRange aUnitRange(0.0, 0.0, 0.0, 1.0, 1.0, 1.0);
33             aUnitRange.transform(getTransform());
34 
35             if(!getSdrLFSAttribute().getLine().isDefault())
36             {
37                 const attribute::SdrLineAttribute& rLine = getSdrLFSAttribute().getLine();
38 
39                 if(!rLine.isDefault() && !basegfx::fTools::equalZero(rLine.getWidth()))
40                 {
41                     // expand by held LineWidth as tube radius
42                     aUnitRange.grow(rLine.getWidth() / 2.0);
43                 }
44             }
45 
46             return aUnitRange;
47         }
48 
get3DRangeFromSlices(const Slice3DVector & rSlices) const49         basegfx::B3DRange SdrPrimitive3D::get3DRangeFromSlices(const Slice3DVector& rSlices) const
50         {
51             basegfx::B3DRange aRetval;
52 
53             if(!rSlices.empty())
54             {
55                 for(const auto & rSlice : rSlices)
56                 {
57                     aRetval.expand(basegfx::utils::getRange(rSlice.getB3DPolyPolygon()));
58                 }
59 
60                 aRetval.transform(getTransform());
61 
62                 if(!getSdrLFSAttribute().getLine().isDefault())
63                 {
64                     const attribute::SdrLineAttribute& rLine = getSdrLFSAttribute().getLine();
65 
66                     if(!rLine.isDefault() && !basegfx::fTools::equalZero(rLine.getWidth()))
67                     {
68                         // expand by half LineWidth as tube radius
69                         aRetval.grow(rLine.getWidth() / 2.0);
70                     }
71                 }
72             }
73 
74             return aRetval;
75         }
76 
SdrPrimitive3D(const basegfx::B3DHomMatrix & rTransform,const basegfx::B2DVector & rTextureSize,const attribute::SdrLineFillShadowAttribute3D & rSdrLFSAttribute,const attribute::Sdr3DObjectAttribute & rSdr3DObjectAttribute)77         SdrPrimitive3D::SdrPrimitive3D(
78             const basegfx::B3DHomMatrix& rTransform,
79             const basegfx::B2DVector& rTextureSize,
80             const attribute::SdrLineFillShadowAttribute3D& rSdrLFSAttribute,
81             const attribute::Sdr3DObjectAttribute& rSdr3DObjectAttribute)
82         :   BufferedDecompositionPrimitive3D(),
83             maTransform(rTransform),
84             maTextureSize(rTextureSize),
85             maSdrLFSAttribute(rSdrLFSAttribute),
86             maSdr3DObjectAttribute(rSdr3DObjectAttribute)
87         {
88         }
89 
operator ==(const BasePrimitive3D & rPrimitive) const90         bool SdrPrimitive3D::operator==(const BasePrimitive3D& rPrimitive) const
91         {
92             if(BufferedDecompositionPrimitive3D::operator==(rPrimitive))
93             {
94                 const SdrPrimitive3D& rCompare = static_cast< const SdrPrimitive3D& >(rPrimitive);
95 
96                 return (getTransform() == rCompare.getTransform()
97                     && getTextureSize() == rCompare.getTextureSize()
98                     && getSdrLFSAttribute() == rCompare.getSdrLFSAttribute()
99                     && getSdr3DObjectAttribute() == rCompare.getSdr3DObjectAttribute());
100             }
101 
102             return false;
103         }
104 
105 } // end of namespace
106 
107 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
108