CGM Objects Library
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
PolyPolylineData.h
1 
3 namespace Larson
4 {
7  {
8  public:
9  PolyPolylineData(int nNewPolys = 0)
10  {
11  if (nNewPolys)
12  {
13  ppPts = new DPoint*[nNewPolys]();
14  counts = new long[nNewPolys]();
15  }
16  else
17  {
18  ppPts = NULL;
19  counts = NULL;
20  }
21  nPolys = nNewPolys;
22  };
24  {
25  for (int n = 0; n < nPolys; n++)
26  {
27  if (ppPts[n])
28  delete[] ppPts[n];
29  }
30  if (ppPts)
31  delete[] ppPts;
32  if (counts)
33  delete[] counts;
34  };
35 
36  DPoint** ppPts; // array of polyline pointers
37  long* counts; // number of points in each polyline
38  long nPolys; // number of polyline
39  void operator=( const PolyPolylineData& a )
40  {
41  ppPts = new DPoint*[a.nPolys]();
42  counts = new long[a.nPolys]();
43 
44  for (int n = 0; n < nPolys; n++)
45  {
46  counts[n-1] = a.counts[n-1];
47  ppPts[n-1] = new DPoint[a.counts[n-1]];
48 
49  for (int i = 0; i < a.counts[n-1]; i++)
50  a.ppPts[n-1][i] = a.ppPts[n-1][i];
51  }
52  }
53 
55  long AddSubPoly(DPoint* pts, long nPts)
56  {
57  // new array of polyline pointers and counts
58  DPoint** newPPts = new DPoint*[nPolys+1];
59  long* newCounts = new long[nPolys+1];
60 
61  // copy old to new
62  long i;
63  for (i = 0; i < nPolys; i++)
64  {
65  newPPts[i] = ppPts[i];
66  newCounts[i] = counts[i];
67  }
68  // delete the old
69  delete[] ppPts;
70  delete[] counts;
71 
72  //add subpath points
73  ppPts = newPPts;
74  counts = newCounts;
75 
76  ppPts[i] = new DPoint[nPts];
77  for (long j = 0; j < nPts; j++)
78  ppPts[i][j] = pts[j];
79  counts[i] = nPts;
80 
81  nPolys++;
82 
83  return nPolys;
84  }
85 
87  long AddPts(long subPoly, DPoint* pts, long nPts)
88  {
89  if (subPoly < 0 || subPoly > nPolys)
90  return 0;
91 
92  // allocate new subpath points array
93  DPoint* newPts = NULL;
94  try { newPts = new DPoint[counts[subPoly-1] + nPts]; }
95  catch(...){ return 0; }
96 
97  // copy old points to new array
98  long i = 0;
99  for (; i < counts[subPoly-1]; i++)
100  newPts[i] = ppPts[subPoly-1][i];
101  // delete old points
102  delete[] ppPts[subPoly-1];
103 
104  // add points to new subpath points array
105  ppPts[subPoly-1] = newPts;
106 
107  for (int j = 0; j < nPts; j++)
108  newPts[i++] = pts[j];
109  counts[subPoly-1] += nPts;
110 
111  // return new subpath number of points
112  return counts[subPoly-1];
113  }
114  };
115 };
PolyPolylineData – poly-polyline data container class.
Definition: PolyPolylineData.h:6
long AddPts(long subPoly, DPoint *pts, long nPts)
add points to a subpath
Definition: PolyPolylineData.h:87
long AddSubPoly(DPoint *pts, long nPts)
add subpath
Definition: PolyPolylineData.h:55