#ifndef CURVEAREA_H
#define CURVEAREA_H
#include <vector>
#include "activearea.h"
class CurvesArea: public ActiveArea {
public:
class CurvePoint {
public:
ActivePoint::Handle p, t;
explicit CurvePoint(const Vector &p = Vector(), const Vector &t = Vector()):
p(new ActivePoint(p)),
t(new ActivePoint(p + t, Color::yellow()))
{ }
const Vector& get_p() const { return p->position; }
Vector get_t() const { return t->position - p->position; }
void add_to(CurvesArea &area) const { area.add_point(p); area.add_point(t); }
void remove_from(CurvesArea &area) const { area.remove_point(p); area.remove_point(t); }
};
class Curve: public std::vector<CurvePoint> {
public:
bool loop;
Curve(): loop() { }
Curve::const_iterator next(Curve::const_iterator i) const
{ return ++i != end() ? i : loop ? begin() : --i; }
Curve::const_iterator prev(Curve::const_iterator i) const
{ return --i != begin() ? i : loop ? end() : ++i; }
};
protected:
Curve curve;
void put_segment(const Context &context, const Segment &segment, const Real width = 0);
void put_curve(const Context &context, const Curve &curve, const Real width = 0);
void draw_curve(const Context &context, const Curve &curve);
public:
CurvesArea();
void on_draw_content(const Context &context) override;
};
#endif