1 /* 2 * Copyright (c) 2018 Helmut Neemann. 3 * Use of this source code is governed by the GPL v3 license 4 * that can be found in the LICENSE file. 5 */ 6 package de.neemann.digital.draw.graphics; 7 8 /** 9 * The base interface of all vectors 10 */ 11 public interface VectorInterface { 12 13 /** 14 * @return the integer x coordinate 15 */ getX()16 int getX(); 17 18 /** 19 * @return the integer y coordinate 20 */ getY()21 int getY(); 22 23 /** 24 * @return the float x coordinate 25 */ getXFloat()26 float getXFloat(); 27 28 /** 29 * @return the float y coordinate 30 */ getYFloat()31 float getYFloat(); 32 33 /** 34 * Transforms the vector with the given transformation. 35 * 36 * @param tr the transformation to use 37 * @return the transformed vector 38 */ transform(Transform tr)39 VectorInterface transform(Transform tr); 40 41 /** 42 * Creates a new vector which has the value this+a 43 * 44 * @param a a 45 * @return this+a 46 */ add(VectorInterface a)47 VectorInterface add(VectorInterface a); 48 49 /** 50 * Creates a new vector which has the value this/d 51 * 52 * @param d d 53 * @return this/d 54 */ div(int d)55 VectorInterface div(int d); 56 57 /** 58 * Creates a new vector which has the value this*m 59 * 60 * @param m m 61 * @return this*m 62 */ mul(float m)63 VectorFloat mul(float m); 64 65 /** 66 * Creates a new vector which has the value this-a 67 * 68 * @param a a 69 * @return this-a 70 */ sub(VectorInterface a)71 VectorInterface sub(VectorInterface a); 72 73 /** 74 * @return the norm of this vector 75 */ norm()76 VectorFloat norm(); 77 78 /** 79 * Rounds the vector to an int vector 80 * 81 * @return a int vector 82 */ round()83 Vector round(); 84 85 /** 86 * @return returns a float vector 87 */ toFloat()88 VectorFloat toFloat(); 89 90 /** 91 * @return the length of the vector 92 */ len()93 float len(); 94 95 /** 96 * @return a vector which is orthogonal to this one 97 */ getOrthogonal()98 VectorInterface getOrthogonal(); 99 100 /** 101 * Calculates the scalar product 102 * 103 * @param v the vector to multiply with 104 * @return the scalar product 105 */ scalar(VectorInterface v)106 default float scalar(VectorInterface v) { 107 return getXFloat() * v.getXFloat() + getYFloat() * v.getYFloat(); 108 } 109 110 } 111