Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
81 lines (59 loc) · 1.66 KB

File metadata and controls

81 lines (59 loc) · 1.66 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"""This module contains code from
Think Python by Allen B. Downey
http://thinkpython.com
Copyright 2012 Allen B. Downey
License: GNU GPLv3 http://www.gnu.org/licenses/gpl.html
"""
import copy
import math
# to avoid duplicating code, I'm importing everything from Point1
from Point1 import *
def distance_between_points(p1, p2):
"""Computes the distance between two Point objects."""
dx = p1.x - p2.x
dy = p1.y - p2.y
dist = math.sqrt(dx**2 + dy**2)
return dist
def move_rectangle(rect, dx, dy):
"""Move the Rectangle by modifying its corner object.
rect: Rectangle object.
dx: change in x coordinate (can be negative).
dy: change in y coordinate (can be negative).
"""
rect.corner.x += dx
rect.corner.y += dy
def move_rectangle_copy(rect, dx, dy):
"""Move the Rectangle and return a new Rectangle object.
rect: Rectangle object.
dx: change in x coordinate (can be negative).
dy: change in y coordinate (can be negative).
"""
new = copy.deepcopy(rect)
move_rectangle(new, dx, dy)
return new
def main():
blank = Point()
blank.x = 0
blank.y = 0
grosse = Point()
grosse.x = 3
grosse.y = 4
print 'distance',
print distance_between_points(grosse, blank)
box = Rectangle()
box.width = 100.0
box.height = 200.0
box.corner = Point()
box.corner.x = 50.0
box.corner.y = 50.0
print box.corner.x
print box.corner.y
print 'move'
move_rectangle(box, 50, 100)
print box.corner.x
print box.corner.y
new_box = move_rectangle_copy(box, 50, 100)
print box.corner.x
print box.corner.y
if __name__ == '__main__':
main()
Morty Proxy This is a proxified and sanitized view of the page, visit original site.