Line | Hits | Source |
---|---|---|
1 | /* | |
2 | * Copyright (c) 2003, the JUNG Project and the Regents of the University | |
3 | * of California | |
4 | * All rights reserved. | |
5 | * | |
6 | * This software is open-source under the BSD license; see either | |
7 | * "license.txt" or | |
8 | * http://jung.sourceforge.net/license.txt for a description. | |
9 | */ | |
10 | package edu.uci.ics.jung.visualization; | |
11 | ||
12 | import java.awt.geom.Point2D; | |
13 | ||
14 | /** | |
15 | * | |
16 | * Stores coordinates (X,Y) for vertices being visualized. | |
17 | * | |
18 | * @author Scott White | |
19 | */ | |
20 | public class Coordinates extends Point2D.Float { | |
21 | ||
22 | public Coordinates() { | |
23 | 900 | super(); |
24 | 900 | } |
25 | ||
26 | public Coordinates(double x, double y) { | |
27 | 0 | super((float)x,(float)y); |
28 | 0 | } |
29 | ||
30 | /** | |
31 | * Initializes this coordinate to the value of the passed-in | |
32 | * coordinate. | |
33 | * @param coordinates | |
34 | */ | |
35 | public Coordinates(Coordinates coordinates) { | |
36 | 0 | this(coordinates.getX(), coordinates.getY()); |
37 | 0 | } |
38 | ||
39 | /** | |
40 | * Sets the x value to be d; | |
41 | * @param d | |
42 | */ | |
43 | public void setX(double d) { | |
44 | 21498 | setLocation(d, getY()); |
45 | 21498 | } |
46 | ||
47 | /** | |
48 | * Sets the y value to be d; | |
49 | * @param d | |
50 | */ | |
51 | public void setY(double d) { | |
52 | 21516 | setLocation(getX(), d); |
53 | 21516 | } |
54 | ||
55 | /** | |
56 | * Increases the x and y values of this | |
57 | * scalar by (x, y). | |
58 | * @param x | |
59 | * @param y | |
60 | */ | |
61 | public void add(double x, double y) { | |
62 | 100 | addX(x); |
63 | 100 | addY(y); |
64 | 100 | } |
65 | ||
66 | /** | |
67 | * Increases the x value by d. | |
68 | * @param d | |
69 | */ | |
70 | public void addX(double d) { | |
71 | 11720 | setX(getX()+d); |
72 | 11720 | } |
73 | ||
74 | /** | |
75 | * Increases the y value by d. | |
76 | * @param d | |
77 | */ | |
78 | public void addY(double d) { | |
79 | 11720 | setY(getY()+d); |
80 | 11720 | } |
81 | ||
82 | /** | |
83 | * Multiplies a coordinate by scalar x and y values. | |
84 | * @param x A scalar to multiple x by | |
85 | * @param y A scalar to multiply y by | |
86 | */ | |
87 | public void mult(double x, double y) { | |
88 | 0 | multX(x); |
89 | 0 | multY(y); |
90 | 0 | } |
91 | ||
92 | /** | |
93 | * Multiplies the X coordinate by a scalar value. | |
94 | * <P> | |
95 | * For example, (3, 10) x-scaled by 2 returns (6, 10). | |
96 | * @param d the scalar value by which x will be multiplied | |
97 | */ | |
98 | public void multX(double d) { | |
99 | 0 | setX(getX()*d); |
100 | 0 | } |
101 | ||
102 | /** | |
103 | * Multiplies the Y coordinate by a scalar value. | |
104 | * <P> | |
105 | * For example, (3, 10) y-scaled by 2 returns (3, 20). | |
106 | * @param d the scalar value by which y will be multiplied | |
107 | */ | |
108 | public void multY(double d) { | |
109 | 0 | setY(getY()*d); |
110 | 0 | } |
111 | ||
112 | /** | |
113 | * Computes the euclidean distance between two coordinates | |
114 | * @param o another coordinates | |
115 | * @return the euclidean distance | |
116 | */ | |
117 | public double distance(Coordinates o) { | |
118 | 0 | return super.distance(o); |
119 | } | |
120 | ||
121 | /** | |
122 | * Computes the midpoint between the two coordinates | |
123 | * @param o another coordinates | |
124 | * @return the midpoint | |
125 | */ | |
126 | public Coordinates midpoint(Coordinates o) { | |
127 | 0 | double midX = (this.getX() + o.getX()) / 2.0; |
128 | 0 | double midY = (this.getY() + o.getY()) / 2.0; |
129 | 0 | Coordinates midpoint = new Coordinates(midX, midY); |
130 | 0 | return midpoint; |
131 | } | |
132 | ||
133 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |