box2.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include <ionCore.h>
5 #include "line2.h"
6 
7 
8 namespace ion
9 {
10 
11  template <typename T>
12  struct box2
13  {
16 
17  line2<T> GetEdge(int const i) const
18  {
19  switch (i % 4)
20  {
21  default:
22  case 0:
23  return line2<T>(
24  vec2<T>(Min.X, Min.Y),
25  vec2<T>(Min.X, Max.Y));
26  case 1:
27  return line2<T>(
28  vec2<T>(Min.X, Min.Y),
29  vec2<T>(Max.X, Min.Y));
30  case 2:
31  return line2<T>(
32  vec2<T>(Max.X, Min.Y),
33  vec2<T>(Max.X, Max.Y));
34  case 3:
35  return line2<T>(
36  vec2<T>(Min.X, Max.Y),
37  vec2<T>(Max.X, Max.Y));
38  }
39  }
40 
41  bool IsPointInside(vec2<T> const & Point) const
42  {
43  return (Max.Y > Point.Y &&
44  Min.Y < Point.Y &&
45  Max.X > Point.X &&
46  Min.X < Point.X);
47  }
48 
49  void Reset(vec2<T> const & Point)
50  {
51  Min = Max = Point;
52  }
53 
54  void AddPoint(vec2<T> const & Point)
55  {
56  Min.X = Minimum(Min.X, Point.X);
57  Min.Y = Minimum(Min.Y, Point.Y);
58  Max.X = Maximum(Max.X, Point.X);
59  Max.Y = Maximum(Max.Y, Point.Y);
60  }
61  };
62 
63  typedef box2<float> box2f;
65  typedef box2<int> box2i;
66 
67 }
2D vector
Definition: vec2.h:17
Definition: box2.h:12
vec2< T > Max
Definition: box2.h:15
vec2< T > Min
Definition: box2.h:14
void Reset(vec2< T > const &Point)
Definition: box2.h:49
box2< double > box2d
Definition: box2.h:64
void AddPoint(vec2< T > const &Point)
Definition: box2.h:54
line2< T > GetEdge(int const i) const
Definition: box2.h:17
bool IsPointInside(vec2< T > const &Point) const
Definition: box2.h:41
T X
Definition: vec2.h:20
box2< int > box2i
Definition: box2.h:65
Definition: CCatmullRomAdvancedSplineInterpolator.h:7
T Y
Definition: vec2.h:21
2D line segment
Definition: line2.h:13
box2< float > box2f
Definition: box2.h:63