-
Notifications
You must be signed in to change notification settings - Fork 0
/
query.py
87 lines (72 loc) · 2.48 KB
/
query.py
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
81
82
83
84
85
86
87
# GEO1000 - Assignment 3
# Authors:
# Studentnumbers:
from reader import read
from geometry import Rectangle, Circle, Point
from os.path import basename
def parse(geom_str):
"""Parse a string into a shape object (Point, Circle, or Rectangle)
# 输入的啥,返回输入点的类型
Formats that can be given:
p <px> <py>
c <cx> <cy> <r>
r <llx> <lly> <urx> <ury>
Returns - Point, Circle, or Rectangle
"""
pass
def print_statistics(result):
"""Prints statistics for the resulting list of Points of a query
* Number of points overlapping (i.e. number of points in the list)
* The leftmost point and its identity given by the id function
* The rightmost point and its identity given by the id function
Returns - None
"""
pass
def print_help():
"""Prints a help message to the user, what can be done with the program.
"""
helptxt = """
Commands available:
-------------------
General:
help
quit
Reading points in a structure, defining how many strips should be used:
open <filenm> into <number_of_strips>
Querying:
with a point: p <px> <py>
with a circle: c <cx> <cy> <radius>
with a rectangle: r <llx> <lly> <urx> <ury>"""
print(helptxt)
# =============================================================================
# Below are some commands that you may use to test your codes:
# open points2.txt into 5
# p 5.0 5.0
# c 10.0 10.0 1.0
# r 2.0 2.0 8.0 4.0
# =============================================================================
def main():
"""The main function of this program.
"""
structure = None
print("Welcome to {0}.".format(basename(__file__)))
print("=" * 76)
print_help()
while True:
in_str = input("your command>>>\n").lower()
if in_str.startswith("quit"):#判断用户输入的字符串0是否以quit开始
print("Bye, bye.")
return
elif in_str.startswith("help"):
print_help()
elif in_str.startswith("open"):
filenm, nstrips = in_str.replace("open ", "").split(" into ")
structure = read(filenm, int(nstrips))
structure.print_strip_statistics()
elif in_str.startswith("p") or in_str.startswith("c") or in_str.startswith("r"):
if structure is None:
print("No points read yet, open a file first!")
else:
print_statistics(structure.query(parse(in_str)))
if __name__ == "__main__":
main()