@@ -217,6 +217,24 @@ export default function litecanvas(settings = {}) {
217217 return value
218218 } ,
219219
220+ /**
221+ * Calculates the distance between a point (x1, y1) to another (x2, y2).
222+ *
223+ * @param {number } x1
224+ * @param {number } y1
225+ * @param {number } x2
226+ * @param {number } y2
227+ * @returns {number }
228+ */
229+ dist : ( x1 , y1 , x2 , y2 ) => {
230+ DEV: assert ( isNumber ( x1 ) , '[litecanvas] dist() 1st param must be a number' )
231+ DEV: assert ( isNumber ( y1 ) , '[litecanvas] dist() 2nd param must be a number' )
232+ DEV: assert ( isNumber ( x2 ) , '[litecanvas] dist() 3rd param must be a number' )
233+ DEV: assert ( isNumber ( y2 ) , '[litecanvas] dist() 4th param must be a number' )
234+
235+ return math . hypot ( x2 - x1 , y2 - y1 )
236+ } ,
237+
220238 /**
221239 * Wraps a number between `min` (inclusive) and `max` (exclusive).
222240 *
@@ -286,25 +304,6 @@ export default function litecanvas(settings = {}) {
286304 return instance . map ( value , start , stop , 0 , 1 )
287305 } ,
288306
289- /**
290- * Interpolate between 2 values using a periodic function.
291- *
292- * @param {number } from - the lower bound
293- * @param {number } to - the higher bound
294- * @param {number } t - value passed to the periodic function
295- * @param {(n: number) => number } [fn] - the periodic function (which default to `Math.sin`)
296- */
297- wave : ( from , to , t , fn = Math . sin ) => {
298- DEV: assert ( isNumber ( from ) , '[litecanvas] wave() 1st param must be a number' )
299- DEV: assert ( isNumber ( to ) , '[litecanvas] wave() 2nd param must be a number' )
300- DEV: assert ( isNumber ( t ) , '[litecanvas] wave() 3rd param must be a number' )
301- DEV: assert (
302- 'function' === typeof fn ,
303- '[litecanvas] wave() 4rd param must be a function (n: number) => number'
304- )
305- return from + ( ( fn ( t ) + 1 ) / 2 ) * ( to - from )
306- } ,
307-
308307 /** RNG API */
309308 /**
310309 * Generates a pseudorandom float between min (inclusive) and max (exclusive)
0 commit comments