< prev index next >

core/JemmyCore/src/org/jemmy/Vector.java

Print this page




  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package org.jemmy;
  27 
  28 /**
  29  * The class for easy computations.
  30  * @author shura
  31  */
  32 public class Vector {
  33 
  34     private double x;
  35     private double y;
  36 
  37     /**
  38      *
  39      * @param x
  40      * @param y
  41      */
  42     public Vector(double x, double y) {
  43         this.x = x;
  44         this.y = y;
  45     }
  46 
  47     /**
  48      *
  49      * @param from
  50      * @param to
  51      */
  52     public Vector(Point from, Point to) {
  53         x = to.x - from.x;
  54         y = to.y - from.y;
  55     }
  56 
  57     /**
  58      *
  59      * @return
  60      */
  61     public double getX() {
  62         return x;
  63     }
  64 
  65     /**
  66      *
  67      * @return
  68      */
  69     public double getY() {
  70         return y;
  71     }
  72 
  73     /**
  74      *
  75      * @return
  76      */
  77     public double lenght() {
  78         return Math.sqrt(x*x + y*y);
  79     }
  80 
  81     /**
  82      *
  83      * @param newLenght
  84      * @return self
  85      */
  86     public Vector setLenght(double newLenght) {
  87         double lenght = lenght();
  88         x = x * newLenght / lenght;
  89         y = y * newLenght / lenght;
  90         return this;
  91     }
  92 
  93     /**
  94      * @param multiplier
  95      * @return self
  96      */
  97     public Vector multiply(double multiplier) {
  98         x*=multiplier;
  99         y*=multiplier;
 100         return this;
 101     }
 102 
 103     /**
 104      *
 105      * @return a clone
 106      */
 107     @Override
 108     public Vector clone() {
 109         return new Vector(x, y);
 110     }
 111 
 112     /**
 113      *
 114      * @return
 115      */
 116     @Override
 117     public String toString() {
 118         return "(" + x + "," + y + ")";
 119     }
 120 
 121     /**
 122      * Adds another vector <code>(x1 + x2, y1 + y2)</code>
 123      * @param v
 124      * @return self
 125      */
 126     public Vector add(Vector v) {
 127         x+=v.x;
 128         y+=v.y;
 129         return this;
 130     }
 131 
 132 
 133 }


  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package org.jemmy;
  27 
  28 /**
  29  * The class for easy computations.
  30  * @author shura
  31  */
  32 public class Vector {
  33 
  34     private double x;
  35     private double y;
  36 





  37     public Vector(double x, double y) {
  38         this.x = x;
  39         this.y = y;
  40     }
  41 





  42     public Vector(Point from, Point to) {
  43         x = to.x - from.x;
  44         y = to.y - from.y;
  45     }
  46 




  47     public double getX() {
  48         return x;
  49     }
  50 




  51     public double getY() {
  52         return y;
  53     }
  54 




  55     public double lenght() {
  56         return Math.sqrt(x*x + y*y);
  57     }
  58 





  59     public Vector setLenght(double newLenght) {
  60         double lenght = lenght();
  61         x = x * newLenght / lenght;
  62         y = y * newLenght / lenght;
  63         return this;
  64     }
  65 




  66     public Vector multiply(double multiplier) {
  67         x*=multiplier;
  68         y*=multiplier;
  69         return this;
  70     }
  71 
  72     /**
  73      * {@inheritDoc}

  74      */
  75     @Override
  76     public Vector clone() {
  77         return new Vector(x, y);
  78     }
  79 
  80     /**
  81      * {@inheritDoc}

  82      */
  83     @Override
  84     public String toString() {
  85         return "(" + x + "," + y + ")";
  86     }
  87 





  88     public Vector add(Vector v) {
  89         x+=v.x;
  90         y+=v.y;
  91         return this;
  92     }

  93 
  94 }
< prev index next >