static int circle_collision(starshp1_state *state, const rectangle *rect) { int center_x = get_circle_hpos(state); int center_y = get_circle_vpos(state); int r = get_radius(state); return point_in_circle(rect->min_x, rect->min_y, center_x, center_y, r) || point_in_circle(rect->min_x, rect->max_y, center_x, center_y, r) || point_in_circle(rect->max_x, rect->min_y, center_x, center_y, r) || point_in_circle(rect->max_x, rect->max_y, center_x, center_y, r); }
inline bool box_in_circle(B const& b, C const& c) { typedef typename point_type<B>::type point_type; // Currently only implemented for 2d geometries assert_dimension<point_type, 2>(); assert_dimension<C, 2>(); // Box: all four points must lie within circle // Check points lower-left and upper-right, then lower-right and upper-left return point_in_circle(get<min_corner, 0>(b), get<min_corner, 1>(b), c) && point_in_circle(get<max_corner, 0>(b), get<max_corner, 1>(b), c) && point_in_circle(get<min_corner, 0>(b), get<max_corner, 1>(b), c) && point_in_circle(get<max_corner, 0>(b), get<min_corner, 1>(b), c); }
inline bool point_in_circle(T const& c1, T const& c2, C const& c) { typedef typename point_type<C>::type point_type; point_type p = geometry::make<point_type>(c1, c2); return point_in_circle(p, c); }
unsigned long long int count_points_in_circle(Vector *p) { unsigned long long int i, success = 0; for(i=0; i < p->size; i+=2) { success += point_in_circle(p->data[i], p->data[i + 1], 1); } return success; }
inline bool range_in_circle(R const& range, C const& c) { assert_dimension<R, 2>(); assert_dimension<C, 2>(); for (typename boost::range_iterator<R const>::type it = boost::begin(range); it != boost::end(range); ++it) { if (! point_in_circle(*it, c)) { return false; } } return true; }
static void paint_battery_icon(BatteryIcon *aIcon, GContext *aCtx, GRect r, GPoint aCenter, int32_t aRadius, bool aZoomedIn) { graphics_context_set_stroke_color(aCtx, GColorWhite); uint8_t percent = battery_icon_get_percent(aIcon); #ifdef PBL_COLOR graphics_context_set_fill_color(aCtx, GColorMalachite); graphics_fill_circle(aCtx, aCenter, aRadius); #endif for (int32_t x = 0; x < r.size.w; ++x) { for (int32_t y = 0; y < r.size.h; ++y) { if (point_in_circle(x-aCenter.x, y-aCenter.y, aCenter.y)) { graphics_context_set_stroke_color(aCtx, GColorWhite); if (!point_in_arc(percent, x-aCenter.x, y-aCenter.y, aCenter.y)) { #ifdef PBL_COLOR graphics_context_set_stroke_color(aCtx, GColorDarkGray); graphics_draw_pixel(aCtx, GPoint(x, y)); #else if (pattern25(x,y)) { graphics_context_set_stroke_color(aCtx, GColorBlack); } #endif } #ifndef PBL_COLOR graphics_draw_pixel(aCtx, GPoint(x, y)); #endif } } } graphics_context_set_fill_color(aCtx, GColorBlack); graphics_fill_circle(aCtx, aCenter, aRadius * (1.f-RING_WIDTH)); // text static char buffer[] = "100"; snprintf(buffer, sizeof(buffer)/sizeof(buffer[0]), "%d", percent); graphics_draw_text(aCtx, buffer, fonts_get_system_font(BATTERY_FONT), GRect(0, (r.size.h - BATTERY_TEXT_ADJUSTMENT) / 2, r.size.w, BATTERY_FONT_SIZE), GTextOverflowModeWordWrap, GTextAlignmentCenter, NULL); }
bool hit_test(value_type x,value_type y, double tol) const { return point_in_circle(pt_.x,pt_.y, x,y,tol); }
static void point_in_map_element (char *line, char *return_url, int point_x, int point_y, char *default_url) { char **tokens, /* Line split into tokens */ *map_type, /* Element type name */ *map_url, /* Element URL value */ *comma; /* Split x,y at comma */ FPOINT click_point, /* Request point */ shape_points [MAP_MAX_POINTS]; /* Array of element point */ int token_nbr, /* Index into token array */ nbr_points; /* Number of points in element */ /* Store selected point in image */ click_point.x = (double) point_x; click_point.y = (double) point_y; /* Now parse the map file line into space-delimited tokens */ tokens = tok_split (line); /* Ignore anything which is unparsable */ if (tokens [0] == NULL || tokens [1] == NULL) { tok_free (tokens); /* Release memory */ return; } /* First token is image element type; second is the URL */ map_type = strlwc (tokens [0]); map_url = tokens [1]; /* Third to n tokens are x,y pairs... */ token_nbr = 2; for (nbr_points = 0; nbr_points < MAP_MAX_POINTS; nbr_points++) { if (!tokens [token_nbr]) break; /* Null token => finished */ comma = strchr (tokens [token_nbr], ','); if (!comma) break; /* Syntax error in line => quit */ *comma = '\0'; /* Else break into separate x & y */ shape_points [nbr_points].x = atof (tokens [token_nbr]); shape_points [nbr_points].y = atof (comma + 1); token_nbr++; /* Bump to next token */ } /* Check element type and test the request point */ if (streq (map_type, "poly")) { if (point_in_poly (&click_point, shape_points, nbr_points)) strcpy (return_url, map_url); } else if (streq (map_type, "circle")) { if (point_in_circle (&click_point, shape_points)) strcpy (return_url, map_url); } else if (streq (map_type, "rect")) { if (point_in_rect (&click_point, shape_points)) strcpy (return_url, map_url); } else if (streq (map_type, "point")) { double dist; dist = ((click_point.x - shape_points [0].x) * (click_point.x - shape_points [0].x)) + ((click_point.y - shape_points [0].y) * (click_point.y - shape_points [0].y)); if (dist < 10) strcpy (return_url, map_url); } else if (streq (map_type, "default")) strcpy (default_url, map_url); tok_free (tokens); /* Release memory */ }