root/tools/routingservice/trunk/src/jp/co/orkney/restlet/util/LimitsHelper.java

Revision 166, 1.7 KB (checked in by anton, 3 years ago)

Some code cleaning

Line 
1package jp.co.orkney.restlet.util;
2
3/**
4 * Copyright (c) 2008 Orkney, Inc. <http://www.orkney.co.jp/>
5 *
6 * This program is free software: you can redistribute it and/or modify it under
7 * the terms of the GNU General Public License as published by the Free Software
8 * Foundation, either version 3 of the License, or (at your option) any later
9 * version.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14 * details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20public class LimitsHelper
21{
22    public static boolean isDistanceAllowed(Point startPoint, Point endPoint,
23            double distance)
24    {
25        double a = startPoint.getX().doubleValue()
26                - endPoint.getX().doubleValue();
27        double b = startPoint.getY().doubleValue()
28                - endPoint.getY().doubleValue();
29
30        return Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2)) < distance;
31    }
32
33    public static boolean isAreaAllowed(Point startPoint, Point endPoint,
34            Point llCorner, Point urCorner)
35    {
36        double llX = llCorner.getX().doubleValue();
37        double llY = llCorner.getY().doubleValue();
38        double urX = urCorner.getX().doubleValue();
39        double urY = urCorner.getY().doubleValue();
40
41        double startX = startPoint.getX().doubleValue();
42        double startY = startPoint.getY().doubleValue();
43        double endX = endPoint.getX().doubleValue();
44        double endY = endPoint.getY().doubleValue();
45
46        return (Math.min(startX, endX) >= llX)
47                && (Math.min(startY, endY) >= llY)
48                && (Math.max(startX, endX) <= urX)
49                && (Math.max(startY, endY) >= urY);
50    }
51}
Note: See TracBrowser for help on using the browser.