Skip to content

Commit 5045ca3

Browse files
committed
avoid name collision between Point in forceBundle and lineCutter
1 parent f3dcb93 commit 5045ca3

File tree

1 file changed

+47
-47
lines changed

1 file changed

+47
-47
lines changed

src/forceBundle.cpp

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -13,99 +13,99 @@
1313

1414
using namespace cpp11::literals;
1515

16-
class Point {
16+
class Point2 {
1717
public:
1818
double x;
1919
double y;
2020

21-
Point() : x(0.0), y(0.0) {};
22-
Point(double _x, double _y) : x(_x), y(_y) {};
23-
Point(const Point& p) : x(p.x), y(p.y) {};
21+
Point2() : x(0.0), y(0.0) {};
22+
Point2(double _x, double _y) : x(_x), y(_y) {};
23+
Point2(const Point2& p) : x(p.x), y(p.y) {};
2424

25-
Point operator+(const Point& p) const {
25+
Point2 operator+(const Point2& p) const {
2626
return {x + p.x, y + p.y};
2727
};
2828

29-
Point& operator+=(const Point& p) {
29+
Point2& operator+=(const Point2& p) {
3030
x += p.x;
3131
y += p.y;
3232
return *this;
3333
};
3434

35-
Point operator-(const Point& p) const {
35+
Point2 operator-(const Point2& p) const {
3636
return {x - p.x, y - p.y};
3737
};
3838

39-
Point& operator-=(const Point& p) {
39+
Point2& operator-=(const Point2& p) {
4040
x -= p.x;
4141
y -= p.y;
4242
return *this;
4343
};
4444

45-
Point operator*(double fac) const {
45+
Point2 operator*(double fac) const {
4646
return {x * fac, y * fac};
4747
};
4848

49-
Point& operator*=(double fac) {
49+
Point2& operator*=(double fac) {
5050
x *= fac;
5151
y *= fac;
5252
return *this;
5353
};
5454

55-
double operator*(const Point& p) const {
55+
double operator*(const Point2& p) const {
5656
return dot(p);
5757
};
5858

59-
Point operator/(double fac) const {
59+
Point2 operator/(double fac) const {
6060
return {x / fac, y / fac};
6161
};
6262

63-
Point& operator/=(double fac) {
63+
Point2& operator/=(double fac) {
6464
x /= fac;
6565
y /= fac;
6666
return *this;
6767
};
6868

69-
bool operator==(const Point& p) const {
69+
bool operator==(const Point2& p) const {
7070
return x == p.x && y == p.y;
7171
};
7272

73-
bool operator!=(const Point& p) const {
73+
bool operator!=(const Point2& p) const {
7474
return x != p.x || y != p.y;
7575
};
7676

77-
double distance_to(const Point& p, double eps = 0) const {
77+
double distance_to(const Point2& p, double eps = 0) const {
7878
double dx = x - p.x;
7979
double dy = y - p.y;
8080
if (std::abs(dx) < eps && std::abs(dy) < eps) return eps;
8181

8282
return std::sqrt(dx * dx + dy * dy);
8383
}
8484

85-
double dot(const Point& p) const {
85+
double dot(const Point2& p) const {
8686
return x * p.x + y * p.y;
8787
}
8888
};
8989
class Segment {
9090
public:
91-
Point a;
92-
Point b;
91+
Point2 a;
92+
Point2 b;
9393

9494
Segment() : a(), b() {};
95-
Segment(Point _a, Point _b) : a(_a), b(_b) {};
95+
Segment(Point2 _a, Point2 _b) : a(_a), b(_b) {};
9696
Segment(double x0, double y0, double x1, double y1) : a(x0, y0), b(x1, y1) {};
9797
Segment(const Segment& s) : a(s.a), b(s.b) {};
9898

9999
double length(double eps = 0.0) const {
100100
return a.distance_to(b, eps);
101101
}
102102

103-
Point as_vec() const {
103+
Point2 as_vec() const {
104104
return b - a;
105105
}
106106

107-
Point project(const Point& p, double eps = 0.0) const {
108-
Point vec = as_vec();
107+
Point2 project(const Point2& p, double eps = 0.0) const {
108+
Point2 vec = as_vec();
109109

110110
double l2 = vec * vec;
111111
double u = ((p.x - a.x) * vec.x + (p.y - a.y) * vec.y) / l2;
@@ -117,7 +117,7 @@ class Segment {
117117
return {project(s.a, eps), project(s.b, eps)};
118118
}
119119

120-
Point midpoint() const {
120+
Point2 midPoint2() const {
121121
return (a + b) / 2.0;
122122
}
123123

@@ -128,7 +128,7 @@ class Segment {
128128
private:
129129
double visibility(const Segment& s, double eps = 0.0) const {
130130
Segment proj_s = project(s, eps);
131-
return std::max(1.0 - 2.0 * midpoint().distance_to(proj_s.midpoint(), eps) / proj_s.length(eps), 0.0);
131+
return std::max(1.0 - 2.0 * midPoint2().distance_to(proj_s.midPoint2(), eps) / proj_s.length(eps), 0.0);
132132
}
133133
double angle_comp(const Segment& Q, double eps = 0.0) const {
134134
double dot_PQ = as_vec() * Q.as_vec();
@@ -148,7 +148,7 @@ class Segment {
148148

149149
double lavg = (euc_P + euc_Q) / 2.0;
150150

151-
double euc_mid = midpoint().distance_to(Q.midpoint(), eps);
151+
double euc_mid = midPoint2().distance_to(Q.midPoint2(), eps);
152152
return lavg / (lavg + euc_mid);
153153
}
154154
double visibility_comp(const Segment& Q, double eps = 0.0) const {
@@ -159,7 +159,7 @@ class Segment {
159159
}
160160
};
161161

162-
typedef std::vector<Point> Path;
162+
typedef std::vector<Point2> Path;
163163

164164

165165
double compute_divided_edge_length(Path& edge) {
@@ -174,7 +174,7 @@ double compute_divided_edge_length(Path& edge) {
174174
void update_edge_divisions(std::vector<Path>& elist, int P) {
175175
for (size_t e_idx = 0; e_idx < elist.size(); ++e_idx) {
176176
if (P == 1) {
177-
elist[e_idx].insert(elist[e_idx].begin() + 1, Segment(elist[e_idx][0], elist[e_idx][1]).midpoint());
177+
elist[e_idx].insert(elist[e_idx].begin() + 1, Segment(elist[e_idx][0], elist[e_idx][1]).midPoint2());
178178
} else {
179179
Path edge = elist[e_idx];
180180
double current_edge_length = compute_divided_edge_length(edge);
@@ -184,19 +184,19 @@ void update_edge_divisions(std::vector<Path>& elist, int P) {
184184
elist[e_idx].reserve(P + 2);
185185
elist[e_idx].push_back(edge[0]);
186186
for (size_t i = 1; i < edge.size(); ++i) {
187-
Point& start_point = edge[i - 1];
188-
Point vec = edge[i] - start_point;
189-
double segment_length = start_point.distance_to(edge[i]);
187+
Point2& start_Point2 = edge[i - 1];
188+
Point2 vec = edge[i] - start_Point2;
189+
double segment_length = start_Point2.distance_to(edge[i]);
190190
while (segment_length > current_segment_length) {
191191
double percent_position = current_segment_length / segment_length;
192192

193-
elist[e_idx].push_back(start_point + vec * percent_position);
193+
elist[e_idx].push_back(start_Point2 + vec * percent_position);
194194

195195
current_segment_length += new_segment_length;
196196
}
197197
current_segment_length -= segment_length;
198198
}
199-
while (elist[e_idx].size() > P + 1) {
199+
while (elist[e_idx].size() > size_t(P + 1)) {
200200
elist[e_idx].pop_back();
201201
}
202202
elist[e_idx].push_back(edge.back());
@@ -220,16 +220,16 @@ std::vector< std::vector<int> > compute_compatibility_lists(std::vector<Path>& e
220220
return comp;
221221
}
222222

223-
Point apply_spring_force(const std::vector<Path>& edges, int e_idx, int i, double kP) {
223+
Point2 apply_spring_force(const std::vector<Path>& edges, int e_idx, int i, double kP) {
224224
const Path& edge = edges[e_idx];
225225

226226
return (edge[i - 1] + edge[i + 1] - edge[i] * 2) * kP;
227227
}
228228

229-
Point apply_electrostatic_force(const std::vector<Path>& edges,
229+
Point2 apply_electrostatic_force(const std::vector<Path>& edges,
230230
const std::vector< std::vector<int> >& comp,
231231
int e_idx, int i, double eps) {
232-
Point sum_of_forces;
232+
Point2 sum_of_forces;
233233
if (comp[e_idx].empty()) {
234234
return sum_of_forces;
235235
}
@@ -238,7 +238,7 @@ Point apply_electrostatic_force(const std::vector<Path>& edges,
238238

239239
for (size_t oe = 0; oe < compatible_edges.size(); ++oe) {
240240
const Path& edge2 = edges[compatible_edges[oe]];
241-
Point force = edge2[i] - edge[i];
241+
Point2 force = edge2[i] - edge[i];
242242
if ((std::abs(force.x) > eps) || (std::abs(force.y) > eps)) {
243243
double euc = edge2[i].distance_to(edge[i]);
244244
double diff = std::pow(euc, -1.0);
@@ -249,7 +249,7 @@ Point apply_electrostatic_force(const std::vector<Path>& edges,
249249
return sum_of_forces;
250250
}
251251

252-
std::vector<Point> apply_resulting_forces_on_subdivision_points(const std::vector<Path>& edges,
252+
std::vector<Point2> apply_resulting_forces_on_subdivision_Point2s(const std::vector<Path>& edges,
253253
const std::vector< std::vector<int> >& comp,
254254
int e_idx, int P,
255255
double S, double K,
@@ -258,16 +258,16 @@ std::vector<Point> apply_resulting_forces_on_subdivision_points(const std::vecto
258258

259259
double kP = K / (edge[0].distance_to(edge[P + 1], eps) * (P + 1));
260260

261-
std::vector<Point> resulting_forces_for_subdivision_points(P + 2);
261+
std::vector<Point2> resulting_forces_for_subdivision_Point2s(P + 2);
262262
for (int i = 1; i < (P + 1); ++i) {
263-
Point spring_force = apply_spring_force(edges, e_idx, i, kP);
263+
Point2 spring_force = apply_spring_force(edges, e_idx, i, kP);
264264

265-
Point electrostatic_force = apply_electrostatic_force(edges, comp, e_idx, i, eps);
265+
Point2 electrostatic_force = apply_electrostatic_force(edges, comp, e_idx, i, eps);
266266

267-
resulting_forces_for_subdivision_points[i] = (spring_force + electrostatic_force) * S;
267+
resulting_forces_for_subdivision_Point2s[i] = (spring_force + electrostatic_force) * S;
268268
}
269269

270-
return resulting_forces_for_subdivision_points;
270+
return resulting_forces_for_subdivision_Point2s;
271271
}
272272

273273

@@ -279,8 +279,8 @@ cpp11::writable::data_frame force_bundle_iter(cpp11::doubles_matrix<> edges_xy,
279279
// first division
280280
std::vector<Path> edges(m);
281281
for (R_xlen_t i = 0; i < m; ++i) {
282-
edges[i].push_back(Point(edges_xy(i, 0), edges_xy(i, 1)));
283-
edges[i].push_back(Point(edges_xy(i, 2), edges_xy(i, 3)));
282+
edges[i].push_back(Point2(edges_xy(i, 0), edges_xy(i, 1)));
283+
edges[i].push_back(Point2(edges_xy(i, 2), edges_xy(i, 3)));
284284
}
285285

286286
// compute compatibility list
@@ -291,9 +291,9 @@ cpp11::writable::data_frame force_bundle_iter(cpp11::doubles_matrix<> edges_xy,
291291
// main loop
292292
for (int cycle = 0; cycle < C; ++cycle) {
293293
for (int iteration = 0; iteration < I; ++iteration) {
294-
std::vector< std::vector<Point> > forces(m);
294+
std::vector< std::vector<Point2> > forces(m);
295295
for (R_xlen_t e = 0; e < m; ++e) {
296-
forces[e] = apply_resulting_forces_on_subdivision_points(edges, comp, e, P, S, K, eps);
296+
forces[e] = apply_resulting_forces_on_subdivision_Point2s(edges, comp, e, P, S, K, eps);
297297
}
298298
for (int e = 0; e < m; ++e) {
299299
for (int i = 0; i < (P + 1); ++i) {

0 commit comments

Comments
 (0)