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

Move BBox.ts to util directory #494

Merged
merged 4 commits into from
Jun 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 1 addition & 1 deletion ts/output/chtml/BBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
* @author dpvc@mathjax.org (Davide Cervone)
*/

export {BBox, BBoxData, BBoxStyleAdjust} from '../common/BBox.js';
export * from '../../util/BBox.js';
2 changes: 1 addition & 1 deletion ts/output/chtml/Wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import * as LENGTHS from '../../util/lengths.js';
import {CommonWrapper, AnyWrapperClass, Constructor, StringMap} from '../common/Wrapper.js';
import {CHTML} from '../chtml.js';
import {CHTMLWrapperFactory} from './WrapperFactory.js';
import {BBox} from './BBox.js';
import {BBox} from '../../util/BBox.js';
import {CHTMLFontData, CHTMLCharOptions, CHTMLDelimiterData} from './FontData.js';

export {Constructor, StringMap} from '../common/Wrapper.js';
Expand Down
2 changes: 1 addition & 1 deletion ts/output/chtml/Wrappers/math.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {CHTMLWrapper, CHTMLConstructor} from '../Wrapper.js';
import {CommonMathMixin} from '../../common/Wrappers/math.js';
import {MmlMath} from '../../../core/MmlTree/MmlNodes/math.js';
import {StyleList} from '../../../util/StyleList.js';
import {BBox} from '../BBox.js';
import {BBox} from '../../../util/BBox.js';

/*****************************************************************/
/**
Expand Down
2 changes: 1 addition & 1 deletion ts/output/chtml/Wrappers/mmultiscripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {CHTMLWrapper, Constructor} from '../Wrapper.js';
import {CHTMLmsubsup} from './msubsup.js';
import {CommonMmultiscriptsMixin} from '../../common/Wrappers/mmultiscripts.js';
import {MmlMmultiscripts} from '../../../core/MmlTree/MmlNodes/mmultiscripts.js';
import {BBox} from '../BBox.js';
import {BBox} from '../../../util/BBox.js';
import {StyleList} from '../../../util/StyleList.js';

/*****************************************************************/
Expand Down
2 changes: 1 addition & 1 deletion ts/output/chtml/Wrappers/mo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import {CHTMLWrapper, CHTMLConstructor, StringMap} from '../Wrapper.js';
import {CommonMoMixin, DirectionVH} from '../../common/Wrappers/mo.js';
import {MmlMo} from '../../../core/MmlTree/MmlNodes/mo.js';
import {BBox} from '../BBox.js';
import {BBox} from '../../../util/BBox.js';
import {StyleList} from '../../../util/StyleList.js';
import {DIRECTION} from '../FontData.js';

Expand Down
2 changes: 1 addition & 1 deletion ts/output/chtml/Wrappers/mroot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import {CHTMLWrapper} from '../Wrapper.js';
import {CHTMLmsqrt} from './msqrt.js';
import {CommonMrootMixin, MrootConstructor} from '../../common/Wrappers/mroot.js';
import {BBox} from '../BBox.js';
import {BBox} from '../../../util/BBox.js';
import {MmlMroot} from '../../../core/MmlTree/MmlNodes/mroot.js';

/*****************************************************************/
Expand Down
2 changes: 1 addition & 1 deletion ts/output/chtml/Wrappers/msqrt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import {CHTMLWrapper, CHTMLConstructor} from '../Wrapper.js';
import {CommonMsqrtMixin} from '../../common/Wrappers/msqrt.js';
import {CHTMLmo} from './mo.js';
import {BBox} from '../BBox.js';
import {BBox} from '../../../util/BBox.js';
import {MmlMsqrt} from '../../../core/MmlTree/MmlNodes/msqrt.js';
import {StyleList} from '../../../util/StyleList.js';

Expand Down
2 changes: 1 addition & 1 deletion ts/output/chtml/Wrappers/scriptbase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

import {CHTMLWrapper, CHTMLConstructor} from '../Wrapper.js';
import {CommonScriptbaseMixin} from '../../common/Wrappers/scriptbase.js';
import {BBox} from '../BBox.js';
import {BBox} from '../../../util/BBox.js';
import {StyleData} from '../../../util/StyleList.js';

/*****************************************************************/
Expand Down
2 changes: 1 addition & 1 deletion ts/output/chtml/Wrappers/semantics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import {CHTMLWrapper, CHTMLConstructor} from '../Wrapper.js';
import {CommonSemanticsMixin} from '../../common/Wrappers/semantics.js';
import {BBox} from '../BBox.js';
import {BBox} from '../../../util/BBox.js';
import {MmlSemantics, MmlAnnotation, MmlAnnotationXML} from '../../../core/MmlTree/MmlNodes/semantics.js';
import {XMLNode} from '../../../core/MmlTree/MmlNode.js';
import {StyleList} from '../../../util/StyleList.js';
Expand Down
153 changes: 2 additions & 151 deletions ts/output/common/BBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,158 +16,9 @@
*/

/**
* @fileoverview Implements a bounding-box object and operations on it
* @fileoverview Implements the common bounding box object
*
* @author dpvc@mathjax.org (Davide Cervone)
*/

import {BIGDIMEN} from '../../util/lengths.js';

/**
* CSS styles that affect BBoxes
*/
export const BBoxStyleAdjust = [
['borderTopWidth', 'h'],
['borderRightWidth', 'w'],
['borderBottomWidth', 'd'],
['borderLeftWidth', 'w', 0],
['paddingTop', 'h'],
['paddingRight', 'w'],
['paddingBottom', 'd'],
['paddingLeft', 'w', 0]
];

/**
* The data used to initialize a BBox
*/
export type BBoxData = {
w?: number,
h?: number,
d?: number
};

/*****************************************************************/
/**
* The BBox class
*/

export class BBox {
/**
* Constant for pwidth of full width box
*/
public static fullWidth = '100%';

/**
* These are the data stored for a bounding box
*/
/* tslint:disable:jsdoc-require */
public w: number;
public h: number;
public d: number;
public scale: number;
public rscale: number; // scale relative to the parent's scale
public L: number; // extra space on the left
public R: number; // extra space on the right
public pwidth: string; // percentage width (for tables)
public ic: number; // italic correction
public sk: number; // skew
/* tslint:enable */

/**
* @return {BBox} A BBox initialized to zeros
*/
public static zero(): BBox {
return new BBox({h: 0, d: 0, w: 0});
}

/**
* @return {BBox} A BBox with height and depth not set
*/
public static empty(): BBox {
return new BBox();
}

/**
* @param {BBoxData} def The data with which to initialize the BBox
*
* @constructor
*/
constructor(def: BBoxData = {w: 0, h: -BIGDIMEN, d: -BIGDIMEN}) {
this.w = def.w || 0;
this.h = ('h' in def ? def.h : -BIGDIMEN);
this.d = ('d' in def ? def.d : -BIGDIMEN);
this.L = this.R = this.ic = this.sk = 0;
this.scale = this.rscale = 1;
this.pwidth = '';
}

/**
* Set up a bbox for append() and combine() operations
* @return {BBox} the boox itself (for chaining calls)
*/
public empty(): BBox {
this.w = 0;
this.h = this.d = -BIGDIMEN;
return this;
}

/**
* Convert any unspecified values into zeros
*/
public clean () {
if (this.w === -BIGDIMEN) this.w = 0;
if (this.h === -BIGDIMEN) this.h = 0;
if (this.d === -BIGDIMEN) this.d = 0;
}

/**
* @param {number} scale The scale to use to modify the bounding box size
*/
public rescale(scale: number) {
this.w *= scale;
this.h *= scale;
this.d *= scale;
}

/**
* @param {BBox} cbox A bounding to combine with this one
* @param {number} x An x-offest for the child bounding box
* @param {number} y A y-offset for the child bounding box
*/
public combine(cbox: BBox, x: number = 0, y: number = 0) {
let rscale = cbox.rscale;
let w = x + rscale * (cbox.w + cbox.L + cbox.R);
let h = y + rscale * cbox.h;
let d = rscale * cbox.d - y;
if (w > this.w) this.w = w;
if (h > this.h) this.h = h;
if (d > this.d) this.d = d;
}

/**
* @param {BBox} cbox A bounding box to be added to the right of this one
*/
public append(cbox: BBox) {
let scale = cbox.rscale;
this.w += scale * (cbox.w + cbox.L + cbox.R);
if (scale * cbox.h > this.h) {
this.h = scale * cbox.h;
}
if (scale * cbox.d > this.d) {
this.d = scale * cbox.d;
}
}

/**
* @param {BBox} cbox The bounding box to use to overwrite this one
*/
public updateFrom(cbox: BBox) {
this.h = cbox.h;
this.d = cbox.d;
this.w = cbox.w;
if (cbox.pwidth) {
this.pwidth = cbox.pwidth;
}
}

}
export * from '../../util/BBox.js';
2 changes: 1 addition & 1 deletion ts/output/common/Wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {Styles} from '../../util/Styles.js';
import {StyleList} from '../../util/StyleList.js';
import {CommonOutputJax} from './OutputJax.js';
import {CommonWrapperFactory} from './WrapperFactory.js';
import {BBox} from './BBox.js';
import {BBox} from '../../util/BBox.js';
import {FontData, DelimiterData, CharData, CharOptions, DIRECTION, NOSTRETCH} from './FontData.js';

/*****************************************************************/
Expand Down
2 changes: 1 addition & 1 deletion ts/output/common/Wrappers/TeXAtom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/

import {AnyWrapper, WrapperConstructor, Constructor} from '../Wrapper.js';
import {BBox} from '../BBox.js';
import {BBox} from '../../../util/BBox.js';
import {TEXCLASS} from '../../../core/MmlTree/MmlNode.js';

/*****************************************************************/
Expand Down
2 changes: 1 addition & 1 deletion ts/output/common/Wrappers/TextNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/

import {AnyWrapper, WrapperConstructor, Constructor} from '../Wrapper.js';
import {BBox} from '../BBox.js';
import {BBox} from '../../../util/BBox.js';
import {TextNode} from '../../../core/MmlTree/MmlNode.js';

/*****************************************************************/
Expand Down
2 changes: 1 addition & 1 deletion ts/output/common/Wrappers/maction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

import {AnyWrapper, WrapperConstructor, Constructor, AnyWrapperClass} from '../Wrapper.js';
import {MmlMaction} from '../../../core/MmlTree/MmlNodes/maction.js';
import {BBox} from '../BBox.js';
import {BBox} from '../../../util/BBox.js';
import {split} from '../../../util/string.js';

/*****************************************************************/
Expand Down
2 changes: 1 addition & 1 deletion ts/output/common/Wrappers/menclose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import {AnyWrapper, WrapperConstructor, Constructor, AnyWrapperClass} from '../Wrapper.js';
import * as Notation from '../Notation.js';
import {CommonMsqrt} from './msqrt.js';
import {BBox} from '../BBox.js';
import {BBox} from '../../../util/BBox.js';
import {AbstractMmlNode} from '../../../core/MmlTree/MmlNode.js';
import {split} from '../../../util/string.js';

Expand Down
2 changes: 1 addition & 1 deletion ts/output/common/Wrappers/mfenced.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {AnyWrapper, WrapperConstructor, Constructor} from '../Wrapper.js';
import {CommonInferredMrow} from './mrow.js';
import {MmlNode, AbstractMmlNode} from '../../../core/MmlTree/MmlNode.js';
import {MmlMfenced} from '../../../core/MmlTree/MmlNodes/mfenced.js';
import {BBox} from '../BBox.js';
import {BBox} from '../../../util/BBox.js';

/*****************************************************************/
/**
Expand Down
2 changes: 1 addition & 1 deletion ts/output/common/Wrappers/mfrac.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

import {AnyWrapper, WrapperConstructor, Constructor} from '../Wrapper.js';
import {CommonMo} from './mo.js';
import {BBox} from '../BBox.js';
import {BBox} from '../../../util/BBox.js';
import {DIRECTION} from '../FontData.js';

/*****************************************************************/
Expand Down
2 changes: 1 addition & 1 deletion ts/output/common/Wrappers/mglyph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/

import {AnyWrapper, WrapperConstructor, Constructor} from '../Wrapper.js';
import {BBox} from '../BBox.js';
import {BBox} from '../../../util/BBox.js';

/*****************************************************************/
/**
Expand Down
2 changes: 1 addition & 1 deletion ts/output/common/Wrappers/mi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/

import {AnyWrapper, WrapperConstructor, Constructor} from '../Wrapper.js';
import {BBox} from '../BBox.js';
import {BBox} from '../../../util/BBox.js';

/*****************************************************************/
/**
Expand Down
2 changes: 1 addition & 1 deletion ts/output/common/Wrappers/mmultiscripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

import {AnyWrapper, Constructor} from '../Wrapper.js';
import {CommonMsubsup, MsubsupConstructor} from './msubsup.js';
import {BBox} from '../BBox.js';
import {BBox} from '../../../util/BBox.js';

/*****************************************************************/

Expand Down
2 changes: 1 addition & 1 deletion ts/output/common/Wrappers/mo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

import {AnyWrapper, WrapperConstructor, Constructor} from '../Wrapper.js';
import {MmlMo} from '../../../core/MmlTree/MmlNodes/mo.js';
import {BBox} from '../BBox.js';
import {BBox} from '../../../util/BBox.js';
import {DelimiterData} from '../FontData.js';
import {DIRECTION, NOSTRETCH} from '../FontData.js';

Expand Down
2 changes: 1 addition & 1 deletion ts/output/common/Wrappers/mpadded.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/

import {AnyWrapper, WrapperConstructor, Constructor} from '../Wrapper.js';
import {BBox} from '../BBox.js';
import {BBox} from '../../../util/BBox.js';
import {Property} from '../../../core/Tree/Node.js';

/*****************************************************************/
Expand Down
2 changes: 1 addition & 1 deletion ts/output/common/Wrappers/mroot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import {Constructor} from '../../common/Wrapper.js';
import {CommonMsqrt, MsqrtConstructor} from './msqrt.js';
import {CommonMo} from './mo.js';
import {BBox} from '../BBox.js';
import {BBox} from '../../../util/BBox.js';

/*****************************************************************/
/**
Expand Down
2 changes: 1 addition & 1 deletion ts/output/common/Wrappers/mrow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

import {AnyWrapper, WrapperConstructor, Constructor} from '../Wrapper.js';
import {CommonMo} from './mo.js';
import {BBox} from '../BBox.js';
import {BBox} from '../../../util/BBox.js';
import {DIRECTION} from '../FontData.js';

/*****************************************************************/
Expand Down
2 changes: 1 addition & 1 deletion ts/output/common/Wrappers/mspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/

import {AnyWrapper, WrapperConstructor, Constructor} from '../Wrapper.js';
import {BBox} from '../BBox.js';
import {BBox} from '../../../util/BBox.js';

/*****************************************************************/
/**
Expand Down
2 changes: 1 addition & 1 deletion ts/output/common/Wrappers/msqrt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

import {AnyWrapper, WrapperConstructor, Constructor} from '../Wrapper.js';
import {CommonMo} from './mo.js';
import {BBox} from '../BBox.js';
import {BBox} from '../../../util/BBox.js';
import {DIRECTION} from '../FontData.js';

/*****************************************************************/
Expand Down
2 changes: 1 addition & 1 deletion ts/output/common/Wrappers/msubsup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import {AnyWrapper, Constructor} from '../Wrapper.js';
import {CommonScriptbase, ScriptbaseConstructor} from './scriptbase.js';
import {BBox} from '../BBox.js';
import {BBox} from '../../../util/BBox.js';
import {MmlMsubsup, MmlMsub, MmlMsup} from '../../../core/MmlTree/MmlNodes/msubsup.js';

/*****************************************************************/
Expand Down
Loading