Skip to content

Commit 66c5eed

Browse files
committed
fixed map bug
1 parent 5ba4d6f commit 66c5eed

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/geometry/planar.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,16 +301,20 @@ std::vector<Point> interSegSeg(Line l1, Line l2){
301301
std::pair<std::vector<Point>, std::vector<std::vector<size_t>>> build_graph(std::vector<Line> segments) {
302302
std::vector<Point> p;
303303
std::vector<std::vector<size_t>> adj;
304-
std::map<Point, size_t> point_id;
304+
std::map<std::pair<int64_t, int64_t>, size_t> point_id;
305305
auto get_point_id = [&](Point pt) {
306-
if (!point_id.count(pt)) {
306+
auto repr = std::make_pair(
307+
int64_t(std::round(pt.x * 1000000000) + 1e-6),
308+
int64_t(std::round(pt.y * 1000000000) + 1e-6)
309+
);
310+
if (!point_id.count(repr)) {
307311
adj.emplace_back();
308312
size_t id = point_id.size();
309-
point_id[pt] = id;
313+
point_id[repr] = id;
310314
p.push_back(pt);
311315
return id;
312316
} else {
313-
return point_id[pt];
317+
return point_id[repr];
314318
}
315319
};
316320
for (size_t i = 0; i < segments.size(); i++) {

test/test_planar_implicit.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#include <assert.h>
33
#include <cmath>
44
#include <map>
5+
#include <stdint.h>
6+
#include <utility>
57
#include <vector>
68

79
#include "planar_implicit.h"

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy