Subversion Repositories DIN Is Noise

Rev

Rev 2009 | Rev 2131 | 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;
15
struct hit_t {
16
  multi_curve* crv; // curve hit
17
  int crv_id; // id among list of curves
18
  enum {NONE = 0, VERTEX, LEFT_TANGENT, RIGHT_TANGENT}; // things that can be hit
19
  int what; // what was hit
20
  int id; // id of hit thing
21
 
22
  static int name_only;
23
 
24
  // tangent vectors from corresponding vertex
25
  //
26
  point<float> left_tangent, right_tangent;
27
  float left_tangent_magnitude, right_tangent_magnitude;
28
 
29
  hit_t (multi_curve* c = 0, int cid = -1, int w = NONE, int i = -1, int no = 0);
30
  hit_t (const hit_t& h);
31
  void clear ();
32
  int operator()() const; // hit?
33
  int operator()(int) const; // hit curve item exists?
34
  int operator== (const hit_t& h) {return ((crv == h.crv) && (what == h.what) && (id == h.id));}
35
  int matched_id (const hit_t& h) {return ( (crv == h.crv) && (id == h.id) ); }
36
  void ensure_id ();
37
  hit_t& operator= (const hit_t& h);
38
  void copy (const hit_t& src);
39
  const point<float>& get ();
40
};
1532 jag 41
 
42
template <typename T> T& operator<< (T& t, const hit_t& h) {
43
  if (hit_t::name_only)
44
    t << h.crv->name;
45
  else {
46
    static const std::string what [] = {"nothing ", "vertex ", "L-tangent ", "R-tangent "};
47
    static const char* of = " of ";
48
    t << what[h.what] << h.id << of << h.crv->name;
49
  }
50
  return t;
51
}
52
 
1528 jag 53
#endif