1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
// This file may be redistributed and modified only under the terms of
// the GNU General Public License (See COPYING for details).
// Copyright (C) 2004 Alistair Riddoch
#include <Mercator/Forest.h>
#include <Mercator/Plant.h>
#include <Mercator/Area.h>
#include <iostream>
#ifdef NDEBUG
#undef NDEBUG
#endif
#ifndef DEBUG
#define DEBUG
#endif
#include <cassert>
typedef WFMath::Point<2> Point2;
void dumpPlants(const Mercator::Forest::PlantStore & plants)
{
Mercator::Forest::PlantStore::const_iterator I = plants.begin();
for(; I != plants.end(); ++I) {
Mercator::Forest::PlantColumn::const_iterator J = I->second.begin();
for(; J != I->second.end(); ++J) {
const Mercator::Plant & p = J->second;
std::cout << "Query found plant at [" << I->first
<< ", " << J->first << "] with height "
<< p.getHeight();
std::cout << " displaced to "
<< (WFMath::Vector<2>(I->first, J->first) +
p.getDisplacement())
<< std::endl << std::flush;
}
}
}
int countPlants(const Mercator::Forest::PlantStore & plants)
{
int plant_count = 0;
Mercator::Forest::PlantStore::const_iterator I = plants.begin();
for(; I != plants.end(); ++I) {
plant_count += I->second.size();
}
return plant_count;
}
int main()
{
// Test constructor
{
Mercator::Forest mf;
}
// Test constructor
{
Mercator::Forest mf(23);
}
// Test getArea()
{
Mercator::Forest mf;
Mercator::Area * a = mf.getArea();
assert(a == 0);
}
// Test species()
{
Mercator::Forest mf;
Mercator::Forest::PlantSpecies & mps = mf.species();
assert(mps.empty());
}
{
Mercator::Forest forest(4249162ul);
Mercator::Forest::PlantSpecies & species = forest.species();
const Mercator::Forest::PlantStore & plants = forest.getPlants();
// Forest is not yet populated
assert(plants.empty());
assert(species.empty());
forest.populate();
// Forest has zero area, so even when populated it is empty
assert(plants.empty());
assert(species.empty());
Mercator::Area* ar = new Mercator::Area(1, false);
WFMath::Polygon<2> p;
p.addCorner(p.numCorners(), Point2(5, 8));
p.addCorner(p.numCorners(), Point2(40, -1));
p.addCorner(p.numCorners(), Point2(45, 16));
p.addCorner(p.numCorners(), Point2(30, 28));
p.addCorner(p.numCorners(), Point2(-2, 26));
p.addCorner(p.numCorners(), Point2(1, 5));
ar->setShape(p);
forest.setArea(ar);
forest.populate();
// Forest has no species, so even when populated it is empty
assert(plants.empty());
assert(species.empty());
{
Mercator::Species pine;
pine.m_probability = 0.04;
pine.m_deviation = 1.f;
species.push_back(pine);
}
forest.populate();
// Forest should now contain some plants
assert(!plants.empty());
dumpPlants(plants);
int plant_count = countPlants(plants);
{
Mercator::Species oak;
oak.m_probability = 0.02;
oak.m_deviation = 1.f;
species.push_back(oak);
}
forest.populate();
// Forest should now contain some plants
assert(!plants.empty());
assert(countPlants(plants) > plant_count);
dumpPlants(plants);
std::cout << countPlants(plants) << "," << plant_count
<< std::endl << std::flush;
}
}
|