Skip to content

Commit

Permalink
PicoGraphics: Use std:: prefix, fix some type issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gadgetoid committed Aug 4, 2023
1 parent beeae65 commit e4349cc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 22 deletions.
24 changes: 11 additions & 13 deletions libraries/pico_graphics/pretty-poly-types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
#include <cstdint>
#include <math.h>

using namespace std;

#ifdef PP_DEBUG
#define debug(...) printf(__VA_ARGS__)
#else
Expand Down Expand Up @@ -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));
}
};

Expand All @@ -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);
}
Expand Down
9 changes: 3 additions & 6 deletions libraries/pico_graphics/pretty-poly.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
#include <new>



using namespace std;

#ifdef PP_DEBUG
#define debug(...) printf(__VA_ARGS__)
#else
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions micropython/modules/picographics/picographics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -1039,7 +1039,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");
Expand All @@ -1048,7 +1048,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");
Expand Down

0 comments on commit e4349cc

Please sign in to comment.