package cse1030.test2;
import cse1030.drawing.Point2D;
/**
* A class for finding two dimensional points that are strictly within a square
* neighbourhood surrounding a point.
*
* @author CSE1030_F13_14
*
*/
public class PointInSquare extends PointMatcher {
private double h;
/**
* Creates an object that matches all points strictly within a square
* neighbourhood surrounding the point p
. The size of the square
* is determined by the parameter halfLength
which is one half of
* the length of the side of the square (see figure below).
*
*
*
*
other
is strictly inside the square
* neighbourhood surrounding the point held by this matcher. If
* other
has coordinates (x, y)
, and the point held by
* this matcher has coordinates (px, py)
, and the half length of
* the square neighbourhood is h
, then the result is
* true
if and only if:
*
*
* | px - x | < h
is true
*
*
* AND * *
* | py - y | < h
is true
*
* @param other
* the point to check for a match
* @return true
if other
is strictly inside the
* square neighbourhood surround the point held by this matcher
* @see cse1030.test2.PointMatcher#matches(cse1030.drawing.Point2D)
*/
@Override
public boolean matches(Point2D other) {
return Math.abs(this.point.getX() - other.getX()) < this.h
&& Math.abs(this.point.getY() - other.getY()) < this.h;
}
}