1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef _BGFX_POLYGON_B2DTRAPEZOID_HXX 25 #define _BGFX_POLYGON_B2DTRAPEZOID_HXX 26 27 #include <basegfx/polygon/b2dpolygon.hxx> 28 #include <basegfx/polygon/b2dpolypolygon.hxx> 29 #include <vector> 30 #include <basegfx/basegfxdllapi.h> 31 32 ////////////////////////////////////////////////////////////////////////////// 33 34 namespace basegfx 35 { 36 // class to hold a single trapezoid 37 class BASEGFX_DLLPUBLIC B2DTrapezoid 38 { 39 private: 40 // Geometry data. YValues are down-oriented, this means bottom should 41 // be bigger than top to be below it. The constructor implementation 42 // guarantees: 43 // 44 // - mfBottomY >= mfTopY 45 // - mfTopXRight >= mfTopXLeft 46 // - mfBottomXRight >= mfBottomXLeft 47 double mfTopXLeft; 48 double mfTopXRight; 49 double mfTopY; 50 double mfBottomXLeft; 51 double mfBottomXRight; 52 double mfBottomY; 53 54 public: 55 // constructor 56 B2DTrapezoid( 57 const double& rfTopXLeft, 58 const double& rfTopXRight, 59 const double& rfTopY, 60 const double& rfBottomXLeft, 61 const double& rfBottomXRight, 62 const double& rfBottomY); 63 64 // data read access getTopXLeft() const65 const double& getTopXLeft() const { return mfTopXLeft; } getTopXRight() const66 const double& getTopXRight() const { return mfTopXRight; } getTopY() const67 const double& getTopY() const { return mfTopY; } getBottomXLeft() const68 const double& getBottomXLeft() const { return mfBottomXLeft; } getBottomXRight() const69 const double& getBottomXRight() const { return mfBottomXRight; } getBottomY() const70 const double& getBottomY() const { return mfBottomY; } 71 72 // convenience method to get content as Polygon 73 B2DPolygon getB2DPolygon() const; 74 }; 75 76 typedef ::std::vector< B2DTrapezoid > B2DTrapezoidVector; 77 78 } // end of namespace basegfx 79 80 ////////////////////////////////////////////////////////////////////////////// 81 82 namespace basegfx 83 { 84 namespace tools 85 { 86 // convert SourcePolyPolygon to trapezoids. The trapezoids will be appended to 87 // ro_Result. ro_Result will not be cleared. If SourcePolyPolygon contains curves, 88 // it's default AdaptiveSubdivision will be used. 89 // CAUTION: Trapezoids are oreintation-dependent in the sense that the upper and lower 90 // lines have to be parallel to the X-Axis, thus this subdivision is NOT simply usable 91 // for primitive decompositions. To use it, the shear and rotate parts of the 92 // involved transformations HAVE to be taken into account. 93 BASEGFX_DLLPUBLIC void trapezoidSubdivide( 94 B2DTrapezoidVector& ro_Result, 95 const B2DPolyPolygon& rSourcePolyPolygon); 96 97 // directly create trapezoids from given edge. Depending on the given geometry, 98 // none up to three trapezoids will be created 99 BASEGFX_DLLPUBLIC void createLineTrapezoidFromEdge( 100 B2DTrapezoidVector& ro_Result, 101 const B2DPoint& rPointA, 102 const B2DPoint& rPointB, 103 double fLineWidth = 1.0); 104 105 // create trapezoids for all edges of the given polygon. The closed state of 106 // the polygon is taken into account. If curves are contaned, the default 107 // AdaptiveSubdivision will be used. 108 BASEGFX_DLLPUBLIC void createLineTrapezoidFromB2DPolygon( 109 B2DTrapezoidVector& ro_Result, 110 const B2DPolygon& rPolygon, 111 double fLineWidth = 1.0); 112 113 // create trapezoids for all edges of the given polyPolygon. The closed state of 114 // the PolyPolygon is taken into account. If curves are contaned, the default 115 // AdaptiveSubdivision will be used. 116 BASEGFX_DLLPUBLIC void createLineTrapezoidFromB2DPolyPolygon( 117 B2DTrapezoidVector& ro_Result, 118 const B2DPolyPolygon& rPolyPolygon, 119 double fLineWidth = 1.0); 120 121 } // end of namespace tools 122 } // end of namespace basegfx 123 124 ////////////////////////////////////////////////////////////////////////////// 125 126 #endif /* _BGFX_POLYGON_B2DTRAPEZOID_HXX */ 127