docs/api_TwoDModule.js.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: api/TwoDModule.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: api/TwoDModule.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>const xml2js = require('xml2js');
const AbstractModule = require('./AbstractModule');
const TwoDModuleFile = require('../file/TwoDModuleFile');
function getVertices(parsedOutput) {
return parsedOutput.path
.reduce((previousValue, currentValue) => {
return previousValue.concat(currentValue.$.d.match(/(-*\d+,-*\d+)/g));
}, [])
.map(value => value
.split(',')
.map(point => parseFloat(point))
);
}
/** @class */
class TwoDModule extends AbstractModule {
/**
* @param {Options} options
*/
constructor(options) {
super(options, TwoDModuleFile);
/**
* @memberof TwoDModule
* @instance
* @member {string} output The extracted output from execution of the .scad file.
*/
/**
* @memberof TwoDModule
* @instance
* @function
* @name isWithinBoundingBox
* @param boundingBox {BoundingBox} The 2D box which the model should fit inside. It is considered 'within' if any coordinate is equal to, or within the box.
* @returns {boolean} True if the model fits within the bounding box.
*/
xml2js.parseString(this.output, (error, result) => {
if(error) {
throw new Error(error);
} else {
/**
* @memberof TwoDModule
* @instance
* @member {Vertex[]} vertices A list of 2D vertices returned from the .scad file execution.
*/
this.vertices = getVertices(result.svg);
/**
* @memberof TwoDModule
* @instance
* @member {number} height The height of the model.
*/
this.height = parseInt(result.svg.$.height, 10);
/**
* @memberof TwoDModule
* @instance
* @member {number} width The width of the model.
*/
this.width = parseInt(result.svg.$.width, 10);
}
});
}
}
module.exports = TwoDModule;</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Function.html">Function</a></li><li><a href="ThreeDModule.html">ThreeDModule</a></li><li><a href="TwoDModule.html">TwoDModule</a></li></ul><h3><a href="global.html">Global</a></h3>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>