Graphics-Fig
view release on metacpan or search on metacpan
lib/Graphics/Fig/Arc.pm view on Meta::CPAN
$point1, $point2, $point3 );
my ( $angle, $controlAngle ) = &calcAnglesFromPoints(\@newPoints);
${$self}{"point1"} = $newPoints[0];
${$self}{"point3"} = $newPoints[2];
${$self}{"angle"} = $angle;
${$self}{"controlAngle"} = $controlAngle;
}
}
#
# Graphics::Fig::Arc::crosses_axis: return positive if a CCW arc
# intersects the given axis (helper for getbbox)
# $point1: first point
# $point3: final point
# $axis: axis
#
sub crosses_axis {
my $point1 = shift;
my $point3 = shift;
my $axis = shift;
my $x1 = ${$point1}[0];
my $y1 = ${$point1}[1];
my $x3 = ${$point3}[0];
my $y3 = ${$point3}[1];
my $x = ${$axis}[0];
my $y = ${$axis}[1];
# Find z component of cross product of (point1 - axis) and (point2 - axis).
return $x1 * $y3 - $x3 * $y1 + ($y1 - $y3) * $x + ($x3 - $x1) * $y;
}
#
# Graphics::Fig::Arc::getbbox: return [[xmin, ymin], [xmax, ymax]]
# $self: object
# $parameters: getbbox parameters
#
sub getbbox {
my $self = shift;
my $parameters = shift;
my $point1 = ${$self}{"point1"};
my $point3 = ${$self}{"point3"};
my $angle = ${$self}{"angle"};
my $x1 = ${$point1}[0];
my $y1 = ${$point1}[1];
my $x3 = ${$point3}[0];
my $y3 = ${$point3}[1];
#
# Find the center and radius.
#
my $half_cot = cot($angle / 2) / 2;
my $xc = $x1 + ($x3 - $x1) / 2 + ($y3 - $y1) * $half_cot;
my $yc = $y1 + ($y3 - $y1) / 2 - ($x3 - $x1) * $half_cot;
my $dx = $x1 - $xc;
my $dy = $y1 - $yc;
my $r = sqrt($dx * $dx + $dy * $dy);
#
# First, find the bounding box of the endpoints. Then for each
# axis the arc crosses, expand the box as needed.
#
my $bbox = Graphics::Fig::Parameters::getbboxFromPoints($point1, $point3);
if (&crosses_axis($point1, $point3, [ $xc - $r, $yc ]) * $angle > 0) {
if ($xc - $r < ${$bbox}[0][0]) {
${$bbox}[0][0] = $xc - $r;
}
}
if (&crosses_axis($point1, $point3, [ $xc, $yc - $r ]) * $angle > 0) {
if ($yc - $r < ${$bbox}[0][1]) {
${$bbox}[0][1] = $yc - $r;
}
}
if (&crosses_axis($point1, $point3, [ $xc + $r, $yc ]) * $angle > 0) {
if ($xc + $r > ${$bbox}[1][0]) {
${$bbox}[1][0] = $xc + $r;
}
}
if (&crosses_axis($point1, $point3, [ $xc, $yc + $r ]) * $angle > 0) {
if ($yc + $r > ${$bbox}[1][1]) {
${$bbox}[1][1] = $yc + $r;
}
}
return $bbox;
}
#
# Graphics::Fig::Arc::print
# $self: object
# $fh: reference to output file handle
# $parameters: save parameters
#
sub print {
my $self = shift;
my $fh = shift;
my $parameters = shift;
my $figPerInch = Graphics::Fig::_figPerInch($parameters);
my $subtype = ${$self}{"subtype"};
my $direction = ${$self}{"angle"} >= 0;
my $point1 = ${$self}{"point1"};
my ( $center, $point2 ) = &findPoint2($self);
my $point3 = ${$self}{"point3"};
#
# Print
#
printf $fh ("5 %d %d %.0f %d %d %d -1 %d %.3f %d %d %d %d ".
"%.0f %.0f %.0f %.0f %.0f %.0f %.0f %.0f\n",
$subtype,
${$self}{"lineStyle"},
${$self}{"lineThickness"} * 80.0,
${$self}{"penColor"},
${$self}{"fillColor"},
${$self}{"depth"},
${$self}{"areaFill"},
${$self}{"styleVal"} * 80.0,
${$self}{"capStyle"},
$direction,
defined(${$self}{"fArrow"}) ? 1 : 0,
( run in 1.191 second using v1.01-cache-2.11-cpan-39bf76dae61 )