How to use calc method in storybook-root

Best JavaScript code snippet using storybook-root

firesight-service.js

Source:firesight-service.js Github

copy

Full Screen

1'use strict';2var JsonUtil = require("./shared/JsonUtil");3var services = angular.module('firenodejs.services');4services.factory('firesight-service', ['$http', 'firestep-service', 'AlertService',5 function($http, firestep, alerts) {6 var available = null;7 var service = {8 processCount: 0,9 results: {},10 location: function() {11 var mpo = firestep.model.mpo || {};12 return "X" + mpo.x + "Y" + mpo.y + "Z" + mpo.z;13 },14 getResults: function() {15 return service.results[service.location()];16 },17 model: {18 calc: "CalcOffset",19 calcOffset: {20 compareBy: "location",21 },22 calcFgRect: {23 compareBy: "location",24 },25 calcGrid: {26 rmseDanger: 0.0025, // 0.1 pixel in 4027 rmseWarning: 0.0020, // 0.1 pixel in 5028 }29 },30 isAvailable: function() {31 return available === true;32 },33 calcOffsetClass: function(dim) {34 var loc = service.location();35 if (!service.results[loc]) {36 return "";37 }38 var co = service.results[loc].calcOffset;39 var vdim = co != null && co[dim];40 if (vdim == null) {41 return "fn-no-data";42 }43 if (vdim === 0) {44 return "success";45 } else if (Math.abs(vdim) <= 1) {46 return "warning";47 }48 return "danger";49 },50 calcGrid: function(camName) {51 var loc = service.location();52 service.results[loc] = service.results[loc] || {};53 service.results[loc].calcGrid = {54 origin: "measuring...",55 angle: "measuring...",56 cellSize: "measuring...",57 rmse: "measuring...",58 class: {59 x: "info", y: "info", xy: "info"60 },61 summary: "measuring...",62 };63 var rmseClass = function(rmse, base) {64 if (typeof rmse !== "number" || typeof base !== "number") {65 return "fn-no-data";66 }67 if (rmse >= base * service.model.calcGrid.rmseDanger) {68 return "danger";69 }70 if (rmse >= base * service.model.calcGrid.rmseWarning) {71 return "warning";72 }73 return "success";74 }75 alerts.taskBegin();76 $.ajax({77 url: "/firesight/" + camName + "/calc-grid",78 success: function(outJson) {79 console.log("calcGrid() ", outJson);80 service.results[loc].calcGrid = outJson;81 service.results[loc].calcGrid.class = {82 x: rmseClass(outJson.rmse && outJson.rmse.x, outJson.cellSize && outJson.cellSize.w),83 y: rmseClass(outJson.rmse && outJson.rmse.y, outJson.cellSize && outJson.cellSize.h),84 xy: rmseClass(85 outJson.rmse && Math.max(outJson.rmse.x, outJson.rmse.y),86 outJson.cellSize && Math.max(outJson.cellSize.w, outJson.cellSize.h)87 ),88 };89 service.processCount++;90 alerts.taskEnd();91 },92 error: function(jqXHR, ex) {93 service.processCount++;94 service.results[loc].calcGrid = {95 origin: "(no match)",96 angle: "(no match)",97 cellSize: "(no match)",98 rmse: "(no match)",99 class: {100 x: "danger", y: "danger", z: "danger"101 },102 };103 alerts.taskEnd();104 }105 });106 },107 readQR: function(camName) {108 var loc = service.location();109 service.results[loc] = service.results[loc] || {};110 var result = service.results[loc].readQR = {111 class: "fn-no-data",112 summary: "scanning...",113 qrdata: [{114 x: "scanning...",115 y: "scanning...",116 text: "scanning...",117 }]118 };119 alerts.taskBegin();120 $.ajax({121 url: "/firesight/" + camName + "/read-qr",122 success: function(outJson) {123 console.log("readQR() ", outJson);124 result = service.results[loc].readQR = outJson;125 if (outJson.qrdata && outJson.qrdata.length > 0) {126 result.class = "";127 } else {128 result.class = "fn-no-data";129 }130 service.processCount++;131 alerts.taskEnd();132 },133 error: function(jqXHR, ex) {134 service.processCount++;135 alerts.taskEnd();136 }137 });138 },139 matchCDS: function(camName) {140 var loc = service.location();141 service.results[loc] = service.results[loc] || {};142 var result = service.results[loc].matchCDS = {143 class: "fn-no-data",144 summary: "scanning...",145 matched: [],146 };147 alerts.taskBegin();148 $.ajax({149 url: "/firesight/" + camName + "/match-cds",150 success: function(outJson) {151 console.log("matchCDS() ", outJson);152 result = service.results[loc].matchCDS = outJson;153 if (outJson.matched && outJson.matched.length > 0) {154 result.class = "";155 } else {156 result.class = "fn-no-data";157 }158 service.processCount++;159 alerts.taskEnd();160 },161 error: function(jqXHR, ex) {162 service.processCount++;163 alerts.taskEnd();164 }165 });166 },167 calcFgRect: function(camName) {168 var loc = service.location();169 var noMatch = {170 x: "(no match)",171 y: "(no match)",172 width: "(no match)",173 length: "(no match)",174 height: "(no match)",175 angle: "(no match)",176 points: "(no match)",177 summary: "(no match)",178 };179 var url = "/firesight/" + camName + "/calc-fg-rect";180 if (service.model.calcFgRect.compareBy === "name") {181 url += "?savedImage=" + encodeURIComponent(service.model.calcFgRect.compareName);182 }183 service.results[loc] = service.results[loc] || {};184 service.results[loc].calcFgRect = {185 x: "measuring...",186 y: "measuring...",187 width: "measuring...",188 height: "measuring...",189 angle: "measuring...",190 points: "measuring...",191 };192 alerts.taskBegin();193 $.ajax({194 url: url,195 success: function(outJson) {196 console.log("calcFgRect() ", outJson);197 service.results[loc].calcFgRect = outJson;198 if (!outJson.points) {199 service.results[loc].calcFgRect.class = "fn-no-data";200 }201 service.processCount++;202 alerts.taskEnd();203 },204 error: function(jqXHR, ex) {205 service.processCount++;206 service.results[loc].calcFgRect = noMatch;207 alerts.taskEnd();208 }209 });210 },211 getSyncJson: function() {212 return service.model;213 },214 calcOffset: function(camName) {215 var loc = service.location();216 service.results[loc] = service.results[loc] || {};217 var result = service.results[loc].calcOffset = {218 summary: "measuring...",219 class: "fn-no-data",220 dx: "...",221 dy: "..."222 };223 var url = "/firesight/" + camName + "/calc-offset";224 if (service.model.calcOffset.compareBy === "name") {225 url += "?savedImage=" + encodeURIComponent(service.model.calcOffset.compareName);226 }227 alerts.taskBegin();228 $.ajax({229 url: url,230 success: function(outJson) {231 console.log("calcOffset() ", outJson);232 result = service.results[loc].calcOffset = outJson;233 var matched = result.dx != null && result.dy != null;234 result.summary = matched ? "Matched" : "No match";235 result.class = matched ? "" : "fn-no-data";236 alerts.taskEnd();237 service.processCount++;238 },239 error: function(jqXHR, ex) {240 service.results[loc].calcOffset = {241 summary: ex.message,242 class: "fn-no-data",243 dx: "(no match)",244 dy: "(no match)"245 };246 service.processCount++;247 console.warn("calcOffset() failed:", jqXHR, ex);248 alerts.taskEnd();249 }250 });251 }252 };253 alerts.taskBegin();254 $.ajax({255 url: "/firesight/model",256 success: function(data) {257 available = data && data.available;258 //console.log("firesight available:", available);259 JsonUtil.applyJson(service.model, data);260 alerts.taskEnd();261 },262 error: function(jqXHR, ex) {263 available = false;264 console.warn("firesight unavailable :", jqXHR, ex);265 alerts.taskEnd();266 }267 });268 return service;269 }...

Full Screen

Full Screen

NURBSUtils.js

Source:NURBSUtils.js Github

copy

Full Screen

1( function () {2 /**3 * NURBS utils4 *5 * See NURBSCurve and NURBSSurface.6 **/7 /**************************************************************8 * NURBS Utils9 **************************************************************/10 /*11Finds knot vector span.12p : degree13u : parametric value14U : knot vector15returns the span16*/17 function findSpan( p, u, U ) {18 const n = U.length - p - 1;19 if ( u >= U[ n ] ) {20 return n - 1;21 }22 if ( u <= U[ p ] ) {23 return p;24 }25 let low = p;26 let high = n;27 let mid = Math.floor( ( low + high ) / 2 );28 while ( u < U[ mid ] || u >= U[ mid + 1 ] ) {29 if ( u < U[ mid ] ) {30 high = mid;31 } else {32 low = mid;33 }34 mid = Math.floor( ( low + high ) / 2 );35 }36 return mid;37 }38 /*39Calculate basis functions. See The NURBS Book, page 70, algorithm A2.240span : span in which u lies41u : parametric point42p : degree43U : knot vector44returns array[p+1] with basis functions values.45*/46 function calcBasisFunctions( span, u, p, U ) {47 const N = [];48 const left = [];49 const right = [];50 N[ 0 ] = 1.0;51 for ( let j = 1; j <= p; ++ j ) {52 left[ j ] = u - U[ span + 1 - j ];53 right[ j ] = U[ span + j ] - u;54 let saved = 0.0;55 for ( let r = 0; r < j; ++ r ) {56 const rv = right[ r + 1 ];57 const lv = left[ j - r ];58 const temp = N[ r ] / ( rv + lv );59 N[ r ] = saved + rv * temp;60 saved = lv * temp;61 }62 N[ j ] = saved;63 }64 return N;65 }66 /*67Calculate B-Spline curve points. See The NURBS Book, page 82, algorithm A3.1.68p : degree of B-Spline69U : knot vector70P : control points (x, y, z, w)71u : parametric point72returns point for given u73*/74 function calcBSplinePoint( p, U, P, u ) {75 const span = findSpan( p, u, U );76 const N = calcBasisFunctions( span, u, p, U );77 const C = new THREE.Vector4( 0, 0, 0, 0 );78 for ( let j = 0; j <= p; ++ j ) {79 const point = P[ span - p + j ];80 const Nj = N[ j ];81 const wNj = point.w * Nj;82 C.x += point.x * wNj;83 C.y += point.y * wNj;84 C.z += point.z * wNj;85 C.w += point.w * Nj;86 }87 return C;88 }89 /*90Calculate basis functions derivatives. See The NURBS Book, page 72, algorithm A2.3.91span : span in which u lies92u : parametric point93p : degree94n : number of derivatives to calculate95U : knot vector96returns array[n+1][p+1] with basis functions derivatives97*/98 function calcBasisFunctionDerivatives( span, u, p, n, U ) {99 const zeroArr = [];100 for ( let i = 0; i <= p; ++ i ) zeroArr[ i ] = 0.0;101 const ders = [];102 for ( let i = 0; i <= n; ++ i ) ders[ i ] = zeroArr.slice( 0 );103 const ndu = [];104 for ( let i = 0; i <= p; ++ i ) ndu[ i ] = zeroArr.slice( 0 );105 ndu[ 0 ][ 0 ] = 1.0;106 const left = zeroArr.slice( 0 );107 const right = zeroArr.slice( 0 );108 for ( let j = 1; j <= p; ++ j ) {109 left[ j ] = u - U[ span + 1 - j ];110 right[ j ] = U[ span + j ] - u;111 let saved = 0.0;112 for ( let r = 0; r < j; ++ r ) {113 const rv = right[ r + 1 ];114 const lv = left[ j - r ];115 ndu[ j ][ r ] = rv + lv;116 const temp = ndu[ r ][ j - 1 ] / ndu[ j ][ r ];117 ndu[ r ][ j ] = saved + rv * temp;118 saved = lv * temp;119 }120 ndu[ j ][ j ] = saved;121 }122 for ( let j = 0; j <= p; ++ j ) {123 ders[ 0 ][ j ] = ndu[ j ][ p ];124 }125 for ( let r = 0; r <= p; ++ r ) {126 let s1 = 0;127 let s2 = 1;128 const a = [];129 for ( let i = 0; i <= p; ++ i ) {130 a[ i ] = zeroArr.slice( 0 );131 }132 a[ 0 ][ 0 ] = 1.0;133 for ( let k = 1; k <= n; ++ k ) {134 let d = 0.0;135 const rk = r - k;136 const pk = p - k;137 if ( r >= k ) {138 a[ s2 ][ 0 ] = a[ s1 ][ 0 ] / ndu[ pk + 1 ][ rk ];139 d = a[ s2 ][ 0 ] * ndu[ rk ][ pk ];140 }141 const j1 = rk >= - 1 ? 1 : - rk;142 const j2 = r - 1 <= pk ? k - 1 : p - r;143 for ( let j = j1; j <= j2; ++ j ) {144 a[ s2 ][ j ] = ( a[ s1 ][ j ] - a[ s1 ][ j - 1 ] ) / ndu[ pk + 1 ][ rk + j ];145 d += a[ s2 ][ j ] * ndu[ rk + j ][ pk ];146 }147 if ( r <= pk ) {148 a[ s2 ][ k ] = - a[ s1 ][ k - 1 ] / ndu[ pk + 1 ][ r ];149 d += a[ s2 ][ k ] * ndu[ r ][ pk ];150 }151 ders[ k ][ r ] = d;152 const j = s1;153 s1 = s2;154 s2 = j;155 }156 }157 let r = p;158 for ( let k = 1; k <= n; ++ k ) {159 for ( let j = 0; j <= p; ++ j ) {160 ders[ k ][ j ] *= r;161 }162 r *= p - k;163 }164 return ders;165 }166 /*167 Calculate derivatives of a B-Spline. See The NURBS Book, page 93, algorithm A3.2.168 p : degree169 U : knot vector170 P : control points171 u : Parametric points172 nd : number of derivatives173 returns array[d+1] with derivatives174 */175 function calcBSplineDerivatives( p, U, P, u, nd ) {176 const du = nd < p ? nd : p;177 const CK = [];178 const span = findSpan( p, u, U );179 const nders = calcBasisFunctionDerivatives( span, u, p, du, U );180 const Pw = [];181 for ( let i = 0; i < P.length; ++ i ) {182 const point = P[ i ].clone();183 const w = point.w;184 point.x *= w;185 point.y *= w;186 point.z *= w;187 Pw[ i ] = point;188 }189 for ( let k = 0; k <= du; ++ k ) {190 const point = Pw[ span - p ].clone().multiplyScalar( nders[ k ][ 0 ] );191 for ( let j = 1; j <= p; ++ j ) {192 point.add( Pw[ span - p + j ].clone().multiplyScalar( nders[ k ][ j ] ) );193 }194 CK[ k ] = point;195 }196 for ( let k = du + 1; k <= nd + 1; ++ k ) {197 CK[ k ] = new THREE.Vector4( 0, 0, 0 );198 }199 return CK;200 }201 /*202Calculate "K over I"203returns k!/(i!(k-i)!)204*/205 function calcKoverI( k, i ) {206 let nom = 1;207 for ( let j = 2; j <= k; ++ j ) {208 nom *= j;209 }210 let denom = 1;211 for ( let j = 2; j <= i; ++ j ) {212 denom *= j;213 }214 for ( let j = 2; j <= k - i; ++ j ) {215 denom *= j;216 }217 return nom / denom;218 }219 /*220Calculate derivatives (0-nd) of rational curve. See The NURBS Book, page 127, algorithm A4.2.221Pders : result of function calcBSplineDerivatives222returns array with derivatives for rational curve.223*/224 function calcRationalCurveDerivatives( Pders ) {225 const nd = Pders.length;226 const Aders = [];227 const wders = [];228 for ( let i = 0; i < nd; ++ i ) {229 const point = Pders[ i ];230 Aders[ i ] = new THREE.Vector3( point.x, point.y, point.z );231 wders[ i ] = point.w;232 }233 const CK = [];234 for ( let k = 0; k < nd; ++ k ) {235 const v = Aders[ k ].clone();236 for ( let i = 1; i <= k; ++ i ) {237 v.sub( CK[ k - i ].clone().multiplyScalar( calcKoverI( k, i ) * wders[ i ] ) );238 }239 CK[ k ] = v.divideScalar( wders[ 0 ] );240 }241 return CK;242 }243 /*244Calculate NURBS curve derivatives. See The NURBS Book, page 127, algorithm A4.2.245p : degree246U : knot vector247P : control points in homogeneous space248u : parametric points249nd : number of derivatives250returns array with derivatives.251*/252 function calcNURBSDerivatives( p, U, P, u, nd ) {253 const Pders = calcBSplineDerivatives( p, U, P, u, nd );254 return calcRationalCurveDerivatives( Pders );255 }256 /*257Calculate rational B-Spline surface point. See The NURBS Book, page 134, algorithm A4.3.258p1, p2 : degrees of B-Spline surface259U1, U2 : knot vectors260P : control points (x, y, z, w)261u, v : parametric values262returns point for given (u, v)263*/264 function calcSurfacePoint( p, q, U, V, P, u, v, target ) {265 const uspan = findSpan( p, u, U );266 const vspan = findSpan( q, v, V );267 const Nu = calcBasisFunctions( uspan, u, p, U );268 const Nv = calcBasisFunctions( vspan, v, q, V );269 const temp = [];270 for ( let l = 0; l <= q; ++ l ) {271 temp[ l ] = new THREE.Vector4( 0, 0, 0, 0 );272 for ( let k = 0; k <= p; ++ k ) {273 const point = P[ uspan - p + k ][ vspan - q + l ].clone();274 const w = point.w;275 point.x *= w;276 point.y *= w;277 point.z *= w;278 temp[ l ].add( point.multiplyScalar( Nu[ k ] ) );279 }280 }281 const Sw = new THREE.Vector4( 0, 0, 0, 0 );282 for ( let l = 0; l <= q; ++ l ) {283 Sw.add( temp[ l ].multiplyScalar( Nv[ l ] ) );284 }285 Sw.divideScalar( Sw.w );286 target.set( Sw.x, Sw.y, Sw.z );287 }288 THREE.NURBSUtils = {};289 THREE.NURBSUtils.calcBSplineDerivatives = calcBSplineDerivatives;290 THREE.NURBSUtils.calcBSplinePoint = calcBSplinePoint;291 THREE.NURBSUtils.calcBasisFunctionDerivatives = calcBasisFunctionDerivatives;292 THREE.NURBSUtils.calcBasisFunctions = calcBasisFunctions;293 THREE.NURBSUtils.calcKoverI = calcKoverI;294 THREE.NURBSUtils.calcNURBSDerivatives = calcNURBSDerivatives;295 THREE.NURBSUtils.calcRationalCurveDerivatives = calcRationalCurveDerivatives;296 THREE.NURBSUtils.calcSurfacePoint = calcSurfacePoint;297 THREE.NURBSUtils.findSpan = findSpan;...

Full Screen

Full Screen

FireSightRESTFactory.js

Source:FireSightRESTFactory.js Github

copy

Full Screen

1var should = require("should");2var FireSightREST = require("./FireSightREST");3var CalcOffset = require("./CalcOffset");4var CalcGrid = require("./CalcGrid");5var CalcFgRect = require("./CalcFgRect");6var MatchCDS = require("./MatchCDS");7var ReadQR = require("./ReadQR");8(function(exports) {9 ////////////////// constructor10 function FireSightRESTFactory() {11 var that = this;12 return that;13 }14 FireSightRESTFactory.create = function(images, options) {15 var that = this;16 var firesight = new FireSightREST(images, options);17 firesight.open();18 firesight.registerCalc("CalcGrid", new CalcGrid(firesight, options));19 firesight.registerCalc("CalcOffset", new CalcOffset(firesight, options));20 firesight.registerCalc("CalcFgRect", new CalcFgRect(firesight, options));21 firesight.registerCalc("MatchCDS", new MatchCDS(firesight, options));22 firesight.registerCalc("ReadQR", new ReadQR(firesight, options));23 return firesight;24 }25 module.exports = exports.FireSightRESTFactory = FireSightRESTFactory;26})(typeof exports === "object" ? exports : (exports = {}));27// mocha -R min --inline-diffs *.js28(typeof describe === 'function') && describe("FireSightRESTFactory", function() {29 var FireSightRESTFactory = require("./FireSightRESTFactory.js");30 var MockImages = new require("../mock/MockImages");31 var mock_images = new MockImages();32 it("FireSightRESTFactory.create() should create a FireSightREST service", function() {33 var options = {};34 var firesight = FireSightRESTFactory.create(mock_images, options);35 firesight.isAvailable().should.equal(false);36 setTimeout(function() {37 firesight.isAvailable().should.equal(true);38 }, 100);39 firesight.calcs.should.exist;40 firesight.calcs.should.have.property("CalcGrid");41 firesight.calcs.should.have.property("CalcOffset");42 firesight.calcs.should.have.property("CalcFgRect");;43 firesight.calcs.should.have.property("ReadQR");;44 })...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { calc } from 'storybook-root';2console.log(calc(2, 3));3import { calc } from 'storybook-root';4console.log(calc(2, 3));5declare module 'storybook-root' {6 export const calc: (a: number, b: number) => number;7}

Full Screen

Using AI Code Generation

copy

Full Screen

1const storybookRoot = require('storybook-root');2const result = storybookRoot.calc(1, 2);3const storybookRoot = require('storybook-root');4const result = storybookRoot.calc(1, 2);5const storybookRoot = require('storybook-root');6const result = storybookRoot.calc(1, 2);7const storybookRoot = require('storybook-root');8const result = storybookRoot.calc(1, 2);9const storybookRoot = require('storybook-root');10const result = storybookRoot.calc(1, 2);11const storybookRoot = require('storybook-root');12const result = storybookRoot.calc(1, 2);13const storybookRoot = require('storybook-root');14const result = storybookRoot.calc(1, 2);15const storybookRoot = require('storybook-root');16const result = storybookRoot.calc(1, 2);17const storybookRoot = require('storybook-root');18const result = storybookRoot.calc(1, 2);19const storybookRoot = require('storybook-root');20const result = storybookRoot.calc(1, 2);21const storybookRoot = require('storybook-root');22const result = storybookRoot.calc(1

Full Screen

Using AI Code Generation

copy

Full Screen

1import { calc } from 'storybook-root';2import { calc } from 'storybook-root';3import { calc } from 'storybook-root';4import { calc } from 'storybook-root';5import { calc } from 'storybook-root';6import { calc } from 'storybook-root';7import { calc } from 'storybook-root';8import { calc } from 'storybook-root';9import { calc } from 'storybook-root';10import { calc } from 'storybook-root';11import { calc } from 'storybook-root';12import { calc } from 'storybook-root';13import { calc } from 'storybook-root';14import { calc } from 'storybook-root';

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run storybook-root automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful