Root/
Source at commit dfac631faf4e02dfb4176ac1415e7608ac699e69 created 11 years 6 months ago. By Xiangfu, debian: update maintainer email. prepare for my DM application | |
---|---|
1 | /* |
2 | * coord.h - Coordinate representation and basic operations |
3 | * |
4 | * Written 2009, 2010 by Werner Almesberger |
5 | * Copyright 2009, 2010 by Werner Almesberger |
6 | * |
7 | * This program is free software; you can redistribute it and/or modify |
8 | * it under the terms of the GNU General Public License as published by |
9 | * the Free Software Foundation; either version 2 of the License, or |
10 | * (at your option) any later version. |
11 | */ |
12 | |
13 | |
14 | #ifndef COORD_H |
15 | #define COORD_H |
16 | |
17 | #include <stdint.h> |
18 | |
19 | |
20 | #define MICRON_UNITS 10 |
21 | #define MIL_UNITS (25.4*MICRON_UNITS) |
22 | #define MM_UNITS (1000.0*MICRON_UNITS) |
23 | #define KICAD_UNIT (MIL_UNITS/10.0) |
24 | |
25 | #define MIL_IN_MM 0.0254 |
26 | |
27 | |
28 | typedef int32_t unit_type; |
29 | |
30 | |
31 | #define UNIT_ERROR ((unit_type) 1 << (sizeof(unit_type)*8-1)) |
32 | |
33 | |
34 | struct coord { |
35 | unit_type x, y; |
36 | }; |
37 | |
38 | |
39 | static inline unit_type mil_to_units(double mil) |
40 | { |
41 | return mil*MIL_UNITS; |
42 | } |
43 | |
44 | |
45 | static inline unit_type mm_to_units(double mm) |
46 | { |
47 | return mm*MM_UNITS; |
48 | } |
49 | |
50 | |
51 | static inline double units_to_mm(unit_type u) |
52 | { |
53 | return (double) u/MM_UNITS; |
54 | } |
55 | |
56 | |
57 | static inline double units_to_mil(unit_type u) |
58 | { |
59 | return (double) u/MIL_UNITS; |
60 | } |
61 | |
62 | |
63 | static inline int units_to_kicad(unit_type u) |
64 | { |
65 | return (double) u/KICAD_UNIT; |
66 | } |
67 | |
68 | |
69 | static inline int coord_eq(struct coord a, struct coord b) |
70 | { |
71 | return a.x == b.x && a.y == b.y; |
72 | } |
73 | |
74 | |
75 | double mm_to_mil(double mm, int exponent); |
76 | double mil_to_mm(double mil, int exponent); |
77 | |
78 | double units_to_best(unit_type u, int *mm); |
79 | |
80 | struct coord normalize(struct coord v, unit_type len); |
81 | struct coord rotate(struct coord v, double angle); |
82 | struct coord add_vec(struct coord a, struct coord b); |
83 | struct coord sub_vec(struct coord a, struct coord b); |
84 | struct coord neg_vec(struct coord v); |
85 | |
86 | struct coord rotate_r(struct coord c, unit_type r, double angle); |
87 | double theta_vec(struct coord v); |
88 | double theta(struct coord c, struct coord p); |
89 | |
90 | void sort_coord(struct coord *min, struct coord *max); |
91 | |
92 | unit_type dist_point(struct coord a, struct coord b); |
93 | unit_type dist_line(struct coord p, struct coord a, struct coord b); |
94 | unit_type dist_rect(struct coord p, struct coord a, struct coord b); |
95 | int inside_rect(struct coord p, struct coord a, struct coord b); |
96 | unit_type dist_circle(struct coord p, struct coord c, unit_type r); |
97 | |
98 | #endif /* !COORD_H */ |
99 |
Branches:
master