1 /* 2 # This file is part of the Astrometry.net suite. 3 # Licensed under a 3-clause BSD style license - see LICENSE 4 */ 5 6 #ifndef MATHUTIL_H 7 #define MATHUTIL_H 8 9 #include "astrometry/keywords.h" 10 #include "bl.h" 11 12 int point_in_polygon(double x, double y, const dl* polygon); 13 14 /* 15 Given a point "pt", computes two unit vectors that are tangent 16 to the point and perpendicular to each other. 17 */ 18 void tan_vectors(const double* pt, double* vec1, double* vec2); 19 20 int invert_2by2(const double A[2][2], double Ainv[2][2]); 21 22 int invert_2by2_arr(const double* A, double* Ainv); 23 24 int is_power_of_two(unsigned int x); 25 26 void matrix_matrix_3(double* m1, double* m2, double* result); 27 28 void matrix_vector_3(double* m, double* v, double* result); 29 30 double dot_product_3(double* v1, double* v2); 31 32 double vector_length_3(double* v); 33 34 double vector_length_squared_3(double* v); 35 36 double inverse_3by3(double *matrix); 37 38 void image_to_xyz(double uu, double vv, double* s, double* transform); 39 40 void fit_transform(double* star, double* field, int N, double* trans); 41 42 double uniform_sample(double low, double high); 43 44 double gaussian_sample(double mean, double stddev); 45 46 // just drop partial blocks off the end. 47 #define EDGE_TRUNCATE 0 48 // just average the pixels in partial blocks. 49 #define EDGE_AVERAGE 1 50 51 int get_output_image_size(int W, int H, int blocksize, int edgehandling, 52 int* outw, int* outh); 53 54 #define SIGN(x) (((x) == 0) ? 0.0 : (((x) > 0) ? 1.0 : -1.0)) 55 56 /** 57 Average the image in "blocksize" x "blocksize" blocks, placing the 58 output in the "output" image. The output image will have size 59 "*newW" by "*newH". If you pass "output = NULL", memory will be 60 allocated for the output image. It is valid to pass in "output" = 61 "image". The output image is returned. 62 */ 63 float* average_image_f(const float* image, int W, int H, 64 int blocksize, int edgehandling, 65 int* newW, int* newH, 66 float* output); 67 68 float* average_weighted_image_f(const float* image, const float* weight, 69 int W, int H, 70 int blocksize, int edgehandling, 71 int* newW, int* newH, 72 float* output, float nilval); 73 74 Const InlineDeclare int imax(int a, int b); 75 76 Const InlineDeclare int imin(int a, int b); 77 78 InlineDeclare double distsq_exceeds(double* d1, double* d2, int D, double limit); 79 80 Const InlineDeclare double square(double d); 81 82 // note, this function works on angles in degrees; it wraps around 83 // at 360. 84 Const InlineDeclare int inrange(double ra, double ralow, double rahigh); 85 86 InlineDeclare double distsq(const double* d1, const double* d2, int D); 87 88 InlineDeclare void cross_product(double* v1, double* v2, double* cross); 89 90 InlineDeclare void normalize(double* x, double* y, double* z); 91 92 InlineDeclare void normalize_3(double* xyz); 93 94 95 #ifdef INCLUDE_INLINE_SOURCE 96 #define InlineDefine InlineDefineH 97 #include "astrometry/mathutil.inc" 98 #undef InlineDefine 99 #endif 100 101 102 #endif 103