Subversion Repositories DIN Is Noise

Rev

Rev 2180 | Rev 2204 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1528 jag 1
/*
2
* hit.h
2097 jag 3
* DIN Is Noise is copyright (c) 2006-2024 Jagannathan Sampath
1713 jag 4
* DIN Is Noise is released under GNU Public License 2.0
1528 jag 5
* For more information, please visit https://dinisnoise.org/
6
*/
7
 
8
#ifndef __hit
9
#define __hit
10
 
11
#include "point.h"
1532 jag 12
#include "multi_curve.h"
1528 jag 13
 
14
struct multi_curve;
2131 jag 15
 
1528 jag 16
struct hit_t {
2131 jag 17
 
1528 jag 18
  multi_curve* crv; // curve hit
19
  int crv_id; // id among list of curves
20
  enum {NONE = 0, VERTEX, LEFT_TANGENT, RIGHT_TANGENT}; // things that can be hit
21
  int what; // what was hit
22
  int id; // id of hit thing
23
 
24
  static int name_only;
25
 
26
  // tangent vectors from corresponding vertex
27
  //
28
  point<float> left_tangent, right_tangent;
29
  float left_tangent_magnitude, right_tangent_magnitude;
30
 
31
  hit_t (multi_curve* c = 0, int cid = -1, int w = NONE, int i = -1, int no = 0);
32
  hit_t (const hit_t& h);
33
  void clear ();
34
  int operator()() const; // hit?
35
  int operator()(int) const; // hit curve item exists?
36
  int operator== (const hit_t& h) {return ((crv == h.crv) && (what == h.what) && (id == h.id));}
37
  int matched_id (const hit_t& h) {return ( (crv == h.crv) && (id == h.id) ); }
38
  void ensure_id ();
39
  hit_t& operator= (const hit_t& h);
40
  void copy (const hit_t& src);
2184 jag 41
  pointinfo<float>& get ();
2131 jag 42
 
1528 jag 43
};
1532 jag 44
 
45
template <typename T> T& operator<< (T& t, const hit_t& h) {
46
  if (hit_t::name_only)
47
    t << h.crv->name;
48
  else {
49
    static const std::string what [] = {"nothing ", "vertex ", "L-tangent ", "R-tangent "};
50
    static const char* of = " of ";
51
    t << what[h.what] << h.id << of << h.crv->name;
52
  }
53
  return t;
54
}
55
 
1528 jag 56
#endif