libdraw: add bezierpts

This patch exposes the bezierpts function,
providing a way to get the points on a path,
similar how bezsplinepts gives them for b
splines.
This commit is contained in:
Ori Bernstein 2021-01-09 12:20:49 -08:00
parent dda99bbfe5
commit c207b78d07
3 changed files with 27 additions and 3 deletions

View file

@ -436,6 +436,7 @@ extern Point _string(Image*, Point, Image*, Point, Font*, char*, Rune*, int, Rec
extern Point stringsubfont(Image*, Point, Image*, Subfont*, char*); extern Point stringsubfont(Image*, Point, Image*, Subfont*, char*);
extern int bezier(Image*, Point, Point, Point, Point, int, int, int, Image*, Point); extern int bezier(Image*, Point, Point, Point, Point, int, int, int, Image*, Point);
extern int bezierop(Image*, Point, Point, Point, Point, int, int, int, Image*, Point, Drawop); extern int bezierop(Image*, Point, Point, Point, Point, int, int, int, Image*, Point, Drawop);
extern int bezierpts(Point, Point, Point, Point, Point**);
extern int bezspline(Image*, Point*, int, int, int, int, Image*, Point); extern int bezspline(Image*, Point*, int, int, int, int, Image*, Point);
extern int bezsplineop(Image*, Point*, int, int, int, int, Image*, Point, Drawop); extern int bezsplineop(Image*, Point*, int, int, int, int, Image*, Point, Drawop);
extern int bezsplinepts(Point*, int, Point**); extern int bezsplinepts(Point*, int, Point**);

View file

@ -103,6 +103,8 @@ int bezierop(Image *dst, Point p0, Point p1, Point p2, Point p3,
int end0, int end1, int radius, Image *src, Point sp, int end0, int end1, int radius, Image *src, Point sp,
Drawop op) Drawop op)
.PB .PB
int bezierpts(Point p0, Point p1, Point p2, Point p3, Point **pp)
.PB
int bezspline(Image *dst, Point *pt, int npt, int end0, int end1, int bezspline(Image *dst, Point *pt, int npt, int end0, int end1,
int radius, Image *src, Point sp) int radius, Image *src, Point sp)
.PB .PB
@ -603,6 +605,16 @@ corresponds to
in in
.IR dst . .IR dst .
.TP .TP
\f5bezierpts(\f2a\fP, \f2b\fP, \f2c\fP, \f2d\fP, \f2pp\fP)
.I Bezierpts
returns in
.I pp
a list of points making up the open polygon that
.I bezier
would draw.
The caller is responsible for freeing
.IR *pp .
.TP
\f5bezspline(\f2dst\fP, \f2p\fP, \f2np\fP, \f2end0\fP, \f2end1\fP, \f2thick\fP, \f2src\fP, \f2sp\fP) \f5bezspline(\f2dst\fP, \f2p\fP, \f2np\fP, \f2end0\fP, \f2end1\fP, \f2thick\fP, \f2src\fP, \f2sp\fP)
.I Bezspline .I Bezspline
takes the same arguments as takes the same arguments as

View file

@ -98,12 +98,23 @@ bpts(Plist *l, Point p0, Point p1, Point p2, Point p3)
} }
static void static void
bezierpts(Plist *l, Point p0, Point p1, Point p2, Point p3) _bezierpts(Plist *l, Point p0, Point p1, Point p2, Point p3)
{ {
bpts(l, p0, p1, p2, p3); bpts(l, p0, p1, p2, p3);
appendpt(l, p3); appendpt(l, p3);
} }
int
bezierpts(Point p0, Point p1, Point p2, Point p3, Point **pp)
{
Plist l;
l.p = nil;
l.np = 0;
_bezierpts(&l, p0, p1, p2, p3);
*pp = l.p;
return l.np;
}
static void static void
_bezsplinepts(Plist *l, Point *pt, int npt) _bezsplinepts(Plist *l, Point *pt, int npt)
{ {
@ -167,7 +178,7 @@ bezierop(Image *dst, Point p0, Point p1, Point p2, Point p3, int end0, int end1,
Plist l; Plist l;
l.np = 0; l.np = 0;
bezierpts(&l, p0, p1, p2, p3); _bezierpts(&l, p0, p1, p2, p3);
if(l.np == -1) if(l.np == -1)
return 0; return 0;
if(l.np != 0){ if(l.np != 0){
@ -211,7 +222,7 @@ fillbezierop(Image *dst, Point p0, Point p1, Point p2, Point p3, int w, Image *s
Plist l; Plist l;
l.np = 0; l.np = 0;
bezierpts(&l, p0, p1, p2, p3); _bezierpts(&l, p0, p1, p2, p3);
if(l.np == -1) if(l.np == -1)
return 0; return 0;
if(l.np != 0){ if(l.np != 0){