File: contains.java

package info (click to toggle)
mauve 20161030-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 44,628 kB
  • ctags: 35,425
  • sloc: java: 336,555; sh: 2,834; xml: 208; makefile: 72
file content (131 lines) | stat: -rw-r--r-- 3,335 bytes parent folder | download | duplicates (5)
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// Tags: JDK1.2

// Copyright (C) 2003 Sascha Brawer <brawer@dandelis.ch>

// This file is part of Mauve.

// Mauve is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2, or (at your option)
// any later version.

// Mauve is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Mauve; see the file COPYING.  If not, write to
// the Free Software Foundation, 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.  */

package gnu.testlet.java.awt.geom.RoundRectangle2D;

import gnu.testlet.Testlet;
import gnu.testlet.TestHarness;

import java.awt.geom.RoundRectangle2D;


/* Uncomment this line and the code towards the end of the class
 * for displaying a visualization of the testlet.
 *

import java.awt.*;

 *
 */



/**
 * Checks that RoundRectangle2D.contains works correctly.  In the
 * illustration below, points considered <em>inside</em> are painted
 * green, and points considered <em>outside</em> are painted red.
 *
 * <p><img src="doc-files/contains-1.png" width="198" height="184"
 * alt="A visualization of the tested points" />
 *
 * @author Sascha Brawer (brawer@dandelis.ch)
 */
public class contains
  implements Testlet
{
  RoundRectangle2D rr = new RoundRectangle2D.Double(0,0,10,10,6,6);

  private static final double[] coords = { -1, 0.5, 5, 9.5, 11 };

  public void test(TestHarness harness)
  {
    for (int y = 0; y < coords.length; y++)
      for (int x = 0; x < coords.length; x++)
        harness.check(rr.contains(coords[x], coords[y])
                      == getExpected(coords[x], coords[y]));
  }


  private boolean getExpected(double x, double y)
  {
    if ((x == 0.5) && (y == 5))
      return true;

    if ((x == 5) && ((y == 0.5) || (y == 5) || (y == 9.5)))
      return true;

    if ((x == 9.5) && (y == 5))
      return true;

    return false;
  }


  /* This code was used to generate the image.
   *
   *

  public void showWindow()
  {
    Frame f = new Frame("Foo");
    Canvas c = new Canvas()
    {
      public void paint(Graphics g)
      {
        Graphics2D g2 = (Graphics2D) g;
        g2.setBackground(Color.WHITE);
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                            RenderingHints.VALUE_ANTIALIAS_ON);
        g2.clearRect(0,0,getWidth(),getHeight());
        g2.scale(10,10);
        g2.translate(4, 4);
        g2.fill(rr);

        Rectangle2D rect = new Rectangle2D.Double();

        for (int y = 0; y < coords.length; y++)
        {
          for (int x = 0; x < coords.length; x++)
          {
            if (getExpected(coords[x], coords[y]))
              g2.setColor(Color.GREEN);
            else
              g2.setColor(Color.RED);

            rect.setRect(coords[x], coords[y], 0.2, 0.2);
            g2.fill(rect);
          }
        }
      }
    };

    f.add(c);
    f.pack();
    f.setSize(new Dimension(200, 200));
    f.show();
  }

  public static void main(String[] args)
  {
    new contains().showWindow();
  }
  */
}