line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
50472
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
2
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
46
|
|
3
|
|
|
|
|
|
|
package Math::Shape::Rectangle; |
4
|
|
|
|
|
|
|
$Math::Shape::Rectangle::VERSION = '0.03'; |
5
|
1
|
|
|
1
|
|
783
|
use Math::Shape::Point; |
|
1
|
|
|
|
|
78248
|
|
|
1
|
|
|
|
|
38
|
|
6
|
1
|
|
|
1
|
|
10
|
use Math::Trig 1.22 ':pi'; |
|
1
|
|
|
|
|
35
|
|
|
1
|
|
|
|
|
208
|
|
7
|
1
|
|
|
1
|
|
17
|
use 5.008; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
38
|
|
8
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
71
|
|
9
|
1
|
|
|
1
|
|
6
|
use List::Util 'max'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
943
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# ABSTRACT: a 2d rectangle in cartesian space |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
16
|
6
|
100
|
|
6
|
1
|
125
|
croak 'Incorrect number of arguments passed to new()' unless @_ == 6; |
17
|
4
|
|
|
|
|
10
|
my ($class, $x, $y, $r, $length, $width) = @_; |
18
|
4
|
|
|
|
|
31
|
my $self = |
19
|
|
|
|
|
|
|
bless { centre => Math::Shape::Point->new($x, $y, $r), |
20
|
|
|
|
|
|
|
length => $length, |
21
|
|
|
|
|
|
|
width => $width }, |
22
|
|
|
|
|
|
|
$class; |
23
|
|
|
|
|
|
|
|
24
|
4
|
|
|
|
|
136
|
$self->_calculate_corners; |
25
|
4
|
|
|
|
|
25
|
return $self; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub rotate { |
30
|
3
|
|
|
3
|
1
|
28
|
$_[0]->{centre}->rotate($_[1]); |
31
|
3
|
|
|
|
|
56
|
$_[0]->{tl}->rotate_about_point($_[0]->{centre}, $_[1]); |
32
|
3
|
|
|
|
|
244
|
$_[0]->{tr}->rotate_about_point($_[0]->{centre}, $_[1]); |
33
|
3
|
|
|
|
|
77
|
$_[0]->{bl}->rotate_about_point($_[0]->{centre}, $_[1]); |
34
|
3
|
|
|
|
|
68
|
$_[0]->{br}->rotate_about_point($_[0]->{centre}, $_[1]); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub get_points { |
39
|
9
|
|
|
9
|
1
|
7559
|
my $self = shift; |
40
|
|
|
|
|
|
|
{ |
41
|
9
|
|
|
|
|
95
|
tl => $self->{tl}, |
42
|
|
|
|
|
|
|
tr => $self->{tr}, |
43
|
|
|
|
|
|
|
bl => $self->{bl}, |
44
|
|
|
|
|
|
|
br => $self->{br}, |
45
|
|
|
|
|
|
|
}; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub detect_collision { |
50
|
8
|
|
|
8
|
1
|
19
|
my ($self, $r2) = @_; |
51
|
8
|
100
|
|
|
|
20
|
return 1 if $self->test_radius_intersect($r2); |
52
|
3
|
|
|
|
|
17
|
0; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub test_radius_intersect { |
57
|
16
|
|
|
16
|
1
|
68
|
my ($self, $r2) = @_; |
58
|
16
|
|
|
|
|
80
|
my $r1_radius = max($self->{width}, $self->{length}) / 2; |
59
|
16
|
|
|
|
|
51
|
my $r2_radius = max($r2->{width}, $r2->{length}) / 2; |
60
|
16
|
|
|
|
|
68
|
my $distance = $self->{centre}->get_distance_to_point($r2->{centre}); |
61
|
16
|
100
|
|
|
|
237
|
return $distance > $r1_radius + $r2_radius ? 0 : 1; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# FIXME - doesn't work when r != 0 or pi |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub _calculate_corners { |
68
|
4
|
|
|
4
|
|
6
|
my $self = shift; |
69
|
|
|
|
|
|
|
|
70
|
4
|
|
|
|
|
118
|
$self->{tl} = Math::Shape::Point->new( |
71
|
|
|
|
|
|
|
$self->{centre}{x} - int (sin($self->{centre}{r} - pip2) |
72
|
|
|
|
|
|
|
* ($self->{length} * 0.5 / sin($self->{centre}{r} - pip2))), |
73
|
|
|
|
|
|
|
$self->{centre}{y} + int( cos($self->{centre}{r} - pip2) |
74
|
|
|
|
|
|
|
* ($self->{width} * 0.5 / cos($self->{centre}{r} - pip2))), |
75
|
|
|
|
|
|
|
$self->{centre}{r}); |
76
|
|
|
|
|
|
|
|
77
|
4
|
|
|
|
|
106
|
$self->{tr} = Math::Shape::Point->new( |
78
|
|
|
|
|
|
|
$self->{centre}{x} + int (sin($self->{centre}{r} - pip2) |
79
|
|
|
|
|
|
|
* ($self->{length} * 0.5 / sin($self->{centre}{r} - pip2))), |
80
|
|
|
|
|
|
|
$self->{centre}{y} + int( cos($self->{centre}{r} - pip2) |
81
|
|
|
|
|
|
|
* ($self->{width} * 0.5 / cos($self->{centre}{r} - pip2))), |
82
|
|
|
|
|
|
|
$self->{centre}{r}); |
83
|
|
|
|
|
|
|
|
84
|
4
|
|
|
|
|
209
|
$self->{bl} = Math::Shape::Point->new( |
85
|
|
|
|
|
|
|
$self->{centre}{x} - int (sin($self->{centre}{r} - pip2) |
86
|
|
|
|
|
|
|
* ($self->{length} * 0.5 / sin($self->{centre}{r} - pip2))), |
87
|
|
|
|
|
|
|
$self->{centre}{y} - int( cos($self->{centre}{r} - pip2) |
88
|
|
|
|
|
|
|
* ($self->{width} * 0.5 / cos($self->{centre}{r} - pip2))), |
89
|
|
|
|
|
|
|
$self->{centre}{r}); |
90
|
|
|
|
|
|
|
|
91
|
4
|
|
|
|
|
100
|
$self->{br} = Math::Shape::Point->new( |
92
|
|
|
|
|
|
|
$self->{centre}{x} + int (sin($self->{centre}{r} - pip2) |
93
|
|
|
|
|
|
|
* ($self->{length} * 0.5 / sin($self->{centre}{r} - pip2))), |
94
|
|
|
|
|
|
|
$self->{centre}{y} - int( cos($self->{centre}{r} - pip2) |
95
|
|
|
|
|
|
|
* ($self->{width} * 0.5 / cos($self->{centre}{r} - pip2))), |
96
|
|
|
|
|
|
|
$self->{centre}{r}); |
97
|
4
|
|
|
|
|
62
|
1; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
1; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
__END__ |