01: // Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.
02: // Released under the terms of the GNU General Public License version 2 or later.
03: package fitnesse.testutil;
04:
05: import java.util.regex.*;
06:
07: public class CartesianVector {
08: private double x = 0;
09:
10: private double y = 0;
11:
12: public CartesianVector() {
13: }
14:
15: public CartesianVector(double x, double y) {
16: this .x = x;
17: this .y = y;
18: }
19:
20: public static CartesianVector parse(String s) {
21: Pattern vectorPattern = Pattern.compile("\\((.*),(.*)\\)");
22: Matcher vectorMatcher = vectorPattern.matcher(s);
23: if (vectorMatcher.matches()) {
24: double x = Double.parseDouble(vectorMatcher.group(1));
25: double y = Double.parseDouble(vectorMatcher.group(2));
26: return new CartesianVector(x, y);
27: }
28: return null;
29: }
30:
31: public boolean equals(Object obj) {
32: if (obj instanceof CartesianVector) {
33: CartesianVector v = (CartesianVector) obj;
34: if (v.x == x && v.y == y)
35: return true;
36: }
37: return false;
38: }
39:
40: public double getX() {
41: return x;
42: }
43:
44: public double getY() {
45: return y;
46: }
47:
48: public CartesianVector add(CartesianVector v) {
49: return new CartesianVector(v.getX() + x, v.getY() + y);
50: }
51: }
|