]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.datatypes/src/org/simantics/datatypes/literal/Vec2d.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.datatypes / src / org / simantics / datatypes / literal / Vec2d.java
1 package org.simantics.datatypes.literal;
2
3 import org.simantics.databoard.Bindings;
4 import org.simantics.databoard.binding.Binding;
5 import org.simantics.databoard.util.Bean;
6
7
8 final public class Vec2d extends Bean {
9
10         public static final Binding BINDING = Bindings.getBindingUnchecked(Vec2d.class);
11
12         public double x;
13         public double y;
14
15         public Vec2d(double x, double y) {
16                 super(BINDING);
17                 this.x = x;
18                 this.y = y;
19         }
20
21         public boolean isZero() {
22                 return x==0.0 && y==0.0; 
23         }
24         
25         public double norm1() {
26                 return Math.abs(x) + Math.abs(y);
27         }
28         
29         public double norm2() {
30                 return Math.sqrt(x*x+y*y);
31         }
32         
33         public double length() {
34                 return norm2();
35         }
36         
37         public double dot(Vec2d other) {
38                 return x*other.x + y*other.y;
39         }
40
41         public Vec2d sum(Vec2d other) {
42                 return new Vec2d(x + other.x , y + other.y);
43         }
44
45         public Vec2d subtraction(Vec2d other) {
46                 return new Vec2d(x - other.x , y - other.y);
47         }
48
49         @Override
50         public String toString() {
51                 return "Vec2d[x=" + x + ", y=" + y + "]";
52         }
53         
54 }