Source code: com/eireneh/bible/control/map/BoundsRule.java
1
2 package com.eireneh.bible.control.map;
3
4 /**
5 * BoundsRule implements Rule and attempts to move the Node within the
6 * space (0, 0, _) to (1, 1, _).
7 *
8 * <table border='1' cellPadding='3' cellSpacing='0' width="100%">
9 * <tr><td bgColor='white'class='TableRowColor'><font size='-7'>
10 * Distribution Licence:<br />
11 * Project B is free software; you can redistribute it
12 * and/or modify it under the terms of the GNU General Public License,
13 * version 2 as published by the Free Software Foundation.<br />
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.<br />
18 * The License is available on the internet
19 * <a href='http://www.gnu.org/copyleft/gpl.html'>here</a>, by writing to
20 * <i>Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
21 * MA 02111-1307, USA</i>, Or locally at the Licence link below.<br />
22 * The copyright to this program is held by it's authors.
23 * </font></td></tr></table>
24 * @see <a href='http://www.eireneh.com/servlets/Web'>Project B Home</a>
25 * @see docs.Licence
26 * @author Joe Walker
27 * @version D0.I0.T0
28 */
29 public class BoundsRule extends AbstractRule
30 {
31 /**
32 * Specify where it would like a node to be positioned in space.
33 * Rules return an array of positions where the average of them
34 * specifies the real desired position. So to specify a single place
35 * simply return an array of one position. The positions are added
36 * to the results from all Rules so to specify a single position
37 * more strongly, return an array conataining that position many
38 * times.
39 * <br />
40 * I expect that any Rule will not return more than 30 positions.
41 * This expectation may be useful in colouring how many times to
42 * include your Position(s) in the array.
43 * @param map The Map to select a node from
44 * @param ord The ordinal number (1 - 31104) of the verse
45 * @return An array of desired positions.
46 */
47 public Position[] getDesiredPosition(Map map, int ord)
48 {
49 if (scale == 0)
50 return new Position[] { };
51
52 float[] arr = map.getPosition(ord);
53
54 boolean oob = false;
55
56 // force the coords to be inside (0, 0, ...) to (1, 1, ...)
57 for (int i=0; i<arr.length; i++)
58 {
59 if (arr[i] < 0)
60 {
61 arr[i] = 0;
62 oob = true;
63 }
64
65 if (arr[i] > 1)
66 {
67 arr[i] = 1;
68 oob = true;
69 }
70 }
71
72 if (oob)
73 {
74 return scale(new Position(arr));
75 }
76 else
77 {
78 return new Position[] { };
79 }
80 }
81 }