|
Chapter: 1. Source code download,
2. Test results, 3. Test item and method,
4. Comment on the resuls, 5. Test code
1. Source code download
=>
CurveHitTest.zip
2. Test resultsreturn=>page top
|
Figure1 Shapes to be tested
|
|
Figure2 Test resuls Performs the hit test for each gridpoint and display the result by color.
red: on the boundary, gray: not on the boundary |
3. Test item and methodreturn=>page top
Basically the mouse cursor is regarded to be hit a curve (including a line and
a polyline), if the minimum distance from the
mouse cursor to the curve is smaller than the specified value. The calculation
of the minimum distance from a point to a curve is performed by the DrawTop Curve2DUtil.getShortestLine (See the Figure 3 below and the video). In the Figure 2, the mouse is regarded to be hit if the minimum distance is smaller than
3 pixels.
|
|
|
Video: GeometricTest
|
Figure 3 The nearest points from the mouse cursor to the five curves |
Similar test |
4. Comment on the resultsreturn=>page top
As you can see in the Figure 2, this test can be applicable to an unclosed curve such as Ex1, Ex5,
Ex6 and Ex9.
In the scrolling of the drawing panel (Figure1, 2), the processing time of rewriting (refreshing) the drawing panel
takes nearly 2 seconds, so the scrolling seems too slow. However, the rewriting
time per one grid point is smaller than 0.1 milli-second. Additionally
you can confirm that the processing speed is fast enough for the real time
operation by the video (Geometric Test).
5. Test codereturn=>page top
5.1 Classes Overview
Class
|
Description
|
CurveHitTest
|
public class CurveHitTest extends JFrame
Creates and assembles the objects of the Jframe, JScrollPane, JViewport
and the Panel.
|
CurveHitTestPanel |
public class CurveHitTestPanel extends JPanel
Draws several closed shapes and their test results on this object.
|
TestCase |
public class TestCase
=> TestCase of the RegionHitTest.
|
TestCurve |
public class TestCurve
=> TestCurve of the RegionHitTest.
|
Parametric Curves |
Segment2D,
Curve2D,
Rectangle2DE,
RoundRectangle2DE,
Ellipse2DE,
Line2DE,
Polyline2DE,
CubicCurve2DE,
GeneralCurve2DE,
FergusonCurve2D |
Geometric library |
Curve2DUtil.getNormalLines,
CurvePT,
Matrix,
Matrix2D
|
5.2 Specifications
5.2.1 public class CurveHitTestPanel extends JPanel
Method
|
Description
|
createTestCase |
public void createTestCase()
Creates nine TestCase objects.
|
getEnlargedBoundingBox |
public Rectangle2D getEnlargedBoundingBox(Rectangle2D boundingBox, double
wideEx, double heightEx)
Parameters:
box - The Rectangle2D object.
wideEx - The horizontal amount of expanding.
heightEx - The vertical amount of expanding.
Returns:
The Enlarged Rectangle2D object.
Processing:
Returns the Enlarged Rectangle2D object. Its width is the width of
box + 2*wideEx andits height width is the height of box + 2*heghtEx.
|
getGridPoints |
public Point2D[] getGridPoints(Rectangle2D box)
parameters:
box - The Rectangle2D object.
Returns: The created grid points in the box.
Processing:
Creates a set of the grid points in the box and returns it.
=>The grid point shown in the Figue 2.
|
ptOnCurve |
private int ptOnCurve(Curve2D curve, Point2D point)
Parameters:
curve - the given curve(including a line and a polyline)
point - the point to be tested (mouse cursor position)
Returns:
0 - out of the curve
1 - on the curve
Processing:
Calls the following ptOnSegments method and ptOnBox method.
|
ptOnSegments |
private int ptOnSegments(Curve2D curve, Point2D point, double tol)
Parameters:
curve - the given curve(including a line and a polyline)
point - the point to be tested (mouse cursor position)
tol - tolerance
Returns:
0 - not on the curve
1 - on the curve
Processing:
Performs the hit test for each curve segment (Segment2D object). Divides the curve segment and covers each piece by a box and
judges the hit test by the ptOnBox method.
|
ptOnBox |
private int ptOnBox(Rectangle2D box, Point2D point, double tol)
Parameters:
box - a rectangle
point - the point to be tested (mouse cursor position)
tol - tolerance
Returns:
0 - not on the box
1 - on the box
Processing:
Judges whether the point is contained in the larger box which expands the box outside by tol.
In other words, returns 1, if the point is contained in the expanded box, otherwise returns 0.
|
paint |
public void paint(Graphics g)
Draws the shapes in the TestCase objects on this panel by the paintShape
method, and draws their test results by the paintOnCurve method.
|
paintShape |
public void paintShape(Graphics g)
Draws the shapes in the TestCase objects on this panel (Figure1).
|
paintOnCurve |
public void paintOnCurve(Graphics g)
Draws the test resuls on this panel (Figure2).
|
|