#include "stdafx.h" #include "clumpplacer.h" #include "random.h" #include "pointmap.h" using namespace std; ClumpPlacer::ClumpPlacer(float size, float coherence, float smoothness, float failFraction, int x, int y) { this->size = size; this->coherence = coherence; this->smoothness = smoothness; this->x = x; this->y = y; this->failFraction = failFraction; } ClumpPlacer::~ClumpPlacer() { } bool ClumpPlacer::place(class Map* m, Constraint* constr, std::vector& retVec) { if(!m->validT(x, y) || !constr->allows(m, x, y)) { return false; } PointMap gotRet; float radius = sqrt(size / PI); float perim = 4 * radius * 2 * PI; int intPerim = (int)(ceil(perim)); vector noise(intPerim); int ctrlPts = 1 + (int)(1.0/max(smoothness,1.0f/intPerim)); if(ctrlPts > radius * 2 * PI) ctrlPts = (int) (radius * 2 * PI) + 1; vector ctrlCoords(ctrlPts+1); vector ctrlVals(ctrlPts+1); for(int i=0; ivalidT(i, j) && constr->allows(m, i, j)) { Point p(i,j); if(!gotRet[p]) { gotRet[p] = 1; retVec.push_back(p); } } else { failed++; } xx += s; yy += c; } } return (failed > size*failFraction ? false : true); }