static void UserToDevice(Cairo::RefPtr<Cairo::Context> cr, int& x, int& y) { double d_x = x, d_y = y; cr->user_to_device(d_x, d_y); x = Round(d_x), y = Round(d_y); }
void cairo::draw_triangle( const Cairo::RefPtr<Cairo::Context>& cr, const Geodesics::edge_handle& e0 ) { const rgba_color_t color( .8, .8, .8, .3); // get edge-free pair const Geodesics::edge_handle e1 ( e0.next() ); const Geodesics::edge_handle e2 ( e1.next() ); const coord_t e0l= e0.length(); const coord_t e1l= e1.length(); const coord_t e2l= e2.length(); // coordinates of C - using circle-circle intersection ( intersect circle (w.b0,w.d0) with (w.b1,w.d1) ) cairo_coord_t A(0.,0.); cairo_coord_t B(e0l,0.); cairo_coord_t C; boost::tie(C[0],C[1]) = utk::triangulate( e0l, e2l, e1l ); //C[1] = - C[1]; const coord2_t centroid = ( ( coord2_t(e0l, 0) += C ) /= coord_t(3) ); cr->save(); //cr->set_operator( Cairo::OPERATOR_DEST_OVER ); cr->set_source_rgba( color[0], color[1], color[2], color[3] ); cr->save(); // shrink slightly towards centroid cr->translate( centroid[0], centroid[1] ); cr->scale( .95, .95 ); cr->translate( -centroid[0], -centroid[1] ); //draw triangle cr->set_line_width( 1. * user_unit_distance( cr ).length() ); draw_half_arrow( cr, A, B ); draw_half_arrow( cr, B, C ); draw_half_arrow( cr, C, A ); cr->restore(); cr->stroke(); cr->restore(); // draw text cr->save(); cr->user_to_device( A[0], A[1] ); cr->user_to_device( B[0], B[1] ); cr->user_to_device( C[0], C[1] ); cr->set_identity_matrix(); //cr->select_font_face( "Purisa", Cairo::FONT_SLANT_NORMAL, Cairo::FONT_WEIGHT_NORMAL ); cr->set_source_rgba( 0., 0., 0.,.5 ); cr->set_font_size( 8. /* user_unit_distance( cr ).length()*/ ); std::ostringstream nrss; nrss << e0.source().descriptor(); draw_centered_text( cr, nrss.str(), A ); nrss.str(""); nrss << e1.source().descriptor(); draw_centered_text( cr, nrss.str(), B ); nrss.str(""); nrss << e2.source().descriptor(); draw_centered_text( cr, nrss.str(), C ); cr->restore(); }