--- /dev/null
+package org.simantics.datatypes.literal;\r
+\r
+import org.simantics.databoard.Bindings;\r
+import org.simantics.databoard.binding.Binding;\r
+import org.simantics.databoard.util.Bean;\r
+\r
+\r
+final public class Vec2d extends Bean {\r
+\r
+ public static final Binding BINDING = Bindings.getBindingUnchecked(Vec2d.class);\r
+\r
+ public double x;\r
+ public double y;\r
+\r
+ public Vec2d(double x, double y) {\r
+ super(BINDING);\r
+ this.x = x;\r
+ this.y = y;\r
+ }\r
+\r
+ public boolean isZero() {\r
+ return x==0.0 && y==0.0; \r
+ }\r
+ \r
+ public double norm1() {\r
+ return Math.abs(x) + Math.abs(y);\r
+ }\r
+ \r
+ public double norm2() {\r
+ return Math.sqrt(x*x+y*y);\r
+ }\r
+ \r
+ public double length() {\r
+ return norm2();\r
+ }\r
+ \r
+ public double dot(Vec2d other) {\r
+ return x*other.x + y*other.y;\r
+ }\r
+\r
+ public Vec2d sum(Vec2d other) {\r
+ return new Vec2d(x + other.x , y + other.y);\r
+ }\r
+\r
+ public Vec2d subtraction(Vec2d other) {\r
+ return new Vec2d(x - other.x , y - other.y);\r
+ }\r
+\r
+ @Override\r
+ public String toString() {\r
+ return "Vec2d[x=" + x + ", y=" + y + "]";\r
+ }\r
+ \r
+}\r