···4444 ];
4545};
46464747+Cone.prototype.updateSortValue = function() {
4848+ // call super
4949+ Ellipse.prototype.updateSortValue.apply( this, arguments );
5050+ var apexNormal = new Vector();
5151+ apexNormal.set( this.renderOrigin )
5252+ .subtract( this.apex.renderOrigin );
5353+ var apexAngleZ = Math.atan2( apexNormal.z, apexNormal.y );
5454+ apexAngleZ = utils.modulo( apexAngleZ, TAU );
5555+ //center of cone is one third of its length.
5656+ var apexZ = this.length/3 * Math.sin(apexAngleZ);
5757+ this.sortValue -= apexZ;
5858+};
5959+4760Cone.prototype.render = function( ctx, renderer ) {
4861 this.renderConeSurface( ctx, renderer );
4962 Ellipse.prototype.render.apply( this, arguments );
-11
js/ellipse.js
···5858 }
5959};
60606161-Ellipse.prototype.updateSortValue = function() {
6262- Shape.prototype.updateSortValue.apply( this, arguments );
6363- if ( this.quarters != 4 ) {
6464- return;
6565- }
6666- // ellipse is self closing, do not count last point twice
6767- var length = this.pathCommands.length;
6868- var lastPoint = this.pathCommands[ length - 1 ].endRenderPoint;
6969- this.sortValue -= lastPoint.z / length;
7070-};
7171-7261return Ellipse;
73627463}));
+10
js/hemisphere.js
···20202121var TAU = utils.TAU;
22222323+Hemisphere.prototype.updateSortValue = function() {
2424+ // call super
2525+ Ellipse.prototype.updateSortValue.apply( this, arguments );
2626+ var contourAngleZ = Math.atan2( this.renderNormal.z, this.renderNormal.y );
2727+ contourAngleZ = utils.modulo( contourAngleZ, TAU );
2828+ //center of dome is half the radius.
2929+ var domeZ = this.diameter/2/2 * Math.sin(contourAngleZ);
3030+ this.sortValue -= domeZ;
3131+};
3232+2333Hemisphere.prototype.render = function( ctx, renderer ) {
2434 this.renderDome( ctx, renderer );
2535 // call super
-8
js/rounded-rect.js
···7272 this.path = path;
7373};
74747575-RoundedRect.prototype.updateSortValue = function() {
7676- Shape.prototype.updateSortValue.apply( this, arguments );
7777- // ellipse is self closing, do not count last point twice
7878- var length = this.pathCommands.length;
7979- var lastPoint = this.pathCommands[ length - 1 ].endRenderPoint;
8080- this.sortValue -= lastPoint.z / length;
8181-};
8282-8375return RoundedRect;
84768577}));
+16-6
js/shape.js
···110110111111112112Shape.prototype.updateSortValue = function() {
113113+ // average sort all z points.
114114+ // ignore the final point if it is a closed shape.
115115+ var howManyPoints = this.pathCommands.length;
113116 var sortValueTotal = 0;
114114- this.pathCommands.forEach( function( command ) {
115115- sortValueTotal += command.endRenderPoint.z;
116116- });
117117- // average sort value of all points
118118- // def not geometrically correct, but works for me
119119- this.sortValue = sortValueTotal / this.pathCommands.length;
117117+ var firstPoint = this.pathCommands[0].endRenderPoint;
118118+ var lastPoint = this.pathCommands[this.pathCommands.length-1].endRenderPoint;
119119+ if (howManyPoints > 2 &&
120120+ firstPoint.isSame(lastPoint)) {
121121+ howManyPoints -= 1; // closed shape; ignore final point.
122122+ }
123123+124124+ for (var i = 0; i < howManyPoints; i++) {
125125+ sortValueTotal += this.pathCommands[i].endRenderPoint.z;
126126+ }
127127+ // average sort value of all points
128128+ // def not geometrically correct, but works for me
129129+ this.sortValue = sortValueTotal / howManyPoints;
120130};
121131122132// ----- render ----- //