-
Notifications
You must be signed in to change notification settings - Fork 857
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
util.getRectPoint: add utility to get a point on a rect from given ke…
…yword (#1658) * util.getRectPoint: add utility to get a point on a rect from given keyword * add docs * rename location to positionName
- Loading branch information
1 parent
2a24944
commit 1a77a9b
Showing
7 changed files
with
138 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<pre class="docs-method-signature"><code>util.getRectPoint(rect, positionName)</code></pre> | ||
<p> | ||
Returns a <a href="geometry.html#g.Point.constructor">g.Point</a> on the rectangle specified by the keyword <code>positionName</code>. | ||
<br> | ||
The <code>rect</code> object has the form <code>{ x: Number, y: Number, width: Number, height: Number }</code>. | ||
<br> | ||
The <code>positionName</code> keyword can be one of the following:</p> | ||
<ul> | ||
<li><code>'top-left'</code></li> | ||
<li><code>'top'</code></li> | ||
<li><code>'top-right'</code></li> | ||
<li><code>'bottom-left'</code></li> | ||
<li><code>'bottom'</code></li> | ||
<li><code>'bottom-right'</code></li> | ||
<li><code>'left'</code></li> | ||
<li><code>'right'</code></li> | ||
<li><code>'center'</code></li> | ||
</ul> | ||
</p> |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import * as g from '../g/index.mjs'; | ||
|
||
const Positions = { | ||
TOP: 'top', | ||
RIGHT: 'right', | ||
BOTTOM: 'bottom', | ||
LEFT: 'left', | ||
TOP_LEFT: 'top-left', | ||
TOP_RIGHT: 'top-right', | ||
BOTTOM_LEFT: 'bottom-left', | ||
BOTTOM_RIGHT: 'bottom-right', | ||
CENTER: 'center', | ||
}; | ||
|
||
export function getRectPoint(rect, position) { | ||
const r = new g.Rect(rect); | ||
switch (position) { | ||
case undefined: | ||
throw new Error('Position required'); | ||
|
||
// Middle Points | ||
case Positions.LEFT: | ||
case 'leftMiddle': | ||
return r.leftMiddle(); | ||
|
||
case Positions.RIGHT: | ||
case 'rightMiddle': | ||
return r.rightMiddle(); | ||
|
||
case Positions.TOP: | ||
case 'topMiddle': | ||
return r.topMiddle(); | ||
|
||
case Positions.BOTTOM: | ||
case 'bottomMiddle': | ||
return r.bottomMiddle(); | ||
|
||
// Corners | ||
case Positions.TOP_LEFT: | ||
case 'topLeft': | ||
case 'origin': | ||
return r.topLeft(); | ||
|
||
case Positions.TOP_RIGHT: | ||
case 'topRight': | ||
return r.topRight(); | ||
|
||
case Positions.BOTTOM_LEFT: | ||
case 'bottomLeft': | ||
return r.bottomLeft(); | ||
|
||
case Positions.BOTTOM_RIGHT: | ||
case 'bottomRight': | ||
case 'corner': | ||
return r.bottomRight(); | ||
|
||
// Center | ||
case Positions.CENTER: | ||
return r.center(); | ||
|
||
// TODO: calc(), percentage etc. | ||
default: | ||
throw new Error(`Unknown position: ${position}`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './wrappers.mjs'; | ||
export * from './util.mjs'; | ||
export * from './cloneCells.mjs'; | ||
export * from './getRectPoint.mjs'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters