Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Dimensions2d class #54

Merged
merged 29 commits into from
Jan 5, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
186a79a
Add Dimensions2d class
amacdonald-google Dec 15, 2020
03c524f
Port additional Toolbox components.
amacdonald-google Dec 15, 2020
eef4b7c
Consolidate and cull duplicated or similar functionality.
amacdonald-google Dec 17, 2020
7cb8ef4
Remove `getStyle`
amacdonald-google Dec 17, 2020
bb22936
Add comments, cull unnecessary code
amacdonald-google Dec 17, 2020
85d9b41
Handle 0 area canvases in WebGlImageSequence
amacdonald-google Dec 17, 2020
821fea8
Polish pass in response to review
amacdonald-google Dec 17, 2020
26c328d
Restore x
amacdonald-google Dec 18, 2020
1276663
Re-work Map classes
amacdonald-google Dec 18, 2020
f4a5c40
Cleanup arrayf
amacdonald-google Dec 18, 2020
4c353d0
Remove unused code
amacdonald-google Dec 18, 2020
6d5393f
Restore ArrayMap
amacdonald-google Dec 18, 2020
0569c8b
Remove unused code in CachedElementVector
amacdonald-google Dec 18, 2020
2731d26
Inline method ComputedStyleService
amacdonald-google Dec 18, 2020
93e665f
Extract duplicated code to ComputedStyleService
amacdonald-google Dec 18, 2020
c93396a
Remove unused Dimensions2dDom code
amacdonald-google Dec 18, 2020
f0bb5f9
Simplify Dimensions cached vector
amacdonald-google Dec 18, 2020
55e56b2
Simplify MatrixDom
amacdonald-google Dec 18, 2020
41c3a4f
Consolidate visible distance from root functions
amacdonald-google Dec 18, 2020
bbc0ccf
Inline single call init function
amacdonald-google Dec 18, 2020
6c394d7
Add comment explaining inspiration for DynamicDefaultMap
amacdonald-google Dec 19, 2020
de16706
Simplify visible-distance-from-root-service
amacdonald-google Dec 19, 2020
9624a3a
Yank abstract classes
amacdonald-google Dec 19, 2020
937735b
Remove a lot of caching classes.
amacdonald-google Dec 19, 2020
726a46e
Remove caching
amacdonald-google Dec 19, 2020
f65bd63
Correct comment
amacdonald-google Dec 19, 2020
2f16261
Remove now unused code
amacdonald-google Dec 19, 2020
c7bf8f5
Respond to review feedback with improvements
amacdonald-google Dec 19, 2020
5debf79
Address feedback from PR
amacdonald-google Jan 5, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/dom/root-element.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const ROOT_ELEMENT = document.children[0];
angusm marked this conversation as resolved.
Show resolved Hide resolved
// Can be cached on load since the browser isn't going to change at run time.
2 changes: 2 additions & 0 deletions src/dom/scroll-element.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const SCROLL_ELEMENT = document.scrollingElement || document.documentElement;
// Can be cached on load since the browser isn't going to change at run time.
60 changes: 60 additions & 0 deletions src/mathf/dimensions-2d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { Vector } from './vector';
import { SCROLL_ELEMENT } from '../dom/scroll-element';
import { ROOT_ELEMENT } from '../dom/root-element';

export class Dimensions2d extends Vector {
angusm marked this conversation as resolved.
Show resolved Hide resolved
get width(): number {
return this.x;
}

get height(): number {
return this.y;
}

static fromCanvas<T extends Dimensions2d>(
element: HTMLCanvasElement = null
): T {
return <T>new this(element.width, element.height);
}

static fromVideo<T extends Dimensions2d>(
element: HTMLVideoElement = null
): T {
return <T>new this(element.videoWidth, element.videoHeight);
}

static fromElementOffset<T extends Dimensions2d>(
element: HTMLElement = null
): T {
if (element) {
return <T>new this(element.offsetWidth, element.offsetHeight);
} else {
return this.fromInnerWindow();
}
}

static fromRootElement<T extends Dimensions2d>() {
return <T>new this(ROOT_ELEMENT.clientWidth, ROOT_ELEMENT.clientHeight);
}

static fromScrollElementClient<T extends Dimensions2d>() {
return <T>new this(SCROLL_ELEMENT.clientWidth, SCROLL_ELEMENT.clientHeight);
}

static fromInnerWindow<T extends Dimensions2d>() {
return <T>new this(window.innerWidth, window.innerHeight);
angusm marked this conversation as resolved.
Show resolved Hide resolved
}

constructor(width: number = 0, height: number = 0) {
super(width, height);
}

sizeElement(element: HTMLElement): void {
element.style.width = `${this.width}px`;
element.style.height = `${this.height}px`;
}

getArea(): number {
return this.width * this.height;
}
}