Removed random engine, using libscnumerics instead

This commit is contained in:
Bob Polis 2021-10-06 11:24:36 +02:00
parent f3b95b0419
commit 42313b010a
2 changed files with 9 additions and 11 deletions

View File

@ -7,6 +7,7 @@
//
#include "ScreensaverPlugin.hpp"
#include <libscnumerics.hpp>
void ScreensaverPlugin::setup(cairo_t* context, const cairo_rectangle_t& rect) {
_c = context;
@ -33,8 +34,8 @@ cairo_rectangle_t ScreensaverPlugin::random_rect_in_rect(const cairo_rectangle_t
std::uniform_real_distribution<double> dx {rect.x, rect.width};
std::uniform_real_distribution<double> dy {rect.y, rect.height};
double v1, v2;
v1 = dx(_eng);
v2 = dx(_eng);
v1 = dx(sc::random::instance().engine());
v2 = dx(sc::random::instance().engine());
if (v1 < v2) {
r.x = v1;
r.width = v2 - v1;
@ -42,8 +43,8 @@ cairo_rectangle_t ScreensaverPlugin::random_rect_in_rect(const cairo_rectangle_t
r.x = v2;
r.width = v1 - v2;
}
v1 = dy(_eng);
v2 = dy(_eng);
v1 = dy(sc::random::instance().engine());
v2 = dy(sc::random::instance().engine());
if (v1 < v2) {
r.y = v1;
r.height = v2 - v1;
@ -56,22 +57,22 @@ cairo_rectangle_t ScreensaverPlugin::random_rect_in_rect(const cairo_rectangle_t
double ScreensaverPlugin::random_x() {
std::uniform_real_distribution<double> dist {0, _r.width};
return dist(_eng);
return dist(sc::random::instance().engine());
}
double ScreensaverPlugin::random_y() {
std::uniform_real_distribution<double> dist {0, _r.height};
return dist(_eng);
return dist(sc::random::instance().engine());
}
double ScreensaverPlugin::random01() {
std::uniform_real_distribution<double> dist {};
return dist(_eng);
return dist(sc::random::instance().engine());
}
double ScreensaverPlugin::random_between(double v1, double v2) {
std::uniform_real_distribution<double> dist {v1, v2};
return dist(_eng);
return dist(sc::random::instance().engine());
}
void ScreensaverPlugin::rounded_rect(const cairo_rectangle_t& rect, double radius) {

View File

@ -10,7 +10,6 @@
#define _ScreensaverPlugin_H_
#include <cairo/cairo.h>
#include <random>
class ScreensaverPlugin {
public:
@ -26,8 +25,6 @@ class ScreensaverPlugin {
protected:
cairo_t* _c {nullptr};
cairo_rectangle_t _r {};
std::random_device _dev {};
std::default_random_engine _eng {_dev()};
void make_black();
cairo_rectangle_t random_rect();