Rev 2184 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1196 | jag | 1 | /* |
2 | * hit.cc |
||
2302 | jag | 3 | * DIN Is Noise is copyright (c) 2006-2025 Jagannathan Sampath |
1713 | jag | 4 | * DIN Is Noise is released under GNU Public License 2.0 |
1479 | jag | 5 | * For more information, please visit https://dinisnoise.org/ |
1196 | jag | 6 | */ |
7 | |||
1177 | jag | 8 | #include "hit.h" |
9 | #include "multi_curve.h" |
||
1196 | jag | 10 | #include "log.h" |
11 | using namespace std; |
||
1177 | jag | 12 | |
1196 | jag | 13 | hit_t::hit_t (multi_curve* cv, int cid, int w, int i, int no) { |
1177 | jag | 14 | crv = cv; |
15 | crv_id = cid; |
||
16 | what = w; |
||
17 | id = i; |
||
18 | name_only = no; |
||
19 | } |
||
20 | |||
21 | void hit_t::clear () { |
||
22 | crv = 0; |
||
23 | crv_id = -1; |
||
24 | what = NONE; |
||
25 | id = -1; |
||
26 | name_only = 0; |
||
27 | } |
||
28 | |||
29 | int hit_t::operator()() const { // hit some curve? |
||
30 | return (crv_id != -1); |
||
31 | } |
||
32 | |||
33 | int hit_t::operator()(int) const { // hit an existing curve item? |
||
34 | return (crv_id != -1 && (id > -1) && (id < crv->num_vertices)); |
||
35 | } |
||
36 | |||
2184 | jag | 37 | pointinfo<float>& hit_t::get () { |
1177 | jag | 38 | points_array* ptr[3] = {&crv->vertices, &crv->left_tangents, &crv->right_tangents}; |
39 | points_array& arr = *ptr[what-1]; |
||
40 | return arr[id]; |
||
41 | } |
||
1196 | jag | 42 | |
43 | hit_t::hit_t (const hit_t& src) { |
||
44 | copy (src); |
||
45 | } |
||
46 | |||
47 | hit_t& hit_t::operator= (const hit_t& src) { |
||
48 | copy (src); |
||
49 | return *this; |
||
50 | } |
||
51 | |||
52 | void hit_t::copy (const hit_t& src) { |
||
53 | if (&src != this) { |
||
54 | crv = src.crv; |
||
55 | crv_id = src.crv_id; |
||
56 | what = src.what; |
||
57 | id = src.id; |
||
58 | left_tangent = src.left_tangent; |
||
59 | right_tangent = src.right_tangent; |
||
60 | left_tangent_magnitude = src.left_tangent_magnitude; |
||
61 | right_tangent_magnitude = src.right_tangent_magnitude; |
||
62 | } |
||
63 | } |
||
1347 | jag | 64 | |
65 | void hit_t::ensure_id () { |
||
66 | if (id < 0) id = 0; |
||
67 | else if (id > crv->last_vertex) id = crv->last_vertex; |
||
68 | } |