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

Refactor #34

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 2 additions & 3 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
{
"presets": [
["env", { "loose": true }]
],
"presets": [["env", { "loose": true }]],
"plugins": [
"transform-runtime",
"transform-export-extensions",
"transform-object-rest-spread",
["transform-class-properties", { "loose": true }]
]
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ yarn.lock
dist
*.pdf
lerna-debug.log
*.ttf
.vscode
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"babel-eslint": "^8.2.2",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-export-extensions": "^6.22.0",
"babel-plugin-transform-object-rest-spread": "^6.22.0",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-env": "^1.7.0",
"eslint": "^4.18.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/bidi-engine/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"prebuild": "rimraf dist",
"prepublish": "npm run build",
"build": "babel index.js --out-dir ./dist",
"build": "babel index.js --out-dir ./dist --source-maps",
"build:watch": "babel index.js --out-dir ./dist --watch",
"precommit": "lint-staged",
"test": "jest"
Expand Down
9 changes: 5 additions & 4 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
{
"name": "@textkit/core",
"version": "0.1.16",
"version": "0.1.23",
"description": "An advanced text layout framework",
"main": "dist/index.js",
"scripts": {
"prebuild": "rimraf dist",
"prepublish": "npm run build",
"build": "babel ./src --out-dir ./dist",
"build": "babel ./src --out-dir ./dist --source-maps",
"build:watch": "babel ./src --out-dir ./dist --watch",
"precommit": "lint-staged",
"test": "jest"
},
"publishConfig": {
"access": "public"
},
"files": [
"dist"
],
"author": "Devon Govett <[email protected]>",
"license": "MIT",
"dependencies": {
"cubic2quad": "^1.1.0",
"iconv-lite": "^0.4.13",
"svgpath": "^2.2.0",
"unicode-properties": "^1.1.0"
}
}
36 changes: 6 additions & 30 deletions packages/core/src/geom/BBox.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,17 @@
/**
* Represents a glyph bounding box
*/
import Rect from './Rect';

class BBox {
constructor(minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity) {
/**
* The minimum X position in the bounding box
* @type {number}
*/
this.minX = minX;

/**
* The minimum Y position in the bounding box
* @type {number}
*/
this.minY = minY;

/**
* The maxmimum X position in the bounding box
* @type {number}
*/
this.maxX = maxX;

/**
* The maxmimum Y position in the bounding box
* @type {number}
*/
this.maxY = maxY;
}

/**
* The width of the bounding box
* @type {number}
*/
get width() {
return this.maxX - this.minX;
}

/**
* The height of the bounding box
* @type {number}
*/
get height() {
return this.maxY - this.minY;
}
Expand Down Expand Up @@ -67,6 +39,10 @@ class BBox {
this.addPoint(rect.maxX, rect.maxY);
}

toRect() {
return new Rect(this.minX, this.minY, this.width, this.height);
}

copy() {
return new BBox(this.minX, this.minY, this.maxX, this.maxY);
}
Expand Down
75 changes: 0 additions & 75 deletions packages/core/src/geom/Rect.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,98 +2,43 @@ import Point from './Point';

const CORNERS = ['topLeft', 'topRight', 'bottomLeft', 'bottomRight'];

/**
* Represents a rectangle
*/
class Rect {
/** @public */
constructor(x = 0, y = 0, width = 0, height = 0) {
/**
* The x-coordinate of the rectangle
* @type {number}
*/
this.x = x;

/**
* The y-coordinate of the rectangle
* @type {number}
*/
this.y = y;

/**
* The width of the rectangle
* @type {number}
*/
this.width = width;

/**
* The height of the rectangle
* @type {number}
*/
this.height = height;
}

/**
* The maximum x-coordinate in the rectangle
* @type {number}
*/
get maxX() {
return this.x + this.width;
}

/**
* The maximum y-coordinate in the rectangle
* @type {number}
*/
get maxY() {
return this.y + this.height;
}

/**
* The area of the rectangle
* @type {number}
*/
get area() {
return this.width * this.height;
}

/**
* The top left corner of the rectangle
* @type {Point}
*/
get topLeft() {
return new Point(this.x, this.y);
}

/**
* The top right corner of the rectangle
* @type {Point}
*/
get topRight() {
return new Point(this.maxX, this.y);
}

/**
* The bottom left corner of the rectangle
* @type {Point}
*/
get bottomLeft() {
return new Point(this.x, this.maxY);
}

/**
* The bottom right corner of the rectangle
* @type {Point}
*/
get bottomRight() {
return new Point(this.maxX, this.maxY);
}

/**
* Returns whether this rectangle intersects another rectangle
* @param {Rect} rect - The rectangle to check
* @return {boolean}
*/
intersects(rect) {
return (
this.x <= rect.x + rect.width &&
Expand All @@ -103,30 +48,14 @@ class Rect {
);
}

/**
* Returns whether this rectangle fully contains another rectangle
* @param {Rect} rect - The rectangle to check
* @return {boolean}
*/
containsRect(rect) {
return this.x <= rect.x && this.y <= rect.y && this.maxX >= rect.maxX && this.maxY >= rect.maxY;
}

/**
* Returns whether the rectangle contains the given point
* @param {Point} point - The point to check
* @return {boolean}
*/
containsPoint(point) {
return this.x <= point.x && this.y <= point.y && this.maxX >= point.x && this.maxY >= point.y;
}

/**
* Returns the first corner of this rectangle (from top to bottom, left to right)
* that is contained in the given rectangle, or null of the rectangles do not intersect.
* @param {Rect} rect - The rectangle to check
* @return {string}
*/
getCornerInRect(rect) {
for (const key of CORNERS) {
if (rect.containsPoint(this[key])) {
Expand Down Expand Up @@ -154,10 +83,6 @@ class Rect {
return this.width === size.width && this.height === size.height;
}

/**
* Returns a copy of this rectangle
* @return {Rect}
*/
copy() {
return new Rect(this.x, this.y, this.width, this.height);
}
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ export {
Run,
Block,
Range,
TabStop,
RunStyle,
GlyphRun,
Container,
Expand Down
Loading