Example #1
0
void GUIAPI Ellipse (HDC hdc, int sx, int sy, int rx, int ry)
{
    PDC pdc;

    if (!(pdc = __mg_check_ecrgn (hdc)))
        return;

    coor_LP2SP (pdc, &sx, &sy);

    pdc->cur_pixel = pdc->pencolor;
    pdc->cur_ban = NULL;

    if (rx < 1 || ry < 1) {
        _set_pixel_helper (pdc, sx, sy);
        goto ret;
    }

    pdc->rc_output.left = sx - rx;
    pdc->rc_output.top  = sy - ry;
    pdc->rc_output.right = sx + rx + 1;
    pdc->rc_output.bottom = sy + ry + 1;

    ENTER_DRAWING (pdc);

    EllipseGenerator (pdc, sx, sy, rx, ry, _dc_set_pixel_pair_clip);

    LEAVE_DRAWING (pdc);

ret:
    UNLOCK_GCRINFO (pdc);
}
Example #2
0
void GUIAPI FillEllipse (HDC hdc, int sx, int sy, int rx, int ry)
{
    PDC pdc;

    if (!(pdc = __mg_check_ecrgn (hdc)))
        return;

    coor_LP2SP (pdc, &sx, &sy);
    pdc->cur_pixel = pdc->brushcolor;
    pdc->cur_ban = NULL;

    if (rx < 1 || ry < 1) {
        _set_pixel_helper (pdc, sx, sy);
        goto ret;
    }

    pdc->rc_output.left = sx - rx;
    pdc->rc_output.top  = sy - ry;
    pdc->rc_output.right = sx + rx + 1;
    pdc->rc_output.bottom = sy + ry + 1;

    ENTER_DRAWING (pdc);

#ifdef _ADV_2DAPI
    if (pdc->brush_type == BT_SOLID)
        EllipseGenerator (pdc, sx, sy, rx, ry, _dc_draw_hline_clip);
    else
        EllipseGenerator (pdc, sx, sy, rx, ry, _dc_fill_hline_clip);
#else
    EllipseGenerator (pdc, sx, sy, rx, ry, _dc_draw_hline_clip);
#endif

    LEAVE_DRAWING (pdc);

ret:
    UNLOCK_GCRINFO (pdc);
}
// eccentricity: 0->circle, limit->1: line
EllipseGenerator get_ellipse_generator(Eigen::Vector2f center_span, Eigen::Vector2f radius_span, float min_r_ratio,
    float min_arc_angle, float sigma)
{
  std::uniform_real_distribution<float> center_dist(center_span(0), center_span(1));
  std::uniform_real_distribution<float> radius_dist(radius_span(0), radius_span(1));
  std::uniform_real_distribution<float> angle_dist(0, 2*M_PI);
  
  // Center.
  float cx = center_dist(G_engine);
  float cy = center_dist(G_engine);
  
  // Rotation. Doesn't make sense to rotate ellipse more than 180 deg.
  float angle = angle_dist(G_engine);
  if (angle > M_PI)
    angle -= M_PI;
  
  // Radii; ratio of minor/major radii must not be < min_r_ratio
  float a, b;
  do {
    a = radius_dist(G_engine);
    b = radius_dist(G_engine);
    if (a < b)
      std::swap(a, b);
  } while (b/a < min_r_ratio);
  
  // Arc span; must be at least min_arc_angle
  float phi_min, phi_max;
  do {
    phi_min = angle_dist(G_engine);
    phi_max = angle_dist(G_engine);
    if (phi_max < phi_min)
      std::swap(phi_max, phi_min);
  } while (phi_max - phi_min < min_arc_angle);
  
  EllipseGeometry geometry{Eigen::Vector2f(cx, cy), Eigen::Vector2f(a, b), angle};
  return EllipseGenerator(geometry, Eigen::Vector2f(phi_min, phi_max), sigma);
}