本文整理汇总了C++中CGESTUREptr::is_almost_ellipse方法的典型用法代码示例。如果您正苦于以下问题:C++ CGESTUREptr::is_almost_ellipse方法的具体用法?C++ CGESTUREptr::is_almost_ellipse怎么用?C++ CGESTUREptr::is_almost_ellipse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CGESTUREptr
的用法示例。
在下文中一共展示了CGESTUREptr::is_almost_ellipse方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: go
//! Returns true if the gesture is valid for beginning a circle_widget
//! session.
bool
CIRCLE_WIDGET::init(CGESTUREptr& gest)
{
static bool debug =
Config::get_var_bool("DEBUG_CIRCLE_WIDGET_INIT",false) || debug_all;
err_adv(debug, "CIRCLE_WIDGET::init");
// Get the ellipse description:
PIXEL center; // the center
VEXEL axis; // the long axis (unit length)
double r1, r2; // the long and short radii, respectively
bool suggest_active;
if (!gest->is_ellipse(center, axis, r1, r2)) {
if (!gest->is_almost_ellipse(center, axis, r1, r2)) {
return 0;
} else {
suggest_active = true;
}
} else {
suggest_active = false;
}
Wplane plane = get_draw_plane(center);
if (!plane.is_valid()) {
// didn't work out this time
return false;
}
///////////////////////////////////////////////////////
//
// y1
//
// x0 c ------> x1
// axis
// y0
//
// Project the extreme points of the ellipse to the
// plane and check that after projection they are
// reasonably equidistant from the center.
//
// I.e., the ellipse should reasonably match the
// foreshortened circle as it would actually appear in
// the given plane.
///////////////////////////////////////////////////////
VEXEL perp = axis.perpend();
Wpt x0 = Wpt(plane, Wline(XYpt(center - axis*r1)));
Wpt x1 = Wpt(plane, Wline(XYpt(center + axis*r1)));
Wpt y0 = Wpt(plane, Wline(XYpt(center - perp*r2)));
Wpt y1 = Wpt(plane, Wline(XYpt(center + perp*r2)));
Wpt c = Wpt(plane, Wline(XYpt(center)));
// The two diameters -- we'll check their ratio
double dx = x0.dist(x1);
double dy = y0.dist(y1);
// XXX - Use environment variable for testing phase:
// XXX - don't make static (see below):
double MIN_RATIO = Config::get_var_dbl("EPC_RATIO", 0.85,true);
// Be more lenient when the plane is more foreshortened:
//
// XXX - not sure what the right policy is, but for a
// completely edge-on plane there's certainly no sense in
// doing a real projection... the following drops the
// min_ratio lower for more foreshortened planes:
double cos_theta = VIEW::eye_vec(c) * plane.normal();
double scale = sqrt(fabs(cos_theta)); // XXX - just trying this out
MIN_RATIO *= scale; // XXX - this is why it can't be static
double ratio = min(dx,dy)/max(dx,dy);
err_adv(debug, "CIRCLE_WIDGET::init: projected ratio: %f, min: %f",
ratio, MIN_RATIO);
if (ratio < MIN_RATIO)
return false;
CIRCLE_WIDGETptr me = get_instance();
static const int DISK_RES = Config::get_var_int("DISK_RES", 4,true);
me->_plane = plane;
me->_radius = dx/2;
me->_disk_res = DISK_RES;
me->_center = c;
me->_init_stamp = VIEW::stamp();
if( me->_suggest_active = suggest_active ) {
me->create_literal(gest);
}
//PIXEL gest_center = gest->center();
me->make_preview();
return go();
}