| 1 | package Imager::Search::Match; | ||||||||||
| 2 | |||||||||||
| 3 | 6 | ▶ | use 5.006; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 6 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 6 | ▶ | use Carp (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 6 | ▶ | use Params::Util qw{ _POSINT _NONNEGINT _INSTANCE }; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 6 | ▶ | use vars qw{$VERSION}; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 6 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 6 | $VERSION = '1.01'; | |||||||||
| 11 | } | ||||||||||
| 12 | |||||||||||
| 13 | 6 | ▶ | use Object::Tiny::XS qw{ | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | name | ||||||||||
| 15 | top | ||||||||||
| 16 | bottom | ||||||||||
| 17 | left | ||||||||||
| 18 | right | ||||||||||
| 19 | height | ||||||||||
| 20 | width | ||||||||||
| 21 | center_x | ||||||||||
| 22 | center_y | ||||||||||
| 23 | 6 | }; | |||||||||
| 24 | |||||||||||
| 25 | |||||||||||
| 26 | |||||||||||
| 27 | |||||||||||
| 28 | |||||||||||
| 29 | ##################################################################### | ||||||||||
| 30 | # Constructor | ||||||||||
| 31 | |||||||||||
| 32 | 10 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=5 SCAR=16.6
Pod
undocumented
| |||||||||||
| 33 | 10 | my $self = shift->SUPER::new(@_); | |||||||||
| 34 | |||||||||||
| 35 | # Temporary checks for the basic geometry | ||||||||||
| 36 | 10 | ▶ | defined(_NONNEGINT($self->top)) or die "Missing or invalid top value"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | 10 | ▶ | defined(_NONNEGINT($self->left)) or die "Missing or invalid left value"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | 10 | ▶ | defined(_NONNEGINT($self->height)) or die "Missing or invalid height value"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | 10 | ▶ | defined(_NONNEGINT($self->width)) or die "Missing or invalid width value"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | |||||||||||
| 41 | # Assume that we've been provided the basic (top/left/height/width) | ||||||||||
| 42 | # geometry, and from that derive the rest. | ||||||||||
| 43 | 10 | $self->{bottom} = $self->top + $self->height - 1; | |||||||||
| 44 | 10 | $self->{right} = $self->left + $self->width - 1; | |||||||||
| 45 | 10 | $self->{center_x} = int( ($self->left + $self->right ) / 2 ); | |||||||||
| 46 | 10 | $self->{center_y} = int( ($self->top + $self->bottom) / 2 ); | |||||||||
| 47 | |||||||||||
| 48 | 10 | return $self; | |||||||||
| 49 | } | ||||||||||
| 50 | |||||||||||
| 51 | 0 | ▶ | sub from_position { | ||||||||
|
Subroutine
from_position: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||
| 52 | 0 | my $class = shift; | |||||||||
| 53 | 0 | my $image = _INSTANCE(shift, 'Imager::Search::Image'); | |||||||||
| 54 | 0 | my $pattern = _INSTANCE(shift, 'Imager::Search::Pattern'); | |||||||||
| 55 | 0 | my $position = _NONNEGINT(shift); | |||||||||
| 56 | |||||||||||
| 57 | # Check params | ||||||||||
| 58 | 0 | ▶ | unless ( $image ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 59 | 0 | Carp::croak("Failed to provide Imager::Search::Image param"); | |||||||||
| 60 | } | ||||||||||
| 61 | 0 | ▶ | unless ( $pattern ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 62 | 0 | Carp::croak("Failed to provide Imager::Search::Pattern param"); | |||||||||
| 63 | } | ||||||||||
| 64 | 0 | ▶ | unless ( defined $position ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 65 | 0 | Carp::croak("Failed to provide position"); | |||||||||
| 66 | } | ||||||||||
| 67 | |||||||||||
| 68 | # Derive additional values from the basic values | ||||||||||
| 69 | 0 | my $width = $pattern->width; | |||||||||
| 70 | 0 | my $height = $pattern->height; | |||||||||
| 71 | 0 | my $top = int($position / $image->width); | |||||||||
| 72 | 0 | my $left = $position % $image->width; | |||||||||
| 73 | 0 | my $bottom = $top + $height - 1; | |||||||||
| 74 | 0 | my $right = $left + $width - 1; | |||||||||
| 75 | 0 | my $center_x = int(($left + $right) / 2); | |||||||||
| 76 | 0 | my $center_y = int(($top + $bottom) / 2); | |||||||||
| 77 | |||||||||||
| 78 | # Create the object | ||||||||||
| 79 | 0 | return $class->new( | |||||||||
| 80 | left => $left, | ||||||||||
| 81 | right => $right, | ||||||||||
| 82 | top => $top, | ||||||||||
| 83 | bottom => $bottom, | ||||||||||
| 84 | height => $height, | ||||||||||
| 85 | width => $width, | ||||||||||
| 86 | center_x => $center_x, | ||||||||||
| 87 | center_y => $center_y, | ||||||||||
| 88 | ); | ||||||||||
| 89 | } | ||||||||||
| 90 | |||||||||||
| 91 | 6 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 92 | 6 | *centre_x = *center_x; | |||||||||
| 93 | 6 | *centre_y = *center_y; | |||||||||
| 94 | } | ||||||||||
| 95 | |||||||||||
| 96 | 6 | 1; | |||||||||
| 97 | |||||||||||
| 98 | __END__ | ||||||||||