Created
March 5, 2019 20:51
-
-
Save Ben1980/71a29de6b38516796368fe2157346660 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ParticleBuilder & ParticleBuilder::position(const Vector2D &position) | |
{ | |
mPosition = position; | |
return *this; | |
} | |
ParticleBuilder & ParticleBuilder::velocity(const Vector2D &velocity) | |
{ | |
mVelocity = velocity; | |
return *this; | |
} | |
ParticleBuilder & ParticleBuilder::acceleration(const Vector2D &acceleration) | |
{ | |
mAcceleration = acceleration; | |
return *this; | |
} | |
ParticleBuilder & ParticleBuilder::mass(double mass) | |
{ | |
mMass = mass; | |
return *this; | |
} | |
Particle ParticleBuilder::build() const | |
{ | |
return {mMass, mAcceleration, mVelocity, mPosition}; | |
} | |
std::vector<Particle> ParticleBuilder::build(size_t numberOfParticles) | |
{ | |
std::vector<Particle> particle(numberOfParticles); | |
std::mt19937 mt(std::random_device{}()); | |
std::uniform_real_distribution real_dist(1.0, static_cast<double>(numberOfParticles)); | |
for(Particle &p : particle) { | |
p = mass(real_dist(mt)) | |
.acceleration({ real_dist(mt), real_dist(mt) }) | |
.velocity({ real_dist(mt), real_dist(mt) }) | |
.position({ real_dist(mt), real_dist(mt) }) | |
.build(); | |
} | |
return particle; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment