Move ui/legacy/geometry into models/geometry Bug: 442509324 Change-Id: Ifa8146e837a7056ddbe124bdfa13fbc83d328d54 Fixed: 442514656 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6903230 Commit-Queue: Jack Franklin <jacktfranklin@chromium.org> Reviewed-by: Alex Rudenko <alexrudenko@chromium.org>
diff --git a/config/gni/devtools_grd_files.gni b/config/gni/devtools_grd_files.gni index 3ebf5dc..21b080d 100644 --- a/config/gni/devtools_grd_files.gni +++ b/config/gni/devtools_grd_files.gni
@@ -397,6 +397,7 @@ "front_end/models/emulation/emulation.js", "front_end/models/extensions/extensions.js", "front_end/models/formatter/formatter.js", + "front_end/models/geometry/geometry.js", "front_end/models/har/har.js", "front_end/models/heap_snapshot_model/heap_snapshot_model.js", "front_end/models/issues_manager/descriptions/CoepCoopSandboxedIframeCannotNavigateToCoopPage.md", @@ -1063,6 +1064,7 @@ "front_end/models/extensions/RecorderPluginManager.js", "front_end/models/formatter/FormatterWorkerPool.js", "front_end/models/formatter/ScriptFormatter.js", + "front_end/models/geometry/GeometryImpl.js", "front_end/models/har/HARFormat.js", "front_end/models/har/Importer.js", "front_end/models/har/Log.js", @@ -2454,7 +2456,6 @@ "front_end/ui/legacy/FilterSuggestionBuilder.js", "front_end/ui/legacy/ForwardedInputEventHandler.js", "front_end/ui/legacy/Fragment.js", - "front_end/ui/legacy/Geometry.js", "front_end/ui/legacy/GlassPane.js", "front_end/ui/legacy/Infobar.js", "front_end/ui/legacy/InplaceEditor.js",
diff --git a/front_end/BUILD.gn b/front_end/BUILD.gn index b43f7f4..13172c2 100644 --- a/front_end/BUILD.gn +++ b/front_end/BUILD.gn
@@ -135,6 +135,7 @@ "models/emulation:unittests", "models/extensions:unittests", "models/formatter:unittests", + "models/geometry:unittests", "models/har:unittests", "models/heap_snapshot_model:unittests", "models/issues_manager:unittests",
diff --git a/front_end/models/emulation/BUILD.gn b/front_end/models/emulation/BUILD.gn index 4b560bb..8a520f2 100644 --- a/front_end/models/emulation/BUILD.gn +++ b/front_end/models/emulation/BUILD.gn
@@ -21,7 +21,7 @@ "../../core/root:bundle", "../../core/sdk:bundle", "../../generated:protocol", - "../../ui/legacy:bundle", + "../geometry:bundle", ] }
diff --git a/front_end/models/emulation/DeviceModeModel.ts b/front_end/models/emulation/DeviceModeModel.ts index 2f50648..633c1a4 100644 --- a/front_end/models/emulation/DeviceModeModel.ts +++ b/front_end/models/emulation/DeviceModeModel.ts
@@ -7,9 +7,7 @@ import * as i18n from '../../core/i18n/i18n.js'; import * as SDK from '../../core/sdk/sdk.js'; import * as Protocol from '../../generated/protocol.js'; -// TODO(crbug.com/442509324): remove UI dependency -// eslint-disable-next-line rulesdir/no-imports-in-directory -import * as UI from '../../ui/legacy/legacy.js'; +import * as Geometry from '../geometry/geometry.js'; import { type EmulatedDevice, @@ -92,10 +90,10 @@ SDK.TargetManager.SDKModelObserver<SDK.EmulationModel.EmulationModel> { #screenRectInternal: Rect; #visiblePageRectInternal: Rect; - #availableSize: UI.Geometry.Size; - #preferredSize: UI.Geometry.Size; + #availableSize: Geometry.Size; + #preferredSize: Geometry.Size; #initialized: boolean; - #appliedDeviceSizeInternal: UI.Geometry.Size; + #appliedDeviceSizeInternal: Geometry.Size; #appliedDeviceScaleFactorInternal: number; #appliedUserAgentTypeInternal: UA; readonly #scaleSettingInternal: Common.Settings.Setting<number>; @@ -120,10 +118,10 @@ super(); this.#screenRectInternal = new Rect(0, 0, 1, 1); this.#visiblePageRectInternal = new Rect(0, 0, 1, 1); - this.#availableSize = new UI.Geometry.Size(1, 1); - this.#preferredSize = new UI.Geometry.Size(1, 1); + this.#availableSize = new Geometry.Size(1, 1); + this.#preferredSize = new Geometry.Size(1, 1); this.#initialized = false; - this.#appliedDeviceSizeInternal = new UI.Geometry.Size(1, 1); + this.#appliedDeviceSizeInternal = new Geometry.Size(1, 1); this.#appliedDeviceScaleFactorInternal = window.devicePixelRatio; this.#appliedUserAgentTypeInternal = UA.DESKTOP; @@ -272,7 +270,7 @@ return this.#scaleSettingInternal; } - setAvailableSize(availableSize: UI.Geometry.Size, preferredSize: UI.Geometry.Size): void { + setAvailableSize(availableSize: Geometry.Size, preferredSize: Geometry.Size): void { this.#availableSize = availableSize; this.#preferredSize = preferredSize; this.#initialized = true; @@ -378,7 +376,7 @@ return this.#fitScaleInternal; } - appliedDeviceSize(): UI.Geometry.Size { + appliedDeviceSize(): Geometry.Size { return this.#appliedDeviceSizeInternal; } @@ -562,9 +560,8 @@ this.#appliedUserAgentTypeInternal = this.#deviceInternal.touch() ? UA.DESKTOP_TOUCH : UA.DESKTOP; } this.applyDeviceMetrics( - new UI.Geometry.Size(orientation.width, orientation.height), insets, outline, - this.#scaleSettingInternal.get(), this.#deviceInternal.deviceScaleFactor, mobile, - this.getScreenOrientationType(), resetPageScaleFactor); + new Geometry.Size(orientation.width, orientation.height), insets, outline, this.#scaleSettingInternal.get(), + this.#deviceInternal.deviceScaleFactor, mobile, this.getScreenOrientationType(), resetPageScaleFactor); this.applyUserAgent(this.#deviceInternal.userAgent, this.#deviceInternal.userAgentMetadata); this.applyTouch(this.#deviceInternal.touch(), mobile); } else if (this.#typeInternal === Type.None) { @@ -588,7 +585,7 @@ this.#fitScaleInternal = this.calculateFitScale(this.#widthSetting.get(), this.#heightSetting.get()); this.#appliedUserAgentTypeInternal = this.#uaSettingInternal.get(); this.applyDeviceMetrics( - new UI.Geometry.Size(screenWidth, screenHeight), new Insets(0, 0, 0, 0), new Insets(0, 0, 0, 0), + new Geometry.Size(screenWidth, screenHeight), new Insets(0, 0, 0, 0), new Insets(0, 0, 0, 0), this.#scaleSettingInternal.get(), this.#deviceScaleFactorSettingInternal.get() || defaultDeviceScaleFactor, mobile, screenHeight >= screenWidth ? Protocol.Emulation.ScreenOrientationType.PortraitPrimary : @@ -644,7 +641,7 @@ } private applyDeviceMetrics( - screenSize: UI.Geometry.Size, insets: Insets, outline: Insets, scale: number, deviceScaleFactor: number, + screenSize: Geometry.Size, insets: Insets, outline: Insets, scale: number, deviceScaleFactor: number, mobile: boolean, screenOrientation: Protocol.Emulation.ScreenOrientationType|null, resetPageScaleFactor: boolean): void { screenSize.width = Math.max(1, Math.floor(screenSize.width));
diff --git a/front_end/models/geometry/BUILD.gn b/front_end/models/geometry/BUILD.gn new file mode 100644 index 0000000..7e25a84 --- /dev/null +++ b/front_end/models/geometry/BUILD.gn
@@ -0,0 +1,37 @@ +# Copyright 2025 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +import("../../../scripts/build/ninja/devtools_entrypoint.gni") +import("../../../scripts/build/ninja/devtools_module.gni") +import("../../../scripts/build/typescript/typescript.gni") +import("../visibility.gni") + +devtools_module("geometry") { + sources = [ "GeometryImpl.ts" ] + + deps = [ "../../core/sdk:bundle" ] +} + +devtools_entrypoint("bundle") { + entrypoint = "geometry.ts" + + deps = [ ":geometry" ] + + visibility = [ + ":*", + "../*", + "../../panels/*", + "../../ui/*", + ] + + visibility += devtools_models_visibility +} + +ts_library("unittests") { + testonly = true + + sources = [ "Geometry.test.ts" ] + + deps = [ ":bundle" ] +}
diff --git a/front_end/ui/legacy/Geometry.test.ts b/front_end/models/geometry/Geometry.test.ts similarity index 72% rename from front_end/ui/legacy/Geometry.test.ts rename to front_end/models/geometry/Geometry.test.ts index 0d95db6..07acad5 100644 --- a/front_end/ui/legacy/Geometry.test.ts +++ b/front_end/models/geometry/Geometry.test.ts
@@ -2,23 +2,23 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import * as UI from './legacy.js'; +import * as Geometry from './geometry.js'; describe('Vector', () => { it('can be instantiated without issues', () => { - const vector = new UI.Geometry.Vector(1, 2, 3); + const vector = new Geometry.Vector(1, 2, 3); assert.strictEqual(vector.x, 1, 'x value was not set correctly'); assert.strictEqual(vector.y, 2, 'y value was not set correctly'); assert.strictEqual(vector.z, 3, 'z value was not set correctly'); }); it('is able to return the length', () => { - const vector = new UI.Geometry.Vector(1, 2, 3); + const vector = new Geometry.Vector(1, 2, 3); assert.strictEqual(vector.length(), 3.7416573867739413, 'length was not returned correctly'); }); it('is able to be normalized if the length was above epsilon', () => { - const vector = new UI.Geometry.Vector(1, 2, 3); + const vector = new Geometry.Vector(1, 2, 3); vector.normalize(); assert.strictEqual(vector.x, 0.2672612419124244, 'x value was not set correctly'); assert.strictEqual(vector.y, 0.5345224838248488, 'y value was not set correctly'); @@ -27,7 +27,7 @@ }); it('does not normalize if the length was below epsilon', () => { - const vector = new UI.Geometry.Vector(0.000001, 0.000002, 0.000003); + const vector = new Geometry.Vector(0.000001, 0.000002, 0.000003); vector.normalize(); assert.strictEqual(vector.x, 0.000001, 'x value was changed'); assert.strictEqual(vector.y, 0.000002, 'y value was changed'); @@ -38,55 +38,55 @@ describe('Point', () => { it('can be instantiated without issues', () => { - const point = new UI.Geometry.Point(1, 2); + const point = new Geometry.Point(1, 2); assert.strictEqual(point.x, 1, 'x value was not set correctly'); assert.strictEqual(point.y, 2, 'y value was not set correctly'); }); it('is able to return distanct to a certain point', () => { - const p1 = new UI.Geometry.Point(0, 0); - const p2 = new UI.Geometry.Point(0, 1); - const p3 = new UI.Geometry.Point(1, 0); - const p4 = new UI.Geometry.Point(3, 4); + const p1 = new Geometry.Point(0, 0); + const p2 = new Geometry.Point(0, 1); + const p3 = new Geometry.Point(1, 0); + const p4 = new Geometry.Point(3, 4); assert.strictEqual(p1.distanceTo(p2), 1, 'distance to the first point was not returned correctly'); assert.strictEqual(p1.distanceTo(p3), 1, 'distance to the second point was not returned correctly'); assert.strictEqual(p1.distanceTo(p4), 5, 'distance to the third point was not returned correctly'); }); it('is able to be scaled to a certain value', () => { - const point = new UI.Geometry.Point(1, 2); + const point = new Geometry.Point(1, 2); const scaledPoint = point.scale(2); assert.strictEqual(scaledPoint.x, 2, 'x was not scaled correctly'); assert.strictEqual(scaledPoint.y, 4, 'y was not scaled correctly'); }); it('is able to be projected on a point that is not the origin', () => { - const p1 = new UI.Geometry.Point(1, 2); - const p2 = new UI.Geometry.Point(3, 4); + const p1 = new Geometry.Point(1, 2); + const p2 = new Geometry.Point(3, 4); const projectedPoint = p1.projectOn(p2); assert.strictEqual(projectedPoint.x, 1.32, 'x was not projected correctly'); assert.strictEqual(projectedPoint.y, 1.76, 'y was not projected correctly'); }); it('is able to be projected on a point that is the origin', () => { - const p1 = new UI.Geometry.Point(1, 2); - const p2 = new UI.Geometry.Point(0, 0); + const p1 = new Geometry.Point(1, 2); + const p2 = new Geometry.Point(0, 0); const projectedPoint = p1.projectOn(p2); assert.strictEqual(projectedPoint.x, 0, 'x was not projected correctly'); assert.strictEqual(projectedPoint.y, 0, 'y was not projected correctly'); }); it('can be represented as a string', () => { - const point = new UI.Geometry.Point(1.23, 4.56); + const point = new Geometry.Point(1.23, 4.56); assert.strictEqual(point.toString(), '1.23, 4.56', 'string representation was not returned correctly'); }); }); describe('CubicBezier', () => { it('can be instantiated without issues', () => { - const p1 = new UI.Geometry.Point(1, 2); - const p2 = new UI.Geometry.Point(3, 4); - const cubicBezier = new UI.Geometry.CubicBezier(p1, p2); + const p1 = new Geometry.Point(1, 2); + const p2 = new Geometry.Point(3, 4); + const cubicBezier = new Geometry.CubicBezier(p1, p2); assert.strictEqual(cubicBezier.controlPoints[0].x, 1, 'x value for the first point was not set correctly'); assert.strictEqual(cubicBezier.controlPoints[0].y, 2, 'y value for the first point was not set correctly'); assert.strictEqual(cubicBezier.controlPoints[1].x, 3, 'x value for the second point was not set correctly'); @@ -95,7 +95,7 @@ it('is able to return a cubic bezier from a valid string', () => { const testText = 'linear'; - const {controlPoints} = UI.Geometry.CubicBezier.parse(testText)!; + const {controlPoints} = Geometry.CubicBezier.parse(testText)!; assert.strictEqual(controlPoints[0].x, 0, 'x value for the first point was not set correctly'); assert.strictEqual(controlPoints[0].y, 0, 'y value for the first point was not set correctly'); assert.strictEqual(controlPoints[1].x, 1, 'x value for the second point was not set correctly'); @@ -104,31 +104,31 @@ it('returns null from an invalid string', () => { const testText = 'invalid text'; - const cubicBezier = UI.Geometry.CubicBezier.parse(testText); + const cubicBezier = Geometry.CubicBezier.parse(testText); assert.isNull(cubicBezier, 'function did not return null'); }); it('is able to evaluate a number to a point', () => { - const p1 = new UI.Geometry.Point(1, 2); - const p2 = new UI.Geometry.Point(3, 4); - const cubicBezier = new UI.Geometry.CubicBezier(p1, p2); + const p1 = new Geometry.Point(1, 2); + const p2 = new Geometry.Point(3, 4); + const cubicBezier = new Geometry.CubicBezier(p1, p2); const resultPoint = cubicBezier.evaluateAt(5); assert.strictEqual(resultPoint.x, -535, 'x value for the resulting point was not set correctly'); assert.strictEqual(resultPoint.y, -595, 'y value for the resulting point was not set correctly'); }); it('is able to be represented as CSS text with raw values', () => { - const p1 = new UI.Geometry.Point(1, 2); - const p2 = new UI.Geometry.Point(3, 4); - const cubicBezier = new UI.Geometry.CubicBezier(p1, p2); + const p1 = new Geometry.Point(1, 2); + const p2 = new Geometry.Point(3, 4); + const cubicBezier = new Geometry.CubicBezier(p1, p2); const cssText = cubicBezier.asCSSText(); assert.strictEqual(cssText, 'cubic-bezier(1, 2, 3, 4)', 'cubic bezier was not represented correctly as CSS text'); }); it('is able to be represented as CSS text with a keyword value', () => { - const p1 = new UI.Geometry.Point(0.25, 0.1); - const p2 = new UI.Geometry.Point(0.25, 1); - const cubicBezier = new UI.Geometry.CubicBezier(p1, p2); + const p1 = new Geometry.Point(0.25, 0.1); + const p2 = new Geometry.Point(0.25, 1); + const cubicBezier = new Geometry.CubicBezier(p1, p2); const cssText = cubicBezier.asCSSText(); assert.strictEqual(cssText, 'ease', 'cubic bezier was not represented correctly as CSS text'); }); @@ -136,7 +136,7 @@ describe('EulerAngles', () => { it('can be instantiated without issues', () => { - const eulerAngles = new UI.Geometry.EulerAngles(1, 2, 3); + const eulerAngles = new Geometry.EulerAngles(1, 2, 3); assert.strictEqual(eulerAngles.alpha, 1, 'alpha value was not set correctly'); assert.strictEqual(eulerAngles.beta, 2, 'beta value was not set correctly'); assert.strictEqual(eulerAngles.gamma, 3, 'gamma value was not set correctly'); @@ -144,7 +144,7 @@ it('is able to return Euler angles from an identity rotation matrix', () => { const matrix = new DOMMatrix(); - const result = UI.Geometry.EulerAngles.fromDeviceOrientationRotationMatrix(matrix); + const result = Geometry.EulerAngles.fromDeviceOrientationRotationMatrix(matrix); assert.strictEqual(result.alpha, 0, 'alpha value was not set correctly'); assert.strictEqual(result.beta, 0, 'beta value was not set correctly'); assert.strictEqual(result.gamma, 0, 'gamma value was not set correctly'); @@ -158,43 +158,43 @@ let matrix, result; matrix = matrixWithZXYRotation(0, 1, 2); - result = UI.Geometry.EulerAngles.fromDeviceOrientationRotationMatrix(matrix); + result = Geometry.EulerAngles.fromDeviceOrientationRotationMatrix(matrix); assert.strictEqual(result.alpha, 0, 'alpha value was not set correctly'); assert.strictEqual(result.beta, 1, 'beta value was not set correctly'); assert.strictEqual(result.gamma, 2, 'gamma value was not set correctly'); matrix = matrixWithZXYRotation(1, 0, 2); - result = UI.Geometry.EulerAngles.fromDeviceOrientationRotationMatrix(matrix); + result = Geometry.EulerAngles.fromDeviceOrientationRotationMatrix(matrix); assert.strictEqual(result.alpha, 1, 'alpha value was not set correctly'); assert.strictEqual(result.beta, 0, 'beta value was not set correctly'); assert.strictEqual(result.gamma, 2, 'gamma value was not set correctly'); matrix = matrixWithZXYRotation(1, 2, 0); - result = UI.Geometry.EulerAngles.fromDeviceOrientationRotationMatrix(matrix); + result = Geometry.EulerAngles.fromDeviceOrientationRotationMatrix(matrix); assert.strictEqual(result.alpha, 1, 'alpha value was not set correctly'); assert.strictEqual(result.beta, 2, 'beta value was not set correctly'); assert.strictEqual(result.gamma, 0, 'gamma value was not set correctly'); matrix = matrixWithZXYRotation(1, 2, 3); - result = UI.Geometry.EulerAngles.fromDeviceOrientationRotationMatrix(matrix); + result = Geometry.EulerAngles.fromDeviceOrientationRotationMatrix(matrix); assert.strictEqual(result.alpha, 1, 'alpha value was not set correctly'); assert.strictEqual(result.beta, 2, 'beta value was not set correctly'); assert.strictEqual(result.gamma, 3, 'gamma value was not set correctly'); matrix = matrixWithZXYRotation(1, -2, -3); - result = UI.Geometry.EulerAngles.fromDeviceOrientationRotationMatrix(matrix); + result = Geometry.EulerAngles.fromDeviceOrientationRotationMatrix(matrix); assert.strictEqual(result.alpha, 1, 'alpha value was not set correctly'); assert.strictEqual(result.beta, -2, 'beta value was not set correctly'); assert.strictEqual(result.gamma, -3, 'gamma value was not set correctly'); matrix = matrixWithZXYRotation(1, -2, 3); - result = UI.Geometry.EulerAngles.fromDeviceOrientationRotationMatrix(matrix); + result = Geometry.EulerAngles.fromDeviceOrientationRotationMatrix(matrix); assert.strictEqual(result.alpha, 1, 'alpha value was not set correctly'); assert.strictEqual(result.beta, -2, 'beta value was not set correctly'); assert.strictEqual(result.gamma, 3, 'gamma value was not set correctly'); matrix = matrixWithZXYRotation(1, 2, -3); - result = UI.Geometry.EulerAngles.fromDeviceOrientationRotationMatrix(matrix); + result = Geometry.EulerAngles.fromDeviceOrientationRotationMatrix(matrix); assert.strictEqual(result.alpha, 1, 'alpha value was not set correctly'); assert.strictEqual(result.beta, 2, 'beta value was not set correctly'); assert.strictEqual(result.gamma, -3, 'gamma value was not set correctly'); @@ -204,49 +204,49 @@ let matrix, result; matrix = matrixWithZXYRotation(30, 90, 45); - result = UI.Geometry.EulerAngles.fromDeviceOrientationRotationMatrix(matrix); + result = Geometry.EulerAngles.fromDeviceOrientationRotationMatrix(matrix); assert.strictEqual(result.alpha, 75, 'alpha value was not set correctly'); assert.strictEqual(result.beta, 90, 'beta value was not set correctly'); assert.strictEqual(result.gamma, 0, 'gamma value was not set correctly'); matrix = matrixWithZXYRotation(30, -90, 45); - result = UI.Geometry.EulerAngles.fromDeviceOrientationRotationMatrix(matrix); + result = Geometry.EulerAngles.fromDeviceOrientationRotationMatrix(matrix); assert.strictEqual(result.alpha, 345, 'alpha value was not set correctly'); assert.strictEqual(result.beta, -90, 'beta value was not set correctly'); assert.strictEqual(result.gamma, 0, 'gamma value was not set correctly'); matrix = matrixWithZXYRotation(30, -90, -45); - result = UI.Geometry.EulerAngles.fromDeviceOrientationRotationMatrix(matrix); + result = Geometry.EulerAngles.fromDeviceOrientationRotationMatrix(matrix); assert.strictEqual(result.alpha, 75, 'alpha value was not set correctly'); assert.strictEqual(result.beta, -90, 'beta value was not set correctly'); assert.strictEqual(result.gamma, 0, 'gamma value was not set correctly'); matrix = matrixWithZXYRotation(0, 90, 45); - result = UI.Geometry.EulerAngles.fromDeviceOrientationRotationMatrix(matrix); + result = Geometry.EulerAngles.fromDeviceOrientationRotationMatrix(matrix); assert.strictEqual(result.alpha, 45, 'alpha value was not set correctly'); assert.strictEqual(result.beta, 90, 'beta value was not set correctly'); assert.strictEqual(result.gamma, 0, 'gamma value was not set correctly'); matrix = matrixWithZXYRotation(0, 90, -45); - result = UI.Geometry.EulerAngles.fromDeviceOrientationRotationMatrix(matrix); + result = Geometry.EulerAngles.fromDeviceOrientationRotationMatrix(matrix); assert.strictEqual(result.alpha, 315, 'alpha value was not set correctly'); assert.strictEqual(result.beta, 90, 'beta value was not set correctly'); assert.strictEqual(result.gamma, 0, 'gamma value was not set correctly'); matrix = matrixWithZXYRotation(45, 90, 0); - result = UI.Geometry.EulerAngles.fromDeviceOrientationRotationMatrix(matrix); + result = Geometry.EulerAngles.fromDeviceOrientationRotationMatrix(matrix); assert.strictEqual(result.alpha, 45, 'alpha value was not set correctly'); assert.strictEqual(result.beta, 90, 'beta value was not set correctly'); assert.strictEqual(result.gamma, 0, 'gamma value was not set correctly'); matrix = matrixWithZXYRotation(0, 90, 0); - result = UI.Geometry.EulerAngles.fromDeviceOrientationRotationMatrix(matrix); + result = Geometry.EulerAngles.fromDeviceOrientationRotationMatrix(matrix); assert.strictEqual(result.alpha, 0, 'alpha value was not set correctly'); assert.strictEqual(result.beta, 90, 'beta value was not set correctly'); assert.strictEqual(result.gamma, 0, 'gamma value was not set correctly'); matrix = matrixWithZXYRotation(0, -90, 0); - result = UI.Geometry.EulerAngles.fromDeviceOrientationRotationMatrix(matrix); + result = Geometry.EulerAngles.fromDeviceOrientationRotationMatrix(matrix); assert.strictEqual(result.alpha, 0, 'alpha value was not set correctly'); assert.strictEqual(result.beta, -90, 'beta value was not set correctly'); assert.strictEqual(result.gamma, 0, 'gamma value was not set correctly'); @@ -256,37 +256,37 @@ let matrix, result; matrix = matrixWithZXYRotation(1, 2, 90); - result = UI.Geometry.EulerAngles.fromDeviceOrientationRotationMatrix(matrix); + result = Geometry.EulerAngles.fromDeviceOrientationRotationMatrix(matrix); assert.strictEqual(result.alpha, 181, 'alpha value was not set correctly'); assert.strictEqual(result.beta, 178, 'beta value was not set correctly'); assert.strictEqual(result.gamma, -90, 'gamma value was not set correctly'); matrix = matrixWithZXYRotation(1, 2, -91); - result = UI.Geometry.EulerAngles.fromDeviceOrientationRotationMatrix(matrix); + result = Geometry.EulerAngles.fromDeviceOrientationRotationMatrix(matrix); assert.strictEqual(result.alpha, 181, 'alpha value was not set correctly'); assert.strictEqual(result.beta, 178, 'beta value was not set correctly'); assert.strictEqual(result.gamma, 89, 'gamma value was not set correctly'); matrix = matrixWithZXYRotation(360, 1, 2); - result = UI.Geometry.EulerAngles.fromDeviceOrientationRotationMatrix(matrix); + result = Geometry.EulerAngles.fromDeviceOrientationRotationMatrix(matrix); assert.strictEqual(result.alpha, 0, 'alpha value was not set correctly'); assert.strictEqual(result.beta, 1, 'beta value was not set correctly'); assert.strictEqual(result.gamma, 2, 'gamma value was not set correctly'); matrix = matrixWithZXYRotation(-1, 1, 2); - result = UI.Geometry.EulerAngles.fromDeviceOrientationRotationMatrix(matrix); + result = Geometry.EulerAngles.fromDeviceOrientationRotationMatrix(matrix); assert.strictEqual(result.alpha, 359, 'alpha value was not set correctly'); assert.strictEqual(result.beta, 1, 'beta value was not set correctly'); assert.strictEqual(result.gamma, 2, 'gamma value was not set correctly'); matrix = matrixWithZXYRotation(1, -181, 2); - result = UI.Geometry.EulerAngles.fromDeviceOrientationRotationMatrix(matrix); + result = Geometry.EulerAngles.fromDeviceOrientationRotationMatrix(matrix); assert.strictEqual(result.alpha, 1, 'alpha value was not set correctly'); assert.strictEqual(result.beta, 179, 'beta value was not set correctly'); assert.strictEqual(result.gamma, 2, 'gamma value was not set correctly'); matrix = matrixWithZXYRotation(1, 180, 2); - result = UI.Geometry.EulerAngles.fromDeviceOrientationRotationMatrix(matrix); + result = Geometry.EulerAngles.fromDeviceOrientationRotationMatrix(matrix); assert.strictEqual(result.alpha, 1, 'alpha value was not set correctly'); assert.strictEqual(result.beta, -180, 'beta value was not set correctly'); assert.strictEqual(result.gamma, 2, 'gamma value was not set correctly'); @@ -295,45 +295,45 @@ describe('Size', () => { it('can be instantiated without issues', () => { - const size = new UI.Geometry.Size(1, 2); + const size = new Geometry.Size(1, 2); assert.strictEqual(size.width, 1, 'width value was not set correctly'); assert.strictEqual(size.height, 2, 'height value was not set correctly'); }); it('can be clipped to another smaller size', () => { - const size1 = new UI.Geometry.Size(3, 4); - const size2 = new UI.Geometry.Size(1, 2); + const size1 = new Geometry.Size(3, 4); + const size2 = new Geometry.Size(1, 2); const resultSize = size1.clipTo(size2); assert.strictEqual(resultSize.width, 1, 'width value was not set correctly'); assert.strictEqual(resultSize.height, 2, 'height value was not set correctly'); }); it('can be clipped to another larger size', () => { - const size1 = new UI.Geometry.Size(1, 2); - const size2 = new UI.Geometry.Size(3, 4); + const size1 = new Geometry.Size(1, 2); + const size2 = new Geometry.Size(3, 4); const resultSize = size1.clipTo(size2); assert.strictEqual(resultSize.width, 1, 'width value was not set correctly'); assert.strictEqual(resultSize.height, 2, 'height value was not set correctly'); }); it('returns the original size if nothing was passed to the clipTo function', () => { - const size = new UI.Geometry.Size(1, 2); + const size = new Geometry.Size(1, 2); const resultSize = size.clipTo(); assert.strictEqual(resultSize.width, 1, 'width value was not set correctly'); assert.strictEqual(resultSize.height, 2, 'height value was not set correctly'); }); it('can be scaled to a different size', () => { - const size = new UI.Geometry.Size(1, 2); + const size = new Geometry.Size(1, 2); const resultSize = size.scale(2); assert.strictEqual(resultSize.width, 2, 'width value was not scaled correctly'); assert.strictEqual(resultSize.height, 4, 'height value was not scaled correctly'); }); it('is able to check if it is equal to another size', () => { - const size1 = new UI.Geometry.Size(1, 2); - const size2 = new UI.Geometry.Size(3, 4); - const size3 = new UI.Geometry.Size(1, 2); + const size1 = new Geometry.Size(1, 2); + const size2 = new Geometry.Size(3, 4); + const size3 = new Geometry.Size(1, 2); const result1 = size1.isEqual(size2); const result2 = size1.isEqual(size3); assert.isFalse(result1, 'size2 was considered equal'); @@ -341,60 +341,60 @@ }); it('is able to change width to the max value given a size', () => { - const size1 = new UI.Geometry.Size(1, 2); - const size2 = new UI.Geometry.Size(3, 4); + const size1 = new Geometry.Size(1, 2); + const size2 = new Geometry.Size(3, 4); const resultSize = size1.widthToMax(size2); assert.strictEqual(resultSize.width, 3, 'width value was not scaled correctly'); assert.strictEqual(resultSize.height, 2, 'height value was not scaled correctly'); }); it('is able to change width to the max value given a number', () => { - const size1 = new UI.Geometry.Size(1, 2); + const size1 = new Geometry.Size(1, 2); const resultSize = size1.widthToMax(5); assert.strictEqual(resultSize.width, 5, 'width value was not scaled correctly'); assert.strictEqual(resultSize.height, 2, 'height value was not scaled correctly'); }); it('is able to increase width by a certain value given a size', () => { - const size1 = new UI.Geometry.Size(1, 2); - const size2 = new UI.Geometry.Size(3, 4); + const size1 = new Geometry.Size(1, 2); + const size2 = new Geometry.Size(3, 4); const resultSize = size1.addWidth(size2); assert.strictEqual(resultSize.width, 4, 'width value was not scaled correctly'); assert.strictEqual(resultSize.height, 2, 'height value was not scaled correctly'); }); it('is able to increase width by a certain value given a number', () => { - const size1 = new UI.Geometry.Size(1, 2); + const size1 = new Geometry.Size(1, 2); const resultSize = size1.addWidth(5); assert.strictEqual(resultSize.width, 6, 'width value was not scaled correctly'); assert.strictEqual(resultSize.height, 2, 'height value was not scaled correctly'); }); it('is able to change height to the max value given a size', () => { - const size1 = new UI.Geometry.Size(1, 2); - const size2 = new UI.Geometry.Size(3, 4); + const size1 = new Geometry.Size(1, 2); + const size2 = new Geometry.Size(3, 4); const resultSize = size1.heightToMax(size2); assert.strictEqual(resultSize.width, 1, 'width value was not scaled correctly'); assert.strictEqual(resultSize.height, 4, 'height value was not scaled correctly'); }); it('is able to change height to the max value given a number', () => { - const size1 = new UI.Geometry.Size(1, 2); + const size1 = new Geometry.Size(1, 2); const resultSize = size1.heightToMax(5); assert.strictEqual(resultSize.width, 1, 'width value was not scaled correctly'); assert.strictEqual(resultSize.height, 5, 'height value was not scaled correctly'); }); it('is able to increase height by a certain value given a size', () => { - const size1 = new UI.Geometry.Size(1, 2); - const size2 = new UI.Geometry.Size(3, 4); + const size1 = new Geometry.Size(1, 2); + const size2 = new Geometry.Size(3, 4); const resultSize = size1.addHeight(size2); assert.strictEqual(resultSize.width, 1, 'width value was not scaled correctly'); assert.strictEqual(resultSize.height, 6, 'height value was not scaled correctly'); }); it('is able to increase height by a certain value given a number', () => { - const size1 = new UI.Geometry.Size(1, 2); + const size1 = new Geometry.Size(1, 2); const resultSize = size1.addHeight(5); assert.strictEqual(resultSize.width, 1, 'width value was not scaled correctly'); assert.strictEqual(resultSize.height, 7, 'height value was not scaled correctly'); @@ -403,9 +403,9 @@ describe('Constraints', () => { it('can be instantiated without issues', () => { - const size1 = new UI.Geometry.Size(1, 2); - const size2 = new UI.Geometry.Size(3, 4); - const constraints = new UI.Geometry.Constraints(size1, size2); + const size1 = new Geometry.Size(1, 2); + const size2 = new Geometry.Size(3, 4); + const constraints = new Geometry.Constraints(size1, size2); assert.strictEqual(constraints.minimum.width, 1, 'size1 width value was not set correctly'); assert.strictEqual(constraints.minimum.height, 2, 'size1 height value was not set correctly'); assert.strictEqual(constraints.preferred.width, 3, 'size2 width value was not set correctly'); @@ -413,13 +413,13 @@ }); it('thows an error if instantiated with a minimum size that is larger than the the preferred size', () => { - const size1 = new UI.Geometry.Size(3, 4); - const size2 = new UI.Geometry.Size(1, 2); - assert.throws(() => new UI.Geometry.Constraints(size1, size2), Error, 'Minimum size is greater than preferred.'); + const size1 = new Geometry.Size(3, 4); + const size2 = new Geometry.Size(1, 2); + assert.throws(() => new Geometry.Constraints(size1, size2), Error, 'Minimum size is greater than preferred.'); }); - it('sets minimum and preferred to UI.Geometry.Size(0, 0) if no values were given to the constructor', () => { - const constraints = new UI.Geometry.Constraints(); + it('sets minimum and preferred to Geometry.Size(0, 0) if no values were given to the constructor', () => { + const constraints = new Geometry.Constraints(); assert.strictEqual(constraints.minimum.width, 0, 'size1 width value was not set correctly'); assert.strictEqual(constraints.minimum.height, 0, 'size1 height value was not set correctly'); assert.strictEqual(constraints.preferred.width, 0, 'size2 width value was not set correctly'); @@ -427,24 +427,24 @@ }); it('is able to check if it is equal to another constraint', () => { - const size1 = new UI.Geometry.Size(1, 2); - const size2 = new UI.Geometry.Size(3, 4); - const size3 = new UI.Geometry.Size(5, 6); - const size4 = new UI.Geometry.Size(7, 8); - const constraints1 = new UI.Geometry.Constraints(size1, size2); - const constraints2 = new UI.Geometry.Constraints(size3, size4); - const constraints3 = new UI.Geometry.Constraints(size1, size2); + const size1 = new Geometry.Size(1, 2); + const size2 = new Geometry.Size(3, 4); + const size3 = new Geometry.Size(5, 6); + const size4 = new Geometry.Size(7, 8); + const constraints1 = new Geometry.Constraints(size1, size2); + const constraints2 = new Geometry.Constraints(size3, size4); + const constraints3 = new Geometry.Constraints(size1, size2); assert.isFalse(constraints1.isEqual(constraints2), 'constraints2 was considered equal'); assert.isTrue(constraints1.isEqual(constraints3), 'constraints3 was not considered equal'); }); it('is able to change widths to the max value given a constraint', () => { - const size1 = new UI.Geometry.Size(1, 2); - const size2 = new UI.Geometry.Size(3, 4); - const size3 = new UI.Geometry.Size(5, 6); - const size4 = new UI.Geometry.Size(7, 8); - const constraints1 = new UI.Geometry.Constraints(size1, size2); - const constraints2 = new UI.Geometry.Constraints(size3, size4); + const size1 = new Geometry.Size(1, 2); + const size2 = new Geometry.Size(3, 4); + const size3 = new Geometry.Size(5, 6); + const size4 = new Geometry.Size(7, 8); + const constraints1 = new Geometry.Constraints(size1, size2); + const constraints2 = new Geometry.Constraints(size3, size4); const resultSize = constraints1.widthToMax(constraints2); assert.strictEqual(resultSize.minimum.width, 5, 'width value was not scaled correctly'); assert.strictEqual(resultSize.minimum.height, 2, 'height value was not scaled correctly'); @@ -453,9 +453,9 @@ }); it('is able to change widths to the max value given a number', () => { - const size1 = new UI.Geometry.Size(1, 2); - const size2 = new UI.Geometry.Size(3, 4); - const constraints = new UI.Geometry.Constraints(size1, size2); + const size1 = new Geometry.Size(1, 2); + const size2 = new Geometry.Size(3, 4); + const constraints = new Geometry.Constraints(size1, size2); const resultSize = constraints.widthToMax(5); assert.strictEqual(resultSize.minimum.width, 5, 'width value was not scaled correctly'); assert.strictEqual(resultSize.minimum.height, 2, 'height value was not scaled correctly'); @@ -464,12 +464,12 @@ }); it('is able to increase widths by a certain value given a constraint', () => { - const size1 = new UI.Geometry.Size(1, 2); - const size2 = new UI.Geometry.Size(3, 4); - const size3 = new UI.Geometry.Size(5, 6); - const size4 = new UI.Geometry.Size(7, 8); - const constraints1 = new UI.Geometry.Constraints(size1, size2); - const constraints2 = new UI.Geometry.Constraints(size3, size4); + const size1 = new Geometry.Size(1, 2); + const size2 = new Geometry.Size(3, 4); + const size3 = new Geometry.Size(5, 6); + const size4 = new Geometry.Size(7, 8); + const constraints1 = new Geometry.Constraints(size1, size2); + const constraints2 = new Geometry.Constraints(size3, size4); const resultSize = constraints1.addWidth(constraints2); assert.strictEqual(resultSize.minimum.width, 6, 'width value was not scaled correctly'); assert.strictEqual(resultSize.minimum.height, 2, 'height value was not scaled correctly'); @@ -478,9 +478,9 @@ }); it('is able to increase widths by a certain value given a number', () => { - const size1 = new UI.Geometry.Size(1, 2); - const size2 = new UI.Geometry.Size(3, 4); - const constraints = new UI.Geometry.Constraints(size1, size2); + const size1 = new Geometry.Size(1, 2); + const size2 = new Geometry.Size(3, 4); + const constraints = new Geometry.Constraints(size1, size2); const resultSize = constraints.addWidth(5); assert.strictEqual(resultSize.minimum.width, 6, 'width value was not scaled correctly'); assert.strictEqual(resultSize.minimum.height, 2, 'height value was not scaled correctly'); @@ -489,12 +489,12 @@ }); it('is able to change heights to the max value given a constraint', () => { - const size1 = new UI.Geometry.Size(1, 2); - const size2 = new UI.Geometry.Size(3, 4); - const size3 = new UI.Geometry.Size(5, 6); - const size4 = new UI.Geometry.Size(7, 8); - const constraints1 = new UI.Geometry.Constraints(size1, size2); - const constraints2 = new UI.Geometry.Constraints(size3, size4); + const size1 = new Geometry.Size(1, 2); + const size2 = new Geometry.Size(3, 4); + const size3 = new Geometry.Size(5, 6); + const size4 = new Geometry.Size(7, 8); + const constraints1 = new Geometry.Constraints(size1, size2); + const constraints2 = new Geometry.Constraints(size3, size4); const resultSize = constraints1.heightToMax(constraints2); assert.strictEqual(resultSize.minimum.width, 1, 'width value was not scaled correctly'); assert.strictEqual(resultSize.minimum.height, 6, 'height value was not scaled correctly'); @@ -503,9 +503,9 @@ }); it('is able to change heights to the max value given a number', () => { - const size1 = new UI.Geometry.Size(1, 2); - const size2 = new UI.Geometry.Size(3, 4); - const constraints = new UI.Geometry.Constraints(size1, size2); + const size1 = new Geometry.Size(1, 2); + const size2 = new Geometry.Size(3, 4); + const constraints = new Geometry.Constraints(size1, size2); const resultSize = constraints.heightToMax(5); assert.strictEqual(resultSize.minimum.width, 1, 'width value was not scaled correctly'); assert.strictEqual(resultSize.minimum.height, 5, 'height value was not scaled correctly'); @@ -514,12 +514,12 @@ }); it('is able to increase heights by a certain value given a constraint', () => { - const size1 = new UI.Geometry.Size(1, 2); - const size2 = new UI.Geometry.Size(3, 4); - const size3 = new UI.Geometry.Size(5, 6); - const size4 = new UI.Geometry.Size(7, 8); - const constraints1 = new UI.Geometry.Constraints(size1, size2); - const constraints2 = new UI.Geometry.Constraints(size3, size4); + const size1 = new Geometry.Size(1, 2); + const size2 = new Geometry.Size(3, 4); + const size3 = new Geometry.Size(5, 6); + const size4 = new Geometry.Size(7, 8); + const constraints1 = new Geometry.Constraints(size1, size2); + const constraints2 = new Geometry.Constraints(size3, size4); const resultSize = constraints1.addHeight(constraints2); assert.strictEqual(resultSize.minimum.width, 1, 'width value was not scaled correctly'); assert.strictEqual(resultSize.minimum.height, 8, 'height value was not scaled correctly'); @@ -528,9 +528,9 @@ }); it('is able to increase heights by a certain value given a number', () => { - const size1 = new UI.Geometry.Size(1, 2); - const size2 = new UI.Geometry.Size(3, 4); - const constraints = new UI.Geometry.Constraints(size1, size2); + const size1 = new Geometry.Size(1, 2); + const size2 = new Geometry.Size(3, 4); + const constraints = new Geometry.Constraints(size1, size2); const resultSize = constraints.addHeight(5); assert.strictEqual(resultSize.minimum.width, 1, 'width value was not scaled correctly'); assert.strictEqual(resultSize.minimum.height, 7, 'height value was not scaled correctly'); @@ -541,18 +541,18 @@ describe('scalarProduct', () => { it('returns the scalar product for two vectors', () => { - const vector1 = new UI.Geometry.Vector(1, 2, 3); - const vector2 = new UI.Geometry.Vector(4, 5, 6); - const result = UI.Geometry.scalarProduct(vector1, vector2); + const vector1 = new Geometry.Vector(1, 2, 3); + const vector2 = new Geometry.Vector(4, 5, 6); + const result = Geometry.scalarProduct(vector1, vector2); assert.strictEqual(result, 32, 'the scalar product was not calculated correctly'); }); }); describe('crossProduct', () => { it('returns the cross product for two vectors', () => { - const vector1 = new UI.Geometry.Vector(1, 2, 3); - const vector2 = new UI.Geometry.Vector(4, 5, 6); - const result = UI.Geometry.crossProduct(vector1, vector2); + const vector1 = new Geometry.Vector(1, 2, 3); + const vector2 = new Geometry.Vector(4, 5, 6); + const result = Geometry.crossProduct(vector1, vector2); assert.strictEqual(result.x, -3, 'x value for the resulting vector was not set correctly'); assert.strictEqual(result.y, 6, 'y value for the resulting vector was not set correctly'); assert.strictEqual(result.z, -3, 'z value for the resulting vector was not set correctly'); @@ -561,9 +561,9 @@ describe('subtract', () => { it('returns the difference between two vectors', () => { - const vector1 = new UI.Geometry.Vector(1, 2, 3); - const vector2 = new UI.Geometry.Vector(4, 5, 6); - const result = UI.Geometry.subtract(vector1, vector2); + const vector1 = new Geometry.Vector(1, 2, 3); + const vector2 = new Geometry.Vector(4, 5, 6); + const result = Geometry.subtract(vector1, vector2); assert.strictEqual(result.x, -3, 'x value for the resulting vector was not set correctly'); assert.strictEqual(result.y, -3, 'y value for the resulting vector was not set correctly'); assert.strictEqual(result.z, -3, 'z value for the resulting vector was not set correctly'); @@ -572,9 +572,9 @@ describe('multiplyVectorByMatrixAndNormalize', () => { it('returns the vector multiplied by a matrix and normalized', () => { - const vector = new UI.Geometry.Vector(1, 2, 3); + const vector = new Geometry.Vector(1, 2, 3); const matrix = new WebKitCSSMatrix(); - const result = UI.Geometry.multiplyVectorByMatrixAndNormalize(vector, matrix); + const result = Geometry.multiplyVectorByMatrixAndNormalize(vector, matrix); assert.strictEqual(result.x, 1, 'x value for the resulting vector was not set correctly'); assert.strictEqual(result.y, 2, 'y value for the resulting vector was not set correctly'); assert.strictEqual(result.z, 3, 'z value for the resulting vector was not set correctly'); @@ -583,9 +583,9 @@ describe('calculateAngle', () => { it('returns the angle between two vectors', () => { - const vector1 = new UI.Geometry.Vector(1, 2, 3); - const vector2 = new UI.Geometry.Vector(4, 5, 6); - const result = UI.Geometry.calculateAngle(vector1, vector2); + const vector1 = new Geometry.Vector(1, 2, 3); + const vector2 = new Geometry.Vector(4, 5, 6); + const result = Geometry.calculateAngle(vector1, vector2); assert.strictEqual(result, 12.933154491899135, 'angle returned was not correct'); }); }); @@ -593,7 +593,7 @@ describe('boundsForTransformedPoints', () => { it('returns the bounds for transformed points', () => { const matrix = new WebKitCSSMatrix(); - const result = UI.Geometry.boundsForTransformedPoints(matrix, [1, 2, 3], {minX: 5, maxX: 6, minY: 7, maxY: 8}); + const result = Geometry.boundsForTransformedPoints(matrix, [1, 2, 3], {minX: 5, maxX: 6, minY: 7, maxY: 8}); assert.strictEqual(result.minX, 1, 'minX was calculated incorrectly'); assert.strictEqual(result.maxX, 6, 'maxX was calculated incorrectly'); assert.strictEqual(result.minY, 2, 'minY was calculated incorrectly'); @@ -602,57 +602,57 @@ describe('degreesToRadians', () => { it('converts degrees to radians correctly', () => { - assert.strictEqual(UI.Geometry.degreesToRadians(45), 0.7853981633974483); - assert.strictEqual(UI.Geometry.degreesToRadians(180), 3.141592653589793); + assert.strictEqual(Geometry.degreesToRadians(45), 0.7853981633974483); + assert.strictEqual(Geometry.degreesToRadians(180), 3.141592653589793); }); }); describe('degreesToGradians', () => { it('converts degrees to gradians correctly', () => { - assert.strictEqual(UI.Geometry.degreesToGradians(45), 50); - assert.strictEqual(UI.Geometry.degreesToGradians(180), 200); + assert.strictEqual(Geometry.degreesToGradians(45), 50); + assert.strictEqual(Geometry.degreesToGradians(180), 200); }); }); describe('degreesToTurns', () => { it('converts degrees to turns correctly', () => { - assert.strictEqual(UI.Geometry.degreesToTurns(45), 0.125); - assert.strictEqual(UI.Geometry.degreesToTurns(180), 0.5); + assert.strictEqual(Geometry.degreesToTurns(45), 0.125); + assert.strictEqual(Geometry.degreesToTurns(180), 0.5); }); }); describe('radiansToDegrees', () => { it('converts radians to degrees correctly', () => { - assert.strictEqual(UI.Geometry.radiansToDegrees(1), 57.29577951308232); - assert.strictEqual(UI.Geometry.radiansToDegrees(1.5), 85.94366926962348); + assert.strictEqual(Geometry.radiansToDegrees(1), 57.29577951308232); + assert.strictEqual(Geometry.radiansToDegrees(1.5), 85.94366926962348); }); }); describe('radiansToGradians', () => { it('converts radians to gradians correctly', () => { - assert.strictEqual(UI.Geometry.radiansToGradians(1), 63.66197723675813); - assert.strictEqual(UI.Geometry.radiansToGradians(1.5), 95.4929658551372); + assert.strictEqual(Geometry.radiansToGradians(1), 63.66197723675813); + assert.strictEqual(Geometry.radiansToGradians(1.5), 95.4929658551372); }); }); describe('radiansToTurns', () => { it('converts radians to turns correctly', () => { - assert.strictEqual(UI.Geometry.radiansToTurns(1), 0.15915494309189535); - assert.strictEqual(UI.Geometry.radiansToTurns(1.5), 0.238732414637843); + assert.strictEqual(Geometry.radiansToTurns(1), 0.15915494309189535); + assert.strictEqual(Geometry.radiansToTurns(1.5), 0.238732414637843); }); }); describe('gradiansToRadians', () => { it('converts gradians to radians correctly', () => { - assert.strictEqual(UI.Geometry.gradiansToRadians(50), 0.7853981633974483); - assert.strictEqual(UI.Geometry.gradiansToRadians(200), 3.141592653589793); + assert.strictEqual(Geometry.gradiansToRadians(50), 0.7853981633974483); + assert.strictEqual(Geometry.gradiansToRadians(200), 3.141592653589793); }); }); describe('turnsToRadians', () => { it('converts turns to radians correctly', () => { - assert.strictEqual(UI.Geometry.gradiansToRadians(0.5), 0.007853981633974483); - assert.strictEqual(UI.Geometry.gradiansToRadians(1), 0.015707963267948967); + assert.strictEqual(Geometry.gradiansToRadians(0.5), 0.007853981633974483); + assert.strictEqual(Geometry.gradiansToRadians(1), 0.015707963267948967); }); }); });
diff --git a/front_end/ui/legacy/Geometry.ts b/front_end/models/geometry/GeometryImpl.ts similarity index 98% rename from front_end/ui/legacy/Geometry.ts rename to front_end/models/geometry/GeometryImpl.ts index bd0210e..de901a1 100644 --- a/front_end/ui/legacy/Geometry.ts +++ b/front_end/models/geometry/GeometryImpl.ts
@@ -219,8 +219,8 @@ } else { // cos(gamma) == 0, cos(beta) < 0 alpha = Math.atan2(rotationMatrix.m21, -rotationMatrix.m22); beta = -Math.asin(rotationMatrix.m23); - beta += (beta > 0 || Math.abs(beta) < EPS) ? -Math.PI : Math.PI; // beta [-pi,-pi/2) U (pi/2,pi) - gamma = -(Math.PI / 2); // gamma = -pi/2 + beta += (beta > 0 || Math.abs(beta) < EPS) ? -Math.PI : Math.PI; // beta [-pi,-pi/2) U (pi/2,pi) + gamma = -(Math.PI / 2); // gamma = -pi/2 } } else if (rotationMatrix.m33 > 0) { // cos(beta) > 0 alpha = Math.atan2(-rotationMatrix.m21, rotationMatrix.m22); @@ -229,8 +229,8 @@ } else { // cos(beta) < 0 alpha = Math.atan2(rotationMatrix.m21, -rotationMatrix.m22); beta = -Math.asin(rotationMatrix.m23); - beta += (beta > 0 || Math.abs(beta) < EPS) ? -Math.PI : Math.PI; // beta [-pi,-pi/2) U (pi/2,pi) - gamma = Math.atan2(rotationMatrix.m13, -rotationMatrix.m33); // gamma (-pi/2, pi/2) + beta += (beta > 0 || Math.abs(beta) < EPS) ? -Math.PI : Math.PI; // beta [-pi,-pi/2) U (pi/2,pi) + gamma = Math.atan2(rotationMatrix.m13, -rotationMatrix.m33); // gamma (-pi/2, pi/2) } // alpha is in [-pi, pi], make sure it is in [0, 2*pi).
diff --git a/front_end/models/geometry/geometry.ts b/front_end/models/geometry/geometry.ts new file mode 100644 index 0000000..0bca6b8 --- /dev/null +++ b/front_end/models/geometry/geometry.ts
@@ -0,0 +1,5 @@ +// Copyright 2025 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +export * from './GeometryImpl.js';
diff --git a/front_end/panels/ai_assistance/BUILD.gn b/front_end/panels/ai_assistance/BUILD.gn index 04eca4e..2e9b411 100644 --- a/front_end/panels/ai_assistance/BUILD.gn +++ b/front_end/panels/ai_assistance/BUILD.gn
@@ -36,6 +36,7 @@ "../../core/i18n:bundle", "../../core/root:bundle", "../../models/ai_assistance:bundle", + "../../models/geometry:bundle", "../../models/persistence:bundle", "../../models/workspace:bundle", "../../models/workspace_diff:bundle",
diff --git a/front_end/panels/ai_assistance/SelectWorkspaceDialog.ts b/front_end/panels/ai_assistance/SelectWorkspaceDialog.ts index 346527f..85da851 100644 --- a/front_end/panels/ai_assistance/SelectWorkspaceDialog.ts +++ b/front_end/panels/ai_assistance/SelectWorkspaceDialog.ts
@@ -7,6 +7,7 @@ import * as i18n from '../../core/i18n/i18n.js'; import type * as Platform from '../../core/platform/platform.js'; import * as Root from '../../core/root/root.js'; +import * as Geometry from '../../models/geometry/geometry.js'; import * as Persistence from '../../models/persistence/persistence.js'; import * as Workspace from '../../models/workspace/workspace.js'; import * as Buttons from '../../ui/components/buttons/buttons.js'; @@ -354,7 +355,7 @@ currentProject?: Workspace.Workspace.Project): void { const dialog = new UI.Dialog.Dialog('select-workspace'); dialog.setAriaLabel(UIStringsNotTranslate.selectFolderAccessibleLabel); - dialog.setMaxContentSize(new UI.Geometry.Size(384, 340)); + dialog.setMaxContentSize(new Geometry.Size(384, 340)); dialog.setSizeBehavior(UI.GlassPane.SizeBehavior.SET_EXACT_WIDTH_MAX_HEIGHT); dialog.setDimmed(true);
diff --git a/front_end/panels/animation/AnimationUI.ts b/front_end/panels/animation/AnimationUI.ts index 35111e2..146c39d 100644 --- a/front_end/panels/animation/AnimationUI.ts +++ b/front_end/panels/animation/AnimationUI.ts
@@ -6,6 +6,7 @@ import * as i18n from '../../core/i18n/i18n.js'; import * as Platform from '../../core/platform/platform.js'; import type * as SDK from '../../core/sdk/sdk.js'; +import * as Geometry from '../../models/geometry/geometry.js'; import * as InlineEditor from '../../ui/legacy/components/inline_editor/inline_editor.js'; import * as UI from '../../ui/legacy/legacy.js'; import * as VisualLogging from '../../ui/visual_logging/visual_logging.js'; @@ -232,7 +233,7 @@ line.style.stroke = strokeColor; } - const bezier = UI.Geometry.CubicBezier.parse(easing); + const bezier = Geometry.CubicBezier.parse(easing); const cache = this.#cachedElements[iteration].keyframeRender; if (!cache[keyframeIndex]) { const svg = bezier ? UI.UIUtils.createSVGChild(parentElement, 'path', 'animation-keyframe') :
diff --git a/front_end/panels/animation/BUILD.gn b/front_end/panels/animation/BUILD.gn index a9c090f..061f125 100644 --- a/front_end/panels/animation/BUILD.gn +++ b/front_end/panels/animation/BUILD.gn
@@ -26,6 +26,7 @@ "../../core/platform:bundle", "../../core/sdk:bundle", "../../generated:protocol", + "../../models/geometry:bundle", "../../ui/legacy:bundle", "../../ui/legacy/components/inline_editor:bundle", "../../ui/visual_logging:bundle",
diff --git a/front_end/panels/application/KeyValueStorageItemsView.ts b/front_end/panels/application/KeyValueStorageItemsView.ts index ccca0b3..b9c1f1b 100644 --- a/front_end/panels/application/KeyValueStorageItemsView.ts +++ b/front_end/panels/application/KeyValueStorageItemsView.ts
@@ -29,6 +29,7 @@ */ /* eslint no-return-assign: "off" */ import * as i18n from '../../core/i18n/i18n.js'; +import * as Geometry from '../../models/geometry/geometry.js'; import * as UI from '../../ui/legacy/legacy.js'; import {Directives as LitDirectives, html, nothing, render} from '../../ui/lit/lit.js'; import * as VisualLogging from '../../ui/visual_logging/visual_logging.js'; @@ -39,7 +40,7 @@ const {ARIAUtils} = UI; const {EmptyWidget} = UI.EmptyWidget; const {VBox, widgetConfig} = UI.Widget; -const {Size} = UI.Geometry; +const {Size} = Geometry; const {repeat} = LitDirectives; type Widget = UI.Widget.Widget;
diff --git a/front_end/panels/common/BUILD.gn b/front_end/panels/common/BUILD.gn index 8331be9..e0f379d 100644 --- a/front_end/panels/common/BUILD.gn +++ b/front_end/panels/common/BUILD.gn
@@ -33,6 +33,7 @@ "../../core/host:bundle", "../../core/i18n:bundle", "../../core/platform:bundle", + "../../models/geometry:bundle", "../../ui/components/buttons:bundle", "../../ui/components/snackbars:bundle", "../../ui/components/spinners:bundle",
diff --git a/front_end/panels/common/common.ts b/front_end/panels/common/common.ts index 7071426..8da2401 100644 --- a/front_end/panels/common/common.ts +++ b/front_end/panels/common/common.ts
@@ -7,6 +7,7 @@ import * as Host from '../../core/host/host.js'; import * as i18n from '../../core/i18n/i18n.js'; import type * as Platform from '../../core/platform/platform.js'; +import * as Geometry from '../../models/geometry/geometry.js'; import * as Buttons from '../../ui/components/buttons/buttons.js'; import * as UI from '../../ui/legacy/legacy.js'; @@ -38,7 +39,7 @@ inputPlaceholder: Platform.UIString.LocalizedString, }): Promise<boolean> { const dialog = new UI.Dialog.Dialog(options.jslogContext.dialog); - dialog.setMaxContentSize(new UI.Geometry.Size(504, 340)); + dialog.setMaxContentSize(new Geometry.Size(504, 340)); dialog.setSizeBehavior(UI.GlassPane.SizeBehavior.SET_EXACT_WIDTH_MAX_HEIGHT); dialog.setDimmed(true); const shadowRoot = UI.UIUtils.createShadowRootWithCoreStyles(dialog.contentElement, {cssFile: commonStyles});
diff --git a/front_end/panels/css_overview/BUILD.gn b/front_end/panels/css_overview/BUILD.gn index c0bde0c..84ff480 100644 --- a/front_end/panels/css_overview/BUILD.gn +++ b/front_end/panels/css_overview/BUILD.gn
@@ -37,6 +37,7 @@ "../../core/root:bundle", "../../core/sdk:bundle", "../../generated:protocol", + "../../models/geometry:bundle", "../../models/text_utils:bundle", "../../ui/components/buttons:bundle", "../../ui/components/helpers:bundle",
diff --git a/front_end/panels/css_overview/CSSOverviewCompletedView.ts b/front_end/panels/css_overview/CSSOverviewCompletedView.ts index 5ed57a6..aa0ee13 100644 --- a/front_end/panels/css_overview/CSSOverviewCompletedView.ts +++ b/front_end/panels/css_overview/CSSOverviewCompletedView.ts
@@ -11,6 +11,7 @@ import * as Root from '../../core/root/root.js'; import * as SDK from '../../core/sdk/sdk.js'; import type * as Protocol from '../../generated/protocol.js'; +import * as Geometry from '../../models/geometry/geometry.js'; import * as TextUtils from '../../models/text_utils/text_utils.js'; import * as Components from '../../ui/legacy/components/utils/utils.js'; import * as UI from '../../ui/legacy/legacy.js'; @@ -280,7 +281,7 @@ <style>${cssOverviewCompletedViewStyles}</style> <devtools-split-view direction="column" sidebar-position="first" sidebar-initial-size="200"> <devtools-widget slot="sidebar" .widgetConfig=${widgetConfig(CSSOverviewSidebarPanel, { - minimumSize: new UI.Geometry.Size(100, 25), + minimumSize: new Geometry.Size(100, 25), items: [ {name: i18nString(UIStrings.overviewSummary), id: 'summary'}, {name: i18nString(UIStrings.colors), id: 'colors'},
diff --git a/front_end/panels/emulation/BUILD.gn b/front_end/panels/emulation/BUILD.gn index 9963fd3..f271c72 100644 --- a/front_end/panels/emulation/BUILD.gn +++ b/front_end/panels/emulation/BUILD.gn
@@ -37,6 +37,7 @@ "../../generated:protocol", "../../models/bindings:bundle", "../../models/emulation:bundle", + "../../models/geometry:bundle", "../../models/workspace:bundle", "../../panels/mobile_throttling:bundle", "../../ui/components/icon_button:bundle",
diff --git a/front_end/panels/emulation/DeviceModeView.ts b/front_end/panels/emulation/DeviceModeView.ts index 51d0806..991bb83 100644 --- a/front_end/panels/emulation/DeviceModeView.ts +++ b/front_end/panels/emulation/DeviceModeView.ts
@@ -9,6 +9,7 @@ import * as Platform from '../../core/platform/platform.js'; import type * as Protocol from '../../generated/protocol.js'; import * as EmulationModel from '../../models/emulation/emulation.js'; +import * as Geometry from '../../models/geometry/geometry.js'; import * as UI from '../../ui/legacy/legacy.js'; import * as VisualLogging from '../../ui/visual_logging/visual_logging.js'; @@ -84,7 +85,7 @@ x: number, y: number, }|null; - private resizeStart?: UI.Geometry.Size; + private resizeStart?: Geometry.Size; private cachedCssScreenRect?: EmulationModel.DeviceModeModel.Rect; private cachedCssVisiblePageRect?: EmulationModel.DeviceModeModel.Rect; private cachedOutlineRect?: EmulationModel.DeviceModeModel.Rect; @@ -214,7 +215,7 @@ private onResizeStart(): void { this.slowPositionStart = null; const rect = this.model.screenRect(); - this.resizeStart = new UI.Geometry.Size(rect.width, rect.height); + this.resizeStart = new Geometry.Size(rect.width, rect.height); } private onResizeUpdate(widthFactor: number, heightFactor: number, event: { @@ -400,7 +401,7 @@ const zoomFactor = UI.ZoomManager.ZoomManager.instance().zoomFactor(); const rect = element.getBoundingClientRect(); const availableSize = - new UI.Geometry.Size(Math.max(rect.width * zoomFactor, 1), Math.max(rect.height * zoomFactor, 1)); + new Geometry.Size(Math.max(rect.width * zoomFactor, 1), Math.max(rect.height * zoomFactor, 1)); this.model.setAvailableSize(availableSize, availableSize); } @@ -408,8 +409,8 @@ const zoomFactor = UI.ZoomManager.ZoomManager.instance().zoomFactor(); const rect = this.contentArea.getBoundingClientRect(); const availableSize = - new UI.Geometry.Size(Math.max(rect.width * zoomFactor, 1), Math.max(rect.height * zoomFactor, 1)); - const preferredSize = new UI.Geometry.Size( + new Geometry.Size(Math.max(rect.width * zoomFactor, 1), Math.max(rect.height * zoomFactor, 1)); + const preferredSize = new Geometry.Size( Math.max((rect.width - 2 * (this.handleWidth || 0)) * zoomFactor, 1), Math.max((rect.height - (this.handleHeight || 0)) * zoomFactor, 1)); this.model.setAvailableSize(availableSize, preferredSize);
diff --git a/front_end/panels/emulation/components/BUILD.gn b/front_end/panels/emulation/components/BUILD.gn index e238e22..ad588c4 100644 --- a/front_end/panels/emulation/components/BUILD.gn +++ b/front_end/panels/emulation/components/BUILD.gn
@@ -9,9 +9,12 @@ sources = [ "DeviceSizeInputElement.ts" ] deps = [ + "../../../core/platform:bundle", "../../../models/emulation:bundle", "../../../ui/components/helpers:bundle", + "../../../ui/legacy:bundle", "../../../ui/lit:bundle", + "../../../ui/visual_logging:bundle", ] }
diff --git a/front_end/panels/layer_viewer/BUILD.gn b/front_end/panels/layer_viewer/BUILD.gn index 4920c87..1afb516 100644 --- a/front_end/panels/layer_viewer/BUILD.gn +++ b/front_end/panels/layer_viewer/BUILD.gn
@@ -32,6 +32,7 @@ "../../core/i18n:bundle", "../../core/platform:bundle", "../../core/sdk:bundle", + "../../models/geometry:bundle", "../../ui/legacy:bundle", "../../ui/legacy/components/perf_ui:bundle", ]
diff --git a/front_end/panels/layer_viewer/Layers3DView.ts b/front_end/panels/layer_viewer/Layers3DView.ts index 814ed05..dd3bd18 100644 --- a/front_end/panels/layer_viewer/Layers3DView.ts +++ b/front_end/panels/layer_viewer/Layers3DView.ts
@@ -35,6 +35,7 @@ import * as Platform from '../../core/platform/platform.js'; import type * as SDK from '../../core/sdk/sdk.js'; import type * as Protocol from '../../generated/protocol.js'; +import * as Geometry from '../../models/geometry/geometry.js'; import * as UI from '../../ui/legacy/legacy.js'; import * as VisualLogging from '../../ui/visual_logging/visual_logging.js'; @@ -364,7 +365,7 @@ let bounds; for (let i = 0; i < this.rects.length; ++i) { - bounds = UI.Geometry.boundsForTransformedPoints(scaleAndRotationMatrix, this.rects[i].vertices, bounds); + bounds = Geometry.boundsForTransformedPoints(scaleAndRotationMatrix, this.rects[i].vertices, bounds); } if (bounds) { @@ -1222,12 +1223,12 @@ // Vertices of the quad with transform matrix applied const points = []; for (i = 0; i < 4; ++i) { - points[i] = UI.Geometry.multiplyVectorByMatrixAndNormalize( - new UI.Geometry.Vector(this.vertices[i * 3], this.vertices[i * 3 + 1], this.vertices[i * 3 + 2]), matrix); + points[i] = Geometry.multiplyVectorByMatrixAndNormalize( + new Geometry.Vector(this.vertices[i * 3], this.vertices[i * 3 + 1], this.vertices[i * 3 + 2]), matrix); } // Calculating quad plane normal - const normal = UI.Geometry.crossProduct( - UI.Geometry.subtract(points[1], points[0]), UI.Geometry.subtract(points[2], points[1])); + const normal = + Geometry.crossProduct(Geometry.subtract(points[1], points[0]), Geometry.subtract(points[2], points[1])); // General form of the equation of the quad plane: A * x + B * y + C * z + D = 0 const A = normal.x; const B = normal.y; @@ -1236,14 +1237,13 @@ // Finding t from the equation const t = -(D + A * x0 + B * y0) / C; // Point of the intersection - const pt = new UI.Geometry.Vector(x0, y0, t); + const pt = new Geometry.Vector(x0, y0, t); // Vectors from the intersection point to vertices of the quad - const tVects = points.map(UI.Geometry.subtract.bind(null, pt)); + const tVects = points.map(Geometry.subtract.bind(null, pt)); // Intersection point lies inside of the polygon if scalar products of normal of the plane and // cross products of successive tVects are all nonstrictly above or all nonstrictly below zero for (i = 0; i < tVects.length; ++i) { - const product = - UI.Geometry.scalarProduct(normal, UI.Geometry.crossProduct(tVects[i], tVects[(i + 1) % tVects.length])); + const product = Geometry.scalarProduct(normal, Geometry.crossProduct(tVects[i], tVects[(i + 1) % tVects.length])); if (product < 0) { return undefined; }
diff --git a/front_end/panels/layers/LayerTreeModel.ts b/front_end/panels/layers/LayerTreeModel.ts index f20eb4c..dca8dfd 100644 --- a/front_end/panels/layers/LayerTreeModel.ts +++ b/front_end/panels/layers/LayerTreeModel.ts
@@ -32,7 +32,7 @@ import * as SDK from '../../core/sdk/sdk.js'; import type * as ProtocolProxyApi from '../../generated/protocol-proxy-api.js'; import type * as Protocol from '../../generated/protocol.js'; -import * as UI from '../../ui/legacy/legacy.js'; +import * as Geometry from '../../models/geometry/geometry.js'; export class LayerTreeModel extends SDK.SDKModel.SDKModel<EventTypes> { readonly layerTreeAgent: ProtocolProxyApi.LayerTreeApi; @@ -405,10 +405,10 @@ if (this.layerPayload.transform) { const transformMatrix = this.matrixFromArray(this.layerPayload.transform); - const anchorVector = new UI.Geometry.Vector( + const anchorVector = new Geometry.Vector( this.layerPayload.width * this.anchorPoint()[0], this.layerPayload.height * this.anchorPoint()[1], this.anchorPoint()[2]); - const anchorPoint = UI.Geometry.multiplyVectorByMatrixAndNormalize(anchorVector, matrix); + const anchorPoint = Geometry.multiplyVectorByMatrixAndNormalize(anchorVector, matrix); const anchorMatrix = new WebKitCSSMatrix().translate(-anchorPoint.x, -anchorPoint.y, -anchorPoint.z); matrix = anchorMatrix.inverse().multiply(transformMatrix.multiply(anchorMatrix.multiply(matrix))); } @@ -426,8 +426,8 @@ this.quadInternal = []; const vertices = this.createVertexArrayForRect(this.layerPayload.width, this.layerPayload.height); for (let i = 0; i < 4; ++i) { - const point = UI.Geometry.multiplyVectorByMatrixAndNormalize( - new UI.Geometry.Vector(vertices[i * 3], vertices[i * 3 + 1], vertices[i * 3 + 2]), matrix); + const point = Geometry.multiplyVectorByMatrixAndNormalize( + new Geometry.Vector(vertices[i * 3], vertices[i * 3 + 1], vertices[i * 3 + 2]), matrix); this.quadInternal.push(point.x, point.y); }
diff --git a/front_end/panels/lighthouse/BUILD.gn b/front_end/panels/lighthouse/BUILD.gn index e89a67e..30ddf99 100644 --- a/front_end/panels/lighthouse/BUILD.gn +++ b/front_end/panels/lighthouse/BUILD.gn
@@ -38,11 +38,12 @@ "../../core/protocol_client:bundle", "../../core/root:bundle", "../../core/sdk:bundle", + "../../models/geometry:bundle", "../../models/text_utils:bundle", "../../models/trace:bundle", "../../models/workspace:bundle", "../../panels/emulation:bundle", - "../../third_party/lighthouse/report:report", + "../../third_party/lighthouse/report", "../../ui/legacy:bundle", "../../ui/legacy/components/utils:bundle", ]
diff --git a/front_end/panels/lighthouse/LighthouseStatusView.ts b/front_end/panels/lighthouse/LighthouseStatusView.ts index 982ecd8..37305a4 100644 --- a/front_end/panels/lighthouse/LighthouseStatusView.ts +++ b/front_end/panels/lighthouse/LighthouseStatusView.ts
@@ -5,6 +5,7 @@ import * as Common from '../../core/common/common.js'; import * as i18n from '../../core/i18n/i18n.js'; +import * as Geometry from '../../models/geometry/geometry.js'; import type * as Buttons from '../../ui/components/buttons/buttons.js'; import * as UI from '../../ui/legacy/legacy.js'; @@ -217,7 +218,7 @@ this.dialog.setDefaultFocusedElement(cancelButton); this.dialog.setSizeBehavior(UI.GlassPane.SizeBehavior.SET_EXACT_WIDTH_MAX_HEIGHT); - this.dialog.setMaxContentSize(new UI.Geometry.Size(500, 400)); + this.dialog.setMaxContentSize(new Geometry.Size(500, 400)); } private reset(): void {
diff --git a/front_end/panels/lighthouse/LighthouseTimespanView.ts b/front_end/panels/lighthouse/LighthouseTimespanView.ts index 623ab54..59249d9 100644 --- a/front_end/panels/lighthouse/LighthouseTimespanView.ts +++ b/front_end/panels/lighthouse/LighthouseTimespanView.ts
@@ -4,6 +4,7 @@ /* eslint-disable rulesdir/no-imperative-dom-api */ import * as i18n from '../../core/i18n/i18n.js'; +import * as Geometry from '../../models/geometry/geometry.js'; import * as Buttons from '../../ui/components/buttons/buttons.js'; import * as UI from '../../ui/legacy/legacy.js'; @@ -105,7 +106,7 @@ dialogRoot.appendChild(fragment.element()); this.setSizeBehavior(UI.GlassPane.SizeBehavior.SET_EXACT_WIDTH_MAX_HEIGHT); - this.setMaxContentSize(new UI.Geometry.Size(500, 400)); + this.setMaxContentSize(new Geometry.Size(500, 400)); this.reset(); }
diff --git a/front_end/panels/sensors/BUILD.gn b/front_end/panels/sensors/BUILD.gn index 0a5894c..13b5126 100644 --- a/front_end/panels/sensors/BUILD.gn +++ b/front_end/panels/sensors/BUILD.gn
@@ -25,6 +25,7 @@ "../../core/host:bundle", "../../core/i18n:bundle", "../../core/sdk:bundle", + "../../models/geometry:bundle", "../../panels/mobile_throttling:bundle", "../../ui/components/buttons:bundle", "../../ui/components/cards:bundle",
diff --git a/front_end/panels/sensors/SensorsView.ts b/front_end/panels/sensors/SensorsView.ts index 6153cb2..d8e16f3 100644 --- a/front_end/panels/sensors/SensorsView.ts +++ b/front_end/panels/sensors/SensorsView.ts
@@ -7,6 +7,7 @@ import * as Host from '../../core/host/host.js'; import * as i18n from '../../core/i18n/i18n.js'; import * as SDK from '../../core/sdk/sdk.js'; +import * as Geometry from '../../models/geometry/geometry.js'; import * as UI from '../../ui/legacy/legacy.js'; import * as VisualLogging from '../../ui/visual_logging/visual_logging.js'; import * as MobileThrottling from '../mobile_throttling/mobile_throttling.js'; @@ -208,7 +209,7 @@ private orientationLayer!: HTMLDivElement; private boxElement?: HTMLElement; private boxMatrix?: DOMMatrix; - private mouseDownVector?: UI.Geometry.Vector|null; + private mouseDownVector?: Geometry.Vector|null; private originalBoxMatrix?: DOMMatrix; constructor() { @@ -720,7 +721,7 @@ // // |this.boxMatrix| is set in the Device Orientation coordinate space // because it represents the phone model we show users and also because the - // calculations in UI.Geometry.EulerAngles assume this coordinate space (so + // calculations in Geometry.EulerAngles assume this coordinate space (so // we apply the rotations in the Z-X'-Y'' order). // The CSS transforms, on the other hand, are done in the CSS coordinate // space, so we need to convert 2) to 1) while keeping 3) in mind. We can @@ -743,11 +744,11 @@ event.consume(true); let axis, angle; if (event.shiftKey) { - axis = new UI.Geometry.Vector(0, 0, 1); + axis = new Geometry.Vector(0, 0, 1); angle = (mouseMoveVector.x - this.mouseDownVector.x) * ShiftDragOrientationSpeed; } else { - axis = UI.Geometry.crossProduct(this.mouseDownVector, mouseMoveVector); - angle = UI.Geometry.calculateAngle(this.mouseDownVector, mouseMoveVector); + axis = Geometry.crossProduct(this.mouseDownVector, mouseMoveVector); + angle = Geometry.calculateAngle(this.mouseDownVector, mouseMoveVector); } // See the comment in setBoxOrientation() for a longer explanation about @@ -758,7 +759,7 @@ const currentMatrix = new DOMMatrixReadOnly().rotateAxisAngle(-axis.x, axis.z, axis.y, angle).multiply(this.originalBoxMatrix); - const eulerAngles = UI.Geometry.EulerAngles.fromDeviceOrientationRotationMatrix(currentMatrix); + const eulerAngles = Geometry.EulerAngles.fromDeviceOrientationRotationMatrix(currentMatrix); const newOrientation = new SDK.EmulationModel.DeviceOrientation(eulerAngles.alpha, eulerAngles.beta, eulerAngles.gamma); this.setDeviceOrientation(newOrientation, DeviceOrientationModificationSource.USER_DRAG); @@ -782,17 +783,17 @@ return true; } - private calculateRadiusVector(x: number, y: number): UI.Geometry.Vector|null { + private calculateRadiusVector(x: number, y: number): Geometry.Vector|null { const rect = this.stageElement.getBoundingClientRect(); const radius = Math.max(rect.width, rect.height) / 2; const sphereX = (x - rect.left - rect.width / 2) / radius; const sphereY = (y - rect.top - rect.height / 2) / radius; const sqrSum = sphereX * sphereX + sphereY * sphereY; if (sqrSum > 0.5) { - return new UI.Geometry.Vector(sphereX, sphereY, 0.5 / Math.sqrt(sqrSum)); + return new Geometry.Vector(sphereX, sphereY, 0.5 / Math.sqrt(sqrSum)); } - return new UI.Geometry.Vector(sphereX, sphereY, Math.sqrt(1 - sqrSum)); + return new Geometry.Vector(sphereX, sphereY, Math.sqrt(1 - sqrSum)); } private appendTouchControl(): void {
diff --git a/front_end/panels/sources/BUILD.gn b/front_end/panels/sources/BUILD.gn index 15163b9..83387bb 100644 --- a/front_end/panels/sources/BUILD.gn +++ b/front_end/panels/sources/BUILD.gn
@@ -76,6 +76,7 @@ "../../models/breakpoints:bundle", "../../models/extensions:bundle", "../../models/formatter:bundle", + "../../models/geometry:bundle", "../../models/issues_manager:bundle", "../../models/persistence:bundle", "../../models/source_map_scopes:bundle",
diff --git a/front_end/panels/sources/CSSPlugin.ts b/front_end/panels/sources/CSSPlugin.ts index dfa0ed8..a0e5c94 100644 --- a/front_end/panels/sources/CSSPlugin.ts +++ b/front_end/panels/sources/CSSPlugin.ts
@@ -10,6 +10,7 @@ import * as SDK from '../../core/sdk/sdk.js'; import type * as Protocol from '../../generated/protocol.js'; import * as Bindings from '../../models/bindings/bindings.js'; +import * as Geometry from '../../models/geometry/geometry.js'; import * as Workspace from '../../models/workspace/workspace.js'; import * as CodeMirror from '../../third_party/codemirror.next/codemirror.next.js'; import * as IconButton from '../../ui/components/icon_button/icon_button.js'; @@ -103,7 +104,7 @@ from: number, to: number, onColor: (pos: number, parsedColor: Common.Color.Color, text: string) => void, - onCurve: (pos: number, curve: UI.Geometry.CubicBezier, text: string) => void, + onCurve: (pos: number, curve: Geometry.CubicBezier, text: string) => void, ): void { let line = state.doc.lineAt(from); function getToken(from: number, to: number): string { @@ -134,7 +135,7 @@ if (parsedColor) { onColor(node.from, parsedColor, content); } else { - const parsedCurve = UI.Geometry.CubicBezier.parse(content); + const parsedCurve = Geometry.CubicBezier.parse(content); if (parsedCurve) { onCurve(node.from, parsedCurve, content); } @@ -199,7 +200,7 @@ } class CurveSwatchWidget extends CodeMirror.WidgetType { - constructor(readonly curve: UI.Geometry.CubicBezier, readonly text: string) { + constructor(readonly curve: Geometry.CubicBezier, readonly text: string) { super(); } @@ -249,7 +250,7 @@ type: TooltipType.CURVE, pos: number, text: string, - curve: UI.Geometry.CubicBezier, + curve: Geometry.CubicBezier, swatch: IconButton.Icon.Icon, };
diff --git a/front_end/panels/timeline/BUILD.gn b/front_end/panels/timeline/BUILD.gn index cd1eef2..22c4b7a 100644 --- a/front_end/panels/timeline/BUILD.gn +++ b/front_end/panels/timeline/BUILD.gn
@@ -112,6 +112,7 @@ "../../generated:protocol", "../../models/cpu_profile:bundle", "../../models/extensions:bundle", + "../../models/geometry:bundle", "../../models/source_map_scopes:bundle", "../../models/text_utils:bundle", "../../models/trace:bundle",
diff --git a/front_end/panels/timeline/LayoutShiftsTrackAppender.ts b/front_end/panels/timeline/LayoutShiftsTrackAppender.ts index 56fbf1f..0db7569 100644 --- a/front_end/panels/timeline/LayoutShiftsTrackAppender.ts +++ b/front_end/panels/timeline/LayoutShiftsTrackAppender.ts
@@ -5,9 +5,9 @@ import * as Common from '../../core/common/common.js'; import * as i18n from '../../core/i18n/i18n.js'; +import * as Geometry from '../../models/geometry/geometry.js'; import * as Trace from '../../models/trace/trace.js'; import * as ComponentHelpers from '../../ui/components/helpers/helpers.js'; -import * as UI from '../../ui/legacy/legacy.js'; import * as ThemeSupport from '../../ui/legacy/theme_support/theme_support.js'; import {buildGroupStyle, buildTrackHeader} from './AppenderUtils.js'; @@ -144,7 +144,7 @@ if (Trace.Types.Events.isSyntheticLayoutShift(event)) { // Screenshots are max 500x500 naturally, but on a laptop in dock-to-right, 500px tall usually doesn't fit. // In the future, we may investigate a way to dynamically scale this tooltip content per available space. - const maxSize = new UI.Geometry.Size(510, 400); + const maxSize = new Geometry.Size(510, 400); const vizElem = LayoutShiftsTrackAppender.createShiftViz(event, this.#parsedTrace, maxSize); if (vizElem) { info.additionalElements.push(vizElem); @@ -227,7 +227,7 @@ static createShiftViz( event: Trace.Types.Events.SyntheticLayoutShift, parsedTrace: Trace.Handlers.Types.ParsedTrace, - maxSize: UI.Geometry.Size): HTMLElement|undefined { + maxSize: Geometry.Size): HTMLElement|undefined { const screenshots = event.parsedData.screenshots; const {viewportRect, devicePixelRatio: dpr} = parsedTrace.Meta; const vizContainer = document.createElement('div');
diff --git a/front_end/panels/timeline/TimelinePaintProfilerView.ts b/front_end/panels/timeline/TimelinePaintProfilerView.ts index 6e80b0e..164c9a3 100644 --- a/front_end/panels/timeline/TimelinePaintProfilerView.ts +++ b/front_end/panels/timeline/TimelinePaintProfilerView.ts
@@ -5,6 +5,7 @@ import * as SDK from '../../core/sdk/sdk.js'; import type * as Protocol from '../../generated/protocol.js'; +import * as Geometry from '../../models/geometry/geometry.js'; import * as Trace from '../../models/trace/trace.js'; import * as UI from '../../ui/legacy/legacy.js'; import * as LayerViewer from '../layer_viewer/layer_viewer.js'; @@ -257,7 +258,7 @@ .translate(clientWidth / 2, clientHeight / 2) .scale(scale, scale) .translate(-width / 2, -height / 2); - const bounds = UI.Geometry.boundsForTransformedPoints(matrix, [0, 0, 0, width, height, 0]); + const bounds = Geometry.boundsForTransformedPoints(matrix, [0, 0, 0, width, height, 0]); this.transformController.clampOffsets( paddingX - bounds.maxX, clientWidth - paddingX - bounds.minX, paddingY - bounds.maxY, clientHeight - paddingY - bounds.minY);
diff --git a/front_end/ui/legacy/BUILD.gn b/front_end/ui/legacy/BUILD.gn index 3feb1a2..c9446f6 100644 --- a/front_end/ui/legacy/BUILD.gn +++ b/front_end/ui/legacy/BUILD.gn
@@ -62,7 +62,6 @@ "FilterSuggestionBuilder.ts", "ForwardedInputEventHandler.ts", "Fragment.ts", - "Geometry.ts", "GlassPane.ts", "Infobar.ts", "InplaceEditor.ts", @@ -111,6 +110,7 @@ "../../core/platform:bundle", "../../core/root:bundle", "../../core/sdk:bundle", + "../../models/geometry:bundle", "../../models/text_utils:bundle", "../../ui/legacy/theme_support:bundle", "../components/adorners:bundle", @@ -183,7 +183,6 @@ "DockController.test.ts", "FilterBar.test.ts", "Fragment.test.ts", - "Geometry.test.ts", "Infobar.test.ts", "InspectorView.test.ts", "KeyboardShortcut.test.ts",
diff --git a/front_end/ui/legacy/GlassPane.ts b/front_end/ui/legacy/GlassPane.ts index d60cbc4..debb1ab 100644 --- a/front_end/ui/legacy/GlassPane.ts +++ b/front_end/ui/legacy/GlassPane.ts
@@ -2,7 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. /* eslint-disable rulesdir/no-imperative-dom-api */ -import type {Size} from './Geometry.js'; +import type {Size} from '../../models/geometry/geometry.js'; + import glassPaneStyles from './glassPane.css.js'; import {deepElementFromEvent, measuredScrollbarWidth} from './UIUtils.js'; import {Widget} from './Widget.js';
diff --git a/front_end/ui/legacy/SoftDropDown.ts b/front_end/ui/legacy/SoftDropDown.ts index e84023f..5b9cec5 100644 --- a/front_end/ui/legacy/SoftDropDown.ts +++ b/front_end/ui/legacy/SoftDropDown.ts
@@ -6,11 +6,11 @@ import type * as Common from '../../core/common/common.js'; import * as i18n from '../../core/i18n/i18n.js'; import * as Platform from '../../core/platform/platform.js'; +import * as Geometry from '../../models/geometry/geometry.js'; import * as IconButton from '../components/icon_button/icon_button.js'; import * as VisualLogging from '../visual_logging/visual_logging.js'; import * as ARIAUtils from './ARIAUtils.js'; -import {Size} from './Geometry.js'; import {AnchorBehavior, GlassPane, MarginBehavior, PointerEventsBehavior} from './GlassPane.js'; import {ListControl, type ListDelegate, ListMode} from './ListControl.js'; import {Events as ListModelEvents, type ItemsReplacedEvent, type ListModel} from './ListModel.js'; @@ -129,7 +129,7 @@ private updateGlasspaneSize(): void { const maxHeight = this.rowHeight * (Math.min(this.model.length, 9)); - this.glassPane.setMaxContentSize(new Size(this.width, maxHeight)); + this.glassPane.setMaxContentSize(new Geometry.Size(this.width, maxHeight)); this.list.viewportResized(); }
diff --git a/front_end/ui/legacy/SplitWidget.ts b/front_end/ui/legacy/SplitWidget.ts index dee82ac..c501359 100644 --- a/front_end/ui/legacy/SplitWidget.ts +++ b/front_end/ui/legacy/SplitWidget.ts
@@ -32,10 +32,10 @@ import * as Common from '../../core/common/common.js'; import * as Platform from '../../core/platform/platform.js'; +import * as Geometry from '../../models/geometry/geometry.js'; import * as VisualLogging from '../visual_logging/visual_logging.js'; import * as ARIAUtils from './ARIAUtils.js'; -import {Constraints} from './Geometry.js'; import {Events as ResizerWidgetEvents, type ResizeUpdatePositionEvent, SimpleResizerWidget} from './ResizerWidget.js'; import splitWidgetStyles from './splitWidget.css.js'; import {ToolbarButton} from './Toolbar.js'; @@ -612,7 +612,8 @@ const totalSize = this.#totalSizeDIP(); const zoomFactor = this.#constraintsInDip ? 1 : ZoomManager.instance().zoomFactor(); - let constraints: Constraints = this.#sidebarWidget ? this.#sidebarWidget.constraints() : new Constraints(); + let constraints: Geometry.Constraints = + this.#sidebarWidget ? this.#sidebarWidget.constraints() : new Geometry.Constraints(); let minSidebarSize: 20|number = this.isVertical() ? constraints.minimum.width : constraints.minimum.height; if (!minSidebarSize) { minSidebarSize = MinPadding; @@ -634,7 +635,7 @@ } preferredSidebarSize += zoomFactor; // 1 css pixel for splitter border. - constraints = this.#mainWidget ? this.#mainWidget.constraints() : new Constraints(); + constraints = this.#mainWidget ? this.#mainWidget.constraints() : new Geometry.Constraints(); let minMainSize: 20|number = this.isVertical() ? constraints.minimum.width : constraints.minimum.height; if (!minMainSize) { minMainSize = MinPadding; @@ -690,16 +691,18 @@ this.#updateLayout(); } - override calculateConstraints(): Constraints { + override calculateConstraints(): Geometry.Constraints { if (this.#showMode === ShowMode.ONLY_MAIN) { - return this.#mainWidget ? this.#mainWidget.constraints() : new Constraints(); + return this.#mainWidget ? this.#mainWidget.constraints() : new Geometry.Constraints(); } if (this.#showMode === ShowMode.ONLY_SIDEBAR) { - return this.#sidebarWidget ? this.#sidebarWidget.constraints() : new Constraints(); + return this.#sidebarWidget ? this.#sidebarWidget.constraints() : new Geometry.Constraints(); } - let mainConstraints: Constraints = this.#mainWidget ? this.#mainWidget.constraints() : new Constraints(); - let sidebarConstraints: Constraints = this.#sidebarWidget ? this.#sidebarWidget.constraints() : new Constraints(); + let mainConstraints: Geometry.Constraints = + this.#mainWidget ? this.#mainWidget.constraints() : new Geometry.Constraints(); + let sidebarConstraints: Geometry.Constraints = + this.#sidebarWidget ? this.#sidebarWidget.constraints() : new Geometry.Constraints(); const min = MinPadding; if (this.#isVertical) { mainConstraints = mainConstraints.widthToMax(min).addWidth(1); // 1 for splitter
diff --git a/front_end/ui/legacy/SuggestBox.ts b/front_end/ui/legacy/SuggestBox.ts index 2dd347d..7b5659c 100644 --- a/front_end/ui/legacy/SuggestBox.ts +++ b/front_end/ui/legacy/SuggestBox.ts
@@ -32,11 +32,11 @@ import * as i18n from '../../core/i18n/i18n.js'; import * as Platform from '../../core/platform/platform.js'; +import * as Geometry from '../../models/geometry/geometry.js'; import type * as TextUtils from '../../models/text_utils/text_utils.js'; import * as VisualLogging from '../visual_logging/visual_logging.js'; import * as ARIAUtils from './ARIAUtils.js'; -import {Size} from './Geometry.js'; import {AnchorBehavior, GlassPane} from './GlassPane.js'; import {ListControl, type ListDelegate, ListMode} from './ListControl.js'; import {ListModel} from './ListModel.js'; @@ -125,7 +125,7 @@ const maxWidth = this.maxWidth(items); const length = this.maxItemsHeight ? Math.min(this.maxItemsHeight, items.length) : items.length; const maxHeight = length * this.rowHeight; - this.glassPane.setMaxContentSize(new Size(maxWidth, maxHeight)); + this.glassPane.setMaxContentSize(new Geometry.Size(maxWidth, maxHeight)); } private maxWidth(items: Suggestion[]): number {
diff --git a/front_end/ui/legacy/TabbedPane.ts b/front_end/ui/legacy/TabbedPane.ts index fcadceb..f410d72 100644 --- a/front_end/ui/legacy/TabbedPane.ts +++ b/front_end/ui/legacy/TabbedPane.ts
@@ -35,13 +35,13 @@ import * as Common from '../../core/common/common.js'; import * as i18n from '../../core/i18n/i18n.js'; import * as Platform from '../../core/platform/platform.js'; +import * as Geometry from '../../models/geometry/geometry.js'; import * as Buttons from '../../ui/components/buttons/buttons.js'; import * as VisualLogging from '../../ui/visual_logging/visual_logging.js'; import * as IconButton from '../components/icon_button/icon_button.js'; import * as ARIAUtils from './ARIAUtils.js'; import {ContextMenu} from './ContextMenu.js'; -import {Constraints, Size} from './Geometry.js'; import tabbedPaneStyles from './tabbedPane.css.js'; import type {Toolbar} from './Toolbar.js'; import {Tooltip} from './Tooltip.js'; @@ -551,14 +551,14 @@ this.tabSlider.classList.toggle('enabled', enable); } - override calculateConstraints(): Constraints { + override calculateConstraints(): Geometry.Constraints { let constraints = super.calculateConstraints(); - const minContentConstraints = new Constraints(new Size(0, 0), new Size(50, 50)); + const minContentConstraints = new Geometry.Constraints(new Geometry.Size(0, 0), new Geometry.Size(50, 50)); constraints = constraints.widthToMax(minContentConstraints).heightToMax(minContentConstraints); if (this.verticalTabLayout) { - constraints = constraints.addWidth(new Constraints(new Size(120, 0))); + constraints = constraints.addWidth(new Geometry.Constraints(new Geometry.Size(120, 0))); } else { - constraints = constraints.addHeight(new Constraints(new Size(0, 30))); + constraints = constraints.addHeight(new Geometry.Constraints(new Geometry.Size(0, 30))); } return constraints; }
diff --git a/front_end/ui/legacy/UIUtils.ts b/front_end/ui/legacy/UIUtils.ts index 9c34fd9..fd5039b 100644 --- a/front_end/ui/legacy/UIUtils.ts +++ b/front_end/ui/legacy/UIUtils.ts
@@ -41,6 +41,7 @@ import * as i18n from '../../core/i18n/i18n.js'; import * as Platform from '../../core/platform/platform.js'; import * as Root from '../../core/root/root.js'; +import * as Geometry from '../../models/geometry/geometry.js'; import * as TextUtils from '../../models/text_utils/text_utils.js'; import * as Buttons from '../components/buttons/buttons.js'; import * as IconButton from '../components/icon_button/icon_button.js'; @@ -53,7 +54,6 @@ import checkboxTextLabelStyles from './checkboxTextLabel.css.js'; import confirmDialogStyles from './confirmDialog.css.js'; import {Dialog} from './Dialog.js'; -import {Size} from './Geometry.js'; import {GlassPane, PointerEventsBehavior, SizeBehavior} from './GlassPane.js'; import inlineButtonStyles from './inlineButton.css.js'; import inspectorCommonStyles from './inspectorCommon.css.js'; @@ -887,7 +887,7 @@ } } -export function measurePreferredSize(element: Element, containerElement?: Element|null): Size { +export function measurePreferredSize(element: Element, containerElement?: Element|null): Geometry.Size { const oldParent = element.parentElement; const oldNextSibling = element.nextSibling; containerElement = containerElement || element.ownerDocument.body; @@ -901,7 +901,7 @@ } else { element.remove(); } - return new Size(result.width, result.height); + return new Geometry.Size(result.width, result.height); } class InvokeOnceHandlers {
diff --git a/front_end/ui/legacy/Widget.ts b/front_end/ui/legacy/Widget.ts index 87d596a..d2a7fab 100644 --- a/front_end/ui/legacy/Widget.ts +++ b/front_end/ui/legacy/Widget.ts
@@ -32,9 +32,9 @@ import '../../core/dom_extension/dom_extension.js'; import * as Platform from '../../core/platform/platform.js'; +import * as Geometry from '../../models/geometry/geometry.js'; import * as Lit from '../../ui/lit/lit.js'; -import {Constraints, Size} from './Geometry.js'; import {createShadowRootWithCoreStyles} from './UIUtils.js'; import {XWidget} from './XWidget.js'; @@ -266,8 +266,8 @@ #invalidationsSuspended = 0; #parentWidget: Widget|null = null; #defaultFocusedElement?: Element|null; - #cachedConstraints?: Constraints; - #constraints?: Constraints; + #cachedConstraints?: Geometry.Constraints; + #constraints?: Geometry.Constraints; #invalidationsRequested?: boolean; #externallyManaged?: boolean; #updateComplete = UPDATE_COMPLETE; @@ -770,11 +770,11 @@ return this.element.hasFocus(); } - calculateConstraints(): Constraints { - return new Constraints(); + calculateConstraints(): Geometry.Constraints { + return new Geometry.Constraints(); } - constraints(): Constraints { + constraints(): Geometry.Constraints { if (typeof this.#constraints !== 'undefined') { return this.#constraints; } @@ -785,16 +785,17 @@ } setMinimumAndPreferredSizes(width: number, height: number, preferredWidth: number, preferredHeight: number): void { - this.#constraints = new Constraints(new Size(width, height), new Size(preferredWidth, preferredHeight)); + this.#constraints = + new Geometry.Constraints(new Geometry.Size(width, height), new Geometry.Size(preferredWidth, preferredHeight)); this.invalidateConstraints(); } setMinimumSize(width: number, height: number): void { - this.minimumSize = new Size(width, height); + this.minimumSize = new Geometry.Size(width, height); } - set minimumSize(size: Size) { - this.#constraints = new Constraints(size); + set minimumSize(size: Geometry.Size) { + this.#constraints = new Geometry.Constraints(size); this.invalidateConstraints(); } @@ -949,8 +950,8 @@ this.contentElement.classList.add('vbox'); } - override calculateConstraints(): Constraints { - let constraints: Constraints = new Constraints(); + override calculateConstraints(): Geometry.Constraints { + let constraints: Geometry.Constraints = new Geometry.Constraints(); function updateForChild(this: Widget): void { const child = this.constraints(); @@ -988,8 +989,8 @@ this.contentElement.classList.add('hbox'); } - override calculateConstraints(): Constraints { - let constraints: Constraints = new Constraints(); + override calculateConstraints(): Geometry.Constraints { + let constraints: Geometry.Constraints = new Geometry.Constraints(); function updateForChild(this: Widget): void { const child = this.constraints();
diff --git a/front_end/ui/legacy/components/inline_editor/AnimationTimingModel.ts b/front_end/ui/legacy/components/inline_editor/AnimationTimingModel.ts index 25cd979..631b757 100644 --- a/front_end/ui/legacy/components/inline_editor/AnimationTimingModel.ts +++ b/front_end/ui/legacy/components/inline_editor/AnimationTimingModel.ts
@@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import * as UI from '../../legacy.js'; +import * as Geometry from '../../../../models/geometry/geometry.js'; import {CSSLinearEasingModel} from './CSSLinearEasingModel.js'; @@ -21,8 +21,8 @@ return cssLinearEasingModel; } - return UI.Geometry.CubicBezier.parse(text) || null; + return Geometry.CubicBezier.parse(text) || null; } } -export const LINEAR_BEZIER = UI.Geometry.LINEAR_BEZIER; +export const LINEAR_BEZIER = Geometry.LINEAR_BEZIER;
diff --git a/front_end/ui/legacy/components/inline_editor/AnimationTimingUI.ts b/front_end/ui/legacy/components/inline_editor/AnimationTimingUI.ts index 2c44c4d..c9795b6 100644 --- a/front_end/ui/legacy/components/inline_editor/AnimationTimingUI.ts +++ b/front_end/ui/legacy/components/inline_editor/AnimationTimingUI.ts
@@ -4,6 +4,7 @@ /* eslint-disable rulesdir/no-imperative-dom-api */ import * as Platform from '../../../../core/platform/platform.js'; +import * as Geometry from '../../../../models/geometry/geometry.js'; import * as VisualLogging from '../../../visual_logging/visual_logging.js'; import * as UI from '../../legacy.js'; @@ -15,18 +16,18 @@ interface Params { container: Element; - bezier: UI.Geometry.CubicBezier; - onBezierChange: (bezier: UI.Geometry.CubicBezier) => void; + bezier: Geometry.CubicBezier; + onBezierChange: (bezier: Geometry.CubicBezier) => void; } class BezierCurveUI { #curveUI: BezierUI; - #bezier: UI.Geometry.CubicBezier; + #bezier: Geometry.CubicBezier; #curve: Element; - #mouseDownPosition?: UI.Geometry.Point; - #controlPosition?: UI.Geometry.Point; + #mouseDownPosition?: Geometry.Point; + #controlPosition?: Geometry.Point; #selectedPoint?: number; - #onBezierChange: (bezier: UI.Geometry.CubicBezier) => void; + #onBezierChange: (bezier: Geometry.CubicBezier) => void; constructor({bezier, container, onBezierChange}: Params) { this.#bezier = bezier; @@ -46,9 +47,9 @@ } private dragStart(event: MouseEvent): boolean { - this.#mouseDownPosition = new UI.Geometry.Point(event.x, event.y); + this.#mouseDownPosition = new Geometry.Point(event.x, event.y); const ui = this.#curveUI; - this.#controlPosition = new UI.Geometry.Point( + this.#controlPosition = new Geometry.Point( Platform.NumberUtilities.clamp((event.offsetX - ui.radius) / ui.curveWidth(), 0, 1), (ui.curveHeight() + ui.marginTop + ui.radius - event.offsetY) / ui.curveHeight()); @@ -70,7 +71,7 @@ } const deltaX = (mouseX - this.#mouseDownPosition.x) / this.#curveUI.curveWidth(); const deltaY = (mouseY - this.#mouseDownPosition.y) / this.#curveUI.curveHeight(); - const newPosition = new UI.Geometry.Point( + const newPosition = new Geometry.Point( Platform.NumberUtilities.clamp(this.#controlPosition.x + deltaX, 0, 1), this.#controlPosition.y - deltaY); this.#bezier.controlPoints[this.#selectedPoint] = newPosition; } @@ -85,7 +86,7 @@ this.#onBezierChange(this.#bezier); } - setBezier(bezier: UI.Geometry.CubicBezier): void { + setBezier(bezier: Geometry.CubicBezier): void { this.#bezier = bezier; this.draw(); } @@ -327,7 +328,7 @@ draw(model: AnimationTimingModel, svg: Element): void { if (model instanceof CSSLinearEasingModel) { this.#linearEasingPresentation.draw(model, svg); - } else if (model instanceof UI.Geometry.CubicBezier) { + } else if (model instanceof Geometry.CubicBezier) { this.#bezierPresentation.drawCurve(model, svg); } } @@ -363,7 +364,7 @@ this.#model = model; this.#onChange = onChange; - if (this.#model instanceof UI.Geometry.CubicBezier) { + if (this.#model instanceof Geometry.CubicBezier) { this.#bezierCurveUI = new BezierCurveUI({bezier: this.#model, container: this.#bezierContainer, onBezierChange: this.#onChange}); } else if (this.#model instanceof CSSLinearEasingModel) { @@ -381,7 +382,7 @@ setModel(model: AnimationTimingModel): void { this.#model = model; - if (this.#model instanceof UI.Geometry.CubicBezier) { + if (this.#model instanceof Geometry.CubicBezier) { if (this.#bezierCurveUI) { this.#bezierCurveUI.setBezier(this.#model); } else { @@ -402,7 +403,7 @@ draw(): void { this.#linearEasingContainer.classList.toggle('hidden', !(this.#model instanceof CSSLinearEasingModel)); - this.#bezierContainer.classList.toggle('hidden', !(this.#model instanceof UI.Geometry.CubicBezier)); + this.#bezierContainer.classList.toggle('hidden', !(this.#model instanceof Geometry.CubicBezier)); if (this.#bezierCurveUI) { this.#bezierCurveUI.draw();
diff --git a/front_end/ui/legacy/components/inline_editor/BezierUI.test.ts b/front_end/ui/legacy/components/inline_editor/BezierUI.test.ts index f633669..79f8f0c 100644 --- a/front_end/ui/legacy/components/inline_editor/BezierUI.test.ts +++ b/front_end/ui/legacy/components/inline_editor/BezierUI.test.ts
@@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import * as UI from '../../legacy.js'; +import * as Geometry from '../../../../models/geometry/geometry.js'; import * as InlineEditor from './inline_editor.js'; @@ -28,7 +28,7 @@ }); it('can draw velocity chart correctly', () => { - const bezier = new UI.Geometry.CubicBezier(new UI.Geometry.Point(1, 1), new UI.Geometry.Point(3, 4)); + const bezier = new Geometry.CubicBezier(new Geometry.Point(1, 1), new Geometry.Point(3, 4)); const path = document.createElement('path'); InlineEditor.BezierUI.BezierUI.drawVelocityChart(bezier, path, 10); assert.strictEqual( @@ -67,7 +67,7 @@ controlPointRadius: 3, shouldDrawLine: true, }); - const bezier = new UI.Geometry.CubicBezier(new UI.Geometry.Point(1, 1), new UI.Geometry.Point(3, 4)); + const bezier = new Geometry.CubicBezier(new Geometry.Point(1, 1), new Geometry.Point(3, 4)); const svg = document.createElement('svg'); bezierUI.drawCurve(bezier, svg); /*
diff --git a/front_end/ui/legacy/components/inline_editor/BezierUI.ts b/front_end/ui/legacy/components/inline_editor/BezierUI.ts index bed7e54..66ba286 100644 --- a/front_end/ui/legacy/components/inline_editor/BezierUI.ts +++ b/front_end/ui/legacy/components/inline_editor/BezierUI.ts
@@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import * as Geometry from '../../../../models/geometry/geometry.js'; import * as VisualLogging from '../../../visual_logging/visual_logging.js'; import * as UI from '../../legacy.js'; @@ -28,7 +29,7 @@ this.shouldDrawLine = shouldDrawLine; } - static drawVelocityChart(bezier: UI.Geometry.CubicBezier, path: Element, width: number): void { + static drawVelocityChart(bezier: Geometry.CubicBezier, path: Element, width: number): void { const height = Height; let pathBuilder: Array<string|number>|Array<string|number> = ['M', 0, height]; /** @constant */ const sampleSize = 1 / 40; @@ -72,7 +73,7 @@ circle.setAttribute('r', String(this.radius)); } - drawCurve(bezier: UI.Geometry.CubicBezier|null, svg: Element): void { + drawCurve(bezier: Geometry.CubicBezier|null, svg: Element): void { if (!bezier) { return; } @@ -89,13 +90,13 @@ const curve = UI.UIUtils.createSVGChild(group, 'path', 'bezier-path'); const curvePoints = [ - new UI.Geometry.Point( + new Geometry.Point( bezier.controlPoints[0].x * width + this.radius, (1 - bezier.controlPoints[0].y) * height + this.radius + this.marginTop), - new UI.Geometry.Point( + new Geometry.Point( bezier.controlPoints[1].x * width + this.radius, (1 - bezier.controlPoints[1].y) * height + this.radius + this.marginTop), - new UI.Geometry.Point(width + this.radius, this.marginTop + this.radius), + new Geometry.Point(width + this.radius, this.marginTop + this.radius), ]; curve.setAttribute( 'd', 'M' + this.radius + ',' + (height + this.radius + this.marginTop) + ' C' + curvePoints.join(' '));
diff --git a/front_end/ui/legacy/components/inline_editor/CSSAngleUtils.ts b/front_end/ui/legacy/components/inline_editor/CSSAngleUtils.ts index af3ba11..aad1fc3 100644 --- a/front_end/ui/legacy/components/inline_editor/CSSAngleUtils.ts +++ b/front_end/ui/legacy/components/inline_editor/CSSAngleUtils.ts
@@ -3,6 +3,7 @@ // found in the LICENSE file. import * as Platform from '../../../../core/platform/platform.js'; +import * as Geometry from '../../../../models/geometry/geometry.js'; import * as UI from '../../legacy.js'; export const CSSAngleRegex = /(?<value>[+-]?\d*\.?\d+)(?<unit>deg|grad|rad|turn)/; @@ -35,13 +36,13 @@ let value = rad; switch (targetUnit) { case AngleUnit.GRAD: - value = UI.Geometry.radiansToGradians(rad); + value = Geometry.radiansToGradians(rad); break; case AngleUnit.DEG: - value = UI.Geometry.radiansToDegrees(rad); + value = Geometry.radiansToDegrees(rad); break; case AngleUnit.TURN: - value = UI.Geometry.radiansToTurns(rad); + value = Geometry.radiansToTurns(rad); break; } @@ -54,11 +55,11 @@ export const getRadiansFromAngle = (angle: Angle): number => { switch (angle.unit) { case AngleUnit.DEG: - return UI.Geometry.degreesToRadians(angle.value); + return Geometry.degreesToRadians(angle.value); case AngleUnit.GRAD: - return UI.Geometry.gradiansToRadians(angle.value); + return Geometry.gradiansToRadians(angle.value); case AngleUnit.TURN: - return UI.Geometry.turnsToRadians(angle.value); + return Geometry.turnsToRadians(angle.value); } return angle.value;
diff --git a/front_end/ui/legacy/components/inline_editor/CSSShadowEditor.ts b/front_end/ui/legacy/components/inline_editor/CSSShadowEditor.ts index 230258f..50a03cc 100644 --- a/front_end/ui/legacy/components/inline_editor/CSSShadowEditor.ts +++ b/front_end/ui/legacy/components/inline_editor/CSSShadowEditor.ts
@@ -6,6 +6,7 @@ import * as Common from '../../../../core/common/common.js'; import * as i18n from '../../../../core/i18n/i18n.js'; import * as Platform from '../../../../core/platform/platform.js'; +import * as Geometry from '../../../../models/geometry/geometry.js'; import * as VisualLogging from '../../../visual_logging/visual_logging.js'; import * as UI from '../../legacy.js'; @@ -108,7 +109,7 @@ private spreadInput: HTMLInputElement; private spreadSlider: HTMLInputElement; private model!: CSSShadowModel; - private canvasOrigin!: UI.Geometry.Point; + private canvasOrigin!: Geometry.Point; private changedElement?: HTMLInputElement|null; constructor() { super({useShadowDom: true}); @@ -368,10 +369,10 @@ private dragStart(event: MouseEvent): boolean { this.xySlider.focus(); this.updateCanvas(true); - this.canvasOrigin = new UI.Geometry.Point( + this.canvasOrigin = new Geometry.Point( this.xySlider.getBoundingClientRect().left + this.halfCanvasSize, this.xySlider.getBoundingClientRect().top + this.halfCanvasSize); - const clickedPoint = new UI.Geometry.Point(event.x - this.canvasOrigin.x, event.y - this.canvasOrigin.y); + const clickedPoint = new Geometry.Point(event.x - this.canvasOrigin.x, event.y - this.canvasOrigin.y); const thumbPoint = this.sliderThumbPosition(); if (clickedPoint.distanceTo(thumbPoint) >= sliderThumbRadius) { this.dragMove(event); @@ -380,7 +381,7 @@ } private dragMove(event: MouseEvent): void { - let point: UI.Geometry.Point = new UI.Geometry.Point(event.x - this.canvasOrigin.x, event.y - this.canvasOrigin.y); + let point: Geometry.Point = new Geometry.Point(event.x - this.canvasOrigin.x, event.y - this.canvasOrigin.y); if (event.shiftKey) { point = this.snapToClosestDirection(point); } @@ -454,20 +455,20 @@ this.dispatchEventToListeners(Events.SHADOW_CHANGED, this.model); } - private constrainPoint(point: UI.Geometry.Point, max: number): UI.Geometry.Point { + private constrainPoint(point: Geometry.Point, max: number): Geometry.Point { if (Math.abs(point.x) <= max && Math.abs(point.y) <= max) { - return new UI.Geometry.Point(point.x, point.y); + return new Geometry.Point(point.x, point.y); } return point.scale(max / Math.max(Math.abs(point.x), Math.abs(point.y))); } - private snapToClosestDirection(point: UI.Geometry.Point): UI.Geometry.Point { + private snapToClosestDirection(point: Geometry.Point): Geometry.Point { let minDistance: number = Number.MAX_VALUE; - let closestPoint: UI.Geometry.Point = point; + let closestPoint: Geometry.Point = point; const directions = [ - new UI.Geometry.Point(0, -1), new UI.Geometry.Point(1, -1), new UI.Geometry.Point(1, 0), - new UI.Geometry.Point(1, 1), // Southeast + new Geometry.Point(0, -1), new Geometry.Point(1, -1), new Geometry.Point(1, 0), + new Geometry.Point(1, 1), // Southeast ]; for (const direction of directions) { @@ -482,10 +483,10 @@ return closestPoint; } - private sliderThumbPosition(): UI.Geometry.Point { + private sliderThumbPosition(): Geometry.Point { const x = (this.model.offsetX().amount / maxRange) * this.innerCanvasSize; const y = (this.model.offsetY().amount / maxRange) * this.innerCanvasSize; - return this.constrainPoint(new UI.Geometry.Point(x, y), this.innerCanvasSize); + return this.constrainPoint(new Geometry.Point(x, y), this.innerCanvasSize); } }
diff --git a/front_end/ui/legacy/components/object_ui/ObjectPopoverHelper.ts b/front_end/ui/legacy/components/object_ui/ObjectPopoverHelper.ts index f8b9294..8de78bb 100644 --- a/front_end/ui/legacy/components/object_ui/ObjectPopoverHelper.ts +++ b/front_end/ui/legacy/components/object_ui/ObjectPopoverHelper.ts
@@ -33,6 +33,7 @@ import * as i18n from '../../../../core/i18n/i18n.js'; import * as Platform from '../../../../core/platform/platform.js'; import * as SDK from '../../../../core/sdk/sdk.js'; +import * as Geometry from '../../../../models/geometry/geometry.js'; import * as UI from '../../legacy.js'; import * as Components from '../utils/utils.js'; @@ -102,7 +103,7 @@ popoverContentElement.appendChild(section.element); } popoverContentElement.dataset.stableNameForTest = 'object-popover-content'; - popover.setMaxContentSize(new UI.Geometry.Size(300, 250)); + popover.setMaxContentSize(new Geometry.Size(300, 250)); popover.setSizeBehavior(UI.GlassPane.SizeBehavior.SET_EXACT_SIZE); popover.contentElement.appendChild(popoverContentElement); return new ObjectPopoverHelper(linkifier, resultHighlightedAsDOM);
diff --git a/front_end/ui/legacy/components/quick_open/FilteredListWidget.ts b/front_end/ui/legacy/components/quick_open/FilteredListWidget.ts index 28357ff..2cdfa7e 100644 --- a/front_end/ui/legacy/components/quick_open/FilteredListWidget.ts +++ b/front_end/ui/legacy/components/quick_open/FilteredListWidget.ts
@@ -6,6 +6,7 @@ import * as Common from '../../../../core/common/common.js'; import * as i18n from '../../../../core/i18n/i18n.js'; import * as Platform from '../../../../core/platform/platform.js'; +import * as Geometry from '../../../../models/geometry/geometry.js'; import * as TextUtils from '../../../../models/text_utils/text_utils.js'; import * as Diff from '../../../../third_party/diff/diff.js'; import * as TextPrompt from '../../../../ui/components/text_prompt/text_prompt.js'; @@ -171,7 +172,7 @@ this.dialog = new UI.Dialog.Dialog('quick-open'); UI.ARIAUtils.setLabel(this.dialog.contentElement, dialogTitle); - this.dialog.setMaxContentSize(new UI.Geometry.Size(576, 320)); + this.dialog.setMaxContentSize(new Geometry.Size(576, 320)); this.dialog.setSizeBehavior(UI.GlassPane.SizeBehavior.SET_EXACT_WIDTH_MAX_HEIGHT); this.dialog.setContentPosition(null, 22); this.dialog.contentElement.style.setProperty('border-radius', 'var(--sys-shape-corner-medium)');
diff --git a/front_end/ui/legacy/legacy.ts b/front_end/ui/legacy/legacy.ts index 08150ce..c329187 100644 --- a/front_end/ui/legacy/legacy.ts +++ b/front_end/ui/legacy/legacy.ts
@@ -16,7 +16,6 @@ import * as FilterSuggestionBuilder from './FilterSuggestionBuilder.js'; import * as ForwardedInputEventHandler from './ForwardedInputEventHandler.js'; import * as Fragment from './Fragment.js'; -import * as Geometry from './Geometry.js'; import * as GlassPane from './GlassPane.js'; import * as Infobar from './Infobar.js'; import * as InplaceEditor from './InplaceEditor.js'; @@ -71,7 +70,6 @@ FilterSuggestionBuilder, ForwardedInputEventHandler, Fragment, - Geometry, GlassPane, Infobar, InplaceEditor,