Subversion Repositories DIN Is Noise

Rev

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