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 31 ////////////////////////////////////////////////////////////////////////////// 32 33 namespace basegfx 34 { 35 // class to hold a single trapezoid 36 class B2DTrapezoid 37 { 38 private: 39 // Geometry data. YValues are down-oriented, this means bottom should 40 // be bigger than top to be below it. The constructor implementation 41 // guarantees: 42 // 43 // - mfBottomY >= mfTopY 44 // - mfTopXRight >= mfTopXLeft 45 // - mfBottomXRight >= mfBottomXLeft 46 double mfTopXLeft; 47 double mfTopXRight; 48 double mfTopY; 49 double mfBottomXLeft; 50 double mfBottomXRight; 51 double mfBottomY; 52 53 public: 54 // constructor 55 B2DTrapezoid( 56 const double& rfTopXLeft, 57 const double& rfTopXRight, 58 const double& rfTopY, 59 const double& rfBottomXLeft, 60 const double& rfBottomXRight, 61 const double& rfBottomY); 62 63 // data read access getTopXLeft() const64 const double& getTopXLeft() const { return mfTopXLeft; } getTopXRight() const65 const double& getTopXRight() const { return mfTopXRight; } getTopY() const66 const double& getTopY() const { return mfTopY; } getBottomXLeft() const67 const double& getBottomXLeft() const { return mfBottomXLeft; } getBottomXRight() const68 const double& getBottomXRight() const { return mfBottomXRight; } getBottomY() const69 const double& getBottomY() const { return mfBottomY; } 70 71 // convenience method to get content as Polygon 72 B2DPolygon getB2DPolygon() const; 73 }; 74 75 typedef ::std::vector< B2DTrapezoid > B2DTrapezoidVector; 76 77 } // end of namespace basegfx 78 79 ////////////////////////////////////////////////////////////////////////////// 80 81 namespace basegfx 82 { 83 namespace tools 84 { 85 // convert SourcePolyPolygon to trapezoids. The trapezoids will be appended to 86 // ro_Result. ro_Result will not be cleared. If SourcePolyPolygon contains curves, 87 // it's default AdaptiveSubdivision will be used. 88 // CAUTION: Trapezoids are oreintation-dependent in the sense that the upper and lower 89 // lines have to be parallel to the X-Axis, thus this subdivision is NOT simply usable 90 // for primitive decompositions. To use it, the shear and rotate parts of the 91 // involved transformations HAVE to be taken into account. 92 void trapezoidSubdivide( 93 B2DTrapezoidVector& ro_Result, 94 const B2DPolyPolygon& rSourcePolyPolygon); 95 96 // directly create trapezoids from given edge. Depending on the given geometry, 97 // none up to three trapezoids will be created 98 void createLineTrapezoidFromEdge( 99 B2DTrapezoidVector& ro_Result, 100 const B2DPoint& rPointA, 101 const B2DPoint& rPointB, 102 double fLineWidth = 1.0); 103 104 // create trapezoids for all edges of the given polygon. The closed state of 105 // the polygon is taken into account. If curves are contaned, the default 106 // AdaptiveSubdivision will be used. 107 void createLineTrapezoidFromB2DPolygon( 108 B2DTrapezoidVector& ro_Result, 109 const B2DPolygon& rPolygon, 110 double fLineWidth = 1.0); 111 112 // create trapezoids for all edges of the given polyPolygon. The closed state of 113 // the PolyPolygon is taken into account. If curves are contaned, the default 114 // AdaptiveSubdivision will be used. 115 void createLineTrapezoidFromB2DPolyPolygon( 116 B2DTrapezoidVector& ro_Result, 117 const B2DPolyPolygon& rPolyPolygon, 118 double fLineWidth = 1.0); 119 120 } // end of namespace tools 121 } // end of namespace basegfx 122 123 ////////////////////////////////////////////////////////////////////////////// 124 125 #endif /* _BGFX_POLYGON_B2DTRAPEZOID_HXX */ 126