56 lines
1017 B
C
56 lines
1017 B
C
#ifndef global_objects
|
|
#define global_objects
|
|
|
|
#include <math.h>
|
|
|
|
#define flaot float
|
|
|
|
typedef struct {
|
|
float x;
|
|
float y;
|
|
} Point;
|
|
|
|
void point_add(Point *A, Point *B){
|
|
A->x = A->x + B->x;
|
|
A->y = A->y + B->y;
|
|
}
|
|
|
|
void point_sub(Point *A, Point *B){
|
|
A->x = A->x - B->x;
|
|
A->y = A->y - B->y;
|
|
}
|
|
|
|
void point_mul(Point *A, Point *B){
|
|
A->x = A->x * B->x;
|
|
A->y = A->y * B->y;
|
|
}
|
|
|
|
/*
|
|
fn set_mag(x: &f64,y: &f64, mag: &f64) -> Vec<f64>{
|
|
let getmag: f64 = magnitude(*x, *y);
|
|
let rx = (*x / getmag) * mag;
|
|
let ry = (*y / getmag) * mag;
|
|
|
|
return vec![rx,ry]
|
|
}
|
|
|
|
fn magnitude(x: f64,y: f64) -> f64 {
|
|
((x).powi(2) + (y).powi(2)).sqrt()
|
|
}
|
|
*/
|
|
|
|
float magnitude(flaot x, flaot y) {
|
|
return sqrt((pow(x,2) + pow(y,2)));
|
|
}
|
|
|
|
void point_set_mag(Point *point, float mag){
|
|
flaot getmag = magnitude(point->x, point->y);
|
|
flaot rx = (point->x / getmag) * mag;
|
|
flaot ry = (point->y / getmag) * mag;
|
|
|
|
point->x = rx;
|
|
point->y = ry;
|
|
}
|
|
|
|
#endif
|