Skip to content

Commit

Permalink
Merge pull request #134 from orange-vertex/cleanup_remove_pqmap_point_h
Browse files Browse the repository at this point in the history
Remove paftl from point.h (and thus replace pqmap with std::map)
  • Loading branch information
pklampros authored Mar 7, 2018
2 parents 96eb854 + 2102a4a commit f4e574d
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 41 deletions.
21 changes: 11 additions & 10 deletions salaTest/testsparksieve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@

#include "catch.hpp"
#include "salalib/sparksieve2.h"
#include <map>


TEST_CASE("One block garbage")
{
Point2f centre(1,1);
sparkSieve2 sieve(centre);
pqmap<int, Line> lines;
std::map<int, Line> lines;
// these lines get turned into "blocks" based by a tanify function based on q and the centre given
// above. Given q=4 and centre 1,1 this line will be from 0.625 to something bigger than 1
lines.add(1, Line(Point2f(0.5, 0.2), Point2f(0.5, 0.7)));
lines[1] = Line(Point2f(0.5, 0.2), Point2f(0.5, 0.7));
sieve.block(lines,4);
sieve.collectgarbage();
REQUIRE(sieve.m_gaps.size() == 1);
Expand All @@ -37,11 +38,11 @@ TEST_CASE("Shift start and end")
{
Point2f centre(1,1);
sparkSieve2 sieve(centre);
pqmap<int, Line> lines;
std::map<int, Line> lines;
// .625 -> > 1
lines.add(1, Line(Point2f(0.5, 0.2), Point2f(0.5, 0.7)));
lines.insert(std::make_pair(1, Line(Point2f(0.5, 0.2), Point2f(0.5, 0.7))));
// < 0 -> 0.55555557
lines.add(2, Line(Point2f(0.5,0.1),Point2f(1.1,0.9)));
lines.insert(std::make_pair(2, Line(Point2f(0.5,0.1),Point2f(1.1,0.9))));
sieve.block(lines,4);
sieve.collectgarbage();
REQUIRE(sieve.m_gaps.size() == 1);
Expand All @@ -53,9 +54,9 @@ TEST_CASE("delete gap")
{
Point2f centre(1,1);
sparkSieve2 sieve(centre);
pqmap<int, Line> lines;
std::map<int, Line> lines;
// < 0 -> > 1 the block covers the whole gap
lines.add(1, Line(Point2f(1.1, 0.2), Point2f(0.5, 0.7)));
lines.insert(std::make_pair(1, Line(Point2f(1.1, 0.2), Point2f(0.5, 0.7))));
sieve.block(lines,4);
sieve.collectgarbage();
REQUIRE(sieve.m_gaps.empty());
Expand All @@ -65,11 +66,11 @@ TEST_CASE("add gap")
{
Point2f centre(1,1);
sparkSieve2 sieve(centre);
pqmap<int, Line> lines;
std::map<int, Line> lines;
// 0.55555 -> .625 the block splits the gap
lines.add(1, Line(Point2f(0.5, 0.2), Point2f(0.5, 0.1)));
lines.insert(std::make_pair(1, Line(Point2f(0.5, 0.2), Point2f(0.5, 0.1))));
// 0.71428571 -> > 1
lines.add(2, Line(Point2f(0.5,0.3), Point2f(0.5,0.7)));
lines.insert(std::make_pair(2, Line(Point2f(0.5,0.3), Point2f(0.5,0.7))));
sieve.block(lines,4);
sieve.collectgarbage();
REQUIRE(sieve.m_gaps.size() == 2);
Expand Down
12 changes: 6 additions & 6 deletions salalib/ngraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ struct PixelVec
//
std::istream &read(std::istream &stream, int version, const char dir);
std::istream &read(std::istream &stream, int version, const char dir, const PixelVec& context);
ofstream& write(ofstream& stream, const char dir);
ofstream& write(ofstream& stream, const char dir, const PixelVec& context);
std::ofstream& write(std::ofstream& stream, const char dir);
std::ofstream& write(std::ofstream& stream, const char dir, const PixelVec& context);
};

class Bin
Expand Down Expand Up @@ -94,9 +94,9 @@ class Bin
PixelRef cursor() const;
//
std::istream &read(std::istream &stream, int version);
ofstream& write(ofstream& stream, int version);
std::ofstream& write(std::ofstream& stream, int version);
//
friend ostream& operator << (ostream& stream, const Bin& bin);
friend std::ostream& operator << (std::ostream& stream, const Bin& bin);
};

class Node
Expand Down Expand Up @@ -158,9 +158,9 @@ class Node
PixelRef cursor() const;
//
std::istream &read(std::istream &stream, int version);
ofstream& write(ofstream& stream, int version);
std::ofstream& write(std::ofstream& stream, int version);
//
friend ostream& operator << (ostream& stream, const Node& node);
friend std::ostream& operator << (std::ostream& stream, const Node& node);
};

// Two little helpers:
Expand Down
4 changes: 2 additions & 2 deletions salalib/point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ float Point::getBinDistance(int i)
return m_node->bindistance(i);
}

istream& Point::read(istream& stream, int version, int attr_count)
std::istream& Point::read(std::istream& stream, int version, int attr_count)
{
if (m_node) {
delete m_node;
Expand Down Expand Up @@ -59,7 +59,7 @@ istream& Point::read(istream& stream, int version, int attr_count)
return stream;
}

ofstream& Point::write(ofstream& stream, int version)
std::ofstream& Point::write(std::ofstream& stream, int version)
{
stream.write( (char *) &m_state, sizeof(m_state) );
// block is the same size as m_noderef used to be for ease of replacement:
Expand Down
4 changes: 2 additions & 2 deletions salalib/point.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#include "genlib/p2dpoly.h"
#include "salalib/pixelref.h"
#include "genlib/paftl.h"
#include <map>

class Node;

Expand Down Expand Up @@ -56,7 +56,7 @@ class Point {
// hmm... this is for my 3rd attempt at a quick line intersect algo:
// every line that goes through the gridsquare -- memory intensive I know, but what can you do:
// accuracy is imperative here! Calculated pre-fillpoints / pre-makegraph, and (importantly) it works.
pqmap<int,Line> m_lines;
std::map<int,Line> m_lines;
int m_processflag;
public:
Point()
Expand Down
27 changes: 15 additions & 12 deletions salalib/pointdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,12 +517,16 @@ bool PointMap::blockLines()
PixelRef curs = PixelRef( i, j );
Point& pt = getPoint( curs );
QtRegion viewport = regionate( curs, 1e-10 );
for (size_t k = pt.m_lines.size() - 1; k != paftl::npos; k--) {
if (!pt.m_lines.value(k).crop( viewport )) {
// the pixelation is fairly rough to make sure that no point is missed: this just
// clears up if any point has been added in error:
pt.m_lines.remove_at(k);
}
std::map<int, Line>::iterator iter = pt.m_lines.begin(), end = pt.m_lines.end();
for(; iter != end; ) {
if (!iter->second.crop( viewport )) {
// the pixelation is fairly rough to make sure that no point is missed: this just
// clears up if any point has been added in error:
iter = pt.m_lines.erase(iter);
end = pt.m_lines.end();
} else {
++iter;
}
}
}
}
Expand All @@ -539,7 +543,7 @@ void PointMap::blockLine(int key, const Line& li)
// although it may catch extra points...
for (size_t n = 0; n < pixels.size(); n++)
{
getPoint(pixels[n]).m_lines.add(key,li);
getPoint(pixels[n]).m_lines.insert(std::make_pair(key,li));
getPoint(pixels[n]).setBlock(true);
}
}
Expand Down Expand Up @@ -2164,13 +2168,12 @@ bool PointMap::sparkPixel2(PixelRef curs, int make, double maxdist)
viewport0.top_right.y = centre0.y;
break;
}
pqmap<int,Line> lines0;
for (size_t m = 0; m < getPoint(curs).m_lines.size(); m++)
std::map<int,Line> lines0;
for (const std::pair<int,Line>& line: getPoint(curs).m_lines)
{
int key = getPoint(curs).m_lines.key(m);
Line l = getPoint(curs).m_lines.value(m);
Line l = line.second;
if (l.crop(viewport0)) {
lines0.add(key,l);
lines0.insert(std::make_pair(line.first,l));
}
}
sieve.block(lines0, q);
Expand Down
14 changes: 7 additions & 7 deletions salalib/sparksieve2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ sparkSieve2::~sparkSieve2()
{
}

bool sparkSieve2::testblock( const Point2f& point, const pqmap<int,Line>& lines, double tolerance )
bool sparkSieve2::testblock( const Point2f& point, const std::map<int,Line>& lines, double tolerance )
{
Line l(m_centre, point);

Expand All @@ -52,10 +52,10 @@ bool sparkSieve2::testblock( const Point2f& point, const pqmap<int,Line>& lines,
return true;
}

for (size_t i = 0; i < lines.size(); i++)
for (auto line: lines)
{
// Note: must check regions intersect before using this intersect_line test -- see notes on intersect_line
if (intersect_region(l,lines.value(i),tolerance) && intersect_line(l,lines.value(i),tolerance)) {
if (intersect_region(l,line.second,tolerance) && intersect_line(l,line.second,tolerance)) {
return true;
}
}
Expand All @@ -65,11 +65,11 @@ bool sparkSieve2::testblock( const Point2f& point, const pqmap<int,Line>& lines,

//

void sparkSieve2::block( const pqmap<int,Line>& lines, int q )
void sparkSieve2::block( const std::map<int,Line>& lines, int q )
{
for (size_t i = 0; i < lines.size(); i++) {
double a = tanify(lines.value(i).start(), q);
double b = tanify(lines.value(i).end(), q);
for (auto line: lines) {
double a = tanify(line.second.start(), q);
double b = tanify(line.second.end(), q);

sparkZone2 block;
if (a < b) {
Expand Down
5 changes: 3 additions & 2 deletions salalib/sparksieve2.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "genlib/p2dpoly.h"
#include "genlib/paftl.h"
#include <list>
#include <map>

class sparkSieve2
{
Expand All @@ -50,8 +51,8 @@ class sparkSieve2
public:
sparkSieve2( const Point2f& centre, double maxdist = -1.0 );
~sparkSieve2();
bool testblock( const Point2f& point, const pqmap<int,Line>& lines, double tolerance );
void block( const pqmap<int,Line>& lines, int q );
bool testblock(const Point2f& point, const std::map<int, Line> &lines, double tolerance );
void block(const std::map<int, Line> &lines, int q );
void collectgarbage();
double tanify( const Point2f& point, int q );
//
Expand Down

0 comments on commit f4e574d

Please sign in to comment.