Jager is an library for touch gesture / symbols recognition.
- Simple API
- Fast recognition (around 0.2 ms)
- Recognition on-the-fly
- No outside dependencies, just pure JavaScript
Library is used in next projects:
- Clone the repo:
git clone https://github.com/vmikhav/jager.git
In the browser:
<script src="/path/to/jager.js"></script>
<script>
var jager = new Jager();
</script>
const jager = new Jager();
jager.addPoint({x, y});
let symbols = jager.recognise();
Also you can see this demo page.
Array of points (x, y) for recognition
Object with symbols enumeration
if (jager.recognise() === jager.symbols['pigtail']) { }
Array of symbol patterns. Pattern contain the following fields:
- symbol:
{name, index}
Symbol info. - sections:
Array
Rules for path sections. Each rule contain the following elements:- x
-1|0|1
Section orientation in X line. Should be0
ify
is not0
. - y
-1|0|1
Section orientation in Y line. Should be0
ifx
is not0
. - skip
bool
Optional Iftrue
, this section can be skipped in mismatch case.
- x
- quarters:
function (sX, sY, eX, eY)
Callback function to check start and end point positions. Each param is in integer range[0, 3]
(top-left corner is (0, 0), bottom-right is (3, 3)).
{
symbol: this.symbols['circle'],
sections: [{x: -1, y: 0, skip: true}, {x: 0, y: 1}, {x: 1, y: 0}, {x: 0, y: -1}, {x: -1, y: 0}],
quarters: function (sX, sY, eX, eY) {
return sY === 0 && eY === 0 && Math.abs(sX - eX) <= 1 && sX <= 2;
}
}
Reset current path.
Extract point object from the event data.
- evt: Event parameter.
Add point to current path without changes.
- point: Point object, contains
x
andy
.
Add point to current path with smoothing.
- point: Point object, contains
x
andy
. - distanceFilter: Ignore point if squared distance to previous point is less than
distanceFilter
. - smoothFactor: How smooth will be current path. Decimal in
[0, 1)
.
Recognizes the painted gesture.
- debug:
Bool
optional
If true jager logging the symbol info.
Draw current path in given ctx
.
- ctx:
Context
Canvas context.