[cairo] Real-time ellipse creation - invalid matrix (not invertible) exception

Lockert Fredrick lockert.fredrick at gmail.com
Thu Aug 23 01:29:40 PDT 2012


Greetings,

I'm having a bit of a problem with my gtkmm/cairo ellipse shape
creation tool. It works as expected, until the mouse pointer is moved
in a negative direction of the initial start location (x, y), which
results in an invalid matrix exception. After studying the gimp
ellipse creation code, I couldn't find anything "obvious", thus I was
hoping that someone might be able to point me in the right direction.

Full source: http://fureloka.com/files/dev/gtkmm/drawingprog/

==Ellipse shape creation code==

double x = mPt0.x; // Initial mouse click x cord.
double y = mPt0.y; // Initial mouse click y cord.
double w = mPt1.x; // Real-time mouse pointer x cord.
double h = mPt1.y; // Real-time mouse pointer y cord.

x = floor(x);
y = floor(y);
w = ceil(w);
h = ceil(h);

double center_x = (x + w) / 2.0;
double center_y = (y + h) / 2.0;

double radius_x = (w - x) / 2.0;
double radius_y = (h - y) / 2.0;

cr->save();
cr->translate(center_x, center_y);
cr->scale(radius_x, radius_y);
cr->arc(0.0, 0.0, 1.0, 0.0, 2 * M_PI);
cr->set_source_rgb(1.0, 1.0, 1.0);
cr->fill_preserve();
cr->restore();
cr->stroke();


As always, any help is highly appreciated!

Cheers,
Fredrick


More information about the cairo mailing list