|
|
faaf7d |
/*
|
|
|
faaf7d |
......... 2015 Ivan Mahonin
|
|
|
faaf7d |
|
|
|
faaf7d |
This program is free software: you can redistribute it and/or modify
|
|
|
faaf7d |
it under the terms of the GNU General Public License as published by
|
|
|
faaf7d |
the Free Software Foundation, either version 3 of the License, or
|
|
|
faaf7d |
(at your option) any later version.
|
|
|
faaf7d |
|
|
|
faaf7d |
This program is distributed in the hope that it will be useful,
|
|
|
faaf7d |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
faaf7d |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
faaf7d |
GNU General Public License for more details.
|
|
|
faaf7d |
|
|
|
faaf7d |
You should have received a copy of the GNU General Public License
|
|
|
faaf7d |
along with this program. If not, see <http: licenses="" www.gnu.org="">.</http:>
|
|
|
faaf7d |
*/
|
|
|
faaf7d |
|
|
|
faaf7d |
#ifndef _CONTOUR_H_
|
|
|
faaf7d |
#define _CONTOUR_H_
|
|
|
faaf7d |
|
|
|
faaf7d |
#include <vector></vector>
|
|
|
faaf7d |
|
|
|
93cbac |
#include "geometry.h"
|
|
|
93cbac |
#include "polyspan.h"
|
|
|
faaf7d |
|
|
|
faaf7d |
class Contour
|
|
|
faaf7d |
{
|
|
|
faaf7d |
public:
|
|
|
faaf7d |
enum ChunkType {
|
|
|
faaf7d |
CLOSE,
|
|
|
faaf7d |
MOVE,
|
|
|
faaf7d |
LINE,
|
|
|
faaf7d |
CUBIC,
|
|
|
faaf7d |
CONIC
|
|
|
faaf7d |
};
|
|
|
faaf7d |
|
|
|
faaf7d |
struct Chunk {
|
|
|
faaf7d |
ChunkType type;
|
|
|
faaf7d |
Vector p1, t0, t1;
|
|
|
faaf7d |
Chunk(): type() { }
|
|
|
faaf7d |
Chunk(ChunkType type, const Vector &p1, const Vector &t0 = Vector(), const Vector &t1 = Vector()):
|
|
|
faaf7d |
type(type), p1(p1), t0(t0), t1(t1) { }
|
|
|
faaf7d |
};
|
|
|
faaf7d |
|
|
|
faaf7d |
typedef std::vector<chunk> ChunkList;</chunk>
|
|
|
faaf7d |
|
|
|
faaf7d |
private:
|
|
|
faaf7d |
static const Vector blank;
|
|
|
faaf7d |
ChunkList chunks;
|
|
|
faaf7d |
size_t first;
|
|
|
faaf7d |
|
|
|
faaf7d |
public:
|
|
|
d989ab |
bool allow_split_lines;
|
|
|
d989ab |
|
|
|
d989ab |
Contour(): first(0), allow_split_lines() { }
|
|
|
faaf7d |
|
|
|
faaf7d |
void clear();
|
|
|
faaf7d |
void move_to(const Vector &v);
|
|
|
faaf7d |
void line_to(const Vector &v);
|
|
|
faaf7d |
void cubic_to(const Vector &v, const Vector &t0, const Vector &t1);
|
|
|
faaf7d |
void conic_to(const Vector &v, const Vector &t);
|
|
|
faaf7d |
void close();
|
|
|
faaf7d |
|
|
|
faaf7d |
const ChunkList& get_chunks() const { return chunks; }
|
|
|
faaf7d |
|
|
|
faaf7d |
const Vector& current() const
|
|
|
faaf7d |
{ return chunks.empty() ? blank : chunks.back().p1; }
|
|
|
faaf7d |
|
|
|
faaf7d |
void split(Contour &c, const Rect &bounds, const Vector &min_size) const;
|
|
|
faaf7d |
|
|
|
93cbac |
void transform(const Rect &from, const Rect &to);
|
|
|
93cbac |
|
|
|
93cbac |
void to_polyspan(Polyspan &polyspan) const;
|
|
|
93cbac |
|
|
|
faaf7d |
private:
|
|
|
faaf7d |
void line_split(
|
|
|
faaf7d |
Rect &ref_line_bounds,
|
|
|
faaf7d |
const Rect &bounds,
|
|
|
faaf7d |
const Vector &min_size,
|
|
|
d989ab |
const Vector &p1,
|
|
|
d989ab |
int level = 64 );
|
|
|
faaf7d |
|
|
|
faaf7d |
void conic_split(
|
|
|
faaf7d |
Rect &ref_line_bounds,
|
|
|
faaf7d |
const Rect &bounds,
|
|
|
faaf7d |
const Vector &min_size,
|
|
|
faaf7d |
const Vector &p1,
|
|
|
faaf7d |
const Vector ¢er,
|
|
|
93cbac |
Real radius,
|
|
|
93cbac |
Real radians0,
|
|
|
93cbac |
Real radians1,
|
|
|
faaf7d |
int level = 64 );
|
|
|
faaf7d |
|
|
|
faaf7d |
void cubic_split(
|
|
|
faaf7d |
Rect &ref_line_bounds,
|
|
|
faaf7d |
const Rect &bounds,
|
|
|
faaf7d |
const Vector &min_size,
|
|
|
faaf7d |
const Vector &p1,
|
|
|
faaf7d |
const Vector &bezier_pp0,
|
|
|
faaf7d |
const Vector &bezier_pp1,
|
|
|
faaf7d |
int level = 64 );
|
|
|
faaf7d |
|
|
|
faaf7d |
static bool conic_convert(
|
|
|
faaf7d |
const Vector &p0,
|
|
|
faaf7d |
const Vector &p1,
|
|
|
faaf7d |
const Vector &t,
|
|
|
faaf7d |
Vector &out_center,
|
|
|
93cbac |
Real &out_radius,
|
|
|
93cbac |
Real &out_radians0,
|
|
|
93cbac |
Real &out_radians1 );
|
|
|
faaf7d |
|
|
|
faaf7d |
static Rect conic_bounds(
|
|
|
faaf7d |
const Vector &p0,
|
|
|
faaf7d |
const Vector &p1,
|
|
|
faaf7d |
const Vector ¢er,
|
|
|
93cbac |
Real radius,
|
|
|
93cbac |
Real radians0,
|
|
|
93cbac |
Real radians1 );
|
|
|
faaf7d |
|
|
|
faaf7d |
static void cubic_convert(
|
|
|
faaf7d |
const Vector &p0,
|
|
|
faaf7d |
const Vector &p1,
|
|
|
faaf7d |
const Vector &t0,
|
|
|
faaf7d |
const Vector &t1,
|
|
|
faaf7d |
Vector &out_bezier_pp0,
|
|
|
faaf7d |
Vector &out_bezier_pp1 );
|
|
|
faaf7d |
|
|
|
faaf7d |
static Rect cubic_bounds(
|
|
|
faaf7d |
const Vector &p0,
|
|
|
faaf7d |
const Vector &p1,
|
|
|
faaf7d |
const Vector &bezier_pp0,
|
|
|
faaf7d |
const Vector &bezier_pp1 );
|
|
|
faaf7d |
};
|
|
|
faaf7d |
|
|
|
faaf7d |
#endif
|