How to use intersection method in storybook-root

Best JavaScript code snippet using storybook-root

test-intersection-observer.js

Source:test-intersection-observer.js Github

copy

Full Screen

1/**2 * Copyright 2020 The AMP HTML Authors. All Rights Reserved.3 *4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 *8 * http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS-IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16import {17 IntersectionObserverStub,18 resetSubsForTesting,19 shouldLoadPolyfill,20 upgradePolyfill,21} from '../../../src/polyfillstub/intersection-observer-stub';22import {23 install,24 installForChildWin,25} from '../../../src/polyfills/intersection-observer';26class NativeIntersectionObserver {27 constructor(callback, options) {28 this.callback = callback;29 this.options = options;30 }31 get root() {32 return 'native.root';33 }34 get rootMargin() {35 return 'native.rootMargin';36 }37 get thresholds() {38 return 'native.thresholds';39 }40 takeRecords() {41 return 'native.takeRecords';42 }43 observe() {}44 unobserve() {}45 disconnect() {}46}47class NativeIntersectionObserverEntry {48 get isIntersecting() {}49}50describes.sandboxed('shouldLoadPolyfill', {}, () => {51 it('should not load with native', () => {52 const win = {53 IntersectionObserver: NativeIntersectionObserver,54 IntersectionObserverEntry: NativeIntersectionObserverEntry,55 };56 expect(shouldLoadPolyfill(win)).to.be.false;57 });58 it('should load when no native', () => {59 const win = {};60 expect(shouldLoadPolyfill(win)).to.be.true;61 });62 it('should load with the stub', () => {63 const win = {64 IntersectionObserver: IntersectionObserverStub,65 IntersectionObserverEntry: NativeIntersectionObserverEntry,66 };67 expect(shouldLoadPolyfill(win)).to.be.true;68 });69 it('should load when no native entry', () => {70 const win = {71 IntersectionObserver: NativeIntersectionObserver,72 };73 expect(shouldLoadPolyfill(win)).to.be.true;74 });75 it('should not load even if entry doesn not have isIntersecting', () => {76 class IntersectionObserverEntryWithMissingIsIntersecting {}77 const win = {78 IntersectionObserver: NativeIntersectionObserver,79 IntersectionObserverEntry: IntersectionObserverEntryWithMissingIsIntersecting,80 };81 expect(shouldLoadPolyfill(win)).to.be.false;82 });83});84describes.fakeWin('install', {}, (env) => {85 it('should install IntersectionObserverStub when no native', () => {86 const {win} = env;87 delete win.IntersectionObserver;88 install(win);89 expect(win.IntersectionObserver).to.equal(IntersectionObserverStub);90 });91 it('should keep native when available', () => {92 const {win} = env;93 const native = function () {};94 win.IntersectionObserver = native;95 install(win);96 expect(win.IntersectionObserver).to.equal(native);97 });98 it('should polyfill isIntersecting when absent in native', () => {99 const {win} = env;100 const native = function () {};101 const nativeEntry = function () {};102 win.IntersectionObserver = native;103 win.IntersectionObserverEntry = nativeEntry;104 expect('isIntersecting' in win.IntersectionObserverEntry.prototype).to.be105 .false;106 install(win);107 expect(win.IntersectionObserver).to.equal(native);108 expect(win.IntersectionObserverEntry).to.equal(nativeEntry);109 expect('isIntersecting' in win.IntersectionObserverEntry.prototype).to.be110 .true;111 const entry = new win.IntersectionObserverEntry();112 expect(entry).to.be.instanceOf(nativeEntry);113 entry.intersectionRatio = 0;114 expect(entry.isIntersecting).to.be.false;115 entry.intersectionRatio = 1;116 expect(entry.isIntersecting).to.be.true;117 });118 it('should keep native isIntersecting when available', () => {119 const {win} = env;120 const native = function () {};121 const nativeEntry = function () {};122 Object.defineProperty(nativeEntry.prototype, 'isIntersecting', {123 value: 'A',124 });125 win.IntersectionObserver = native;126 win.IntersectionObserverEntry = nativeEntry;127 expect('isIntersecting' in win.IntersectionObserverEntry.prototype).to.be128 .true;129 install(win);130 const entry = new win.IntersectionObserverEntry();131 expect(entry).to.be.instanceOf(nativeEntry);132 entry.intersectionRatio = 0;133 expect(entry.isIntersecting).to.equal('A');134 entry.intersectionRatio = 1;135 expect(entry.isIntersecting).to.equal('A');136 });137});138describes.fakeWin('installForChildWin', {}, (env) => {139 const IntersectionObserver1 = function () {};140 const IntersectionObserverEntry1 = function () {};141 const IntersectionObserver2 = function () {};142 const IntersectionObserverEntry2 = function () {};143 it('should install IntersectionObserverStub when no native', () => {144 const {win} = env;145 delete win.IntersectionObserver;146 const parentWin = {147 IntersectionObserver: IntersectionObserver1,148 IntersectionObserverEntry: IntersectionObserverEntry1,149 };150 installForChildWin(parentWin, win);151 expect(win.IntersectionObserver).to.equal(IntersectionObserver1);152 expect(win.IntersectionObserverEntry).to.equal(IntersectionObserverEntry1);153 // Change parent.154 parentWin.IntersectionObserver = IntersectionObserver2;155 parentWin.IntersectionObserverEntry = IntersectionObserverEntry2;156 expect(win.IntersectionObserver).to.equal(IntersectionObserver2);157 expect(win.IntersectionObserverEntry).to.equal(IntersectionObserverEntry2);158 });159 it('should keep native when available', () => {160 const {win} = env;161 const native = function () {};162 const nativeEntry = function () {};163 win.IntersectionObserver = native;164 win.IntersectionObserverEntry = nativeEntry;165 const parentWin = {166 IntersectionObserver: IntersectionObserver1,167 IntersectionObserverEntry: IntersectionObserverEntry1,168 };169 installForChildWin(parentWin, win);170 expect(win.IntersectionObserver).to.equal(native);171 expect(win.IntersectionObserverEntry).to.equal(nativeEntry);172 });173});174describes.fakeWin('upgradePolyfill', {}, (env) => {175 beforeEach(() => {176 env.sandbox.stub(NativeIntersectionObserver.prototype, 'observe');177 env.sandbox.stub(NativeIntersectionObserver.prototype, 'disconnect');178 });179 afterEach(() => {180 resetSubsForTesting();181 });182 function nextMicroTask() {183 return Promise.resolve().then(() => Promise.resolve());184 }185 it('should reset stub before running the installer', () => {186 const {win} = env;187 delete win.IntersectionObserver;188 install(win);189 expect(win.IntersectionObserver).to.equal(IntersectionObserverStub);190 upgradePolyfill(win, function () {191 expect(win.IntersectionObserver).to.not.be.ok;192 expect(win.IntersectionObserverEntry).to.not.be.ok;193 });194 });195 it('should upgrade all stubs', async () => {196 const {win} = env;197 delete win.IntersectionObserver;198 install(win);199 const callback = function () {};200 const element1 = win.document.createElement('div');201 const io1 = new win.IntersectionObserver(callback);202 const io2 = new win.IntersectionObserver(callback);203 expect(io1).to.be.instanceOf(IntersectionObserverStub);204 expect(io2).to.be.instanceOf(IntersectionObserverStub);205 io1.observe(element1);206 io2.observe(element1);207 expect(NativeIntersectionObserver.prototype.observe).to.not.be.called;208 upgradePolyfill(win, function () {209 win.IntersectionObserver = NativeIntersectionObserver;210 win.IntersectionObserverEntry = NativeIntersectionObserverEntry;211 });212 await nextMicroTask();213 expect(NativeIntersectionObserver.prototype.observe).to.be.calledTwice;214 expect(NativeIntersectionObserver.prototype.observe).to.be.calledWith(215 element1216 );217 expect(NativeIntersectionObserver.prototype.disconnect).to.not.be.called;218 io1.disconnect();219 io2.disconnect();220 expect(NativeIntersectionObserver.prototype.disconnect).to.be.calledTwice;221 });222 it('should auto-upgrade any stub post upgrade', async () => {223 const {win} = env;224 delete win.IntersectionObserver;225 install(win);226 expect(win.IntersectionObserver).to.equal(IntersectionObserverStub);227 upgradePolyfill(win, function () {228 win.IntersectionObserver = NativeIntersectionObserver;229 win.IntersectionObserverEntry = NativeIntersectionObserverEntry;230 });231 const callback = function () {};232 const element1 = win.document.createElement('div');233 const io = new IntersectionObserverStub(callback);234 await nextMicroTask();235 io.observe(element1);236 expect(NativeIntersectionObserver.prototype.observe).to.be.calledOnce;237 expect(NativeIntersectionObserver.prototype.observe).to.be.calledWith(238 element1239 );240 });241 it('should run installer even when native is available', () => {242 const {win} = env;243 win.IntersectionObserver = NativeIntersectionObserver;244 win.IntersectionObserverEntry = NativeIntersectionObserverEntry;245 const upgradeCall = env.sandbox.spy();246 upgradePolyfill(win, function () {247 expect(win.IntersectionObserver).to.equal(NativeIntersectionObserver);248 expect(win.IntersectionObserverEntry).to.equal(249 NativeIntersectionObserverEntry250 );251 upgradeCall();252 });253 expect(upgradeCall).to.be.calledOnce;254 });255});256describes.fakeWin('IntersectionObserverStub', {}, (env) => {257 let win;258 let callback;259 let element1;260 let element2;261 beforeEach(() => {262 win = env.win;263 callback = env.sandbox.spy();264 element1 = win.document.createElement('div');265 element2 = win.document.createElement('div');266 });267 describe('constructor', () => {268 it('should disallow non-element root', () => {269 // Must fail on any non-element root. This is critical because this270 // failure is used as a feature-detection for document root support.271 expect(272 () => new IntersectionObserverStub(callback, {root: win.document})273 ).to.throw(/root must be an Element/);274 });275 it('should allow default options', () => {276 const io = new IntersectionObserverStub(callback);277 expect(io.root).to.be.null;278 expect(io.rootMargin).to.equal('0px 0px 0px 0px');279 expect(io.thresholds).to.deep.equal([0]);280 });281 it('should allow null root', () => {282 const io = new IntersectionObserverStub(callback, {root: null});283 expect(io.root).to.be.null;284 expect(io.rootMargin).to.equal('0px 0px 0px 0px');285 expect(io.thresholds).to.deep.equal([0]);286 });287 it('should allow element root', () => {288 const element = win.document.createElement('div');289 const io = new IntersectionObserverStub(callback, {root: element});290 expect(io.root).to.equal(element);291 });292 it('should override rootMargin', () => {293 const io = new IntersectionObserverStub(callback, {rootMargin: '10px'});294 expect(io.rootMargin).to.equal('10px');295 });296 it('should override threshold as number', () => {297 const io = new IntersectionObserverStub(callback, {threshold: 0.1});298 expect(io.thresholds).to.deep.equal([0.1]);299 });300 it('should override threshold as array', () => {301 const io = new IntersectionObserverStub(callback, {302 threshold: [0.1, 0.2],303 });304 expect(io.thresholds).to.deep.equal([0.1, 0.2]);305 });306 });307 describe('takeRecords', () => {308 it('should always be empty', () => {309 const io = new IntersectionObserverStub(callback);310 expect(io.takeRecords()).to.deep.equal([]);311 });312 });313 describe('observe/unobserve/disconnect', () => {314 it('should queue up elements when observed, but only once', () => {315 const io = new IntersectionObserverStub(callback);316 io.observe(element1);317 expect(io.elements_).to.deep.equal([element1]);318 io.observe(element1);319 expect(io.elements_).to.deep.equal([element1]);320 io.observe(element2);321 expect(io.elements_).to.deep.equal([element1, element2]);322 });323 it('should dequeue elements when observed', () => {324 const io = new IntersectionObserverStub(callback);325 io.observe(element1);326 io.observe(element2);327 expect(io.elements_).to.deep.equal([element1, element2]);328 io.unobserve(element1);329 expect(io.elements_).to.deep.equal([element2]);330 io.unobserve(element2);331 expect(io.elements_).to.deep.equal([]);332 io.unobserve(element1);333 io.unobserve(element2);334 expect(io.elements_).to.deep.equal([]);335 });336 it('should dequeue elements when disconnected', () => {337 const io = new IntersectionObserverStub(callback);338 io.observe(element1);339 io.observe(element2);340 expect(io.elements_).to.deep.equal([element1, element2]);341 io.disconnect();342 expect(io.elements_).to.deep.equal([]);343 io.disconnect();344 expect(io.elements_).to.deep.equal([]);345 });346 });347 describe('upgrade', () => {348 beforeEach(() => {349 env.sandbox.stub(NativeIntersectionObserver.prototype, 'observe');350 env.sandbox.stub(NativeIntersectionObserver.prototype, 'unobserve');351 env.sandbox.stub(NativeIntersectionObserver.prototype, 'disconnect');352 });353 function upgrade(io) {354 io.upgrade_(NativeIntersectionObserver);355 return io.inst_;356 }357 it('should forward callback and default options', () => {358 const io = new IntersectionObserverStub(callback);359 const native = upgrade(io);360 expect(native.callback).to.equal(callback);361 expect(native.options).to.deep.equal({362 root: null,363 rootMargin: '0px 0px 0px 0px',364 });365 });366 it('should forward custom options', () => {367 const io = new IntersectionObserverStub(callback, {368 root: element1,369 rootMargin: '10px',370 threshold: 0.1,371 });372 const native = upgrade(io);373 expect(native.options).to.deep.equal({374 root: element1,375 rootMargin: '10px',376 threshold: 0.1,377 });378 });379 it('should delegate getters to the native', () => {380 const io = new IntersectionObserverStub(callback);381 upgrade(io);382 expect(io.root).to.equal('native.root');383 expect(io.rootMargin).to.equal('native.rootMargin');384 expect(io.thresholds).to.equal('native.thresholds');385 expect(io.takeRecords()).to.equal('native.takeRecords');386 });387 it('should not re-queue if nothing is currently observed', () => {388 const io = new IntersectionObserverStub(callback);389 io.observe(element1);390 io.unobserve(element1);391 const native = upgrade(io);392 expect(native.observe).to.not.be.called;393 expect(io.elements_).to.be.null;394 });395 it('should re-queue previously observed elements', () => {396 const io = new IntersectionObserverStub(callback);397 io.observe(element1);398 io.observe(element2);399 const native = upgrade(io);400 expect(native.observe).to.be.calledTwice;401 expect(native.observe).to.be.calledWith(element1);402 expect(native.observe).to.be.calledWith(element2);403 expect(io.elements_).to.be.null;404 });405 it('should observe new elements only on native', () => {406 const io = new IntersectionObserverStub(callback);407 const native = upgrade(io);408 io.observe(element1);409 expect(native.observe).to.be.calledOnce.calledWith(element1);410 });411 it('should unobserve new elements only on native', () => {412 const io = new IntersectionObserverStub(callback);413 const native = upgrade(io);414 io.unobserve(element1);415 expect(native.unobserve).to.be.calledOnce.calledWith(element1);416 });417 it('should disconnect on native', () => {418 const io = new IntersectionObserverStub(callback);419 const native = upgrade(io);420 io.disconnect();421 expect(native.disconnect).to.be.calledOnce;422 });423 });...

Full Screen

Full Screen

intersection.js

Source:intersection.js Github

copy

Full Screen

1(function() {2 QUnit.module('fabric.Intersection');3 QUnit.test('constructor & properties', function(assert) {4 assert.ok(typeof fabric.Intersection === 'function');5 var intersection = new fabric.Intersection();6 assert.ok(intersection);7 assert.ok(intersection instanceof fabric.Intersection);8 assert.ok(intersection.constructor === fabric.Intersection);9 assert.ok(typeof intersection.constructor === 'function');10 assert.deepEqual(intersection.points, [], 'starts with empty array of points');11 assert.ok('status' in intersection, 'has status property');12 assert.equal(intersection.status, undefined, 'no default value for status');13 var status = 'status';14 intersection = new fabric.Intersection(status);15 assert.equal(intersection.status, status, 'constructor pass status value');16 });17 QUnit.test('appendPoint', function(assert) {18 var point = new fabric.Point(1, 1);19 var intersection = new fabric.Intersection();20 assert.ok(typeof intersection.appendPoint === 'function', 'has appendPoint method');21 var returned = intersection.appendPoint(point);22 assert.ok(returned instanceof fabric.Intersection, 'returns a fabric.Intersection');23 assert.equal(returned, intersection, 'is chainable');24 assert.equal(intersection.points.indexOf(point), 0, 'now intersection contain points');25 });26 QUnit.test('appendPoints', function(assert) {27 var point = new fabric.Point(1, 1);28 var intersection = new fabric.Intersection();29 assert.ok(typeof intersection.appendPoints === 'function', 'has appendPoint method');30 var returned = intersection.appendPoints([point, point]);31 assert.ok(returned instanceof fabric.Intersection, 'returns a fabric.Intersection');32 assert.equal(returned, intersection, 'is chainable');33 assert.equal(intersection.points.indexOf(point), 0, 'now intersection contain points');34 assert.equal(intersection.points.length, 2, 'now intersection contains 2 points');35 });36 QUnit.test('intersectLineLine simple intersection', function(assert) {37 var p1 = new fabric.Point(0, 0), p2 = new fabric.Point(10,10),38 p3 = new fabric.Point(0, 10), p4 = new fabric.Point(10, 0),39 intersection = fabric.Intersection.intersectLineLine(p1, p2, p3, p4);40 assert.ok(typeof fabric.Intersection.intersectLineLine === 'function', 'has intersectLineLine function');41 assert.ok(intersection instanceof fabric.Intersection, 'returns a fabric.Intersection');42 assert.equal(intersection.status, 'Intersection', 'it return a inteserction result');43 assert.deepEqual(intersection.points[0], new fabric.Point(5, 5), 'intersect in 5,5');44 });45 QUnit.test('intersectLineLine parallel', function(assert) {46 var p1 = new fabric.Point(0, 0), p2 = new fabric.Point(0,10),47 p3 = new fabric.Point(10, 0), p4 = new fabric.Point(10, 10),48 intersection = fabric.Intersection.intersectLineLine(p1, p2, p3, p4);49 assert.ok(intersection instanceof fabric.Intersection, 'returns a fabric.Intersection');50 assert.equal(intersection.status, 'Parallel', 'it return a Parallel result');51 assert.deepEqual(intersection.points, [], 'no point of intersections');52 });53 QUnit.test('intersectLineLine coincident', function(assert) {54 var p1 = new fabric.Point(0, 0), p2 = new fabric.Point(0, 10),55 p3 = new fabric.Point(0, 0), p4 = new fabric.Point(0, 10),56 intersection = fabric.Intersection.intersectLineLine(p1, p2, p3, p4);57 assert.ok(intersection instanceof fabric.Intersection, 'returns a fabric.Intersection');58 assert.equal(intersection.status, 'Coincident', 'it return a Coincident result');59 assert.deepEqual(intersection.points, [], 'no point of intersections');60 });61 QUnit.test('intersectLineLine coincident but different', function(assert) {62 var p1 = new fabric.Point(0, 0), p2 = new fabric.Point(0, 10),63 p3 = new fabric.Point(0, 1), p4 = new fabric.Point(0, 9),64 intersection = fabric.Intersection.intersectLineLine(p1, p2, p3, p4);65 assert.ok(intersection instanceof fabric.Intersection, 'returns a fabric.Intersection');66 assert.equal(intersection.status, 'Coincident', 'it return a Coincident result');67 assert.deepEqual(intersection.points, [], 'no point of intersections');68 });69 QUnit.test('intersectLineLine no intersect', function(assert) {70 var p1 = new fabric.Point(0, 0), p2 = new fabric.Point(0,10),71 p3 = new fabric.Point(10, 0), p4 = new fabric.Point(1, 10),72 intersection = fabric.Intersection.intersectLineLine(p1, p2, p3, p4);73 assert.ok(intersection instanceof fabric.Intersection, 'returns a fabric.Intersection');74 assert.equal(intersection.status, undefined, 'it return a undefined status result');75 assert.deepEqual(intersection.points, [], 'no point of intersections');76 });77 QUnit.test('intersectLinePolygon', function(assert) {78 var p1 = new fabric.Point(0, 5), p2 = new fabric.Point(10, 5),79 p3 = new fabric.Point(5, 0), p4 = new fabric.Point(2, 10),80 p5 = new fabric.Point(8, 10), points = [p3, p4, p5],81 intersection = fabric.Intersection.intersectLinePolygon(p1, p2, points);82 assert.ok(intersection instanceof fabric.Intersection, 'returns a fabric.Intersection');83 assert.ok(typeof fabric.Intersection.intersectLinePolygon === 'function', 'has intersectLinePolygon function');84 assert.equal(intersection.status, 'Intersection', 'it return a Intersection result');85 assert.equal(intersection.points.length, 2, '2 points of intersections');86 assert.deepEqual(intersection.points[0], new fabric.Point(3.5, 5), 'intersect in 3.5 ,5');87 assert.deepEqual(intersection.points[1], new fabric.Point(6.5, 5), 'intersect in 6.5 ,5');88 });89 QUnit.test('intersectLinePolygon in one point', function(assert) {90 var p1 = new fabric.Point(0, 5), p2 = new fabric.Point(5, 5),91 p3 = new fabric.Point(5, 0), p4 = new fabric.Point(2, 10),92 p5 = new fabric.Point(8, 10), points = [p3, p4, p5],93 intersection = fabric.Intersection.intersectLinePolygon(p1, p2, points);94 assert.ok(intersection instanceof fabric.Intersection, 'returns a fabric.Intersection');95 assert.equal(intersection.status, 'Intersection', 'it return a Intersection result');96 assert.equal(intersection.points.length, 1, '1 points of intersections');97 assert.deepEqual(intersection.points[0], new fabric.Point(3.5, 5), 'intersect in 3.5 ,5');98 });99 QUnit.test('intersectLinePolygon in one point', function(assert) {100 var p1 = new fabric.Point(0, 5), p2 = new fabric.Point(3, 5),101 p3 = new fabric.Point(5, 0), p4 = new fabric.Point(2, 10),102 p5 = new fabric.Point(8, 10), points = [p3, p4, p5],103 intersection = fabric.Intersection.intersectLinePolygon(p1, p2, points);104 assert.ok(intersection instanceof fabric.Intersection, 'returns a fabric.Intersection');105 assert.equal(intersection.status, undefined, 'it return a undefined result');106 assert.equal(intersection.points.length, 0, '0 points of intersections');107 });108 QUnit.test('intersectLinePolygon on a polygon segment', function(assert) {109 //TODO: fix this. it should return coincident.110 var p1 = new fabric.Point(1, 10), p2 = new fabric.Point(9, 10),111 p3 = new fabric.Point(5, 0), p4 = new fabric.Point(2, 10),112 p5 = new fabric.Point(8, 10), points = [p3, p4, p5],113 intersection = fabric.Intersection.intersectLinePolygon(p1, p2, points);114 assert.ok(intersection instanceof fabric.Intersection, 'returns a fabric.Intersection');115 assert.equal(intersection.status, 'Intersection', 'it return a Intersection result');116 assert.equal(intersection.points.length, 2, '2 points of intersections');117 assert.deepEqual(intersection.points[0], new fabric.Point(2, 10), 'intersect in 2, 10');118 assert.deepEqual(intersection.points[1], new fabric.Point(8, 10), 'intersect in 8, 10');119 });120 QUnit.test('intersectPolygonPolygon not intersecting', function(assert) {121 var p3b = new fabric.Point(50, 0), p4b = new fabric.Point(20, 100),122 p5b = new fabric.Point(80, 100), pointsb = [p3b, p4b, p5b],123 p3 = new fabric.Point(5, 0), p4 = new fabric.Point(2, 10),124 p5 = new fabric.Point(8, 10), points = [p3, p4, p5],125 intersection = fabric.Intersection.intersectPolygonPolygon(pointsb, points);126 assert.ok(typeof fabric.Intersection.intersectPolygonPolygon === 'function', 'has intersectPolygonPolygon function');127 assert.ok(intersection instanceof fabric.Intersection, 'returns a fabric.Intersection');128 assert.equal(intersection.status, undefined, 'it return a Intersection with no status');129 assert.equal(intersection.points.length, 0, '0 points of intersections');130 });131 QUnit.test('intersectPolygonPolygon intersecting', function(assert) {132 var p3b = new fabric.Point(1, 1), p4b = new fabric.Point(3, 1),133 p5b = new fabric.Point(3, 3), p6b = new fabric.Point(1, 3),134 pointsb = [p3b, p4b, p5b, p6b],135 p3 = new fabric.Point(2, 2), p4 = new fabric.Point(4, 2),136 p5 = new fabric.Point(4, 4), p6 = new fabric.Point(2, 4),137 points = [p3, p4, p5, p6],138 intersection = fabric.Intersection.intersectPolygonPolygon(pointsb, points);139 assert.ok(typeof fabric.Intersection.intersectPolygonPolygon === 'function', 'has intersectPolygonPolygon function');140 assert.ok(intersection instanceof fabric.Intersection, 'returns a fabric.Intersection');141 assert.equal(intersection.status, 'Intersection', 'it return a Intersection result');142 assert.equal(intersection.points.length, 2, '2 points of intersections');143 assert.deepEqual(intersection.points[0], new fabric.Point(3, 2), 'point of intersections 3, 2');144 assert.deepEqual(intersection.points[1], new fabric.Point(2, 3), 'point of intersections 2, 3');145 });146 QUnit.test('intersectPolygonRectangle intersecting', function(assert) {147 var p3b = new fabric.Point(1, 1),148 p5b = new fabric.Point(3, 3),149 p3 = new fabric.Point(2, 2), p4 = new fabric.Point(4, 2),150 p5 = new fabric.Point(4, 4), p6 = new fabric.Point(2, 4),151 points = [p3, p4, p5, p6],152 intersection = fabric.Intersection.intersectPolygonRectangle(points, p3b, p5b);153 assert.ok(typeof fabric.Intersection.intersectPolygonRectangle === 'function', 'has intersectPolygonPolygon function');154 assert.ok(intersection instanceof fabric.Intersection, 'returns a fabric.Intersection');155 assert.equal(intersection.status, 'Intersection', 'it return a Intersection result');156 assert.equal(intersection.points.length, 2, '2 points of intersections');157 assert.deepEqual(intersection.points[0], new fabric.Point(3, 2), 'point of intersections 3, 2');158 assert.deepEqual(intersection.points[1], new fabric.Point(2, 3), 'point of intersections 2, 3');159 });160 QUnit.test('intersectPolygonRectangle not intersecting', function(assert) {161 var p3b = new fabric.Point(10, 10),162 p5b = new fabric.Point(30, 30),163 p3 = new fabric.Point(2, 2), p4 = new fabric.Point(4, 2),164 p5 = new fabric.Point(4, 4), p6 = new fabric.Point(2, 4),165 points = [p3, p4, p5, p6],166 intersection = fabric.Intersection.intersectPolygonRectangle(points, p3b, p5b);167 assert.ok(typeof fabric.Intersection.intersectPolygonRectangle === 'function', 'has intersectPolygonPolygon function');168 assert.ok(intersection instanceof fabric.Intersection, 'returns a fabric.Intersection');169 assert.equal(intersection.status, undefined, 'it return a Intersection result');170 assert.equal(intersection.points.length, 0, '0 points of intersections');171 });...

Full Screen

Full Screen

IntersectionAdder.js

Source:IntersectionAdder.js Github

copy

Full Screen

1/* Copyright (c) 2011 by The Authors.2 * Published under the LGPL 2.1 license.3 * See /license-notice.txt for the full text of the license notice.4 * See /license.txt for the full text of the license.5 */6/**7 *@requires jsts/noding/SegmentIntersector.js8 */9/**10 * Computes the intersections between two line segments in {@link SegmentString}s11 * and adds them to each string. The {@link SegmentIntersector} is passed to a12 * {@link Noder}. The {@link addIntersections} method is called whenever the13 * {@link Noder} detects that two SegmentStrings <i>might</i> intersect. This14 * class is an example of the <i>Strategy</i> pattern.15 *16 * @constructor17 */18jsts.noding.IntersectionAdder = function(li) {19 this.li = li;20};21jsts.noding.IntersectionAdder.prototype = new jsts.noding.SegmentIntersector();22jsts.noding.IntersectionAdder.constructor = jsts.noding.IntersectionAdder;23jsts.noding.IntersectionAdder.isAdjacentSegments = function(i1, i2) {24 return Math.abs(i1 - i2) === 1;25};26/**27 * These variables keep track of what types of intersections were found during28 * ALL edges that have been intersected.29 */30/**31 * @type {boolean}32 * @private33 */34jsts.noding.IntersectionAdder.prototype._hasIntersection = false;35/**36 * @type {boolean}37 * @private38 */39jsts.noding.IntersectionAdder.prototype.hasProper = false;40/**41 * @type {boolean}42 * @private43 */44jsts.noding.IntersectionAdder.prototype.hasProperInterior = false;45/**46 * @type {boolean}47 * @private48 */49jsts.noding.IntersectionAdder.prototype.hasInterior = false;50// the proper intersection point found51/**52 * @type {Coordinate}53 * @private54 */55jsts.noding.IntersectionAdder.prototype.properIntersectionPoint = null;56/**57 * @type {LineIntersector}58 * @private59 */60jsts.noding.IntersectionAdder.prototype.li = null;61/**62 * @type {boolean}63 * @private64 */65jsts.noding.IntersectionAdder.prototype.isSelfIntersection = null;66jsts.noding.IntersectionAdder.prototype.numIntersections = 0;67jsts.noding.IntersectionAdder.prototype.numInteriorIntersections = 0;68jsts.noding.IntersectionAdder.prototype.numProperIntersections = 0;69// testing only70jsts.noding.IntersectionAdder.prototype.numTests = 0;71jsts.noding.IntersectionAdder.prototype.getLineIntersector = function() {72 return this.li;73};74/**75 * @return the proper intersection point, or <code>null</code> if none was76 * found.77 */78jsts.noding.IntersectionAdder.prototype.getProperIntersectionPoint = function() {79 return this.properIntersectionPoint;80};81jsts.noding.IntersectionAdder.prototype.hasIntersection = function() {82 return this._hasIntersection;83};84/**85 * A proper intersection is an intersection which is interior to at least two86 * line segments. Note that a proper intersection is not necessarily in the87 * interior of the entire Geometry, since another edge may have an endpoint88 * equal to the intersection, which according to SFS semantics can result in the89 * point being on the Boundary of the Geometry.90 */91jsts.noding.IntersectionAdder.prototype.hasProperIntersection = function() {92 return this.hasProper;93};94/**95 * A proper interior intersection is a proper intersection which is <b>not</b>96 * contained in the set of boundary nodes set for this SegmentIntersector.97 */98jsts.noding.IntersectionAdder.prototype.hasProperInteriorIntersection = function() {99 return this.hasProperInterior;100};101/**102 * An interior intersection is an intersection which is in the interior of some103 * segment.104 */105jsts.noding.IntersectionAdder.prototype.hasInteriorIntersection = function() {106 return this.hasInterior;107};108/**109 * A trivial intersection is an apparent self-intersection which in fact is110 * simply the point shared by adjacent line segments. Note that closed edges111 * require a special check for the point shared by the beginning and end112 * segments.113 *114 * @private115 */116jsts.noding.IntersectionAdder.prototype.isTrivialIntersection = function(e0,117 segIndex0, e1, segIndex1) {118 if (e0 == e1) {119 if (this.li.getIntersectionNum() == 1) {120 if (jsts.noding.IntersectionAdder121 .isAdjacentSegments(segIndex0, segIndex1))122 return true;123 if (e0.isClosed()) {124 var maxSegIndex = e0.size() - 1;125 if ((segIndex0 === 0 && segIndex1 === maxSegIndex) ||126 (segIndex1 === 0 && segIndex0 === maxSegIndex)) {127 return true;128 }129 }130 }131 }132 return false;133};134/**135 * This method is called by clients of the {@link SegmentIntersector} class to136 * process intersections for two segments of the {@link SegmentString}s being137 * intersected. Note that some clients (such as {@link MonotoneChain}s) may138 * optimize away this call for segment pairs which they have determined do not139 * intersect (e.g. by an disjoint envelope test).140 */141jsts.noding.IntersectionAdder.prototype.processIntersections = function(e0,142 segIndex0, e1, segIndex1) {143 if (e0 === e1 && segIndex0 === segIndex1)144 return;145 this.numTests++;146 var p00 = e0.getCoordinates()[segIndex0];147 var p01 = e0.getCoordinates()[segIndex0 + 1];148 var p10 = e1.getCoordinates()[segIndex1];149 var p11 = e1.getCoordinates()[segIndex1 + 1];150 this.li.computeIntersection(p00, p01, p10, p11);151 if (this.li.hasIntersection()) {152 this.numIntersections++;153 if (this.li.isInteriorIntersection()) {154 this.numInteriorIntersections++;155 this.hasInterior = true;156 }157 // if the segments are adjacent they have at least one trivial intersection,158 // the shared endpoint. Don't bother adding it if it is the159 // only intersection.160 if (!this.isTrivialIntersection(e0, segIndex0, e1, segIndex1)) {161 this._hasIntersection = true;162 e0.addIntersections(this.li, segIndex0, 0);163 e1.addIntersections(this.li, segIndex1, 1);164 if (this.li.isProper()) {165 this.numProperIntersections++;166 this.hasProper = true;167 this.hasProperInterior = true;168 }169 }170 }171};172/**173 * Always process all intersections174 *175 * @return false always.176 */177jsts.noding.IntersectionAdder.prototype.isDone = function() {178 return false;...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { intersection } = require('storybook-root');2const a = [1, 2, 3, 4, 5];3const b = [3, 4, 5, 6, 7];4const { intersection } = require('storybook-root');5const a = [1, 2, 3, 4, 5];6const b = [3, 4, 5, 6, 7];7const { intersection } = require('storybook-root');8const a = [1, 2, 3, 4, 5];9const b = [3, 4, 5, 6, 7];10const { intersection } = require('storybook-root');11const a = [1, 2, 3, 4, 5];12const b = [3, 4, 5, 6, 7];13const { intersection } = require('storybook-root');14const a = [1, 2, 3, 4, 5];15const b = [3, 4, 5, 6, 7];16const { intersection } = require('storybook-root');17const a = [1, 2, 3, 4, 5];18const b = [3, 4, 5, 6, 7];19const { intersection } = require('storybook-root');20const a = [1, 2, 3, 4, 5];

Full Screen

Using AI Code Generation

copy

Full Screen

1import { intersection } from 'storybook-root';2import { intersection } from 'storybook-root';3import { intersection } from 'storybook-root';4import { intersection } from 'storybook-root';5import { intersection } from 'storybook-root';6import { intersection } from 'storybook-root';7import { intersection } from 'storybook-root';8import { intersection } from 'storybook-root';9import { intersection } from 'storybook-root';10import { intersection } from 'storybook-root';11import { intersection } from 'storybook-root';12import { intersection } from 'storybook-root';13import { intersection } from 'storybook-root';14import { intersection } from 'storybook-root';15import { intersection } from 'storybook-root';16import { intersection } from 'storybook-root';17import { intersection } from 'storybook-root';18import { intersection } from 'storybook-root';19import { intersection } from 'storybook-root';20import { intersection } from 'storybook-root';21import { intersection } from 'storybook-root';22import { intersection } from 'storybook-root';

Full Screen

Using AI Code Generation

copy

Full Screen

1import { intersection } from "storybook-root";2import { intersection } from "storybook-root";3import { intersection } from "storybook-root";4import { intersection } from "storybook-root";5import { intersection } from "storybook-root";6import { intersection } from "storybook-root";7import { intersection } from "storybook-root";8import { intersection } from "storybook-root";9import { intersection } from "storybook-root";10import { intersection } from "storybook-root";

Full Screen

Using AI Code Generation

copy

Full Screen

1import { intersection } from 'storybook-root/.storybook/utils';2import { intersection } from 'storybook-root/src/.storybook/utils';3import { intersection } from 'storybook-root/src/utils';4import { intersection } from 'storybook-root/src/utils';5import { intersection } from 'storybook-root/src/utils';6import { intersection } from 'storybook-root/src/utils';7import { intersection } from 'storybook-root/src/utils';8import { intersection } from 'storybook-root/src/utils';9import { intersection } from 'storybook-root/src/utils';10import { intersection } from 'storybook-root/src/utils';11import { intersection } from 'storybook-root/src/utils';12import { intersection } from 'storybook-root/src/utils';13import { intersection } from 'storybook-root/src/utils';14import { intersection } from 'storybook-root/src/utils';15import { intersection } from 'storybook-root/src/utils';16import { intersection } from 'storybook-root/src/utils';17import { intersection } from 'storybook-root/src/utils';18import { intersection } from 'storybook-root/src/utils';19import { intersection } from 'storybook-root/src/utils';20import { intersection } from 'storybook-root/src/utils';

Full Screen

Using AI Code Generation

copy

Full Screen

1import { intersection } from 'storybook-root';2console.log(intersection([1, 2], [2, 3]));3export { intersection } from './utils';4export const intersection = (arr1, arr2) => {5 return arr1.filter((item) => arr2.includes(item));6};7export const intersection = (arr1, arr2) => {8 return arr1.filter((item) => arr2.includes(item));9};10export const intersection = (arr1, arr2) => {11 return arr1.filter((item) => arr2.includes(item));12};13export const intersection = (arr1, arr2) => {14 return arr1.filter((item) => arr2.includes(item));15};16export const intersection = (arr1, arr2) => {17 return arr1.filter((item) => arr2.includes(item));18};19export const intersection = (arr1, arr2) => {20 return arr1.filter((item) => arr2.includes(item));21};22export const intersection = (arr1, arr2) => {23 return arr1.filter((item) => arr2.includes(item));24};25export const intersection = (arr1, arr2) => {26 return arr1.filter((item) => arr2.includes(item));27};28export const intersection = (arr1, arr2) => {29 return arr1.filter((item) => arr2.includes(item));30};31export const intersection = (arr1, arr2) => {32 return arr1.filter((item) => arr2.includes(item));33};34export const intersection = (arr1, arr2) => {

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