Skip to content

Commit

Permalink
Adding examples support for phetsims/chipper#411
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanolson committed Nov 25, 2015
1 parent 322399d commit b8ec76e
Show file tree
Hide file tree
Showing 6 changed files with 1,836 additions and 744 deletions.
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ module.exports = function( grunt ) {
attachComment: true
} );
var doc = extractDocumentation( program );
if ( baseName === 'Vector2' ) { // for testing
if ( baseName === 'ConvexHull2' ) { // for testing
// console.log( JSON.stringify( doc, null, 2 ) );
}
var htmlDoc = documentationToHTML( doc, baseName, typeNames, localTypeIds, externalTypeURLs );
Expand Down
2,511 changes: 1,775 additions & 736 deletions doc/index.html

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions doc/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
.exampleScene {
margin: 15px auto;
border: 1px solid black;
display: block;
}

#sidebar {
Expand Down Expand Up @@ -197,6 +198,7 @@
padding: 10px;
padding-left: 20px;
height: 100%;
max-width: 800px;
}

</style>
Expand Down
22 changes: 20 additions & 2 deletions js/BinPacker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,27 @@

/**
* Given a rectangular containing area, takes care of allocating and deallocating smaller rectangular "bins" that fit
* together inside the area and do not overlap.
* together inside the area and do not overlap. Optimized more for runtime CPU usage than space currently.
*
* Inpsired from https://github.com/jakesgordon/bin-packing/blob/master/js/packer.js
* For example:
* #begin canvasExample binPacker 256x256
* #on
* var binPacker = new dot.BinPacker( new dot.Bounds2( 0, 0, 256, 256 ) );
* var bins = [];
* for ( var i = 0; i < 100; i++ ) {
* var bin = binPacker.allocate( Math.random() * 64, Math.random() * 64 );
* if ( bin ) {
* bins.push( bin );
* }
* }
* #off
*
* context.strokeStyle = '#000';
* bins.forEach( function( bin ) {
* var bounds = bin.bounds;
* context.strokeRect( bounds.x, bounds.y, bounds.width, bounds.height );
* } );
* #end canvasExample
*
* @author Sharfudeen Ashraf
* @author Jonathan Olson <jonathan.olson@colorado.edu>
Expand Down
27 changes: 27 additions & 0 deletions js/ConvexHull2.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,33 @@
/**
* Construction of 2D convex hulls from a list of points.
*
* For example:
* #begin canvasExample grahamScan 256x128
* #on
* var points = _.range( 50 ).map( function() {
* return new dot.Vector2( 5 + ( 256 - 10 ) * Math.random(), 5 + ( 128 - 10 ) * Math.random() );
* } );
* var hullPoints = dot.ConvexHull2.grahamScan( points, false );
* #off
* context.beginPath();
* hullPoints.forEach( function( point ) {
* context.lineTo( point.x, point.y );
* } );
* context.closePath();
* context.fillStyle = '#eee';
* context.fill();
* context.strokeStyle = '#f00';
* context.stroke();
*
* context.beginPath();
* points.forEach( function( point ) {
* context.arc( point.x, point.y, 2, 0, Math.PI * 2, false );
* context.closePath();
* } );
* context.fillStyle = '#00f';
* context.fill();
* #end canvasExample
*
* @author Jonathan Olson <jonathan.olson@colorado.edu>
*/

Expand Down
16 changes: 11 additions & 5 deletions js/Transform4.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ define( function( require ) {
require( 'DOT/Vector3' );
require( 'DOT/Ray3' );

var scratchMatrix = new dot.Matrix4();

function checkMatrix( matrix ) {
return ( matrix instanceof dot.Matrix4 ) && matrix.isFinite();
}

/**
* Creates a transform based around an initial matrix.
* @constructor
Expand Down Expand Up @@ -70,7 +76,7 @@ define( function( require ) {

/**
* Sets the value of the primary matrix directly from a Matrix4. Does not change the Matrix4 instance of this
* Transform3.
* Transform4.
* @public
*
* @param {Matrix4} matrix
Expand Down Expand Up @@ -140,7 +146,7 @@ define( function( require ) {
* Like prepend(), but prepends the other transform's matrix.
* @public
*
* @param {Transform3} transform
* @param {Transform4} transform
*/
prependTransform: function( transform ) {
this.prepend( transform.matrix );
Expand All @@ -150,7 +156,7 @@ define( function( require ) {
* Like append(), but appends the other transform's matrix.
* @public
*
* @param {Transform3} transform
* @param {Transform4} transform
*/
appendTransform: function( transform ) {
this.append( transform.matrix );
Expand All @@ -174,10 +180,10 @@ define( function( require ) {
* Creates a copy of this transform.
* @public
*
* @returns {Transform3}
* @returns {Transform4}
*/
copy: function() {
var transform = new Transform3( this.matrix );
var transform = new Transform4( this.matrix );

transform.inverse = this.inverse;
transform.matrixTransposed = this.matrixTransposed;
Expand Down

0 comments on commit b8ec76e

Please sign in to comment.