Tanoda
SlidingMax.cs
Go to the documentation of this file.
1
/******************************************************************************
2
* Copyright (C) Ultraleap, Inc. 2011-2020. *
3
* *
4
* Use subject to the terms of the Apache License 2.0 available at *
5
* http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
6
* between Ultraleap and you, your company or other organization. *
7
******************************************************************************/
8
9
namespace
Leap.Unity
{
10
11
public
class
SlidingMax
{
12
13
private
struct
IndexValuePair {
14
public
int
index;
15
public
float
value;
16
17
public
IndexValuePair(
int
index,
float
value) {
18
this.index = index;
19
this.value = value;
20
}
21
}
22
23
private
int
_history;
24
private
int
_count;
25
private
Deque<IndexValuePair>
_buffer =
new
Deque<IndexValuePair>
();
26
27
public
SlidingMax
(
int
history) {
28
_history = history;
29
_count = 0;
30
}
31
32
public
void
AddValue
(
float
value) {
33
while
(_buffer.
Count
!= 0 && _buffer.
Front
.value <= value) {
34
_buffer.
PopFront
();
35
}
36
37
_buffer.
PushFront
(
new
IndexValuePair(_count, value));
38
_count++;
39
40
while
(_buffer.
Back
.index < (_count - _history)) {
41
_buffer.
PopBack
();
42
}
43
}
44
45
public
float
Max
{
46
get
{
47
return
_buffer.
Back
.value;
48
}
49
}
50
}
51
}
Leap.Unity.Deque< IndexValuePair >
Leap.Unity.Deque.Count
int Count
Definition:
Deque.cs:36
Leap.Unity.Deque.Front
T Front
Definition:
Deque.cs:96
Leap.Unity.Deque.PopFront
void PopFront()
Definition:
Deque.cs:70
Leap.Unity.Deque.PopBack
void PopBack()
Definition:
Deque.cs:63
Leap.Unity.Deque.Back
T Back
Definition:
Deque.cs:107
Leap.Unity.Deque.PushFront
void PushFront(T t)
Definition:
Deque.cs:56
Leap.Unity.SlidingMax
Definition:
SlidingMax.cs:11
Leap.Unity.SlidingMax.Max
float Max
Definition:
SlidingMax.cs:45
Leap.Unity.SlidingMax.SlidingMax
SlidingMax(int history)
Definition:
SlidingMax.cs:27
Leap.Unity.SlidingMax.AddValue
void AddValue(float value)
Definition:
SlidingMax.cs:32
Leap.Unity
Definition:
AssetFolderPropertyDrawer.cs:15
Source
Assets
Plugins
LeapMotion
Core
Scripts
Algorithms
SlidingMax.cs
Generated by
1.9.3