Source code: com/arranger/jarl/util/MathUtil.java
1 package com.arranger.jarl.util;
2
3 public class MathUtil {
4
5 public static double round(double result, double round) {
6 double mod = result % round;
7 result -= mod;
8 result += (mod >= round / 2) ? round : 0;
9 return result;
10 }
11
12 public static boolean inSet(int value, int[] set) {
13 for (int index = 0; index < set.length; index++) {
14 if (value == set[index]) {
15 return true;
16 }
17 }
18 return false;
19 }
20
21 public static boolean inSet(double value, double[] set) {
22 for (int index = 0; index < set.length; index++) {
23 if (value == set[index]) {
24 return true;
25 }
26 }
27 return false;
28 }
29
30 public static double findRadians(double x1, double y1, double x2, double y2) {
31 if (x1 < x2 && y1 <= y2) {
32 double tmp = (y1 - y2) / (x1 - x2);
33 return Math.atan(tmp);
34 } else if (x1 >= x2 && y1 < y2) {
35 double tmp = (x1 - x2) / (y1 - y2);
36 return Math.atan(tmp) + (Math.PI / 2);
37 } else if (x1 > x2 && y1 >= y2) {
38 double tmp = (y1 - y2) / (x1 - x2);
39 return Math.atan(tmp) + Math.PI;
40 } else if (x1 <= x2 && y1 > y2) {
41 double tmp = (x1 - x2) / (y1 - y2);
42 return Math.atan(tmp) + (Math.PI * 3 / 2);
43 } else {
44 return 0;
45 }
46 }
47 }