Skip to content

Commit d6aca2a

Browse files
committed
iterator bug
1 parent 4d0b5ce commit d6aca2a

File tree

8 files changed

+30
-14
lines changed

8 files changed

+30
-14
lines changed

CMakeLists.txt

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 2.6)
1+
cmake_minimum_required(VERSION 2.8)
22
project(free_packingPFA)
33
set(BOOST_LIBS program_options)
44
set(LIBS_DIR third_party/boost/stage/lib/)
@@ -9,9 +9,9 @@ set(EXE_NAME "packer")
99
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wfatal-errors -std=c++11 -fopenmp")
1010

1111
# Options
12-
option(FORCE_UNPACK "Boost unpack forcing" 0) #Set to 1 to force local installation of Boost (ensure that it will take priority)
13-
option(DISPLAY "Display build" 0)
14-
option(DEBUG "Enable debug compilation flags" 0)
12+
option(FORCE_UNPACK "Boost unpack forcing") #Set to 1 to force local installation of Boost (ensure that it will take priority)
13+
option(DISPLAY "Display build")
14+
option(DEBUG "Enable debug compilation flags")
1515

1616
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMakeModules)
1717

@@ -30,6 +30,7 @@ endif ()
3030

3131
# Debug enabling (use it with cmake -DDEBUG=1 ..)
3232
if(${DEBUG})
33+
message(STATUS "Will build sebug configuration")
3334
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -g")
3435
else ()
3536
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")

conf/default.ce

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
HoleTransformer();
21
DO 2 TIMES
32
SimpleTransformer(rotate_step=30, criteria=intersection);
43
ScanlineSolver();

src/Layout.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void Layout::replaceShapes(std::vector<Shape>* s) {
4040
*/
4141
void Layout::push_back(const Shape& s) {
4242
if (usingQuads)
43-
_q->push_back(dynamic_cast<const QuadTree&>(s));
43+
_q->push_back(dynamic_cast<const QuadTree&>(s));
4444
else
4545
_s->push_back(s);
4646
}

src/Layout.hpp

+3
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ class Layout {
4444
Shape& operator[](unsigned n);
4545
void push_back(const Shape& s);
4646
void erase(unsigned n);
47+
bool useQuads() {
48+
return usingQuads;
49+
}
4750

4851
class iterator : public std::iterator <
4952
std::random_access_iterator_tag,

src/Shape.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef SHAPE__H
22
#define SHAPE__H
33

4+
#include <iostream> //need to remove after
45
#include <string>
56
#include <array>
67

@@ -40,6 +41,7 @@ class Shape {
4041
Shape(Point P1, Point P2, unsigned i1, unsigned i2, unsigned id) : _oldP1(P1),
4142
_oldP2(P2), _indexP1(i1), _indexP2(i2), _id(id) {}
4243
virtual Shape& operator=(const Shape& s) {
44+
std::cerr << "shape assignement called" << std::endl;
4345
_multiP = s._multiP;
4446
_oldP1 = s._oldP1;
4547
_oldP2 = s._oldP2;

src/quadtree/QuadTree.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ QuadTree::QuadTree(const QuadTree& q) : Shape(q) {
5656
* @param qi
5757
* @return the quadtree copied
5858
*/
59-
QuadTree& QuadTree::operator=(const QuadTree& q) {
59+
QuadTree& QuadTree::operator=(const Shape& s) {
60+
cerr << "quadtree assignement called" << endl;
61+
62+
const QuadTree &q = dynamic_cast<const QuadTree &>(s);
6063
if (this != &q) {
6164
destroy();
6265
Shape::operator=(q);
@@ -191,7 +194,7 @@ QuadTree::QuadTree(MultiPolygon& mult, float precision, unsigned id)
191194
*/
192195
bool QuadTree::intersectsWith(const Shape& s) const {
193196
cerr << "QuadTree intersect" << endl;
194-
const QuadTree& q = static_cast<const QuadTree &>(s);
197+
const QuadTree& q = dynamic_cast<const QuadTree &>(s);
195198
return trees[currentTree]->intersectsRec(*q.trees[q.currentTree], _totalX, _totalY,
196199
q._totalX, q._totalY);
197200
}

src/quadtree/QuadTree.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ class QuadTree : public Shape {
2828
void copy(const QuadTree&);
2929
void destroy();
3030
public:
31-
QuadTree(const QuadTree&); //copy operator
32-
QuadTree& operator=(const QuadTree&); //assignment operator
31+
QuadTree(const QuadTree&); //copy operator
32+
QuadTree& operator=(const Shape&) override; //assignment operator
3333
QuadTree& operator=(QuadTree&& q);
3434
~QuadTree();
3535

src/transformer/SimpleTransformer.cpp

+12-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "Merger.hpp"
1111
#include "Parser.hpp"
1212
#include "Display.hpp"
13+
#include "quadtree/QuadTree.hpp"
1314

1415
using namespace std;
1516

@@ -48,6 +49,9 @@ void applyTrans(Shape& a, Shape& b, double alpha, double beta, double offset, Bo
4849
* (uses precomputed boxA)
4950
*/
5051
double getClose(Shape& shapeA, Shape& shapeB, Box& boxA) {
52+
//QuadTree& q1 = dynamic_cast<QuadTree &>(shapeA);
53+
//QuadTree& q2 = dynamic_cast<QuadTree &>(shapeB);
54+
5155
//Dichotomy to find closest non-intersecting position (by translating on the x-axis)
5256
double x1, x2, mid;
5357
x1 = boxA.min_corner().x();
@@ -73,6 +77,8 @@ vector<vector<unsigned> > SimpleTransformer::transform() {
7377
LOG(info) << "Merging shapes";
7478
vector<vector<unsigned> > ret;
7579
vector<bool> mergedV(_shapes.size(), false);
80+
81+
cerr << "USE QUADS :" << _shapes.useQuads() << endl;
7682
//Initial shufle
7783
random_shuffle(_shapes.begin(), _shapes.end());
7884

@@ -85,7 +91,7 @@ vector<vector<unsigned> > SimpleTransformer::transform() {
8591
double bestAlpha = 0., bestBeta = 0., bestMid = 0; //Best rotations
8692
int bestOffset = 0.; //Best translation
8793
double bestArea = 0.; //Best area of merged couples of shapes
88-
unsigned j = i + 1;
94+
unsigned j = i + 1;
8995
unsigned bestJ = j;
9096
//Move shapes
9197
bool merged = false; //Check if a merge occured
@@ -95,9 +101,11 @@ vector<vector<unsigned> > SimpleTransformer::transform() {
95101
for (int beta = 0.; beta < 360 ; beta += _rotateStep) { //Rotate second shape
96102
for (int offset = 0; offset < _translateNb ; ++offset) { //Trying different offsets
97103
Box boxA, boxB;
98-
Shape shapeA, shapeB;
99-
shapeA = _shapes[i];
100-
shapeB = _shapes[j];
104+
Shape shapeA = _shapes[i];
105+
Shape shapeB = _shapes[j];
106+
//QuadTree& q1 = dynamic_cast<QuadTree &>(_shapes[i]);
107+
//QuadTree& q2 = dynamic_cast<QuadTree &>(_shapes[j]);
108+
101109
applyTrans(shapeA, shapeB, alpha, beta, static_cast<double>(offset) / _translateNb, boxA,
102110
boxB, 0, true);
103111
double mid = getClose(shapeA, shapeB, boxA);

0 commit comments

Comments
 (0)