|
- #ifndef IZ_VECTOR_H
- #define IZ_VECTOR_H
-
- #include "IZ_math.h"
-
- typedef struct {
- // positive X is rightwards
- IZ_Real x;
-
- // positive Y is downwards
- IZ_Real y;
- } IZ_Vector;
-
- inline IZ_Vector IZ_VectorAdd(IZ_Vector a, IZ_Vector b) {
- return (IZ_Vector) {
- .x = a.x + b.x,
- .y = a.y + b.y,
- };
- }
-
- inline IZ_Vector IZ_VectorSubtract(IZ_Vector a, IZ_Vector b) {
- return (IZ_Vector) {
- .x = a.x - b.x,
- .y = a.y - b.y,
- };
- }
-
- inline IZ_Vector IZ_VectorMultiply(IZ_Vector a, IZ_Real b) {
- return (IZ_Vector) {
- .x = a.x * b,
- .y = a.y * b,
- };
- }
-
- inline IZ_Vector IZ_VectorDivide(IZ_Vector a, IZ_Real b) {
- return (IZ_Vector) {
- .x = a.x / b,
- .y = a.y / b,
- };
- }
-
- inline IZ_Real IZ_VectorDot(IZ_Vector a, IZ_Vector b) {
- return a.x * b.x + a.y * b.y;
- }
-
- inline IZ_Real IZ_VectorDistance(IZ_Vector a, IZ_Vector b) {
- IZ_Real x = b.x - a.x;
- IZ_Real y = b.y - a.y;
- return IZ_Sqrt(x * x + y * y);
- }
-
- #endif //IZ_VECTOR_H
|