Skip to content

Commit 7898fca

Browse files
committed
Use std::vector for TrapezoidMapTriFinder::_points
We already use one for `_edges`, so might as well use one for `_points` as well.
1 parent 8d011fc commit 7898fca

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

src/tri/_tri.cpp

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,7 +1064,6 @@ XY TriContourGenerator::interp(int point1,
10641064

10651065
TrapezoidMapTriFinder::TrapezoidMapTriFinder(Triangulation& triangulation)
10661066
: _triangulation(triangulation),
1067-
_points(nullptr),
10681067
_tree(nullptr)
10691068
{}
10701069

@@ -1291,8 +1290,7 @@ TrapezoidMapTriFinder::add_edge_to_tree(const Edge& edge)
12911290
void
12921291
TrapezoidMapTriFinder::clear()
12931292
{
1294-
delete [] _points;
1295-
_points = nullptr;
1293+
_points.clear();
12961294

12971295
_edges.clear();
12981296

@@ -1399,7 +1397,7 @@ TrapezoidMapTriFinder::initialize()
13991397
// Set up points array, which contains all of the points in the
14001398
// triangulation plus the 4 corners of the enclosing rectangle.
14011399
int npoints = triang.get_npoints();
1402-
_points = new Point[npoints + 4];
1400+
_points.reserve(npoints + 4);
14031401
BoundingBox bbox;
14041402
for (int i = 0; i < npoints; ++i) {
14051403
XY xy = triang.get_point_coords(i);
@@ -1408,7 +1406,7 @@ TrapezoidMapTriFinder::initialize()
14081406
xy.x = 0.0;
14091407
if (xy.y == -0.0)
14101408
xy.y = 0.0;
1411-
_points[i] = Point(xy);
1409+
_points.emplace_back(xy);
14121410
bbox.add(xy);
14131411
}
14141412

@@ -1423,10 +1421,10 @@ TrapezoidMapTriFinder::initialize()
14231421
const double small = 0.1; // Any value > 0.0
14241422
bbox.expand( (bbox.upper - bbox.lower)*small );
14251423
}
1426-
_points[npoints ] = Point(bbox.lower); // SW point.
1427-
_points[npoints+1] = Point(bbox.upper.x, bbox.lower.y); // SE point.
1428-
_points[npoints+2] = Point(bbox.lower.x, bbox.upper.y); // NW point.
1429-
_points[npoints+3] = Point(bbox.upper); // NE point.
1424+
_points.emplace_back(bbox.lower); // SW point.
1425+
_points.emplace_back(bbox.upper.x, bbox.lower.y); // SE point.
1426+
_points.emplace_back(bbox.lower.x, bbox.upper.y); // NW point.
1427+
_points.emplace_back(bbox.upper); // NE point.
14301428

14311429
// Set up edges array.
14321430
// First the bottom and top edges of the enclosing rectangle.
@@ -1442,16 +1440,14 @@ TrapezoidMapTriFinder::initialize()
14421440
for (int tri = 0; tri < ntri; ++tri) {
14431441
if (!triang.is_masked(tri)) {
14441442
for (int edge = 0; edge < 3; ++edge) {
1445-
Point* start = _points + triang.get_triangle_point(tri,edge);
1446-
Point* end = _points +
1447-
triang.get_triangle_point(tri,(edge+1)%3);
1448-
Point* other = _points +
1449-
triang.get_triangle_point(tri,(edge+2)%3);
1443+
Point* start = &_points[triang.get_triangle_point(tri, edge)];
1444+
Point* end = &_points[triang.get_triangle_point(tri,(edge+1)%3)];
1445+
Point* other = &_points[triang.get_triangle_point(tri,(edge+2)%3)];
14501446
TriEdge neighbor = triang.get_neighbor_edge(tri,edge);
14511447
if (end->is_right_of(*start)) {
14521448
const Point* neighbor_point_below = (neighbor.tri == -1) ?
1453-
nullptr : _points + triang.get_triangle_point(
1454-
neighbor.tri, (neighbor.edge+2)%3);
1449+
nullptr :
1450+
&_points[triang.get_triangle_point(neighbor.tri, (neighbor.edge+2)%3)];
14551451
_edges.emplace_back(start, end, neighbor.tri, tri,
14561452
neighbor_point_below, other);
14571453
}

src/tri/_tri.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -784,8 +784,8 @@ class TrapezoidMapTriFinder final
784784
Triangulation& _triangulation;
785785

786786
// Variables internal to C++ only.
787-
Point* _points; // Array of all points in triangulation plus corners of
788-
// enclosing rectangle. Owned.
787+
std::vector<Point> _points; // Array of all points in triangulation plus corners of
788+
// enclosing rectangle. Owned.
789789

790790
typedef std::vector<Edge> Edges;
791791
Edges _edges; // All Edges in triangulation plus bottom and top Edges of

0 commit comments

Comments
 (0)