1#ifndef RNAPUZZLER_DEFINITIONS_H
2#define RNAPUZZLER_DEFINITIONS_H
3
4/*
5 *      RNApuzzler options
6 *
7 *      c  Daniel Wiegreffe, Daniel Alexander, Dirk Zeckzer
8 *      ViennaRNA package
9 */
10
11#include <stdlib.h>
12#include <math.h>
13
14#include "ViennaRNA/utils/basic.h"
15
16#define FANCY_PS 0
17
18#define EXTERIOR_Y 100.0
19
20#define epsilonRecognize 14 // font size
21#define epsilonFix 19       // font size + 5 @ resolveIntersections.c
22#define EPSILON_0 1.0
23#define EPSILON_3 1e-3
24#define EPSILON_7 1e-7
25#define MIN_POSITIVE_ANGLE +0.0000000001
26#define MIN_NEGATIVE_ANGLE -0.0000000001
27
28#define _false     0x0000
29#define _intersect 0x0001
30#define _changed   0x0002
31
32#include "vector_math.inc"
33
34PRIVATE void
35bubblesort(const int            numValues,
36           const double *const  valuesLevel1,
37           const double *const  valuesLevel2,
38           int *const           indices);
39
40
41/**
42 * @brief
43 *      Given a circle's radius and a distance between two points on the circle
44 *      this function calculates the angle between those points.
45 *      Note that the resulting angle will always be smaller than or equal to 180°.
46 *      If knowing the wanted angle being greater than 180° just subtract the result from 360°.
47 * @param radius the circle's radius
48 * @param distance the distance between two points on the circle
49 * @return angle in degree
50 */
51PRIVATE double
52distanceToAngle(const double  radius,
53                const double  distance);
54
55
56PRIVATE double
57angleToDistance(const double  radius,
58                const double  degreeAngle);
59
60
61PRIVATE void
62bubblesort(const int            numValues,
63           const double *const  valuesLevel1,
64           const double *const  valuesLevel2,
65           int *const           indices)
66{
67  for (int i = 0; i < numValues; i++)
68    indices[i] = i;
69
70  double  thisValue = 0.0;
71  double  nextValue = 0.0;
72  short   swap      = 0;
73  for (int i = 0; i < numValues - 1; i++) {
74    for (int j = 0; j < numValues - i - 1; j++) {
75      thisValue = valuesLevel1[indices[j + 0]];
76      nextValue = valuesLevel1[indices[j + 1]];
77      swap      = 0;
78      if (nextValue - thisValue > EPSILON_7) {
79        swap = 1;
80      } else if (fabs(nextValue - thisValue) < EPSILON_7) {
81        thisValue = valuesLevel2[indices[j + 0]];
82        nextValue = valuesLevel2[indices[j + 1]];
83        if (nextValue - thisValue > EPSILON_7)
84          swap = 1;
85      }
86
87      if (swap) {
88        int tmp = indices[j + 0];
89        indices[j + 0]  = indices[j + 1];
90        indices[j + 1]  = tmp;
91      }
92    }
93  }
94}
95
96
97/**
98 * @brief
99 *      Given a circle's radius and a distance between two points on the circle
100 *      this function calculates the angle between those points.
101 *      Note that the resulting angle will always be smaller than or equal to 180°.
102 *      If knowing the wanted angle being greater than 180° just subtract the result from 360°.
103 * @param radius the circle's radius
104 * @param distance the distance between two points on the circle
105 * @return angle in degree
106 */
107PRIVATE double
108distanceToAngle(const double  radius,
109                const double  distance)
110{
111  return 2.0 * asin(distance / (2.0 * radius));
112}
113
114
115PRIVATE double
116angleToDistance(const double  radius,
117                const double  angle)
118{
119  return 2.0 * radius * sin(angle / 2.0);
120}
121
122
123#endif
124