@genome-spy/core 0.64.0 → 0.66.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle/{index-CCJIjehY.js → AbortablePromiseCache-CcuMrnn7.js} +22 -91
- package/dist/bundle/browser-BRemItdO.js +138 -0
- package/dist/bundle/index-BatuyGAI.js +271 -0
- package/dist/bundle/index-ByuE8dvu.js +332 -0
- package/dist/bundle/index-Cq3QFUxX.js +1781 -0
- package/dist/bundle/{index-C08YCM2T.js → index-D-w7Mmt9.js} +246 -126
- package/dist/bundle/index-D28m8tSW.js +1607 -0
- package/dist/bundle/index-D74H8TTz.js +508 -0
- package/dist/bundle/index-DbJ0oeYM.js +631 -0
- package/dist/bundle/index.es.js +15034 -13842
- package/dist/bundle/index.js +223 -237
- package/dist/bundle/inflate-GtwLkvSP.js +1048 -0
- package/dist/bundle/unzip-NywezaRR.js +1492 -0
- package/dist/schema.json +22 -4
- package/dist/src/config/scaleDefaults.d.ts +8 -0
- package/dist/src/config/scaleDefaults.d.ts.map +1 -0
- package/dist/src/config/scaleDefaults.js +45 -0
- package/dist/src/data/collector.d.ts +7 -2
- package/dist/src/data/collector.d.ts.map +1 -1
- package/dist/src/data/collector.js +13 -2
- package/dist/src/data/dataFlow.d.ts +20 -42
- package/dist/src/data/dataFlow.d.ts.map +1 -1
- package/dist/src/data/dataFlow.js +57 -80
- package/dist/src/data/flowHandle.d.ts +15 -0
- package/dist/src/data/flowHandle.d.ts.map +1 -0
- package/dist/src/data/flowHandle.js +13 -0
- package/dist/src/data/flowInit.d.ts +85 -0
- package/dist/src/data/flowInit.d.ts.map +1 -0
- package/dist/src/data/flowInit.js +238 -0
- package/dist/src/data/flowInit.test.d.ts +2 -0
- package/dist/src/data/flowInit.test.d.ts.map +1 -0
- package/dist/src/data/flowOptimizer.d.ts +6 -4
- package/dist/src/data/flowOptimizer.d.ts.map +1 -1
- package/dist/src/data/flowOptimizer.js +29 -14
- package/dist/src/data/sources/lazy/axisTickSource.js +1 -1
- package/dist/src/data/sources/lazy/bamSource.js +1 -1
- package/dist/src/data/sources/lazy/bigBedSource.js +1 -1
- package/dist/src/data/sources/lazy/bigWigSource.js +1 -1
- package/dist/src/data/sources/lazy/gff3Source.d.ts +2 -6
- package/dist/src/data/sources/lazy/gff3Source.d.ts.map +1 -1
- package/dist/src/data/sources/lazy/gff3Source.js +4 -8
- package/dist/src/data/sources/lazy/indexedFastaSource.d.ts.map +1 -1
- package/dist/src/data/sources/lazy/indexedFastaSource.js +17 -17
- package/dist/src/data/sources/lazy/singleAxisLazySource.d.ts +1 -1
- package/dist/src/data/sources/lazy/singleAxisLazySource.d.ts.map +1 -1
- package/dist/src/data/sources/lazy/singleAxisLazySource.js +10 -3
- package/dist/src/data/sources/lazy/singleAxisWindowedSource.d.ts.map +1 -1
- package/dist/src/data/sources/lazy/singleAxisWindowedSource.js +5 -1
- package/dist/src/data/sources/lazy/tabixSource.js +1 -1
- package/dist/src/data/transforms/filterScoredLabels.d.ts +1 -1
- package/dist/src/data/transforms/filterScoredLabels.d.ts.map +1 -1
- package/dist/src/data/transforms/filterScoredLabels.js +1 -1
- package/dist/src/data/transforms/linearizeGenomicCoordinate.d.ts.map +1 -1
- package/dist/src/data/transforms/linearizeGenomicCoordinate.js +2 -1
- package/dist/src/encoder/encoder.d.ts +1 -1
- package/dist/src/encoder/encoder.d.ts.map +1 -1
- package/dist/src/encoder/encoder.js +1 -1
- package/dist/src/genome/scaleLocus.d.ts +39 -0
- package/dist/src/genome/scaleLocus.d.ts.map +1 -1
- package/dist/src/genome/scaleLocus.js +76 -0
- package/dist/src/genomeSpy/canvasExport.d.ts +19 -0
- package/dist/src/genomeSpy/canvasExport.d.ts.map +1 -0
- package/dist/src/genomeSpy/canvasExport.js +66 -0
- package/dist/src/genomeSpy/containerUi.d.ts +17 -0
- package/dist/src/genomeSpy/containerUi.d.ts.map +1 -0
- package/dist/src/genomeSpy/containerUi.js +78 -0
- package/dist/src/genomeSpy/eventListenerRegistry.d.ts +19 -0
- package/dist/src/genomeSpy/eventListenerRegistry.d.ts.map +1 -0
- package/dist/src/genomeSpy/eventListenerRegistry.js +38 -0
- package/dist/src/genomeSpy/inputBindingManager.d.ts +14 -0
- package/dist/src/genomeSpy/inputBindingManager.d.ts.map +1 -0
- package/dist/src/genomeSpy/inputBindingManager.js +63 -0
- package/dist/src/genomeSpy/interactionController.d.ts +40 -0
- package/dist/src/genomeSpy/interactionController.d.ts.map +1 -0
- package/dist/src/genomeSpy/interactionController.js +371 -0
- package/dist/src/genomeSpy/keyboardListenerManager.d.ts +10 -0
- package/dist/src/genomeSpy/keyboardListenerManager.d.ts.map +1 -0
- package/dist/src/genomeSpy/keyboardListenerManager.js +31 -0
- package/dist/src/genomeSpy/loadingIndicatorManager.d.ts +15 -0
- package/dist/src/genomeSpy/loadingIndicatorManager.d.ts.map +1 -0
- package/dist/src/genomeSpy/loadingIndicatorManager.js +92 -0
- package/dist/src/genomeSpy/renderCoordinator.d.ts +22 -0
- package/dist/src/genomeSpy/renderCoordinator.d.ts.map +1 -0
- package/dist/src/genomeSpy/renderCoordinator.js +118 -0
- package/dist/src/genomeSpy/viewContextFactory.d.ts +18 -0
- package/dist/src/genomeSpy/viewContextFactory.d.ts.map +1 -0
- package/dist/src/genomeSpy/viewContextFactory.js +79 -0
- package/dist/src/genomeSpy/viewDataInit.d.ts +12 -0
- package/dist/src/genomeSpy/viewDataInit.d.ts.map +1 -0
- package/dist/src/genomeSpy/viewDataInit.js +41 -0
- package/dist/src/genomeSpy/viewHierarchyConfig.d.ts +14 -0
- package/dist/src/genomeSpy/viewHierarchyConfig.d.ts.map +1 -0
- package/dist/src/genomeSpy/viewHierarchyConfig.js +24 -0
- package/dist/src/genomeSpy/viewHighlight.d.ts +5 -0
- package/dist/src/genomeSpy/viewHighlight.d.ts.map +1 -0
- package/dist/src/genomeSpy/viewHighlight.js +30 -0
- package/dist/src/genomeSpy.d.ts +17 -72
- package/dist/src/genomeSpy.d.ts.map +1 -1
- package/dist/src/genomeSpy.js +180 -789
- package/dist/src/gl/glslScaleGenerator.d.ts +1 -1
- package/dist/src/gl/webGLHelper.d.ts +2 -2
- package/dist/src/gl/webGLHelper.d.ts.map +1 -1
- package/dist/src/gl/webGLHelper.js +4 -4
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +2 -12
- package/dist/src/marks/mark.d.ts +1 -0
- package/dist/src/marks/mark.d.ts.map +1 -1
- package/dist/src/marks/mark.js +26 -3
- package/dist/src/{view → scales}/axisResolution.d.ts +12 -14
- package/dist/src/scales/axisResolution.d.ts.map +1 -0
- package/dist/src/{view → scales}/axisResolution.js +38 -12
- package/dist/src/scales/axisResolution.test.d.ts.map +1 -0
- package/dist/src/scales/scaleDomainAggregator.d.ts +57 -0
- package/dist/src/scales/scaleDomainAggregator.d.ts.map +1 -0
- package/dist/src/scales/scaleDomainAggregator.js +162 -0
- package/dist/src/scales/scaleDomainAggregator.test.d.ts +2 -0
- package/dist/src/scales/scaleDomainAggregator.test.d.ts.map +1 -0
- package/dist/src/scales/scaleInstanceManager.d.ts +40 -0
- package/dist/src/scales/scaleInstanceManager.d.ts.map +1 -0
- package/dist/src/scales/scaleInstanceManager.js +313 -0
- package/dist/src/scales/scaleInstanceManager.test.d.ts +2 -0
- package/dist/src/scales/scaleInstanceManager.test.d.ts.map +1 -0
- package/dist/src/scales/scaleInteractionController.d.ts +73 -0
- package/dist/src/scales/scaleInteractionController.d.ts.map +1 -0
- package/dist/src/scales/scaleInteractionController.js +336 -0
- package/dist/src/scales/scaleInteractionController.test.d.ts +2 -0
- package/dist/src/scales/scaleInteractionController.test.d.ts.map +1 -0
- package/dist/src/scales/scalePropsResolver.d.ts +23 -0
- package/dist/src/scales/scalePropsResolver.d.ts.map +1 -0
- package/dist/src/scales/scalePropsResolver.js +74 -0
- package/dist/src/{view → scales}/scaleResolution.d.ts +53 -31
- package/dist/src/scales/scaleResolution.d.ts.map +1 -0
- package/dist/src/scales/scaleResolution.js +658 -0
- package/dist/src/scales/scaleResolution.test.d.ts.map +1 -0
- package/dist/src/scales/scaleResolutionConstants.d.ts +6 -0
- package/dist/src/scales/scaleResolutionConstants.d.ts.map +1 -0
- package/dist/src/scales/scaleResolutionConstants.js +5 -0
- package/dist/src/scales/scaleRules.d.ts +16 -0
- package/dist/src/scales/scaleRules.d.ts.map +1 -0
- package/dist/src/scales/scaleRules.js +103 -0
- package/dist/src/scales/scaleRules.test.d.ts +2 -0
- package/dist/src/scales/scaleRules.test.d.ts.map +1 -0
- package/dist/src/spec/channel.d.ts +13 -18
- package/dist/src/spec/sampleView.d.ts +3 -2
- package/dist/src/spec/scale.d.ts +6 -0
- package/dist/src/types/embedApi.d.ts +5 -0
- package/dist/src/types/scaleResolutionApi.d.ts +1 -1
- package/dist/src/types/viewContext.d.ts +1 -1
- package/dist/src/view/concatView.d.ts +18 -0
- package/dist/src/view/concatView.d.ts.map +1 -1
- package/dist/src/view/concatView.js +73 -0
- package/dist/src/view/concatView.test.d.ts +2 -0
- package/dist/src/view/concatView.test.d.ts.map +1 -0
- package/dist/src/view/containerMutationHelper.d.ts +74 -0
- package/dist/src/view/containerMutationHelper.d.ts.map +1 -0
- package/dist/src/view/containerMutationHelper.js +114 -0
- package/dist/src/view/containerView.d.ts +0 -7
- package/dist/src/view/containerView.d.ts.map +1 -1
- package/dist/src/view/containerView.js +0 -10
- package/dist/src/view/facetView.d.ts.map +1 -1
- package/dist/src/view/facetView.js +0 -14
- package/dist/src/view/flowBuilder.d.ts +2 -2
- package/dist/src/view/flowBuilder.d.ts.map +1 -1
- package/dist/src/view/flowBuilder.js +21 -4
- package/dist/src/view/gridView/gridChild.d.ts +11 -0
- package/dist/src/view/gridView/gridChild.d.ts.map +1 -1
- package/dist/src/view/gridView/gridChild.js +32 -6
- package/dist/src/view/gridView/gridView.d.ts +39 -1
- package/dist/src/view/gridView/gridView.d.ts.map +1 -1
- package/dist/src/view/gridView/gridView.js +113 -42
- package/dist/src/view/gridView/gridView.test.d.ts +2 -0
- package/dist/src/view/gridView/gridView.test.d.ts.map +1 -0
- package/dist/src/view/gridView/scrollbar.d.ts +39 -8
- package/dist/src/view/gridView/scrollbar.d.ts.map +1 -1
- package/dist/src/view/gridView/scrollbar.js +184 -69
- package/dist/src/view/gridView/selectionRect.d.ts +8 -4
- package/dist/src/view/gridView/selectionRect.d.ts.map +1 -1
- package/dist/src/view/gridView/selectionRect.js +28 -3
- package/dist/src/view/gridView/selectionRect.test.d.ts +2 -0
- package/dist/src/view/gridView/selectionRect.test.d.ts.map +1 -0
- package/dist/src/view/layerView.d.ts +14 -0
- package/dist/src/view/layerView.d.ts.map +1 -1
- package/dist/src/view/layerView.js +66 -0
- package/dist/src/view/layerView.test.d.ts +2 -0
- package/dist/src/view/layerView.test.d.ts.map +1 -0
- package/dist/src/view/paramMediator.d.ts +2 -1
- package/dist/src/view/paramMediator.d.ts.map +1 -1
- package/dist/src/view/paramMediator.js +13 -1
- package/dist/src/view/testUtils.d.ts.map +1 -1
- package/dist/src/view/testUtils.js +18 -5
- package/dist/src/view/unitView.d.ts.map +1 -1
- package/dist/src/view/unitView.js +52 -12
- package/dist/src/view/view.d.ts +23 -7
- package/dist/src/view/view.d.ts.map +1 -1
- package/dist/src/view/view.js +61 -5
- package/dist/src/view/viewDispose.test.d.ts +2 -0
- package/dist/src/view/viewDispose.test.d.ts.map +1 -0
- package/dist/src/view/viewUtils.d.ts +4 -4
- package/dist/src/view/viewUtils.d.ts.map +1 -1
- package/dist/src/view/viewUtils.js +19 -15
- package/dist/src/view/viewUtils.test.d.ts +2 -0
- package/dist/src/view/viewUtils.test.d.ts.map +1 -0
- package/package.json +10 -10
- package/dist/bundle/__vite-browser-external-C--ziKoh.js +0 -8
- package/dist/bundle/_commonjsHelpers-DjF3Plf2.js +0 -26
- package/dist/bundle/index-5ajWdKly.js +0 -1319
- package/dist/bundle/index-B03-Om4z.js +0 -274
- package/dist/bundle/index-BftNdA0O.js +0 -27
- package/dist/bundle/index-Bg7C4Xat.js +0 -2750
- package/dist/bundle/index-C3QR8Lv6.js +0 -2131
- package/dist/bundle/index-DTcHjAHp.js +0 -505
- package/dist/bundle/index-DnIkxb0L.js +0 -1025
- package/dist/bundle/index-Ww3TAo6_.js +0 -71
- package/dist/bundle/index-g8iXgW0W.js +0 -651
- package/dist/bundle/long-B-FASCSo.js +0 -2387
- package/dist/bundle/remoteFile-BuaqFGWk.js +0 -94
- package/dist/src/data/collector.test.js +0 -138
- package/dist/src/data/dataFlow.test.js +0 -5
- package/dist/src/data/flow.test.js +0 -81
- package/dist/src/data/flowNode.test.js +0 -50
- package/dist/src/data/flowOptimizer.test.js +0 -204
- package/dist/src/data/formats/fasta.test.js +0 -27
- package/dist/src/data/sources/inlineSource.test.js +0 -63
- package/dist/src/data/sources/sequenceSource.test.js +0 -81
- package/dist/src/data/transforms/aggregate.test.js +0 -134
- package/dist/src/data/transforms/clone.test.js +0 -11
- package/dist/src/data/transforms/coverage.test.js +0 -238
- package/dist/src/data/transforms/filter.test.js +0 -20
- package/dist/src/data/transforms/flatten.test.js +0 -96
- package/dist/src/data/transforms/flattenDelimited.test.js +0 -90
- package/dist/src/data/transforms/flattenSequence.test.js +0 -34
- package/dist/src/data/transforms/formula.test.js +0 -25
- package/dist/src/data/transforms/identifier.test.js +0 -92
- package/dist/src/data/transforms/pileup.test.js +0 -70
- package/dist/src/data/transforms/project.test.js +0 -32
- package/dist/src/data/transforms/regexExtract.test.js +0 -70
- package/dist/src/data/transforms/regexFold.test.js +0 -201
- package/dist/src/data/transforms/sample.test.js +0 -38
- package/dist/src/data/transforms/stack.test.js +0 -91
- package/dist/src/encoder/accessor.test.js +0 -162
- package/dist/src/encoder/encoder.test.js +0 -105
- package/dist/src/genome/genome.test.js +0 -268
- package/dist/src/genome/genomes.test.js +0 -8
- package/dist/src/genome/scaleIndex.test.js +0 -78
- package/dist/src/genome/scaleLocus.test.js +0 -4
- package/dist/src/scale/scale.test.js +0 -326
- package/dist/src/scale/ticks.test.js +0 -46
- package/dist/src/selection/selection.test.js +0 -14
- package/dist/src/utils/addBaseUrl.test.js +0 -30
- package/dist/src/utils/binnedIndex.test.js +0 -201
- package/dist/src/utils/cloner.test.js +0 -35
- package/dist/src/utils/coalesce.test.js +0 -16
- package/dist/src/utils/concatIterables.test.js +0 -8
- package/dist/src/utils/domainArray.test.js +0 -130
- package/dist/src/utils/indexer.test.js +0 -49
- package/dist/src/utils/interactionEvent.test.js +0 -35
- package/dist/src/utils/iterateNestedMaps.test.js +0 -33
- package/dist/src/utils/kWayMerge.test.js +0 -30
- package/dist/src/utils/mergeObjects.test.js +0 -42
- package/dist/src/utils/numberExtractor.test.js +0 -6
- package/dist/src/utils/propertyCacher.test.js +0 -89
- package/dist/src/utils/propertyCoalescer.test.js +0 -25
- package/dist/src/utils/radixSort.test.js +0 -51
- package/dist/src/utils/reservationMap.test.js +0 -20
- package/dist/src/utils/ringBuffer.test.js +0 -39
- package/dist/src/utils/topK.test.js +0 -54
- package/dist/src/utils/trees.test.js +0 -135
- package/dist/src/utils/url.test.js +0 -28
- package/dist/src/utils/variableTools.test.js +0 -13
- package/dist/src/view/axisResolution.d.ts.map +0 -1
- package/dist/src/view/axisResolution.test.d.ts.map +0 -1
- package/dist/src/view/axisResolution.test.js +0 -206
- package/dist/src/view/flowBuilder.test.js +0 -125
- package/dist/src/view/layout/flexLayout.test.js +0 -323
- package/dist/src/view/layout/grid.test.js +0 -71
- package/dist/src/view/layout/rectangle.test.js +0 -192
- package/dist/src/view/paramMediator.test.js +0 -260
- package/dist/src/view/scaleResolution.d.ts.map +0 -1
- package/dist/src/view/scaleResolution.js +0 -1049
- package/dist/src/view/scaleResolution.test.d.ts.map +0 -1
- package/dist/src/view/scaleResolution.test.js +0 -645
- package/dist/src/view/view.test.js +0 -245
- package/dist/src/view/viewFactory.test.js +0 -25
- /package/dist/src/{view → scales}/axisResolution.test.d.ts +0 -0
- /package/dist/src/{view → scales}/scaleResolution.test.d.ts +0 -0
|
@@ -1,323 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from "vitest";
|
|
2
|
-
import {
|
|
3
|
-
mapToPixelCoords,
|
|
4
|
-
getMinimumSize,
|
|
5
|
-
getLargestSize,
|
|
6
|
-
isStretching,
|
|
7
|
-
parseSizeDef,
|
|
8
|
-
sumSizeDefs,
|
|
9
|
-
} from "./flexLayout.js";
|
|
10
|
-
|
|
11
|
-
test("parseSize", () => {
|
|
12
|
-
expect(parseSizeDef(10)).toEqual({ px: 10, grow: 0 });
|
|
13
|
-
expect(parseSizeDef({ px: 20, grow: 2 })).toEqual({ px: 20, grow: 2 });
|
|
14
|
-
expect(parseSizeDef(undefined)).toEqual({ px: 0, grow: 1 });
|
|
15
|
-
expect(parseSizeDef(null)).toEqual({ px: 0, grow: 1 });
|
|
16
|
-
expect(parseSizeDef("container")).toEqual({ px: 0, grow: 1 });
|
|
17
|
-
expect(() => parseSizeDef({})).toThrow();
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
describe("Basic flex functionality", () => {
|
|
21
|
-
test("Absolute sizes", () => {
|
|
22
|
-
const items = [10, 30, 20].map((x) => ({ px: x }));
|
|
23
|
-
const containerSize = 100;
|
|
24
|
-
|
|
25
|
-
const mapped = mapToPixelCoords(items, containerSize);
|
|
26
|
-
|
|
27
|
-
expect(mapped[0]).toEqual({ location: 0, size: 10 });
|
|
28
|
-
expect(mapped[1]).toEqual({ location: 10, size: 30 });
|
|
29
|
-
expect(mapped[2]).toEqual({ location: 40, size: 20 });
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
test("Absolute sizes with spacing", () => {
|
|
33
|
-
const items = [10, 30, 20].map((x) => ({ px: x }));
|
|
34
|
-
const containerSize = 100;
|
|
35
|
-
|
|
36
|
-
const mapped = mapToPixelCoords(items, containerSize, { spacing: 10 });
|
|
37
|
-
|
|
38
|
-
expect(mapped[0]).toEqual({ location: 0, size: 10 });
|
|
39
|
-
expect(mapped[1]).toEqual({ location: 20, size: 30 });
|
|
40
|
-
expect(mapped[2]).toEqual({ location: 60, size: 20 });
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
test("Absolute sizes with spacing, reversed", () => {
|
|
44
|
-
const items = [10, 30, 20].map((x) => ({ px: x }));
|
|
45
|
-
const containerSize = 100;
|
|
46
|
-
|
|
47
|
-
const mapped = mapToPixelCoords(items, containerSize, {
|
|
48
|
-
spacing: 10,
|
|
49
|
-
reverse: true,
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
expect(mapped[0]).toEqual({ location: 90, size: 10 });
|
|
53
|
-
expect(mapped[1]).toEqual({ location: 50, size: 30 });
|
|
54
|
-
expect(mapped[2]).toEqual({ location: 20, size: 20 });
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
test("Absolute sizes with spacing, reversed and insufficient containerSize", () => {
|
|
58
|
-
const items = [10, 30, 20].map((x) => ({ px: x }));
|
|
59
|
-
const containerSize = 0;
|
|
60
|
-
|
|
61
|
-
const mapped = mapToPixelCoords(items, containerSize, {
|
|
62
|
-
spacing: 10,
|
|
63
|
-
reverse: true,
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
expect(mapped[0]).toEqual({ location: 70, size: 10 });
|
|
67
|
-
expect(mapped[1]).toEqual({ location: 30, size: 30 });
|
|
68
|
-
expect(mapped[2]).toEqual({ location: 0, size: 20 });
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
test("Growing sizes", () => {
|
|
72
|
-
const items = [10, 20, 70].map((x) => ({ grow: x }));
|
|
73
|
-
const containerSize = 200;
|
|
74
|
-
|
|
75
|
-
const mapped = mapToPixelCoords(items, containerSize);
|
|
76
|
-
|
|
77
|
-
expect(mapped[0]).toEqual({ location: 0, size: 20 });
|
|
78
|
-
expect(mapped[1]).toEqual({ location: 20, size: 40 });
|
|
79
|
-
expect(mapped[2]).toEqual({ location: 60, size: 140 });
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
test("Growing sizes with spacing", () => {
|
|
83
|
-
const items = [10, 20, 70].map((x) => ({ grow: x }));
|
|
84
|
-
const containerSize = 220;
|
|
85
|
-
const mapped = mapToPixelCoords(items, containerSize, { spacing: 10 });
|
|
86
|
-
|
|
87
|
-
expect(mapped[0]).toEqual({ location: 0, size: 20 });
|
|
88
|
-
expect(mapped[1]).toEqual({ location: 30, size: 40 });
|
|
89
|
-
expect(mapped[2]).toEqual({ location: 80, size: 140 });
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
test("Mixed absolute and relative sizes", () => {
|
|
93
|
-
const items = [{ px: 100 }, { grow: 1 }, { grow: 9 }, { px: 200 }];
|
|
94
|
-
const containerSize = 1100;
|
|
95
|
-
const mapped = mapToPixelCoords(items, containerSize);
|
|
96
|
-
|
|
97
|
-
expect(mapped[0]).toEqual({ location: 0, size: 100 });
|
|
98
|
-
expect(mapped[1]).toEqual({ location: 100, size: 80 });
|
|
99
|
-
expect(mapped[2]).toEqual({ location: 180, size: 720 });
|
|
100
|
-
expect(mapped[3]).toEqual({ location: 900, size: 200 });
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
test("Sizes having both absolute and growing components", () => {
|
|
104
|
-
const items = [
|
|
105
|
-
{ px: 1 },
|
|
106
|
-
{ px: 2 },
|
|
107
|
-
{ px: 3, grow: 2 },
|
|
108
|
-
{ px: 4, grow: 1 },
|
|
109
|
-
];
|
|
110
|
-
const containerSize = 16;
|
|
111
|
-
const mapped = mapToPixelCoords(items, containerSize);
|
|
112
|
-
|
|
113
|
-
expect(mapped[0]).toEqual({ location: 0, size: 1 });
|
|
114
|
-
expect(mapped[1]).toEqual({ location: 1, size: 2 });
|
|
115
|
-
expect(mapped[2]).toEqual({ location: 3, size: 7 });
|
|
116
|
-
expect(mapped[3]).toEqual({ location: 10, size: 6 });
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
test("Zero sizes return zero coords", () => {
|
|
120
|
-
const items = [{ grow: 0 }, { grow: 0 }];
|
|
121
|
-
|
|
122
|
-
const mapped = mapToPixelCoords(items, 0);
|
|
123
|
-
expect(mapped[0]).toEqual({ location: 0, size: 0 });
|
|
124
|
-
expect(mapped[1]).toEqual({ location: 0, size: 0 });
|
|
125
|
-
|
|
126
|
-
const mapped2 = mapToPixelCoords(items, 1);
|
|
127
|
-
expect(mapped2[0]).toEqual({ location: 0, size: 0 });
|
|
128
|
-
expect(mapped2[1]).toEqual({ location: 0, size: 0 });
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
test("Offset is added", () => {
|
|
132
|
-
const items = [10, 30, 20].map((x) => ({ px: x }));
|
|
133
|
-
const containerSize = 100;
|
|
134
|
-
|
|
135
|
-
const mapped = mapToPixelCoords(items, containerSize, { offset: 5 });
|
|
136
|
-
|
|
137
|
-
expect(mapped[0]).toEqual({ location: 5, size: 10 });
|
|
138
|
-
expect(mapped[1]).toEqual({ location: 15, size: 30 });
|
|
139
|
-
expect(mapped[2]).toEqual({ location: 45, size: 20 });
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
describe("Collapse gaps when items have zero px and grow", () => {
|
|
144
|
-
test("Zero as first", () => {
|
|
145
|
-
const items = [0, 30, 20].map((x) => ({ px: x }));
|
|
146
|
-
const containerSize = 100;
|
|
147
|
-
|
|
148
|
-
const mapped = mapToPixelCoords(items, containerSize, { spacing: 10 });
|
|
149
|
-
|
|
150
|
-
expect(mapped[0]).toEqual({ location: 0, size: 0 });
|
|
151
|
-
expect(mapped[1]).toEqual({ location: 0, size: 30 });
|
|
152
|
-
expect(mapped[2]).toEqual({ location: 40, size: 20 });
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
test("Zero in the middle", () => {
|
|
156
|
-
const items = [10, 0, 20].map((x) => ({ px: x }));
|
|
157
|
-
const containerSize = 100;
|
|
158
|
-
|
|
159
|
-
const mapped = mapToPixelCoords(items, containerSize, { spacing: 10 });
|
|
160
|
-
|
|
161
|
-
expect(mapped[0]).toEqual({ location: 0, size: 10 });
|
|
162
|
-
expect(mapped[1]).toEqual({ location: 15, size: 0 });
|
|
163
|
-
expect(mapped[2]).toEqual({ location: 20, size: 20 });
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
test("Multiple zeroes in the middle", () => {
|
|
167
|
-
const items = [10, 0, 0, 0, 20].map((x) => ({ px: x }));
|
|
168
|
-
const containerSize = 100;
|
|
169
|
-
|
|
170
|
-
const mapped = mapToPixelCoords(items, containerSize, { spacing: 10 });
|
|
171
|
-
|
|
172
|
-
expect(mapped[0]).toEqual({ location: 0, size: 10 });
|
|
173
|
-
expect(mapped[1]).toEqual({ location: 12.5, size: 0 });
|
|
174
|
-
expect(mapped[2]).toEqual({ location: 15, size: 0 });
|
|
175
|
-
expect(mapped[3]).toEqual({ location: 17.5, size: 0 });
|
|
176
|
-
expect(mapped[4]).toEqual({ location: 20, size: 20 });
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
test("Zero as last", () => {
|
|
180
|
-
const items = [10, 30, 0].map((x) => ({ px: x }));
|
|
181
|
-
const containerSize = 100;
|
|
182
|
-
|
|
183
|
-
const mapped = mapToPixelCoords(items, containerSize, { spacing: 10 });
|
|
184
|
-
|
|
185
|
-
expect(mapped[0]).toEqual({ location: 0, size: 10 });
|
|
186
|
-
expect(mapped[1]).toEqual({ location: 20, size: 30 });
|
|
187
|
-
expect(mapped[2]).toEqual({ location: 50, size: 0 });
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
test("Only a zero", () => {
|
|
191
|
-
const items = [0].map((x) => ({ px: x }));
|
|
192
|
-
const containerSize = 100;
|
|
193
|
-
|
|
194
|
-
const mapped = mapToPixelCoords(items, containerSize, { spacing: 10 });
|
|
195
|
-
|
|
196
|
-
expect(mapped[0]).toEqual({ location: 0, size: 0 });
|
|
197
|
-
});
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
describe("Collapse gaps when items have zero px and grow, reversed", () => {
|
|
201
|
-
test("Zero as first", () => {
|
|
202
|
-
const items = [0, 30, 20].map((x) => ({ px: x }));
|
|
203
|
-
const containerSize = 100;
|
|
204
|
-
|
|
205
|
-
const mapped = mapToPixelCoords(items, containerSize, {
|
|
206
|
-
spacing: 10,
|
|
207
|
-
reverse: true,
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
expect(mapped[0]).toEqual({ location: 100, size: 0 });
|
|
211
|
-
expect(mapped[1]).toEqual({ location: 70, size: 30 });
|
|
212
|
-
expect(mapped[2]).toEqual({ location: 40, size: 20 });
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
test("Zero in the middle", () => {
|
|
216
|
-
const items = [10, 0, 20].map((x) => ({ px: x }));
|
|
217
|
-
const containerSize = 100;
|
|
218
|
-
|
|
219
|
-
const mapped = mapToPixelCoords(items, containerSize, {
|
|
220
|
-
spacing: 10,
|
|
221
|
-
reverse: true,
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
expect(mapped[0]).toEqual({ location: 90, size: 10 });
|
|
225
|
-
expect(mapped[1]).toEqual({ location: 85, size: 0 });
|
|
226
|
-
expect(mapped[2]).toEqual({ location: 60, size: 20 });
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
test("Multiple zeroes in the middle", () => {
|
|
230
|
-
const items = [10, 0, 0, 0, 20].map((x) => ({ px: x }));
|
|
231
|
-
const containerSize = 100;
|
|
232
|
-
|
|
233
|
-
const mapped = mapToPixelCoords(items, containerSize, {
|
|
234
|
-
spacing: 10,
|
|
235
|
-
reverse: true,
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
expect(mapped[0]).toEqual({ location: 90, size: 10 });
|
|
239
|
-
expect(mapped[1]).toEqual({ location: 87.5, size: 0 });
|
|
240
|
-
expect(mapped[2]).toEqual({ location: 85, size: 0 });
|
|
241
|
-
expect(mapped[3]).toEqual({ location: 82.5, size: 0 });
|
|
242
|
-
expect(mapped[4]).toEqual({ location: 60, size: 20 });
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
test("Zero as last", () => {
|
|
246
|
-
const items = [10, 30, 0].map((x) => ({ px: x }));
|
|
247
|
-
const containerSize = 100;
|
|
248
|
-
|
|
249
|
-
const mapped = mapToPixelCoords(items, containerSize, {
|
|
250
|
-
spacing: 10,
|
|
251
|
-
reverse: true,
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
expect(mapped[0]).toEqual({ location: 90, size: 10 });
|
|
255
|
-
expect(mapped[1]).toEqual({ location: 50, size: 30 });
|
|
256
|
-
expect(mapped[2]).toEqual({ location: 50, size: 0 });
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
test("Only a zero", () => {
|
|
260
|
-
const items = [0].map((x) => ({ px: x }));
|
|
261
|
-
const containerSize = 100;
|
|
262
|
-
|
|
263
|
-
const mapped = mapToPixelCoords(items, containerSize, {
|
|
264
|
-
spacing: 10,
|
|
265
|
-
reverse: true,
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
expect(mapped[0]).toEqual({ location: 100, size: 0 });
|
|
269
|
-
});
|
|
270
|
-
});
|
|
271
|
-
|
|
272
|
-
describe("Utility fuctions", () => {
|
|
273
|
-
test("sumSizeDefs", () => {
|
|
274
|
-
const items = [
|
|
275
|
-
{ px: 100 },
|
|
276
|
-
{ px: 10, grow: 1 },
|
|
277
|
-
{ grow: 9 },
|
|
278
|
-
{ px: 200 },
|
|
279
|
-
];
|
|
280
|
-
|
|
281
|
-
expect(sumSizeDefs(items)).toEqual({ px: 310, grow: 10 });
|
|
282
|
-
});
|
|
283
|
-
|
|
284
|
-
test("getMinimumSize", () => {
|
|
285
|
-
const items = [{ px: 100 }, { grow: 1 }, { grow: 9 }, { px: 200 }];
|
|
286
|
-
|
|
287
|
-
expect(getMinimumSize(items)).toEqual(300);
|
|
288
|
-
|
|
289
|
-
expect(getMinimumSize(items, { spacing: 10 })).toEqual(330);
|
|
290
|
-
});
|
|
291
|
-
|
|
292
|
-
test("getMinimumSize, items include zeroes", () => {
|
|
293
|
-
const items = [
|
|
294
|
-
{ px: 100 },
|
|
295
|
-
{ px: 0, grow: 0 },
|
|
296
|
-
{ grow: 1 },
|
|
297
|
-
{ grow: 9 },
|
|
298
|
-
{ px: 200 },
|
|
299
|
-
];
|
|
300
|
-
|
|
301
|
-
expect(getMinimumSize(items)).toEqual(300);
|
|
302
|
-
|
|
303
|
-
expect(getMinimumSize(items, { spacing: 10 })).toEqual(330);
|
|
304
|
-
});
|
|
305
|
-
|
|
306
|
-
test("getLargestSize", () => {
|
|
307
|
-
const items = [
|
|
308
|
-
{ px: 100 },
|
|
309
|
-
{ px: 0, grow: 0 },
|
|
310
|
-
{ grow: 1 },
|
|
311
|
-
{ grow: 9 },
|
|
312
|
-
{ px: 200 },
|
|
313
|
-
{ px: 50 },
|
|
314
|
-
];
|
|
315
|
-
|
|
316
|
-
expect(getLargestSize(items)).toEqual({ px: 200, grow: 9 });
|
|
317
|
-
});
|
|
318
|
-
|
|
319
|
-
test("isStretching", () => {
|
|
320
|
-
expect(isStretching([{ grow: 1 }])).toBeTruthy();
|
|
321
|
-
expect(isStretching([{ px: 1 }])).toBeFalsy();
|
|
322
|
-
});
|
|
323
|
-
});
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { expect, test, describe } from "vitest";
|
|
2
|
-
|
|
3
|
-
import Grid from "./grid.js";
|
|
4
|
-
|
|
5
|
-
describe("Grid indexing", () => {
|
|
6
|
-
test("Single row", () => {
|
|
7
|
-
const g = new Grid(3);
|
|
8
|
-
|
|
9
|
-
expect(g.maxCols).toEqual(Infinity);
|
|
10
|
-
expect(g.nCols).toEqual(3);
|
|
11
|
-
expect(g.nRows).toEqual(1);
|
|
12
|
-
expect(g.colIndices).toEqual([[0], [1], [2]]);
|
|
13
|
-
expect(g.rowIndices).toEqual([[0, 1, 2]]);
|
|
14
|
-
expect(g.getCellIndex(1, 0)).toEqual(1);
|
|
15
|
-
expect(g.getCellIndex(1, 1)).toBeUndefined();
|
|
16
|
-
expect(g.getCellCoords(1)).toEqual([1, 0]);
|
|
17
|
-
expect(g.getCellCoords(-1)).toBeUndefined();
|
|
18
|
-
expect(g.getCellCoords(3)).toBeUndefined();
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
test("Single column", () => {
|
|
22
|
-
const g = new Grid(3, 1);
|
|
23
|
-
|
|
24
|
-
expect(g.maxCols).toEqual(1);
|
|
25
|
-
expect(g.nCols).toEqual(1);
|
|
26
|
-
expect(g.nRows).toEqual(3);
|
|
27
|
-
expect(g.colIndices).toEqual([[0, 1, 2]]);
|
|
28
|
-
expect(g.rowIndices).toEqual([[0], [1], [2]]);
|
|
29
|
-
expect(g.getCellIndex(0, 1)).toEqual(1);
|
|
30
|
-
expect(g.getCellIndex(1, 1)).toBeUndefined();
|
|
31
|
-
expect(g.getCellCoords(1)).toEqual([0, 1]);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
test("Two columns", () => {
|
|
35
|
-
const g = new Grid(6, 2);
|
|
36
|
-
|
|
37
|
-
expect(g.maxCols).toEqual(2);
|
|
38
|
-
expect(g.nCols).toEqual(2);
|
|
39
|
-
expect(g.nRows).toEqual(3);
|
|
40
|
-
expect(g.colIndices).toEqual([
|
|
41
|
-
[0, 2, 4],
|
|
42
|
-
[1, 3, 5],
|
|
43
|
-
]);
|
|
44
|
-
expect(g.rowIndices).toEqual([
|
|
45
|
-
[0, 1],
|
|
46
|
-
[2, 3],
|
|
47
|
-
[4, 5],
|
|
48
|
-
]);
|
|
49
|
-
expect(g.getCellIndex(1, 0)).toEqual(1);
|
|
50
|
-
expect(g.getCellIndex(0, 1)).toEqual(2);
|
|
51
|
-
expect(g.getCellIndex(1, 1)).toEqual(3);
|
|
52
|
-
expect(g.getCellCoords(3)).toEqual([1, 1]);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
test("Two columns, second is partial", () => {
|
|
56
|
-
const g = new Grid(5, 2);
|
|
57
|
-
|
|
58
|
-
expect(g.maxCols).toEqual(2);
|
|
59
|
-
expect(g.nCols).toEqual(2);
|
|
60
|
-
expect(g.nRows).toEqual(3);
|
|
61
|
-
expect(g.colIndices).toEqual([
|
|
62
|
-
[0, 2, 4],
|
|
63
|
-
[1, 3],
|
|
64
|
-
]);
|
|
65
|
-
expect(g.rowIndices).toEqual([[0, 1], [2, 3], [4]]);
|
|
66
|
-
expect(g.getCellIndex(1, 0)).toEqual(1);
|
|
67
|
-
expect(g.getCellIndex(0, 1)).toEqual(2);
|
|
68
|
-
expect(g.getCellIndex(1, 2)).toBeUndefined();
|
|
69
|
-
expect(g.getCellCoords(3)).toEqual([1, 1]);
|
|
70
|
-
});
|
|
71
|
-
});
|
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
import { expect, test } from "vitest";
|
|
2
|
-
import Rectangle from "./rectangle.js";
|
|
3
|
-
import Padding from "./padding.js";
|
|
4
|
-
|
|
5
|
-
test("Rectangle creation", () => {
|
|
6
|
-
const r = Rectangle.create(1, 2, 3, 4);
|
|
7
|
-
expect(r.x).toEqual(1);
|
|
8
|
-
expect(r.y).toEqual(2);
|
|
9
|
-
expect(r.width).toEqual(3);
|
|
10
|
-
expect(r.height).toEqual(4);
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
test("equals", () => {
|
|
14
|
-
const r = Rectangle.create(1, 2, 3, 4);
|
|
15
|
-
expect(r.equals(r)).toBeTruthy();
|
|
16
|
-
expect(r.equals(Rectangle.create(1, 2, 3, 4))).toBeTruthy();
|
|
17
|
-
expect(r.equals(undefined)).toBeFalsy();
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
test("x2 and y2 calculation", () => {
|
|
21
|
-
const r = Rectangle.create(1, 2, 3, 4);
|
|
22
|
-
expect(r.x2).toEqual(4);
|
|
23
|
-
expect(r.y2).toEqual(6);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
test("translate", () => {
|
|
27
|
-
const r = Rectangle.create(1, 2, 3, 4).translate(2, 3);
|
|
28
|
-
expect(r.x).toEqual(3);
|
|
29
|
-
expect(r.y).toEqual(5);
|
|
30
|
-
expect(r.width).toEqual(3);
|
|
31
|
-
expect(r.height).toEqual(4);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
test("Dynamic translate", () => {
|
|
35
|
-
let tx = 0;
|
|
36
|
-
let ty = 0;
|
|
37
|
-
|
|
38
|
-
const r = Rectangle.create(1, 2, 3, 4)
|
|
39
|
-
.translate(
|
|
40
|
-
() => tx,
|
|
41
|
-
() => ty
|
|
42
|
-
)
|
|
43
|
-
.translate(2, 3);
|
|
44
|
-
|
|
45
|
-
expect(r.x).toEqual(3);
|
|
46
|
-
expect(r.y).toEqual(5);
|
|
47
|
-
expect(r.width).toEqual(3);
|
|
48
|
-
expect(r.height).toEqual(4);
|
|
49
|
-
|
|
50
|
-
tx = 1;
|
|
51
|
-
ty = 2;
|
|
52
|
-
|
|
53
|
-
expect(r.x).toEqual(4);
|
|
54
|
-
expect(r.y).toEqual(7);
|
|
55
|
-
expect(r.width).toEqual(3);
|
|
56
|
-
expect(r.height).toEqual(4);
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
test("expand", () => {
|
|
60
|
-
const r = Rectangle.create(1, 2, 3, 4).expand(
|
|
61
|
-
Padding.createFromRecord({ top: 2, right: 3, bottom: 4, left: 5 })
|
|
62
|
-
);
|
|
63
|
-
|
|
64
|
-
expect(r.x).toEqual(-4);
|
|
65
|
-
expect(r.width).toEqual(11);
|
|
66
|
-
expect(r.y).toEqual(0);
|
|
67
|
-
expect(r.height).toEqual(10);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
test("shrink", () => {
|
|
71
|
-
const r = Rectangle.create(1, 2, 3, 4).shrink(
|
|
72
|
-
Padding.createUniformPadding(1)
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
expect(r.x).toEqual(2);
|
|
76
|
-
expect(r.width).toEqual(1);
|
|
77
|
-
expect(r.y).toEqual(3);
|
|
78
|
-
expect(r.height).toEqual(2);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
test("modify", () => {
|
|
82
|
-
const r = Rectangle.create(1, 2, 3, 4);
|
|
83
|
-
const m = r.modify({ x: 5 });
|
|
84
|
-
|
|
85
|
-
expect(m.equals(r)).toBeFalsy();
|
|
86
|
-
expect(m.equals(Rectangle.create(5, 2, 3, 4))).toBeTruthy();
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
test("Dynamic modify", () => {
|
|
90
|
-
let x = 1;
|
|
91
|
-
const r = Rectangle.create(1, 2, 3, 4);
|
|
92
|
-
const m = r.modify({ x: () => x });
|
|
93
|
-
|
|
94
|
-
expect(m.equals(r)).toBeTruthy();
|
|
95
|
-
expect(m.equals(Rectangle.create(1, 2, 3, 4))).toBeTruthy();
|
|
96
|
-
|
|
97
|
-
x = 5;
|
|
98
|
-
|
|
99
|
-
expect(m.equals(r)).toBeFalsy();
|
|
100
|
-
expect(m.equals(Rectangle.create(5, 2, 3, 4))).toBeTruthy();
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
test("intersect", () => {
|
|
104
|
-
const a = Rectangle.create(1, 1, 6, 3);
|
|
105
|
-
const b = Rectangle.create(5, 2, 3, 4);
|
|
106
|
-
const c = Rectangle.create(5, 2, 2, 2);
|
|
107
|
-
|
|
108
|
-
expect(a.intersect(b).equals(c)).toBeTruthy();
|
|
109
|
-
expect(a.intersect(b).isDefined()).toBeTruthy();
|
|
110
|
-
|
|
111
|
-
const x = Rectangle.create(1, 1, 1, 1);
|
|
112
|
-
const y = Rectangle.create(3, 3, 1, 1);
|
|
113
|
-
|
|
114
|
-
expect(x.intersect(y).isDefined()).toBeFalsy();
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
test("union", () => {
|
|
118
|
-
const a = Rectangle.create(1, 1, 6, 3);
|
|
119
|
-
const b = Rectangle.create(5, 2, 3, 4);
|
|
120
|
-
const c = Rectangle.create(1, 1, 7, 5);
|
|
121
|
-
|
|
122
|
-
expect(a.union(b).equals(c)).toBeTruthy();
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
test("isDefined", () => {
|
|
126
|
-
expect(Rectangle.create(0, 0, 1, 1).isDefined()).toBeTruthy();
|
|
127
|
-
expect(Rectangle.create(0, 0, 0, 0).isDefined()).toBeTruthy();
|
|
128
|
-
|
|
129
|
-
expect(Rectangle.create(0, 0, -1, 0).isDefined()).toBeFalsy();
|
|
130
|
-
expect(Rectangle.create(0, 0, 0, -1).isDefined()).toBeFalsy();
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
test("flatten", () => {
|
|
134
|
-
let tx = 0;
|
|
135
|
-
let ty = 0;
|
|
136
|
-
|
|
137
|
-
const r = Rectangle.create(1, 2, 3, 4).translate(
|
|
138
|
-
() => tx,
|
|
139
|
-
() => ty
|
|
140
|
-
);
|
|
141
|
-
|
|
142
|
-
const flattened = r.flatten();
|
|
143
|
-
|
|
144
|
-
tx = -1;
|
|
145
|
-
ty = -2;
|
|
146
|
-
|
|
147
|
-
expect(r.equals(Rectangle.create(0, 0, 3, 4)));
|
|
148
|
-
expect(flattened.equals(Rectangle.create(1, 2, 3, 4)));
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
test("containsPoint", () => {
|
|
152
|
-
const r = Rectangle.create(1, 2, 3, 4);
|
|
153
|
-
|
|
154
|
-
expect(r.containsPoint(0, 0)).toBeFalsy();
|
|
155
|
-
expect(r.containsPoint(0, 10)).toBeFalsy();
|
|
156
|
-
expect(r.containsPoint(10, 0)).toBeFalsy();
|
|
157
|
-
expect(r.containsPoint(10, 10)).toBeFalsy();
|
|
158
|
-
|
|
159
|
-
expect(r.containsPoint(2, 0)).toBeFalsy();
|
|
160
|
-
expect(r.containsPoint(2, 10)).toBeFalsy();
|
|
161
|
-
expect(r.containsPoint(0, 3)).toBeFalsy();
|
|
162
|
-
expect(r.containsPoint(10, 3)).toBeFalsy();
|
|
163
|
-
|
|
164
|
-
// Inclusive corner
|
|
165
|
-
expect(r.containsPoint(1, 2)).toBeTruthy();
|
|
166
|
-
|
|
167
|
-
// Inside
|
|
168
|
-
expect(r.containsPoint(2, 3)).toBeTruthy();
|
|
169
|
-
|
|
170
|
-
// Exclusive corner
|
|
171
|
-
expect(r.containsPoint(4, 6)).toBeFalsy();
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
test("normalizePoint", () => {
|
|
175
|
-
const r = Rectangle.create(1, 2, 6, 4);
|
|
176
|
-
|
|
177
|
-
expect(r.normalizePoint(1, 2)).toEqual({ x: 0, y: 0 });
|
|
178
|
-
expect(r.normalizePoint(7, 2)).toEqual({ x: 1, y: 0 });
|
|
179
|
-
expect(r.normalizePoint(4, 4)).toEqual({ x: 0.5, y: 0.5 });
|
|
180
|
-
|
|
181
|
-
expect(r.normalizePoint(1, 6, true)).toEqual({ x: 0, y: 0 });
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
test("denormalizePoint", () => {
|
|
185
|
-
const r = Rectangle.create(1, 2, 6, 4);
|
|
186
|
-
|
|
187
|
-
expect(r.denormalizePoint(0, 0)).toEqual({ x: 1, y: 2 });
|
|
188
|
-
expect(r.denormalizePoint(1, 0)).toEqual({ x: 7, y: 2 });
|
|
189
|
-
expect(r.denormalizePoint(0.5, 0.5)).toEqual({ x: 4, y: 4 });
|
|
190
|
-
|
|
191
|
-
expect(r.denormalizePoint(0, 0, true)).toEqual({ x: 1, y: 6 });
|
|
192
|
-
});
|