some progress on util
This commit is contained in:
@@ -3,8 +3,10 @@ module.exports = {
|
||||
'browser': true,
|
||||
'es6': true
|
||||
},
|
||||
'extends': ['eslint:recommended',
|
||||
'plugin:@typescript-eslint/recommended'],
|
||||
'extends': [
|
||||
'eslint:recommended',
|
||||
'plugin:@typescript-eslint/recommended'
|
||||
],
|
||||
'globals': {
|
||||
'Atomics': 'readonly',
|
||||
'SharedArrayBuffer': 'readonly'
|
||||
@@ -100,7 +102,6 @@ module.exports = {
|
||||
'lines-around-comment': 'error',
|
||||
'lines-around-directive': 'off',
|
||||
'lines-between-class-members': 'error',
|
||||
'max-classes-per-file': 'error',
|
||||
'max-depth': 'error',
|
||||
'max-len': 'off',
|
||||
'max-lines': 'error',
|
||||
|
||||
@@ -37,6 +37,7 @@ class ImpressNotSupportedError extends Error {}
|
||||
class ImpressInitError extends Error {}
|
||||
|
||||
class ImpressConfig {
|
||||
// eslint-disable-next-line max-params
|
||||
constructor( width, height, perspective, transitionDuration, maxScale, minScale ) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
@@ -153,7 +154,7 @@ window.impress = ( impressConfig ) => {
|
||||
rotation: rotation,
|
||||
id: DOMElementID
|
||||
};
|
||||
_positionElements();
|
||||
positionElements();
|
||||
|
||||
// Dispatch event that an element was added
|
||||
document.dispatchEvent( new Event( 'impress:addedElement' ) );
|
||||
@@ -173,7 +174,7 @@ window.impress = ( impressConfig ) => {
|
||||
} catch ( err ) {
|
||||
return false;
|
||||
}
|
||||
_positionElements();
|
||||
positionElements();
|
||||
// Dispatch event that an element was removed
|
||||
document.dispatchEvent( new Event( 'impress:removedElement' ) );
|
||||
|
||||
@@ -184,7 +185,7 @@ window.impress = ( impressConfig ) => {
|
||||
* Internal function that positions elements on the canvas. Called every time a element is added / removed
|
||||
* @returns {undefined}
|
||||
*/
|
||||
const _positionElements = () => {
|
||||
const positionElements = () => {
|
||||
// Gets current position and calls moveTo function
|
||||
moveTo( getCurrentPos().coordinates, getCurrentPos().rotation );
|
||||
};
|
||||
@@ -232,18 +233,16 @@ window.impress = ( impressConfig ) => {
|
||||
* Use this function to get the current impress config
|
||||
* @returns {ImpressConfig} Returns the current impress config
|
||||
*/
|
||||
const getCurrentConfig = () => {
|
||||
return impressConfig;
|
||||
}
|
||||
const getCurrentConfig = () => impressConfig;
|
||||
|
||||
/**
|
||||
* Update the impress config.
|
||||
* @param {ImpressConfig} impressConfig The new impress config
|
||||
* @param {ImpressConfig} impressConfigs The new impress config
|
||||
* @returns {undefined} Returns nothing
|
||||
*/
|
||||
const updateConfig = ( impressConfig ) => {
|
||||
impressConfig = impressConfig;
|
||||
}
|
||||
const updateConfig = ( impressConfigs ) => {
|
||||
impressConfig = impressConfigs;
|
||||
};
|
||||
|
||||
// Return all functions that are exposed by impress. This is superior to using classes as we can control what functions we expose.
|
||||
return {
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
/* ! Licensed under MIT License - https://github.com/impress/impress.js/blob/master/LICENSE */
|
||||
/**
|
||||
* impress.js
|
||||
*
|
||||
* impress.js is a presentation tool based on the power of CSS3 transforms and transitions
|
||||
* in modern browsers and inspired by the idea behind prezi.com.
|
||||
*
|
||||
*
|
||||
* Copyright 2011-2012 Bartek Szopka (@bartaz), 2016-2024 Henrik Ingo (@henrikingo), 2024 Janis Hutz
|
||||
* and 70+ other contributors
|
||||
*
|
||||
* Released under the MIT License.
|
||||
*
|
||||
* ------------------------------------------------
|
||||
* authors: Bartek Szopka, Henrik Ingo, Janis Hutz
|
||||
* version: 3.0.0
|
||||
* url: http://impress.js.org
|
||||
* source: http://github.com/impress/impress.js/
|
||||
*/
|
||||
|
||||
// Welcome to the util.ts file. This file exposes various functions for use in calculating with vectors
|
||||
75
src/lib/vectorUtil.js
Normal file
75
src/lib/vectorUtil.js
Normal file
@@ -0,0 +1,75 @@
|
||||
/* ! Licensed under MIT License - https://github.com/impress/impress.js/blob/master/LICENSE */
|
||||
/**
|
||||
* impress.js
|
||||
*
|
||||
* impress.js is a presentation tool based on the power of CSS3 transforms and transitions
|
||||
* in modern browsers and inspired by the idea behind prezi.com.
|
||||
*
|
||||
*
|
||||
* Copyright 2011-2012 Bartek Szopka (@bartaz), 2016-2024 Henrik Ingo (@henrikingo), 2024 Janis Hutz
|
||||
* and 70+ other contributors
|
||||
*
|
||||
* Released under the MIT License.
|
||||
*
|
||||
* ------------------------------------------------
|
||||
* authors: Bartek Szopka, Henrik Ingo, Janis Hutz
|
||||
* version: 3.0.0
|
||||
* url: http://impress.js.org
|
||||
* source: http://github.com/impress/impress.js/
|
||||
*/
|
||||
|
||||
// Welcome to the vectorUtil.js file. This file exposes various functions for use in calculating with vectors
|
||||
|
||||
class Vector {
|
||||
|
||||
/**
|
||||
* Description
|
||||
* @param {number} x The x-coordinate
|
||||
* @param {number} y The y-coordinate
|
||||
* @param {number} z The z-coordinate
|
||||
* @returns {undefined} Returns nothing
|
||||
*/
|
||||
constructor ( x, y, z ) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
}
|
||||
|
||||
window.impressVectorUtil = () => {
|
||||
|
||||
/**
|
||||
* Get the cross product of two vectors (https://en.wikipedia.org/wiki/Cross_product)
|
||||
* @param {Vector} vec1 The first vector
|
||||
* @param {Vector} vec2 The second vector
|
||||
* @returns {Vector} Returns a vector object
|
||||
*/
|
||||
const vectorProduct = ( vec1, vec2 ) => new Vector(
|
||||
( vec1.y * vec2.z ) - ( vec1.z * vec2.y ),
|
||||
( vec1.z * vec2.x ) - ( vec1.x * vec2.z ),
|
||||
( vec1.x * vec2.y ) - ( vec1.y * vec2.x )
|
||||
);
|
||||
|
||||
/**
|
||||
* Get the dot product of two vectors (https://en.wikipedia.org/wiki/Dot_product)
|
||||
* @param {Vector} vec1 The first vector
|
||||
* @param {Vector} vec2 The second vector
|
||||
* @returns {number} Returns the calculated value of the dot product
|
||||
*/
|
||||
const dotProduct = ( vec1, vec2 ) => ( vec1.x * vec2.x ) + ( vec1.y * vec2.y ) + ( vec1.z * vec2.z );
|
||||
|
||||
/**
|
||||
* Get the norm of a vector (https://en.wikipedia.org/wiki/Norm_(mathematics))
|
||||
* @param {Vector} vec The vector of which to calculate the norm
|
||||
* @returns {number} Returns the norm
|
||||
*/
|
||||
var norm = function( vec ) {
|
||||
return Math.sqrt( ( vec.x * vec.x ) + ( vec.y * vec.y ) + ( vec.z * vec.z ) );
|
||||
};
|
||||
|
||||
return {
|
||||
norm,
|
||||
dotProduct,
|
||||
vectorProduct
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user