-
Notifications
You must be signed in to change notification settings - Fork 2
/
PointSET.java
42 lines (39 loc) · 1.22 KB
/
PointSET.java
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
import java.util.HashSet;
import java.util.Set;
import java.util.TreeSet;
public class PointSET {
private TreeSet<Point2D> points;
public PointSET() // construct an empty set of points
{
points = new TreeSet<Point2D>();
}
public boolean isEmpty() // is the set empty?
{
return points.isEmpty();
}
public int size() // number of points in the set
{
return points.size();
}
public void insert(Point2D p) // add the point p to the set (if it is not already in the set)
{
points.add(p);
}
public boolean contains(Point2D p) // does the set contain the point p?
{
return points.contains(p);
}
public void draw() // draw all of the points to standard draw
{
for(Point2D p : points )
p.draw();
}
public Iterable<Point2D> range(RectHV rect) // all points in the set that are inside the rectangle
{
Set<Point2D> rangePoints = new HashSet<Point2D>();
for(Point2D p : points)
if(rect.contains( p))
rangePoints.add(p);
return rangePoints;
}
}