File: point.py

package info (click to toggle)
pycode-browser 20120614%2Bgit%2Bb041dd2-7
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 6,236 kB
  • ctags: 1,194
  • sloc: python: 2,220; xml: 152; makefile: 39
file content (26 lines) | stat: -rwxr-xr-x 548 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
class Point:
  xpos = 0
  ypos = 0
  
  def __init__(self, x=0, y=0):
    self.xpos = x
    self.ypos = y

  def __str__(self):
    return 'Point at (%f,%f)'%(self.xpos, self.ypos)

  def __add__(self, other):
    xpos = self.xpos + other.xpos
    ypos = self.ypos + other.ypos
    res = Point(xpos,ypos)
    return res

  def __sub__(self, other):
    import math
    dx = self.xpos - other.xpos
    dy = self.ypos - other.ypos
    return math.sqrt(dx**2+dy**2)

  def dist(self):
    import math
    return math.sqrt(self.xpos**2 + self.ypos**2)