摘自:http://sourceforge.net/p/vector-agg/mailman/vector-agg-general/?viewmonth=200312&viewday=2
A little modification. I forgot to catch the exceptions. However, it throws an
unknown exception, not KBool one. And under Cygwin it dumps core.
double random(double min, double max)
{
int r = (rand() << 15) | rand();
return ((r & 0xFFFFFFF) / double(0xFFFFFFF + 1)) * (max - min) + min;
}
virtual void on_mouse_button_down(int x, int y, unsigned flags)
{
agg::scanline_u8 sl;
agg::rasterizer_scanline_aa<> ras;
typedef agg::renderer_base
typedef agg::renderer_scanline_u_solid
agg::pixfmt_bgr24 pf(rbuf_window());
base_ren_type ren_base(pf);
renderer_solid ren_solid(ren_base);
agg::path_storage ps1;
agg::path_storage ps2;
try
{
agg::conv_kbool
ps2);
kbool.winding_rule(m_winding_rule.status());
unsigned i;
for(i = 0; i < 100; i++)
{
ren_base.clear(agg::rgba(1,1,1));
unsigned num_poly1 = 2;//rand() % 10 + 1;
unsigned num_poly2 = 2;//rand() % 10 + 1;
unsigned j;
ps1.remove_all();
ps2.remove_all();
for(j = 0; j < num_poly1; j++)
{
ps1.move_to(random(0, width()), random(0, height()));
unsigned k;
unsigned np = 3;//rand() % 20 + 2;
for(k = 0; k < np; k++)
{
ps1.line_to(random(0, width()), random(0, height()));
}
}
for(j = 0; j < num_poly2; j++)
{
ps2.move_to(random(0, width()), random(0, height()));
unsigned k;
unsigned np = 3;//rand() % 20 + 2;
for(k = 0; k < np; k++)
{
ps2.line_to(random(0, width()), random(0, height()));
}
}
unsigned op = rand() % 5;
switch(op)
{
case 0: kbool.operation(agg::kbool_or); break;
case 1: kbool.operation(agg::kbool_and); break;
case 2: kbool.operation(agg::kbool_xor); break;
case 3: kbool.operation(agg::kbool_a_minus_b); break;
case 4: kbool.operation(agg::kbool_b_minus_a); break;
}
ras.add_path(kbool);
ren_solid.color(agg::rgba(0.5, 0.0, 0, 0.5));
ras.render(sl, ren_solid);
update_window();
}
message("Done");
}
catch(Bool_Engine_Error& e)
{
if(e.GetErrorMessage())
{
message(e.GetErrorMessage());
}
else
{
message("Unknown kbool error");
}
}
catch(...)
{
message("Unknown exception");
}
}