Skip to content

Commit

Permalink
Refactored Zone and Block. Created base class for areas in libcity "A…
Browse files Browse the repository at this point in the history
…rea".

New class -- Lot. Fixed unit tests, everything up and running.
  • Loading branch information
pazdera committed Apr 26, 2011
1 parent 2ef8e4b commit 4b84389
Show file tree
Hide file tree
Showing 16 changed files with 287 additions and 81 deletions.
17 changes: 12 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ GEOMETRY_PACKAGE=src/geometry/curve.o \
src/geometry/ray.o

# Streetgraph package
STREETGRAPH_PACKAGE=src/streetgraph/zone.o \
src/streetgraph/intersection.o \
STREETGRAPH_PACKAGE=src/streetgraph/intersection.o \
src/streetgraph/road.o \
src/streetgraph/primaryroad.o \
src/streetgraph/secondaryroad.o \
Expand All @@ -42,14 +41,20 @@ LSYSTEM_PACKAGE=src/lsystem/lsystem.o \
src/lsystem/graphiclsystem.o \
src/lsystem/roadlsystem.o

# Area package
AREA_PACKAGE=src/area/block.o \
src/area/area.o \
src/area/zone.o \
src/area/lot.o

# Buildings package
BUILDINGS_PACKAGE=src/buildings/block.o
BUILDINGS_PACKAGE=

# No package
MISC=src/random.o \
src/city.o

LIB_OBJECTS=$(GEOMETRY_PACKAGE) $(STREETGRAPH_PACKAGE) $(LSYSTEM_PACKAGE) $(BUILDINGS_PACKAGE) $(MISC)
LIB_OBJECTS=$(GEOMETRY_PACKAGE) $(STREETGRAPH_PACKAGE) $(LSYSTEM_PACKAGE) $(AREA_PACKAGE) $(BUILDINGS_PACKAGE) $(MISC)

$(LIB_OBJECTS): %.o: %.cpp %.h
$(COMPILER) $(COMPILER_FLAGS) -c $< -o $@
Expand All @@ -72,7 +77,9 @@ TEST_UNITS=test/testPoint.o \
test/testAreaExtractor.o \
test/testPath.o \
test/testRay.o \
test/testBlock.o
test/testBlock.o \
test/testLot.o \
test/testZone.o

TEST_MAIN=test/main.o
TEST_OBJECTS=$(TEST_UNITS) $(TEST_MAIN)
Expand Down
9 changes: 6 additions & 3 deletions include/libcity.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,20 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "../src/streetgraph/path.h"
#include "../src/streetgraph/intersection.h"
#include "../src/streetgraph/streetgraph.h"
#include "../src/streetgraph/zone.h"
#include "../src/streetgraph/rasterroadpattern.h"
#include "../src/streetgraph/organicroadpattern.h"
#include "../src/streetgraph/areaextractor.h"

#include "../src/area/area.h"
#include "../src/area/zone.h"
#include "../src/area/block.h"
#include "../src/area/lot.h"


#include "../src/lsystem/lsystem.h"
#include "../src/lsystem/graphiclsystem.h"
#include "../src/lsystem/roadlsystem.h"

#include "../src/buildings/block.h"

#include "../src/random.h"
#include "../src/city.h"
#include "../src/debug.h"
Expand Down
75 changes: 75 additions & 0 deletions src/area/area.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/**
* This code is part of libcity library.
*
* @file area/area.cpp
* @date 26.04.2011
* @author Radek Pazdera ([email protected])
*
* @see lot.h
*
*/

#include "area.h"

#include "../debug.h"
#include "../geometry/units.h"
#include "../geometry/point.h"
#include "../geometry/polygon.h"
#include "../geometry/vector.h"

Area::Area()
{
initialize();
}

Area::Area(Area const& source)
{
initialize();

*constraints = *(source.constraints);
parentArea = source.parentArea;
}

void Area::initialize()
{
parentArea = 0;
constraints = new Polygon();
}

Area& Area::operator=(Area const& source)
{
*constraints = *(source.constraints);
parentArea = source.parentArea;

return *this;
}

Area::~Area()
{
freeMemory();
}

void Area::freeMemory()
{
delete constraints;
}

Polygon Area::areaConstraints()
{
return *constraints;
}

void Area::setAreaConstraints(Polygon const& area)
{
*constraints = area;
}

void Area::setParent(Area* area)
{
parentArea = area;
}

Area* Area::parent()
{
return parentArea;
}
51 changes: 51 additions & 0 deletions src/area/area.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* This code is part of libcity library.
*
* @file area/area.h
* @date 26.04.2011
* @author Radek Pazdera ([email protected])
*
* @brief Base class for city areas (zones, districts, blocks, alottments).
*
*/

#ifndef _AREA_H_
#define _AREA_H_

/* STL */
#include <vector>
#include <list>
#include <map>

class Polygon;
class StreetGraph;
class RoadLSystem;
class Intersection;
class Block;

class Area;
class Area
{
public:
Area();
virtual ~Area();

Area(Area const& source);
Area& operator=(Area const& source);

virtual void setAreaConstraints(Polygon const& area);
virtual Polygon areaConstraints();

virtual void setParent(Area* area);
virtual Area* parent();

protected:
Polygon* constraints;
Area* parentArea;

private:
void initialize();
void freeMemory();
};

#endif
44 changes: 10 additions & 34 deletions src/buildings/block.cpp → src/area/block.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* This code is part of libcity library.
*
* @file buildings/block.cpp
* @file area/block.cpp
* @date 25.04.2011
* @author Radek Pazdera ([email protected])
*
Expand All @@ -16,7 +16,8 @@
#include "../geometry/point.h"
#include "../geometry/polygon.h"
#include "../geometry/vector.h"
#include "../streetgraph/zone.h"
#include "zone.h"
#include "lot.h"

Block::Block()
{
Expand All @@ -26,65 +27,40 @@ Block::Block()
Block::Block(Zone* parentZone)
{
initialize();
associatedZone = parentZone;
setParent(parentZone);
}

Block::Block(Zone* parentZone, Polygon const& border)
{
initialize();
associatedZone = parentZone;
*constraints = border;
setParent(parentZone);
setAreaConstraints(border);
}

Block::Block(Block const& source)
: Area(source)
{
initialize();

associatedZone = source.associatedZone;
*constraints = *(source.constraints);
}

void Block::initialize()
{
constraints = new Polygon();
lots.clear();
}

Block& Block::operator=(Block const& source)
{
reset();

associatedZone = source.associatedZone;
*constraints = *(source.constraints);
Area::operator=(source);

return *this;
}

void Block::reset()
{
constraints->clear();
}

Block::~Block()
{
freeMemory();
}

void Block::freeMemory()
{
delete constraints;
lots.clear();
}

Polygon Block::areaConstraints()
{
return *constraints;
}

void Block::setAreaConstraints(Polygon const& area)
{
*constraints = area;
}

void Block::setZone(Zone* zone)
{
associatedZone = zone;
}
19 changes: 9 additions & 10 deletions src/buildings/block.h → src/area/block.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* This code is part of libcity library.
*
* @file buildings/block.h
* @file area/block.h
* @date 25.04.2011
* @author Radek Pazdera ([email protected])
*
Expand All @@ -12,15 +12,20 @@
#ifndef _BLOCK_H_
#define _BLOCK_H_

/* STL */
#include <string>

/* libcity */
#include "area.h"

class LineSegment;
class Point;
class Vector;
class Polygon;
class Zone;
class Lot;

class Block
class Block : public Area
{
public:
Block();
Expand All @@ -32,17 +37,11 @@ class Block

~Block();

Polygon areaConstraints();
void setAreaConstraints(Polygon const& area);

void setZone(Zone* zone);
private:
std::list<Lot*> lots;

void initialize();
void reset();
void freeMemory();

Polygon* constraints;
Zone* associatedZone;
};


Expand Down
56 changes: 56 additions & 0 deletions src/area/lot.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* This code is part of libcity library.
*
* @file area/lot.cpp
* @date 26.04.2011
* @author Radek Pazdera ([email protected])
*
* @see lot.h
*
*/

#include "lot.h"

#include "../debug.h"
#include "../geometry/units.h"
#include "../geometry/point.h"
#include "../geometry/polygon.h"
#include "../geometry/vector.h"
#include "block.h"

Lot::Lot()
{
initialize();
}

Lot::Lot(Block* parentBlock)
{
initialize();
setParent(parentBlock);
}

Lot::Lot(Lot const& source)
: Area(source)
{
initialize();
}

void Lot::initialize()
{
}

Lot& Lot::operator=(Lot const& source)
{
Area::operator=(source);

return *this;
}

Lot::~Lot()
{
freeMemory();
}

void Lot::freeMemory()
{
}
Loading

0 comments on commit 4b84389

Please sign in to comment.