Skip to content

Commit

Permalink
slightly better curved line joins, needs more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Tony Cook committed Dec 29, 2008
1 parent 4cde543 commit a92bfd5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion polyline.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,5 @@ i_polyline_dump(const i_polyline_t *poly) {
printf("Points: %d (%d allocated)\n", poly->point_count,
poly->point_alloc);
for (i = 0; i < poly->point_count; ++i)
printf(" %4d: (%g,%g)\n", i, poly->x[i], poly->y[i]);
printf(" %4d: (%.3f,%.3f) (%d, %d)\n", i, poly->x[i], poly->y[i], (int)(poly->x[i]+0.5), (int)(poly->y[i]+0.5));
}
13 changes: 8 additions & 5 deletions t/t22thick.t
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,25 @@ use Imager;
use Imager::Fill;

use_ok('Imager::Pen::Thick');
my $im = Imager->new(xsize => 100, ysize => 100);
my $im = Imager->new(xsize => 200, ysize => 200);
{
#my $pen = Imager::Pen::Thick->new(thickness => 5, color => '#888');
my $pen = Imager::Pen::Thick->new
(
thickness => 9,
fill => Imager::Fill->new(solid => '#888', combine => 'normal'),
thickness => 17,
fill => Imager::Fill->new(solid => '#880', combine => 'normal'),
front => 'round',
back => 'round',
corner => 'round',
);

my $line = Imager::Polyline->new(0, 10, 10, 90, 10, 10, 90, 90, 90);#, 10, 90);
my @pts = ( [ 20, 20 ], [ 180, 20 ], [ 20, 180 ], [ 180, 180 ]);#, [ 10, 90 ]);
my $line = Imager::Polyline->new(0, map @$_, @pts);
ok($line, "made a polyline object");
ok($pen->draw(image => $im, lines => [ $line ]), "draw it");
$im->setpixel(x => [ 10, 90, 90 ], 'y' => [10,10,90], color => '#00f');
$im->setpixel(x => [ map $_->[0], @pts ],
'y' => [ map $_->[1], @pts],
color => '#00f');
#my $line2 = Imager::Polyline->new(0, 20, 20, 80, 80);
#my $pen2 = Imager::Pen::Thick->new(thickness => 5, color => 'red');
#ok($pen2->draw(image => $im, lines => [ $line2 ]), "draw another");
Expand Down
13 changes: 8 additions & 5 deletions thickline.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ make_poly_round(thick_seg *segs, int seg_count, int closed,
if (i) { /* if not the first point */
/* curve to the new point */
double start_angle = atan2(-segs[i-1].cos_slope, -segs[i-1].sin_slope);
double end_angle = atan2(-segs[i].cos_slope, -segs[i-1].sin_slope);
double end_angle = atan2(-segs[i].cos_slope, segs[i].sin_slope);
double angle;
double cx = (seg->left.a.x + seg->right.b.x) / 2.0;
double cy = (seg->left.a.y + seg->right.b.y) / 2.0;
Expand Down Expand Up @@ -607,7 +607,7 @@ thick_draw_line(i_img *im, i_pen_thick_t *thick, const i_polyline_t *line) {

#if 1
if (poly->point_count) {
#if 0
#if 1
{
i_color red;
int i;
Expand All @@ -617,13 +617,13 @@ thick_draw_line(i_img *im, i_pen_thick_t *thick, const i_polyline_t *line) {
red.rgba.g = red.rgba.b = 0;

for (i = 0; i < poly->point_count-1; ++i) {
i_line(im, x[i], y[i], x[i+1], y[i+1], &red, 0);
i_line(im, x[i]+0.5, y[i]+0.5, x[i+1]+0.5, y[i+1]+0.5, &red, 0);
}
i_line(im, x[poly->point_count-1], y[poly->point_count-1], x[0], y[0], &red, 0);
i_line(im, x[poly->point_count-1]+0.5, y[poly->point_count-1]+0.5, x[0]+0.5, y[0]+0.5, &red, 0);
}
#endif

#if 1
#if 0
{
int i;
i_color white;
Expand All @@ -648,7 +648,10 @@ thick_draw(i_pen_t *pen, i_img *im, int line_count, const i_polyline_t **lines)

for (i = 0; i < line_count; ++i) {
i_polyline_t *poly = thick_draw_line(im, thick, lines[i]);
//i_polyline_dump(poly);
#if 0
i_poly_aa_cfill(im, poly->point_count, poly->x, poly->y, thick->fill);
#endif
i_polyline_delete(poly);
}

Expand Down

0 comments on commit a92bfd5

Please sign in to comment.