PicoGraphics: Use std:: prefix, fix some type issues.

This commit is contained in:
Phil Howard 2023-05-25 12:10:49 +01:00
parent 09a58b269f
commit e8dba75aff
3 changed files with 17 additions and 22 deletions

View File

@ -2,8 +2,6 @@
#include <cstdint>
#include <math.h>
using namespace std;
#ifdef PP_DEBUG
#define debug(...) printf(__VA_ARGS__)
#else
@ -81,14 +79,14 @@ namespace pretty_poly {
rect_t(int x, int y, int w, int h) : x(x), y(y), w(w), h(h) {}
bool empty() const {return this->w == 0 && this->h == 0;}
rect_t intersection(const rect_t &c) {
return rect_t(max(this->x, c.x), max(this->y, c.y),
max(0, min(this->x + this->w, c.x + c.w) - max(this->x, c.x)),
max(0, min(this->y + this->h, c.y + c.h) - max(this->y, c.y)));
return rect_t(std::max(this->x, c.x), std::max(this->y, c.y),
std::max(0, std::min(this->x + this->w, c.x + c.w) - std::max(this->x, c.x)),
std::max(0, std::min(this->y + this->h, c.y + c.h) - std::max(this->y, c.y)));
}
rect_t merge(const rect_t &c) {
return rect_t(min(this->x, c.x), min(this->y, c.y),
max(this->x + this->w, c.x + c.w) - min(this->x, c.x),
max(this->y + this->h, c.y + c.h) - min(this->y, c.y));
return rect_t(std::min(this->x, c.x), std::min(this->y, c.y),
std::max(this->x + this->w, c.x + c.w) - std::min(this->x, c.x),
std::max(this->y + this->h, c.y + c.h) - std::min(this->y, c.y));
}
};
@ -110,17 +108,17 @@ namespace pretty_poly {
unsigned count;
contour_t() {}
contour_t(vector<point_t<T>> v) : points(v.data()), count(v.size()) {};
contour_t(std::vector<point_t<T>> v) : points(v.data()), count(v.size()) {};
contour_t(point_t<T> *points, unsigned count) : points(points), count(count) {};
rect_t bounds() {
T minx = this->points[0].x, maxx = minx;
T miny = this->points[0].y, maxy = miny;
for(auto i = 1u; i < this->count; i++) {
minx = min(minx, this->points[i].x);
miny = min(miny, this->points[i].y);
maxx = max(maxx, this->points[i].x);
maxy = max(maxy, this->points[i].y);
minx = std::min(minx, this->points[i].x);
miny = std::min(miny, this->points[i].y);
maxx = std::max(maxx, this->points[i].x);
maxy = std::max(maxy, this->points[i].y);
}
return rect_t(minx, miny, maxx - minx, maxy - miny);
}

View File

@ -5,9 +5,6 @@
#include <new>
using namespace std;
#ifdef PP_DEBUG
#define debug(...) printf(__VA_ARGS__)
#else
@ -92,8 +89,8 @@ namespace pretty_poly {
int sx = start.x, sy = start.y, ex = end.x, ey = end.y;
if(ey < sy) {
swap(sy, ey);
swap(sx, ex);
std::swap(sy, ey);
std::swap(sx, ex);
}
/*sx <<= settings::antialias;
@ -120,7 +117,7 @@ namespace pretty_poly {
if(y >= 0 && y < (int)node_buffer_size) {
// clamp node x value to tile bounds
int nx = max(min(x, (int)(tile_bounds.w << settings::antialias)), 0);
int nx = std::max(std::min(x, (int)(tile_bounds.w << settings::antialias)), 0);
debug(" + adding node at %d, %d\n", x, y);
// add node to node list
nodes[y][node_counts[y]++] = nx;

View File

@ -309,7 +309,7 @@ mp_obj_t ModPicoGraphics_make_new(const mp_obj_type_t *type, size_t n_args, size
_PimoroniBus_obj_t *bus = (_PimoroniBus_obj_t *)MP_OBJ_TO_PTR(args[ARG_bus].u_obj);
parallel_bus = *(ParallelPins *)(bus->pins);
} else if (mp_obj_is_exact_type(args[ARG_bus].u_obj, &PimoroniI2C_type) || mp_obj_is_exact_type(args[ARG_bus].u_obj, &machine_hw_i2c_type)) {
} else if (mp_obj_is_exact_type(args[ARG_bus].u_obj, &PimoroniI2C_type) || mp_obj_is_exact_type(args[ARG_bus].u_obj, &machine_i2c_type)) {
if(bus_type != BUS_I2C) mp_raise_ValueError("unexpected I2C bus!");
self->i2c = PimoroniI2C_from_machine_i2c_or_native(args[ARG_bus].u_obj);
i2c_bus = (pimoroni::I2C *)(self->i2c->i2c);
@ -1041,7 +1041,7 @@ mp_obj_t ModPicoGraphics_pretty_polygon(size_t n_args, const mp_obj_t *pos_args,
std::vector<pretty_poly::contour_t<int>> contours;
for(auto i = 0; i < num_tuples; i++) {
for(auto i = 0u; i < num_tuples; i++) {
mp_obj_t c_obj = lists[i];
if(!mp_obj_is_exact_type(c_obj, &mp_type_list)) mp_raise_ValueError("Not a list");
@ -1050,7 +1050,7 @@ mp_obj_t ModPicoGraphics_pretty_polygon(size_t n_args, const mp_obj_t *pos_args,
pretty_poly::point_t<int> *points = new pretty_poly::point_t<int>[t_contour->len];
for(auto p = 0; p < t_contour->len; p++) {
for(auto p = 0u; p < t_contour->len; p++) {
mp_obj_t p_obj = t_contour->items[p];
if(!mp_obj_is_exact_type(p_obj, &mp_type_tuple)) mp_raise_ValueError("Not a tuple");