#include <cmath>
#include "activepoint.h"
#include "context.h"
Real Context::pixelsize_sqr() const {
Cairo::Matrix m;
ctx()->get_matrix(m);
return 0.25*sqrt(m.xx*m.xx + m.xy*m.xy + m.yx*m.yx + m.yy*m.yy);
}
Real Context::pixelsize() const {
return sqrt(pixelsize_sqr());
}
void Context::point(const ActivePoint &point) const {
if (!point.visible) return;
Color color = point.color;
Color stroke_color = Color::black();
if (!point.enabled) {
color = color.mergecolor(Color::gray()).mulalpha();
stroke_color = stroke_color.mergecolor(Color::gray()).mulalpha();
}
ctx()->save();
ctx()->arc(point.position.x, point.position.y, point.radius, 0, 2*pi);
set_source_rgba(color);
ctx()->fill_preserve();
set_line_width_px(point.active ? 2 : 1);
set_source_rgba(stroke_color);
ctx()->stroke();
ctx()->restore();
}
void Context::bezier(const Bezier &bezier, bool jump) const {
if (jump) move_to(bezier.p0); else line_to(bezier.p0);
ctx()->curve_to(bezier.pp0.x, bezier.pp0.y, bezier.pp1.x, bezier.pp1.y, bezier.p1.x, bezier.p1.y);
}