123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <title>JSDoc: Source: math/Box2.js</title>
- <script src="scripts/prettify/prettify.js"> </script>
- <script src="scripts/prettify/lang-css.js"> </script>
- <!--[if lt IE 9]>
- <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
- <![endif]-->
- <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
- <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
- </head>
- <body>
- <div id="main">
- <h1 class="page-title">Source: math/Box2.js</h1>
-
-
- <section>
- <article>
- <pre class="prettyprint source linenums"><code>import {Vector2} from "./Vector2.js";
- /**
- * Box is described by a minimum and maximum points.
- *
- * Can be used for collision detection with points and other boxes.
- *
- * @class
- * @param {Vector2} min Minimum point of the box.
- * @param {Vector2} max Maximum point of the box.
- */
- function Box2(min, max)
- {
- /**
- * Minimum point of the box.
- *
- * @type {Vector2}
- */
- this.min = (min !== undefined) ? min : new Vector2();
- /**
- * Maximum point of the box.
- *
- * @type {Vector2}
- */
- this.max = (max !== undefined) ? max : new Vector2();
- }
- /**
- * Set the box values.
- *
- * @param {Vector2} min Minimum point of the box.
- * @param {Vector2} max Maximum point of the box.
- */
- Box2.prototype.set = function(min, max)
- {
- this.min.copy(min);
- this.max.copy(max);
- return this;
- };
- /**
- * Set the box from a list of Vector2 points.
- *
- * @param {Array} points
- */
- Box2.prototype.setFromPoints = function(points)
- {
- this.min = new Vector2(+Infinity, +Infinity);
- this.max = new Vector2(-Infinity, -Infinity);
- for(var i = 0, il = points.length; i < il; i++)
- {
- this.expandByPoint(points[i]);
- }
- return this;
- };
- /**
- * Set the box minimum and maximum from center point and size.
- *
- * @param {Vector2} center
- * @param {Vector2} size
- */
- Box2.prototype.setFromCenterAndSize = function(center, size)
- {
- var v1 = new Vector2();
- var halfSize = v1.copy(size).multiplyScalar(0.5);
- this.min.copy(center).sub(halfSize);
- this.max.copy(center).add(halfSize);
- return this;
- };
- /**
- * Clone the box into a new object.
- *
- * Should be used when it it necessary to make operations to this box.
- *
- * @return {Box2} New box object with the copy of this object.
- */
- Box2.prototype.clone = function()
- {
- var box = new Box2();
- box.copy(this);
- return box;
- };
- /**
- * Copy the box value from another box.
- *
- * @param {Box2} point
- */
- Box2.prototype.copy = function(box)
- {
- this.min.copy(box.min);
- this.max.copy(box.max);
- };
- /**
- * Check if the box is empty (size equals zero or is negative).
- *
- * The box size is condireded valid on two negative axis.
- *
- * @return {boolean} True if the box is empty.
- */
- Box2.prototype.isEmpty = function()
- {
- return (this.max.x < this.min.x) || (this.max.y < this.min.y);
- };
- /**
- * Calculate the center point of the box.
- *
- * @param {Vector2} [target] Vector to store the result.
- * @return {Vector2} Central point of the box.
- */
- Box2.prototype.getCenter = function(target)
- {
- if(target === undefined)
- {
- target = new Vector2();
- }
- this.isEmpty() ? target.set(0, 0) : target.addVectors(this.min, this.max).multiplyScalar(0.5);
- return target;
- };
- /**
- * Get the size of the box from its min and max points.
- *
- * @param {Vector2} [target] Vector to store the result.
- * @return {Vector2} Vector with the calculated size.
- */
- Box2.prototype.getSize = function(target)
- {
- if(target === undefined)
- {
- target = new Vector2();
- }
- this.isEmpty() ? target.set(0, 0) : target.subVectors(this.max, this.min);
- return target;
- };
- /**
- * Expand the box to contain a new point.
- *
- * @param {Vector2} point
- */
- Box2.prototype.expandByPoint = function(point)
- {
- this.min.min(point);
- this.max.max(point);
- return this;
- };
- /**
- * Expand the box by adding a border with the vector size.
- *
- * Vector is subtracted from min and added to the max points.
- *
- * @param {Vector2} vector
- */
- Box2.prototype.expandByVector = function(vector)
- {
- this.min.sub(vector);
- this.max.add(vector);
- };
- /**
- * Expand the box by adding a border with the scalar value.
- *
- * @param {number} scalar
- */
- Box2.prototype.expandByScalar = function(scalar)
- {
- this.min.addScalar(-scalar);
- this.max.addScalar(scalar);
- };
- /**
- * Check if the box contains a point inside.
- *
- * @param {Vector2} point
- * @return {boolean} True if the box contains point.
- */
- Box2.prototype.containsPoint = function(point)
- {
- return !(point.x < this.min.x || point.x > this.max.x || point.y < this.min.y || point.y > this.max.y);
- };
- /**
- * Check if the box fully contains another box inside (different from intersects box).
- *
- * Only returns true if the box is fully contained.
- *
- * @param {Box2} box
- * @return {boolean} True if the box contains box.
- */
- Box2.prototype.containsBox = function(box)
- {
- return this.min.x <= box.min.x && box.max.x <= this.max.x && this.min.y <= box.min.y && box.max.y <= this.max.y;
- };
- /**
- * Check if two boxes intersect each other, using 4 splitting planes to rule out intersections.
- *
- * @param {Box2} box
- * @return {boolean} True if the boxes intersect each other.
- */
- Box2.prototype.intersectsBox = function(box)
- {
- return !(box.max.x < this.min.x || box.min.x > this.max.x || box.max.y < this.min.y || box.min.y > this.max.y);
- };
- /**
- * Calculate the distance to a point.
- *
- * @param {Vector2} point
- * @return {number} Distance to point calculated.
- */
- Box2.prototype.distanceToPoint = function(point)
- {
- var v = new Vector2();
- var clampedPoint = v.copy(point).clamp(this.min, this.max);
- return clampedPoint.sub(point).length();
- };
- /**
- * Make a intersection between this box and another box.
- *
- * Store the result in this object.
- *
- * @param {Box2} box
- */
- Box2.prototype.intersect = function(box)
- {
- this.min.max(box.min);
- this.max.min(box.max);
- };
- /**
- * Make a union between this box and another box.
- *
- * Store the result in this object.
- *
- * @param {Box2} box
- */
- Box2.prototype.union = function(box)
- {
- this.min.min(box.min);
- this.max.max(box.max);
- };
- /**
- * Translate the box by a offset value, adds the offset to booth min and max.
- *
- * @param {Vector2} offset
- */
- Box2.prototype.translate = function(offset)
- {
- this.min.add(offset);
- this.max.add(offset);
- };
- /**
- * Checks if two boxes are equal.
- *
- * @param {Box2} box
- * @return {boolean} True if the two boxes are equal.
- */
- Box2.prototype.equals = function(box)
- {
- return box.min.equals(this.min) && box.max.equals(this.max);
- };
- /**
- * Store the box data into a numeric array.
- *
- * @return {number[]} Numeric array with box data min and max.
- */
- Box2.prototype.toArray = function()
- {
- return [this.min.x, this.min.y, this.max.x, this.max.y];
- };
- /**
- * Set box data min and max from numeric array.
- *
- * @param {number[]} array Numeric array with box data min and max.
- */
- Box2.prototype.fromArray = function(array)
- {
- this.min.set(array[0], array[1]);
- this.max.set(array[2], array[3]);
- };
- export {Box2};
- </code></pre>
- </article>
- </section>
- </div>
- <nav>
- <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="AnimationTimer.html">AnimationTimer</a></li><li><a href="BarGraph.html">BarGraph</a></li><li><a href="BezierCurve.html">BezierCurve</a></li><li><a href="Box.html">Box</a></li><li><a href="Box2.html">Box2</a></li><li><a href="BoxMask.html">BoxMask</a></li><li><a href="Circle.html">Circle</a></li><li><a href="ColorStyle.html">ColorStyle</a></li><li><a href="DOM.html">DOM</a></li><li><a href="EventManager.html">EventManager</a></li><li><a href="FileUtils.html">FileUtils</a></li><li><a href="Gauge.html">Gauge</a></li><li><a href="GradientColorStop.html">GradientColorStop</a></li><li><a href="GradientStyle.html">GradientStyle</a></li><li><a href="Graph.html">Graph</a></li><li><a href="Helpers.html">Helpers</a></li><li><a href="Image.html">Image</a></li><li><a href="Key.html">Key</a></li><li><a href="Line.html">Line</a></li><li><a href="LinearGradientStyle.html">LinearGradientStyle</a></li><li><a href="Mask.html">Mask</a></li><li><a href="Matrix.html">Matrix</a></li><li><a href="MultiLineText.html">MultiLineText</a></li><li><a href="Node.html">Node</a></li><li><a href="NodeConnector.html">NodeConnector</a></li><li><a href="NodeGraph.html">NodeGraph</a></li><li><a href="NodeSocket.html">NodeSocket</a></li><li><a href="Object2D.html">Object2D</a></li><li><a href="Path.html">Path</a></li><li><a href="Pattern.html">Pattern</a></li><li><a href="PatternStyle.html">PatternStyle</a></li><li><a href="PieChart.html">PieChart</a></li><li><a href="Pointer.html">Pointer</a></li><li><a href="QuadraticCurve.html">QuadraticCurve</a></li><li><a href="RadialGradientStyle.html">RadialGradientStyle</a></li><li><a href="Renderer.html">Renderer</a></li><li><a href="RoundedBox.html">RoundedBox</a></li><li><a href="ScatterGraph.html">ScatterGraph</a></li><li><a href="Style.html">Style</a></li><li><a href="Text.html">Text</a></li><li><a href="UUID.html">UUID</a></li><li><a href="Vector2.html">Vector2</a></li><li><a href="Viewport.html">Viewport</a></li><li><a href="ViewportControls.html">ViewportControls</a></li></ul><h3>Global</h3><ul><li><a href="global.html#writeFile">writeFile</a></li></ul>
- </nav>
- <br class="clear">
- <footer>
- Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.11</a> on Sat Sep 17 2022 14:24:36 GMT+0100 (Hora de verão da Europa Ocidental)
- </footer>
- <script> prettyPrint(); </script>
- <script src="scripts/linenumber.js"> </script>
- </body>
- </html>
|