summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--board.c12
-rw-r--r--board.h3
-rw-r--r--comp.c16
-rw-r--r--comp.h2
4 files changed, 17 insertions, 16 deletions
diff --git a/board.c b/board.c
index 7aceed6..94dd764 100644
--- a/board.c
+++ b/board.c
@@ -52,6 +52,18 @@ void init_board()
init_rings();
}
+struct ccoords pol_to_cart(struct pcoords c)
+{
+ double t = c.a * (M_PI / 180);
+ return (struct ccoords){ .x = c.r * cos(t), .y = c.r * sin(t) };
+}
+
+struct pcoords cart_to_pol(struct ccoords c)
+{
+ return (struct pcoords){ .a = atan2(c.y, c.x) * (180 / M_PI),
+ .r = sqrt(pow(c.x, 2) + pow(c.y, 2)) };
+}
+
static int sector_from_angle(double angle)
{
double shifted = angle - 90 - (SECTOR_WIDTH / 2);
diff --git a/board.h b/board.h
index 440143f..cc60e62 100644
--- a/board.h
+++ b/board.h
@@ -60,6 +60,9 @@ struct pcoords {
void init_board();
+struct ccoords pol_to_cart(struct pcoords c);
+struct pcoords cart_to_pol(struct ccoords c);
+
struct segment segment_from_pcoords(struct pcoords c);
struct segment segment_from_name(const char *name);
struct pcoords segment_centre(struct segment seg);
diff --git a/comp.c b/comp.c
index 6b4ec26..3ce0c5e 100644
--- a/comp.c
+++ b/comp.c
@@ -70,28 +70,16 @@ static double gauss(double mean, double stdev)
return mean + (curr * stdev);
}
-static struct ccoords get_offset()
+static struct ccoords gauss_offset()
{
return (struct ccoords){ .x = gauss(0, horizontal_stdev),
.y = gauss(0, vertical_stdev) };
}
-struct ccoords pol_to_cart(struct pcoords c)
-{
- double t = c.a * (M_PI / 180);
- return (struct ccoords){ .x = c.r * cos(t), .y = c.r * sin(t) };
-}
-
-static struct pcoords cart_to_pol(struct ccoords c)
-{
- return (struct pcoords){ .a = atan2(c.y, c.x) * (180 / M_PI),
- .r = sqrt(pow(c.x, 2) + pow(c.y, 2)) };
-}
-
static struct pcoords throw_dart(struct pcoords target, struct ccoords *cc)
{
struct ccoords tc = pol_to_cart(target);
- struct ccoords offset = get_offset();
+ struct ccoords offset = gauss_offset();
cc->x = tc.x + offset.x;
cc->y = tc.y + offset.y;
diff --git a/comp.h b/comp.h
index 792eb3c..009028f 100644
--- a/comp.h
+++ b/comp.h
@@ -5,8 +5,6 @@
extern double horizontal_stdev, vertical_stdev;
-struct ccoords pol_to_cart(struct pcoords c);
-
void comp_set_difficulty(int diff);
void comp_visit(struct leg *l);