Exemplo n.º 1
0
Geom::PathVector
LPEGears::doEffect_path (Geom::PathVector const &path_in)
{
    Geom::PathVector path_out;
    Geom::Path gearpath = path_in[0];

    Geom::Path::iterator it(gearpath.begin());
    if ( it == gearpath.end() ) return path_out;

    Gear * gear = new Gear(teeth, 200.0, phi * M_PI / 180);
    Geom::Point gear_centre = (*it).finalPoint();
    gear->centre(gear_centre);
    gear->angle(atan2((*it).initialPoint() - gear_centre));

    ++it;
	if ( it == gearpath.end() ) return path_out;
    gear->pitch_radius(Geom::distance(gear_centre, (*it).finalPoint()));

    path_out.push_back( gear->path());

    for (++it; it != gearpath.end() ; ++it) {
        // iterate through Geom::Curve in path_in
        Gear* gearnew = new Gear(gear->spawn( (*it).finalPoint() ));
        path_out.push_back( gearnew->path() );
        delete gear;
        gear = gearnew;
    }
    delete gear;

    return path_out;
}
Exemplo n.º 2
0
static gboolean
expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer data)
{
    int width = 256;
    int height = 256;
    std::ostringstream notify;
    gdk_drawable_get_size(widget->window, &width, &height);

    for(int i = 0; i < display_path.handles.size(); i++) {
        draw_handle(widget->window, display_path.handles[i]);
    }
    draw_path(widget->window, display_path);
    //draw_elip(widget->window, handles);
    
    Geom::Point dir(1,1);
    /*
    vector<Geom::Path::Location> pts = find_vector_extreme_points(display_path, dir);
    
    for(int i = 0; i < pts.size(); i++) {
        draw_circ(widget->window, display_path.point_at(pts[i]));
        }*/
    
    double dist = INFINITY;

    Geom::Path::Location pl = 
        display_path.nearest_location(old_mouse_point, dist);
    {
        Geom::Point pos, tgt, acc;
        display_path.point_tangent_acc_at (pl, pos, tgt, acc);
        draw_circ(widget->window, pos);
        double kurvature = dot(acc, rot90(tgt))/pow(Geom::L2(tgt),3);
        
        if(fabs(kurvature) > 0.001)
            draw_ray(widget->window, pos, 
                     (1./kurvature)*Geom::unit_vector(rot90(tgt)));
        else // just normal
            draw_ray(widget->window, pos, rot90(tgt));
            
    }
    Geom::Path pth = display_path.subpath(display_path.begin(), display_path.end());
    pth = pth*Geom::translate(Geom::Point(30, 30));
    draw_path(widget->window, pth);
    Bezier a, b;
    const int curve_seg = 3;
    Geom::Path::Elem ai(*display_path.indexed_elem(curve_seg)), bi(*pth.indexed_elem(curve_seg));
    
    for(int i = 0; i < 4; i++) {
        a.p[i] = ai[i];
        b.p[i] = bi[i];
    }
    
    std::vector<std::pair <double, double> > ts = Geom::FindIntersections(a, b);
    for(int i = 0; i < ts.size(); i++) {
        Geom::Path::Location pl(display_path.indexed_elem(curve_seg), ts[i].first);
        
        draw_handle(widget->window, display_path.point_at(pl));
        Geom::Path::Location p2(pth.indexed_elem(curve_seg), ts[i].second);
        
        draw_circ(widget->window, display_path.point_at(p2));
    }
    
    
    /*
    vector<Geom::Path::Location> pts = 
        find_inflection_points(display_path);
  
    for(int i = 0; i < pts.size(); i++) {
        Geom::Point pos, tgt, acc;
        display_path.point_tangent_acc_at (pts[i], pos, tgt, acc);
        //tgt *= 0.1;
        //acc *= 0.1;
        draw_handle(widget->window, display_path.point_at(pts[i]));
        draw_circ(widget->window, pos);
        
        //draw_ray(widget->window, pos+tgt, acc);
    }
    */
    notify << "path length: " << arc_length_integrating(display_path, 1e3) << "\n";
    

    {
        notify << std::ends;
        PangoLayout *layout = gtk_widget_create_pango_layout(widget, notify.str().c_str());
        PangoRectangle logical_extent;
        pango_layout_get_pixel_extents(layout,
                                       NULL,
                                       &logical_extent);
        
        gdk_draw_layout(widget->window,
                        widget->style->fg_gc[GTK_STATE_NORMAL],
                        0, height-logical_extent.height, layout);
    }
    
    return TRUE;
}