···34343535 // vectors used for calculation
3636 this.renderApex = new Vector();
3737+ this.renderCentroid = new Vector();
3738 this.tangentA = new Vector();
3839 this.tangentB = new Vector();
3940···4546};
46474748Cone.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;
4949+ // center of cone is one third of its length
5050+ this.renderCentroid.set( this.renderOrigin )
5151+ .lerp( this.apex.renderOrigin, 1/3 );
5252+ this.sortValue = this.renderCentroid.z;
5853};
59546055Cone.prototype.render = function( ctx, renderer ) {
···108108 });
109109};
110110111111-112111Shape.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;
116116- var sortValueTotal = 0;
112112+ // sort by average z of all points
113113+ // def not geometrically correct, but works for me
114114+ var pointCount = this.pathCommands.length;
117115 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.
116116+ var lastPoint = this.pathCommands[ pointCount - 1 ].endRenderPoint;
117117+ // ignore the final point if self closing shape
118118+ var isSelfClosing = pointCount > 2 && firstPoint.isSame( lastPoint );
119119+ if ( isSelfClosing ) {
120120+ pointCount -= 1;
122121 }
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;
122122+123123+ var sortValueTotal = 0;
124124+ for ( var i = 0; i < pointCount; i++ ) {
125125+ sortValueTotal += this.pathCommands[i].endRenderPoint.z;
126126+ }
127127+ this.sortValue = sortValueTotal / pointCount;
130128};
131129132130// ----- render ----- //