diff --git a/article.js b/article.js index 1f925e44..efc2b0b0 100644 --- a/article.js +++ b/article.js @@ -62,7 +62,7 @@ var React = __webpack_require__(8); var ReactDOM = __webpack_require__(165); var Article = __webpack_require__(166); - var style = __webpack_require__(193); + var style = __webpack_require__(194); ReactDOM.render(React.createElement(Article, null), document.getElementById("article")); @@ -19695,15 +19695,15 @@ return React.createElement(Type, { key: name, ref: name, name: name, number: entry }); }, - generateNavItem: function generateNavItem(name, entry) { - var Type = this.state.sections[name]; + generateNavItem: function generateNavItem(section, entry) { + var name = section.props.name; return React.createElement( "li", { key: name, "data-number": entry }, React.createElement( "a", { href: '#' + name }, - Type.title || name + section.props.title ) ); }, @@ -19722,7 +19722,7 @@ React.createElement( "ul", { className: "navigation" }, - this.sectionMap(this.generateNavItem) + sections.map(this.generateNavItem) ) ) ), @@ -19766,11 +19766,11 @@ components: __webpack_require__(189), extremities: __webpack_require__(190), boundingbox: __webpack_require__(191), - aligning: __webpack_require__(192) + aligning: __webpack_require__(192), + tightbounds: __webpack_require__(193) }; /* - tightbounds: require("./tightbounds"), canonical: require("./canonical"), arclength: require("./arclength"), @@ -19800,23 +19800,7 @@ /* - A lightning introduction - What is a Bézier curve? - The basics of Bézier curves - Controlling Bézier curvatures - Bézier curvatures as matrix operations - de Casteljau's algorithm - Simplified drawing - Splitting curves - Splitting curves using matrices - Lowering and elevating curve order - Derivatives - Tangents and normals - Component functions - Finding extremities - Bounding boxes - Aligning curves - Tight boxes + The canonical form (for cubic curves) Arc length Approximated arc length @@ -20339,7 +20323,7 @@ }, drawHull: function drawHull(curve, t, offset) { - var hull = curve.hull(t); + var hull = typeof curve === "array" ? curve : curve.hull(t); if (hull.length === 6) { this.drawLine(hull[0], hull[1], offset); this.drawLine(hull[1], hull[2], offset); @@ -28646,62 +28630,124 @@ module.exports = Aligning; - /* - void setupCurve() { - setupDefaultQuadratic(); - } - - void drawCurve(BezierCurve curve) { - additionals(); - curve.draw(); - - nextPanel(); - stroke(0); - line(0,0,0,dim); - - stroke(0,50); - translate(3*dim/4,dim/2); - line(-3*dim/4,0,dim/4,0); - line(0,-dim/2,0,dim/2); - - curve.align().draw(color(150)); - } - - - - void setupCurve() { - setupDefaultCubic(); - } - - void drawCurve(BezierCurve curve) { - additionals(); - curve.draw(); - - nextPanel(); - stroke(0); - line(0,0,0,dim); - - stroke(0,50); - translate(3*dim/4,dim/2); - line(-3*dim/4,0,dim/4,0); - line(0,-dim/2,0,dim/2); - - curve.align().draw(color(150)); - } - - */ - /***/ }, /* 193 */ +/***/ function(module, exports, __webpack_require__) { + + "use strict"; + + var React = __webpack_require__(8); + var Graphic = __webpack_require__(170); + var SectionHeader = __webpack_require__(175); + + var TightBounds = React.createClass({ + displayName: "TightBounds", + + getDefaultProps: function getDefaultProps() { + return { + title: "Tight boxes" + }; + }, + + setupQuadratic: function setupQuadratic(api) { + var curve = api.getDefaultQuadratic(); + api.setCurve(curve); + }, + + setupCubic: function setupCubic(api) { + var curve = api.getDefaultCubic(); + api.setCurve(curve); + }, + + align: function align(points, line) { + var tx = line.p1.x, + ty = line.p1.y, + a = -Math.atan2(line.p2.y - ty, line.p2.x - tx), + cos = Math.cos, + sin = Math.sin, + d = function d(v) { + return { + x: (v.x - tx) * cos(a) - (v.y - ty) * sin(a), + y: (v.x - tx) * sin(a) + (v.y - ty) * cos(a), + a: a + }; + }; + return points.map(d); + }, + + // FIXME: I'm not satisfied with needing to turn a bbox[] into a point[], + // this needs a bezier.js solution, really, with a call curve.tightbbox() + transpose: function transpose(points, angle, offset) { + var tx = offset.x, + ty = offset.y, + cos = Math.cos, + sin = Math.sin, + v = [points.x.min, points.y.min, points.x.max, points.y.max], + points = [{ x: v[0], y: v[1] }, { x: v[2], y: v[1] }, { x: v[2], y: v[3] }, { x: v[0], y: v[3] }].map(function (p) { + var x = p.x, + y = p.y; + return { + x: x * cos(angle) - y * sin(angle) + tx, + y: x * sin(angle) + y * cos(angle) + ty + }; + }); + return points; + }, + + draw: function draw(api, curve) { + api.reset(); + api.drawSkeleton(curve); + api.drawCurve(curve); + + var pts = curve.points; + var line = { p1: pts[0], p2: pts[pts.length - 1] }; + var apts = this.align(pts, line); + var angle = -apts[0].a; + var aligned = new api.Bezier(apts); + var bbox = aligned.bbox(); + var tpts = this.transpose(bbox, angle, pts[0]); + + api.setColor("#00FF00"); + api.drawLine(tpts[0], tpts[1]); + api.drawLine(tpts[1], tpts[2]); + api.drawLine(tpts[2], tpts[3]); + api.drawLine(tpts[3], tpts[0]); + }, + + render: function render() { + return React.createElement( + "section", + null, + React.createElement(SectionHeader, this.props), + React.createElement( + "p", + null, + "With our knowledge of bounding boxes, and curve alignment, We can now form the \"tight\" bounding box for curves. We first align our curve, recording the translation we performed, \"T\", and the rotation angle we used, \"R\". We then determine the aligned curve's normal bounding box. Once we have that, we can map that bounding box back to our original curve by rotating it by -R, and then translating it by -T. We now have nice tight bounding boxes for our curves:" + ), + React.createElement(Graphic, { preset: "twopanel", title: "Aligning a quadratic curve", setup: this.setupQuadratic, draw: this.draw }), + React.createElement(Graphic, { preset: "twopanel", title: "Aligning a cubic curve", setup: this.setupCubic, draw: this.draw }), + React.createElement( + "p", + null, + "These are, strictly speaking, not necessarily the tightest possible bounding boxes. It is possible to compute the optimal bounding box by determining which spanning lines we need to effect a minimal box area, but because of the parametric nature of Bézier curves this is actually a rather costly operation, and the gain in bounding precision is often not worth it. If there is high demand for it, I'll add a section on how to precisely compute the best fit bounding box, but the maths is fairly gruelling and just not really worth spending time on." + ) + ); + } + }); + + module.exports = TightBounds; + +/***/ }, +/* 194 */ /***/ function(module, exports, __webpack_require__) { // style-loader: Adds some css to the DOM by adding a