Skip Menu |
 

This queue is for tickets about the Geometry-AffineTransform CPAN distribution.

Report information
The Basics
Id: 64636
Status: open
Priority: 0/
Queue: Geometry-AffineTransform

People
Owner: reg.cpan [...] entropy.ch
Requestors: user42 [...] zip.com.au
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: untransform coordinates
Date: Mon, 10 Jan 2011 08:34:05 +1100
To: bug-Geometry-AffineTransform [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
Download (untitled) / with headers
text/plain 637b
After transforming some coordinate values to screen pixel positions I thought to do the reverse, taking a pixel position back to original values. Is there an untransform hiding in the code?, like ($x,$y) = $aff->untransform($x,y) I suppose an ->invert() or something could invert the whole transform object. So maybe $rev=$aff->clone->invert to get a reverse. Though I think I only want a handful of untransforms. Incidentally, as a suggestion for the docs, I like seeing a sample call for methods rather than a description in words (or a sample as well as words). I find a sample easier to read quickly, cut and paste, etc.
Subject: Re: [rt.cpan.org #64636] untransform coordinates
Date: Tue, 11 Jan 2011 09:07:27 +1100
To: bug-Geometry-AffineTransform [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
Download (untitled) / with headers
text/plain 1007b
Marc Liyanage <marc@entropy.ch> writes: Show quoted text
> > both are good suggestions, unfortunately I don't have time to work on > it anytime soon.
I might have a go at what I think I want. Show quoted text
> I looked into the inverse a while ago, and I wasn't sure how to do it > properly so all cases are handled.
It might be as easy as the matrix inverse (a division by the determinant, and taking the values swapped, or some such) and applying the offset either before or after, whichever is the right way around :) Show quoted text
> You're the first person ever other than me who I know using it. What > are you doing with it and how did you find the module?
I was experimenting in my math-image program (on cpan!) with a bit of a rotate, scale and offset. I'd had my own few lines for scale and offset, and had seen Transform::Canvas doing similar, then twigged to search for "affine" for rotate as well. I'm not sure how much rotating I'll end up wanting, but even for just scale and offset I was thinking "why can't someone else do it" :-)
Subject: Re: [rt.cpan.org #64636] untransform coordinates
Date: Sat, 15 Jan 2011 08:54:12 +1100
To: bug-Geometry-AffineTransform [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
Download (untitled) / with headers
text/plain 1.3k
I got to the few lines below. Haven't made actual tests, but seems pretty close. I might make a croak for det==0 instead of letting it throw divide by zero. (That arising from a scale==0 factor, either X or Y or both, and there being no way to get back original positions in that case.) I see the java class has longer name inverseTransform, but I think I like untransform better. # ($x,$y, $x,$y, ...) = $aff->untransform($x,$y, $x,$y, ...) sub untransform { my $self = shift; my @result; my $det = $self->{m11}*$self->{m22} - $self->{m12}*$self->{m21}; while (@_) { my $x = shift() - $self->{tx}; my $y = shift() - $self->{ty}; push @result, ($self->{m22} * $x - $self->{m21} * $y) / $det, ($self->{m11} * $y - $self->{m12} * $x) / $det; } return @result; } # $aff->invert, and returning the modified $aff sub invert { my ($self) = @_; my $det = $self->{m11}*$self->{m22} - $self->{m12}*$self->{m21}; return $self->set_matrix_2x3 ($self->{m22} / $det, # 11 - $self->{m12} / $det, # 12 - $self->{m21} / $det, # 21 $self->{m11} / $det, # 22 $self->untransform(0,0)); # tx,ty as full expressions instead of untransform(), if preferred # ($self->{m21} * $self->{ty} - $self->{m22} * $self->{tx}) / $det, # ($self->{m12} * $self->{tx} - $self->{m11} * $self->{ty}) / $det); }
Subject: Re: [rt.cpan.org #64636] untransform coordinates
Date: Wed, 19 Jan 2011 11:10:14 -0800
To: bug-Geometry-AffineTransform [...] rt.cpan.org
From: Marc Liyanage <marc [...] entropy.ch>
Download (untitled) / with headers
text/plain 1.9k
Thanks for this implementation, that's great. I added an invert() method to the class, everything else can be composed with that method: $t->invert()->transform(...) $t->clone()->invert()->transform(...) etc. I added the exception when the determinant is zero, and some new unit tests to test it all. Thanks again. On Jan 14, 2011, at 13:55 , Kevin Ryde via RT wrote: Show quoted text
> Queue: Geometry-AffineTransform > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=64636 > > > I got to the few lines below. Haven't made actual tests, but seems > pretty close. > > I might make a croak for det==0 instead of letting it throw divide by > zero. (That arising from a scale==0 factor, either X or Y or both, and > there being no way to get back original positions in that case.) > > I see the java class has longer name inverseTransform, but I think I > like untransform better. > > > > # ($x,$y, $x,$y, ...) = $aff->untransform($x,$y, $x,$y, ...) > sub untransform { > my $self = shift; > my @result; > my $det = $self->{m11}*$self->{m22} - $self->{m12}*$self->{m21}; > while (@_) { > my $x = shift() - $self->{tx}; > my $y = shift() - $self->{ty}; > push @result, > ($self->{m22} * $x - $self->{m21} * $y) / $det, > ($self->{m11} * $y - $self->{m12} * $x) / $det; > } > return @result; > } > > # $aff->invert, and returning the modified $aff > sub invert { > my ($self) = @_; > my $det = $self->{m11}*$self->{m22} - $self->{m12}*$self->{m21}; > return $self->set_matrix_2x3 > ($self->{m22} / $det, # 11 > - $self->{m12} / $det, # 12 > - $self->{m21} / $det, # 21 > $self->{m11} / $det, # 22 > $self->untransform(0,0)); > > # tx,ty as full expressions instead of untransform(), if preferred > # ($self->{m21} * $self->{ty} - $self->{m22} * $self->{tx}) / $det, > # ($self->{m12} * $self->{tx} - $self->{m11} * $self->{ty}) / $det); > } >
Show quoted text
______________________________ Marc Liyanage www.entropy.ch skype mliyanage iChat liyanage@mac.com
Fixed in 1.3
Subject: Re: [rt.cpan.org #64636] untransform coordinates
Date: Wed, 02 Feb 2011 11:55:26 +1100
To: bug-Geometry-AffineTransform [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
Download (untitled) / with headers
text/plain 474b
"Marc Liyanage via RT" <bug-Geometry-AffineTransform@rt.cpan.org> writes: Show quoted text
> > $t->clone()->invert()->transform(...)
And the untransform() method to do that too? You don't want the java class having more ways to do it than perl! :) The untransform() doesn't have to be particularly fast. I don't mind that it might calculate the determinant each time. You could leave the comment in invert() that the inverted tx,ty are the 0,0 point untransformed, as it's a bit hairy.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.