geowin_poly_choice.c

来自「A Library of Efficient Data Types and Al」· C语言 代码 · 共 77 行

C
77
字号
#include <LEDA/geowin.h>#include <LEDA/plane_alg.h>static void f_unite( const list<rat_gen_polygon>& Lin, rat_gen_polygon& Lout){ if( Lin.length() < 2 ) return;  rat_gen_polygon p1=Lin[Lin[0]];  rat_gen_polygon p2=Lin[Lin[1]];  Lout =p1.unite(p2);}static void f_inter( const list<rat_gen_polygon>& Lin, rat_gen_polygon& Lout){ if( Lin.length() < 2 ) return;  rat_gen_polygon p1=Lin[Lin[0]];  rat_gen_polygon p2=Lin[Lin[1]];  Lout=p1.intersection(p2);}static void f_diff( const list<rat_gen_polygon>& Lin, rat_gen_polygon& Lout){ if( Lin.length() < 2 ) return;  rat_gen_polygon p1=Lin[Lin[0]];  rat_gen_polygon p2=Lin[Lin[1]];  Lout=p1.diff(p2);}static void f_sdiff( const list<rat_gen_polygon>& Lin, rat_gen_polygon& Lout){ if( Lin.length() < 2 ) return;  rat_gen_polygon p1=Lin[Lin[0]];  rat_gen_polygon p2=Lin[Lin[1]];  Lout=p1.sym_diff(p2);}int main(){  GeoWin gw("Polygon Demo");  geo_scene  sc[4];  list<rat_gen_polygon> L;  geo_scene input = geowin_new_scene(gw, L);   gw.set_fill_color(input, invisible);    geowin_update<list<rat_gen_polygon>, list<rat_gen_polygon> > unite(f_unite);  geowin_update<list<rat_gen_polygon>, list<rat_gen_polygon> > inter(f_inter);  geowin_update<list<rat_gen_polygon>, list<rat_gen_polygon> > diff(f_diff);  geowin_update<list<rat_gen_polygon>, list<rat_gen_polygon> > sdiff(f_sdiff);         sc[0] = geowin_new_scene(gw, unite, input, "Union");  gw.set_color(sc[0], blue);  gw.set_fill_color(sc[0], blue);  sc[1] = geowin_new_scene(gw, inter, input, "Intersection");  gw.set_color(sc[1], red);  gw.set_fill_color(sc[1], red);  sc[2] = geowin_new_scene(gw, diff, input, "Difference");  gw.set_color(sc[2], green );  gw.set_fill_color(sc[2], green);  sc[3] = geowin_new_scene(gw, sdiff, input, "Symmetric Difference");    gw.set_color(sc[3], yellow );  gw.set_fill_color(sc[3], yellow);    gw.set_all_visible(true);  list<geo_scene> vis_scenes;  vis_scenes.append(sc[0]); vis_scenes.append(sc[1]);  vis_scenes.append(sc[2]); vis_scenes.append(sc[3]);    list<string> choices;  choices.append("union"); choices.append("inter");  choices.append("diff"); choices.append("sdiff");  gw.add_scene_buttons(vis_scenes, choices);  gw.edit(input);  return 0;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?