alcemirfernandes / pynguin

Automatically exported from code.google.com/p/pynguin
GNU General Public License v3.0
0 stars 0 forks source link

it would be great to be able to get the coordinate I _would_ be at if I moved forward(x) #40

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Instead of needing to move there, record that point, and move back (which slows 
stuff down enormously).

Original issue reported on code.google.com by aresnick...@gmail.com on 25 Jul 2010 at 2:07

GoogleCodeExporter commented 9 years ago
Not quite sure what to call it, or if it is useful enough
generally to add it directly to the Pynguin class, but it's
easy enough to do ...

from math import sin, cos
class PP(Pynguin):
    def getforward(self, distance):
        deg = self.heading
        rad = deg * (PI / 180)
        dx = distance * cos(rad)
        dy = distance * sin(rad)

        x0, y0 = self.xy()

        x = x0 + dx
        y = y0 + dy

        return x, y

Do you have a better name, or an example that makes a great
case for adding the method to the base class?

Original comment by miss...@hotmail.com on 25 Jul 2010 at 8:47

GoogleCodeExporter commented 9 years ago
Mostly, it's come up for when people want to constantly check if they are 
within some shape or region they've made--they go forward 1, check something, 
if it's true, go back, and then actually go forward.

Maybe a name like "peekforward" or something?

I'm not sure it should be in the base class either--it's really a workaround a 
speed issue for a common workflow, I suppose.

Original comment by aresnick...@gmail.com on 25 Jul 2010 at 4:39

GoogleCodeExporter commented 9 years ago
Ok. I've done something like that before and it was pretty useful.

I've added the method as:

xyforward(distance)

but I did not pull it in to builtins yet. Give it a try and let 
me know how it works out.

Original comment by miss...@hotmail.com on 28 Jul 2010 at 1:34

GoogleCodeExporter commented 9 years ago
Thanks!  I'll check it out.

Original comment by aresnick...@gmail.com on 28 Jul 2010 at 1:51

GoogleCodeExporter commented 9 years ago
Nope, I can't seem to reproduce it.  I'll let you know if it comes up again.  
Thanks!

Original comment by aresnick...@gmail.com on 1 Aug 2010 at 3:37

GoogleCodeExporter commented 9 years ago
I went ahead and added xyforward() to the built-in functions

Original comment by miss...@hotmail.com on 12 Jun 2011 at 9:30