-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpoint.h
49 lines (44 loc) · 1.35 KB
/
point.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#ifndef POINT_H
#define POINT_H
#include <math.h>
#include <gmp.h>
#include <assert.h>
#include "utils.h"
#define FLOAT_PRECISION 64
typedef struct {
mpf_t x, y;
} point_t;
void point_init(point_t *p);
void point_set(point_t *p, const char *x, const char *y);
/**
* Subtracts p2 from p1 and stores the result to dest.
*/
void point_sub(point_t *dest, point_t p1, point_t p2);
/**
* Returns the vectorial norm of p, storing it into result. At the moment
* only bidimensional vectors are supported, so the returned value will be the
* direct application of Pythagoras' theorem.
*/
void point_modulus(mpf_t result, point_t p);
void point_free(point_t *p);
/**
* Returns an arbitrarily-precision floating-point bidimensional point_t value with pseudo random
* components, both bounded by min and max.
*
* Returns:
* 0 on success;
* -1 if max is not strictly greater than min.
*/
int point_random(point_t *result, gmp_randstate_t rstate, const char *min, const char *max);
/**
* Stores a return value result such that:
* result > 0 if the point_t p is outside the circle described by center and radius;
* result == 0 if it occurs over its boundary;
* result < 0 if it is enclosed in the area of the circle.
*
* Returns:
* -1 if radius <= 0;
* 0 on success.
*/
int is_within_circle(point_t center, const char *radius, point_t p, int *result);
#endif