LTP GCOV extension - code coverage report
Current view: directory - ogr/ogrsf_frmts/dxf - ogrdxf_polyline_smooth.h
Test: gdal_filtered.info
Date: 2010-07-12 Instrumented lines: 34
Code covered: 100.0 % Executed lines: 34

       1                 : /******************************************************************************
       2                 :  * File:   ogrdxf_polyline_smooth.h
       3                 :  *
       4                 :  * Project:  Interpolation support for smooth POLYLINE and LWPOLYLINE entities.
       5                 :  * Purpose:  Definition of classes for OGR .dxf driver.
       6                 :  * Author:   TJ Snider, timsn@thtree.com
       7                 :  *           Ray Gardener, Daylon Graphics Ltd.
       8                 :  *
       9                 :  ******************************************************************************
      10                 :  * Copyright (c) 2010 Daylon Graphics Ltd.
      11                 :  *
      12                 :  * Permission is hereby granted, free of charge, to any person obtaining a
      13                 :  * copy of this software and associated documentation files (the "Software"),
      14                 :  * to deal in the Software without restriction, including without limitation
      15                 :  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      16                 :  * and/or sell copies of the Software, and to permit persons to whom the
      17                 :  * Software is furnished to do so, subject to the following conditions:
      18                 :  *
      19                 :  * The above copyright notice and this permission notice shall be included
      20                 :  * in all copies or substantial portions of the Software.
      21                 :  *
      22                 :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
      23                 :  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      24                 :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
      25                 :  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      26                 :  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
      27                 :  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
      28                 :  * DEALINGS IN THE SOFTWARE.
      29                 :  ****************************************************************************/
      30                 : 
      31                 : 
      32                 : #ifndef __OGRDXF_SMOOTH_POLYLINE_H__
      33                 : #define __OGRDXF_SMOOTH_POLYLINE_H__
      34                 : 
      35                 : #include "ogrsf_frmts.h"
      36                 : #include "cpl_conv.h"
      37                 : #include <vector>
      38                 : #include "assert.h"
      39                 : 
      40                 : #ifndef M_PI
      41                 :     #define M_PI        3.14159265358979323846  /* pi */
      42                 : #endif
      43                 : 
      44                 : 
      45                 : class DXFSmoothPolylineVertex
      46              54 : {
      47                 :     public:
      48                 :         double  x, y, z, bulge;
      49                 : 
      50                 : 
      51              32 :         DXFSmoothPolylineVertex()
      52                 :         {
      53              32 :             x = y = z = bulge = 0.0;
      54              32 :         }
      55                 : 
      56                 : 
      57              24 :         DXFSmoothPolylineVertex(double dfX, double dfY, double dfZ, double dfBulge)
      58                 :         {
      59              24 :             this->set(dfX, dfY, dfZ, dfBulge);
      60              24 :         }
      61                 : 
      62                 : 
      63              24 :         void set(double dfX, double dfY, double dfZ, double dfBulge)
      64                 :         {
      65              24 :             x = dfX;
      66              24 :             y = dfY;
      67              24 :             z = dfZ;
      68              24 :             bulge = dfBulge;
      69              24 :         }
      70                 : 
      71                 : 
      72                 :         void scale(double s)
      73                 :         {
      74                 :             x *= s;
      75                 :             y *= s;
      76                 :         }
      77                 : 
      78                 :           
      79               8 :         double length() const
      80                 :         {
      81               8 :             return (sqrt(x*x + y*y));
      82                 :         }
      83                 : 
      84                 : 
      85               8 :         void normalize()
      86                 :         {
      87               8 :             const double len = this->length();
      88               8 :             assert(len != 0.0);
      89                 : 
      90               8 :             x /= len;
      91               8 :             y /= len;
      92               8 :         }
      93                 : 
      94                 : 
      95               3 :         bool shares_2D_pos(const DXFSmoothPolylineVertex& v) const
      96                 :         {
      97               3 :             return (x == v.x && y == v.y);
      98                 :         }
      99                 : 
     100                 : };
     101                 : 
     102                 : 
     103                 : class DXFSmoothPolyline
     104               6 : {
     105                 :     // A DXF polyline that includes vertex bulge information.
     106                 :     // Call Tesselate() to convert to an OGRGeometry.
     107                 :     // We treat Z as constant over the entire string; this may
     108                 :     // change in the future.
     109                 : 
     110                 :     private:
     111                 : 
     112                 :         std::vector<DXFSmoothPolylineVertex>    m_vertices;
     113                 :         mutable bool                            m_blinestringstarted;
     114                 :         bool                                    m_bClosed;
     115                 :     int                   m_dim;
     116                 : 
     117                 :        
     118                 :     public:
     119               6 :         DXFSmoothPolyline()
     120               6 :         {
     121               6 :             m_bClosed = false;
     122               6 :       m_dim = 2;
     123               6 :         }
     124                 : 
     125                 :         OGRGeometry* Tesselate() const;
     126                 : 
     127                 :         void SetSize(int n) { m_vertices.reserve(n); }
     128                 : 
     129              24 :         void AddPoint(double dfX, double dfY, double dfZ, double dfBulge)
     130                 :         {
     131              24 :             m_vertices.push_back(DXFSmoothPolylineVertex(dfX, dfY, dfZ, dfBulge));
     132              24 :         }
     133                 : 
     134                 :         void Close();
     135                 : 
     136               5 :         bool IsEmpty() const { return m_vertices.empty(); }
     137                 : 
     138                 :         bool HasConstantZ(double&) const;
     139                 : 
     140              12 :       void setCoordinateDimension(int n) { m_dim = n; }
     141                 : 
     142                 : 
     143                 : 
     144                 :     private:
     145                 :         void EmitArc(const DXFSmoothPolylineVertex&, const DXFSmoothPolylineVertex&,
     146                 :                 double radius, double len, double saggita, 
     147                 :                 OGRLineString*, double dfZ = 0.0) const;
     148                 : 
     149                 :         void EmitLine(const DXFSmoothPolylineVertex&, const DXFSmoothPolylineVertex&, 
     150                 :             OGRLineString*, bool bConstantZ, double dfZ) const;
     151                 : };
     152                 : 
     153                 : #endif  /* __OGRDXF_SMOOTH_POLYLINE_H__ */
     154                 : 

Generated by: LTP GCOV extension version 1.5