Skip to content

Commit

Permalink
corners for cut30
Browse files Browse the repository at this point in the history
  • Loading branch information
Tony Cook committed Jul 31, 2009
1 parent e56b8c0 commit 10467ab
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 14 deletions.
29 changes: 17 additions & 12 deletions t/t22thick.t
Expand Up @@ -52,7 +52,7 @@ my @septagon = map
or diag(Imager->errstr);
my $pen2 = Imager::Pen::Thick->new
(
thickness => 35,
thickness => 31,
color => '#0F0',
corner => $corner,
);
Expand All @@ -62,28 +62,31 @@ my @septagon = map
ok($pen1->draw(image => $im, lines => [ $line ]),
"draw heptagon $corner corners");
my $line2 = Imager::Polyline->new(1, map @$_, reverse @septagon);
#$line2->dump;
#ok($pen2->draw(image => $im, lines => [ $line2 ]),
# "draw heptagon $corner corners (reverse order)");
$line2->dump;
ok($pen2->draw(image => $im, lines => [ $line2 ]),
"draw heptagon $corner corners (reverse order)");
ok($im->write(file => "testout/t22c$corner.ppm"), "save it");
}
}

{
my $im = Imager->new(xsize => 200, ysize => 200);
my $step = PI / 18;
my $step = PI / 15;
my $start = PI - $step / 2;
my $y = 20;
my $green = 64;
my $blue = 255;
for my $corner (qw(round cut ptc_30)) {
my $pen = Imager::Pen::Thick->new
(
thickness => 10,
color => '#888',
corner => $corner,
);
my $red = 64;
my $x = 10;
my $angle = $start;
while ($x < 180) {
my $pen = Imager::Pen::Thick->new
(
thickness => 10,
color => [ $red, $green, $blue, 192 ],
corner => $corner,
);
my $line = Imager::Polyline->new
(
0,
Expand All @@ -93,10 +96,12 @@ my @septagon = map
);
ok($pen->draw(image => $im, lines => [ $line ]),
"corner $corner, angle $angle");
$x += 20;
$x += 30;
$angle -= $step;
$red += 32;
}
$y += 60;
$green += 40;
}
ok($im->write(file => 'testout/t22angles.ppm'), "save angles");
}
Expand Down
54 changes: 52 additions & 2 deletions thickline.c
Expand Up @@ -401,7 +401,21 @@ make_poly_cut30(thick_seg *segs, int seg_count, int closed,

if (closed) {
if (add_start) {

thick_seg *last_seg = segs + seg_count - 1;
double cos_x_m_y =
last_seg->cos_slope * segs->cos_slope + last_seg->sin_slope * segs->sin_slope;
if (cos_x_m_y > COS_150_DEG) {
double end = last_seg->left.end;
i_polyline_add_point_xy(poly,
line_x(&last_seg->left, end),
line_y(&last_seg->left, end));
i_polyline_add_point_xy(poly,
line_x(&segs->left, 0),
line_y(&segs->left, 0));
}
else {
add_start = 1;
}
}
}
else {
Expand All @@ -427,14 +441,50 @@ make_poly_cut30(thick_seg *segs, int seg_count, int closed,
}

if (end > start) {
if (seg->right.end > 1 && i > 0) {
thick_seg *next = segs + i - 1;
double cos_x_m_y =
seg->cos_slope * next->cos_slope + seg->sin_slope * next->sin_slope;
if (cos_x_m_y > COS_150_DEG) {
end = seg->right.end;
}
else {
add_start = 1;
}
}
else
add_start = end == 1.0;

i_polyline_add_point_xy(poly,
line_x(&seg->right, end),
line_y(&seg->right, end));
}
add_start = end == 1.0;
}

if (!closed) {
if (closed) {
if (add_start) {
thick_seg *last_seg = segs + seg_count - 1;
double cos_x_m_y =
last_seg->cos_slope * segs->cos_slope + last_seg->sin_slope * segs->sin_slope;
if (cos_x_m_y > COS_150_DEG) {
double start = last_seg->right.start;
i_polyline_add_point_xy(poly,
line_x(&last_seg->right, start),
line_y(&last_seg->right, start));
}
#if 0
i_polyline_add_point_xy(poly,
line_x(&last_seg->right, 0.0),
line_y(&last_seg->right, 0.0));
#else
i_polyline_add_point_xy(poly,
last_seg->right.a.x,
last_seg->right.a.y);
#endif
}
}
else {
line_end(poly, segs, &segs->right, &segs->left, pen->back, pen);
}

Expand Down

0 comments on commit 10467ab

Please sign in to comment.