@webarkit/oneeurofilter-ts
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -1,1 +0,1 @@ | ||
!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var i=e();for(var r in i)("object"==typeof exports?exports:t)[r]=i[r]}}(self,(()=>(()=>{"use strict";var t={d:(e,i)=>{for(var r in i)t.o(i,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:i[r]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{OneEuroFilter:()=>i});class i{minCutOff;beta;dCutOff;xPrev;dxPrev;tPrev;initialized;constructor(t,e){this.minCutOff=t,this.beta=e,this.dCutOff=.001,this.xPrev=null,this.dxPrev=null,this.tPrev=null,this.initialized=!1}smoothingFactor(t,e){const i=2*Math.PI*e*t;return i/(i+1)}exponentialSmoothing(t,e,i){return t*e+(1-t)*i}reset(){this.initialized=!1}filter(t,e){if(!this.initialized)return this.initialized=!0,this.xPrev=e,this.dxPrev=e.map((()=>0)),this.tPrev=t,e;const{xPrev:i,tPrev:r,dxPrev:o}=this,n=t-r,s=this.smoothingFactor(n,this.dCutOff),f=[],h=[],l=[];for(let t=0;t<e.length;t++){f[t]=(e[t]-i[t])/n,h[t]=this.exponentialSmoothing(s,f[t],o[t]);const r=this.minCutOff+this.beta*Math.abs(h[t]),a=this.smoothingFactor(n,r);l[t]=this.exponentialSmoothing(a,e[t],i[t])}return this.xPrev=l,this.dxPrev=h,this.tPrev=t,l}}return e})())); | ||
!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var i=e();for(var o in i)("object"==typeof exports?exports:t)[o]=i[o]}}(self,(()=>(()=>{"use strict";var t={d:(e,i)=>{for(var o in i)t.o(i,o)&&!t.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:i[o]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{OneEuroFilter:()=>o});const{rE:i}={rE:"0.1.0"};class o{minCutOff;beta;dCutOff;xPrev;dxPrev;tPrev;initialized;version=i;constructor(t,e){this.minCutOff=t,this.beta=e,this.dCutOff=.001,this.xPrev=null,this.dxPrev=null,this.tPrev=null,this.initialized=!1,console.log("OneEuroFilter: ",this.version)}smoothingFactor(t,e){const i=2*Math.PI*e*t;return i/(i+1)}exponentialSmoothing(t,e,i){return t*e+(1-t)*i}reset(){this.initialized=!1}filter(t,e){if(!this.initialized)return this.initialized=!0,this.xPrev=e,this.dxPrev=e.map((()=>0)),this.tPrev=t,e;const{xPrev:i,tPrev:o,dxPrev:r}=this,n=t-o,s=this.smoothingFactor(n,this.dCutOff),l=[],h=[],f=[];for(let t=0;t<e.length;t++){l[t]=(e[t]-i[t])/n,h[t]=this.exponentialSmoothing(s,l[t],r[t]);const o=this.minCutOff+this.beta*Math.abs(h[t]),a=this.smoothingFactor(n,o);f[t]=this.exponentialSmoothing(a,e[t],i[t])}return this.xPrev=f,this.dxPrev=h,this.tPrev=t,f}}return e})())); |
{ | ||
"name": "@webarkit/oneeurofilter-ts", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "One euro filter algorithm with typescript support", | ||
@@ -20,3 +20,4 @@ "main": "dist/OneEuroFilter.js", | ||
"euro", | ||
"filter" | ||
"filter", | ||
"oef" | ||
], | ||
@@ -26,7 +27,7 @@ "author": "Walter Perdan", | ||
"devDependencies": { | ||
"ts-loader": "^9.4.2", | ||
"typescript": "^5.0.3", | ||
"webpack": "^5.77.0", | ||
"webpack-cli": "^5.0.1" | ||
"ts-loader": "9.5.1", | ||
"typescript": "5.7.2", | ||
"webpack": "5.97.1", | ||
"webpack-cli": "5.1.4" | ||
} | ||
} |
@@ -5,2 +5,91 @@ # OneEuroFilter-ts | ||
It's not well tested yet, so I can not assure of the correctness of the code. | ||
I will provide a npm package when it will be available. | ||
## Installation | ||
Install with npm: | ||
```bash | ||
npm install @webarkit/oneeurofilter-ts | ||
``` | ||
Install with yarn: | ||
```bash | ||
yarn add @webarkit/oneeurofilter-ts | ||
``` | ||
## Usage | ||
In a typescript file: | ||
```typescript | ||
// import the OneEuroFilter class into your project | ||
import { OneEuroFilter } from "@webarkit/oneeurofilter-ts"; | ||
let filterMinCF: number = 0.0001; | ||
let filterBeta: number = 0.01; | ||
const filter = new OneEuroFilter(filterMinCF, filterBeta); | ||
/* yourData is the data you want to filter, createData() is a dummy function here, | ||
use it you method or data instead... | ||
*/ | ||
let yourData = createData(); | ||
// filter the data (yourData) with the filter method | ||
filter.filter(Date.now(), yourData); | ||
// then use yourData... | ||
``` | ||
In a javascript file: | ||
```javascript | ||
// import the OneEuroFilter class into your project | ||
import { OneEuroFilter } from "@webarkit/oneeurofilter-ts"; | ||
let filterMinCF = 0.0001; | ||
let filterBeta = 0.01; | ||
const filter = new OneEuroFilter(filterMinCF, filterBeta); | ||
/* yourData is the data you want to filter, createData() is a dummy function here, | ||
use it you method or data instead... | ||
*/ | ||
let yourData = createData(); | ||
// filter the data (yourData) with the filter method | ||
filter.filter(Date.now(), yourData); | ||
// then use yourData... | ||
``` | ||
in a html script tag with module support: | ||
```html | ||
<script type="importmap"> | ||
{ | ||
"imports": { | ||
"oef": "https://raw.github.com/webarkit/oneeurofilter-ts/main/dist/OneEuroFilter.mjs", | ||
} | ||
} | ||
</script> | ||
// import the OneEuroFilter class into your project | ||
<script type="module"> | ||
import { OneEuroFilter } from "oef"; | ||
let filterMinCF = 0.0001; | ||
let filterBeta = 0.01; | ||
const filter = new OneEuroFilter(filterMinCF, filterBeta); | ||
/* yourData is the data you want to filter, createData() is a dummy function here, | ||
use it you method or data instead... | ||
*/ | ||
let yourData = createData(); | ||
// filter the data (yourData) with the filter method | ||
filter.filter(Date.now(), yourData); | ||
// then use yourData... | ||
</script> | ||
``` |
@@ -0,3 +1,40 @@ | ||
/* | ||
* index.ts | ||
* index | ||
* | ||
* This file is part of OneEuroFilter-ts - WebARKit. | ||
* | ||
* OneEuroFilter-ts is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* OneEuroFilter-ts is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with OneEuroFilter. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* As a special exception, the copyright holders of this library give you | ||
* permission to link this library with independent modules to produce an | ||
* executable, regardless of the license terms of these independent modules, and to | ||
* copy and distribute the resulting executable under terms of your choice, | ||
* provided that you also meet, for each linked independent module, the terms and | ||
* conditions of the license of that module. An independent module is a module | ||
* which is neither derived from nor based on this library. If you modify this | ||
* library, you may extend this exception to your version of the library, but you | ||
* are not obligated to do so. If you do not wish to do so, delete this exception | ||
* statement from your version. | ||
* | ||
* Copyright 2023-2024 WebARKit. | ||
* | ||
* Author(s): Walter Perdan @kalwalt https://github.com/kalwalt | ||
* | ||
* Ref: https://jaantollander.com/post/noise-filtering-using-one-euro-filter/#mjx-eqn%3A1 | ||
* | ||
*/ | ||
import { OneEuroFilter } from "./OneEuroFilter"; | ||
export { OneEuroFilter } |
@@ -1,2 +0,42 @@ | ||
// Ref: https://jaantollander.com/post/noise-filtering-using-one-euro-filter/#mjx-eqn%3A1 | ||
/* | ||
* OneEuroFilter.ts | ||
* OneEuroFilter | ||
* | ||
* This file is part of OneEuroFilter-ts - WebARKit. | ||
* | ||
* OneEuroFilter-ts is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* OneEuroFilter-ts is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with OneEuroFilter. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* As a special exception, the copyright holders of this library give you | ||
* permission to link this library with independent modules to produce an | ||
* executable, regardless of the license terms of these independent modules, and to | ||
* copy and distribute the resulting executable under terms of your choice, | ||
* provided that you also meet, for each linked independent module, the terms and | ||
* conditions of the license of that module. An independent module is a module | ||
* which is neither derived from nor based on this library. If you modify this | ||
* library, you may extend this exception to your version of the library, but you | ||
* are not obligated to do so. If you do not wish to do so, delete this exception | ||
* statement from your version. | ||
* | ||
* Copyright 2023-2024 WebARKit. | ||
* | ||
* Author(s): Walter Perdan @kalwalt https://github.com/kalwalt | ||
* | ||
* Ref: https://jaantollander.com/post/noise-filtering-using-one-euro-filter/#mjx-eqn%3A1 | ||
* | ||
*/ | ||
import packageJson from "../package.json"; | ||
const { version } = packageJson; | ||
export class OneEuroFilter { | ||
@@ -10,2 +50,3 @@ private minCutOff: number; | ||
private initialized: boolean; | ||
private version: string = version; | ||
constructor(minCutOff: number, beta: number) { | ||
@@ -20,2 +61,3 @@ this.minCutOff = minCutOff; | ||
this.initialized = false; | ||
console.log("OneEuroFilter: ", this.version); | ||
} | ||
@@ -22,0 +64,0 @@ |
@@ -8,4 +8,9 @@ { | ||
"declarationDir": "./types", | ||
"allowSyntheticDefaultImports": true, | ||
/* Module Resolution Options */ | ||
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ | ||
/* Advanced Options */ | ||
"resolveJsonModule": true, /* Include modules imported with '.json' extension */ | ||
"outDir": "dist", /* Redirect output structure to the directory. */ | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Copyleft License
License(Experimental) Copyleft license information was found.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
Non-permissive License
License(Experimental) A license not known to be considered permissive was found.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Copyleft License
License(Experimental) Copyleft license information was found.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
Non-permissive License
License(Experimental) A license not known to be considered permissive was found.
Found 1 instance in 1 package
43161
14
250
94