2 lines
5.1 KiB
JavaScript
2 lines
5.1 KiB
JavaScript
|
/* 2020-9-22 15:23:25 | 版权所有 军懋国兴 */
|
||
|
define(["exports","./when-cbf8cd21","./Check-35e1a91d","./Cartesian2-43e3a3be","./Transforms-2d1ac5ec","./IntersectionTests-459f6f08","./Plane-46b5436f"],function(e,p,o,x,s,c,a){"use strict";function y(e,n,t){this.minimum=x.Cartesian3.clone(p.defaultValue(e,x.Cartesian3.ZERO)),this.maximum=x.Cartesian3.clone(p.defaultValue(n,x.Cartesian3.ZERO)),t=p.defined(t)?x.Cartesian3.clone(t):x.Cartesian3.midpoint(this.minimum,this.maximum,new x.Cartesian3),this.center=t}y.fromPoints=function(e,n){if(p.defined(n)||(n=new y),!p.defined(e)||0===e.length)return n.minimum=x.Cartesian3.clone(x.Cartesian3.ZERO,n.minimum),n.maximum=x.Cartesian3.clone(x.Cartesian3.ZERO,n.maximum),n.center=x.Cartesian3.clone(x.Cartesian3.ZERO,n.center),n;for(var t=e[0].x,i=e[0].y,a=e[0].z,r=e[0].x,s=e[0].y,o=e[0].z,c=e.length,m=1;m<c;m++)var l=e[m],d=l.x,u=l.y,f=l.z,t=Math.min(d,t),r=Math.max(d,r),i=Math.min(u,i),s=Math.max(u,s),a=Math.min(f,a),o=Math.max(f,o);var h=n.minimum;h.x=t,h.y=i,h.z=a;var C=n.maximum;return C.x=r,C.y=s,C.z=o,n.center=x.Cartesian3.midpoint(h,C,n.center),n},y.clone=function(e,n){if(p.defined(e))return p.defined(n)?(n.minimum=x.Cartesian3.clone(e.minimum,n.minimum),n.maximum=x.Cartesian3.clone(e.maximum,n.maximum),n.center=x.Cartesian3.clone(e.center,n.center),n):new y(e.minimum,e.maximum,e.center)},y.equals=function(e,n){return e===n||p.defined(e)&&p.defined(n)&&x.Cartesian3.equals(e.center,n.center)&&x.Cartesian3.equals(e.minimum,n.minimum)&&x.Cartesian3.equals(e.maximum,n.maximum)};var m=new x.Cartesian3;y.intersectPlane=function(e,n){o.Check.defined("box",e),o.Check.defined("plane",n),m=x.Cartesian3.subtract(e.maximum,e.minimum,m);var t=x.Cartesian3.multiplyByScalar(m,.5,m),i=n.normal,a=t.x*Math.abs(i.x)+t.y*Math.abs(i.y)+t.z*Math.abs(i.z),r=x.Cartesian3.dot(e.center,i)+n.distance;return 0<r-a?s.Intersect.INSIDE:r+a<0?s.Intersect.OUTSIDE:s.Intersect.INTERSECTING},y.prototype.clone=function(e){return y.clone(this,e)},y.prototype.intersectPlane=function(e){return y.intersectPlane(this,e)},y.prototype.equals=function(e){return y.equals(this,e)};var r=new s.Cartesian4;function t(e,n){if(o.Check.defined("origin",e),e=(n=p.defaultValue(n,x.Ellipsoid.WGS84)).scaleToGeodeticSurface(e),!p.defined(e))throw new o.DeveloperError("origin must not be at the center of the ellipsoid.");var t=s.Transforms.eastNorthUpToFixedFrame(e,n);this._ellipsoid=n,this._origin=e,this._xAxis=x.Cartesian3.fromCartesian4(s.Matrix4.getColumn(t,0,r)),this._yAxis=x.Cartesian3.fromCartesian4(s.Matrix4.getColumn(t,1,r));var i=x.Cartesian3.fromCartesian4(s.Matrix4.getColumn(t,2,r));this._plane=a.Plane.fromPointNormal(e,i)}Object.defineProperties(t.prototype,{ellipsoid:{get:function(){return this._ellipsoid}},origin:{get:function(){return this._origin}},plane:{get:function(){return this._plane}},xAxis:{get:function(){return this._xAxis}},yAxis:{get:function(){return this._yAxis}},zAxis:{get:function(){return this._plane.normal}}});var i=new y;t.fromPoints=function(e,n){return o.Check.defined("cartesians",e),new t(y.fromPoints(e,i).center,n)};var l=new c.Ray,d=new x.Cartesian3;t.prototype.projectPointOntoPlane=function(e,n){o.Check.defined("cartesian",e);var t=l;t.origin=e,x.Cartesian3.normalize(e,t.direction);var i=c.IntersectionTests.rayPlane(t,this._plane,d);if(p.defined(i)||(x.Cartesian3.negate(t.direction,t.direction),i=c.IntersectionTests.rayPlane(t,this._plane,d)),p.defined(i)){var a=x.Cartesian3.subtract(i,this._origin,i),r=x.Cartesian3.dot(this._xAxis,a),s=x.Cartesian3.dot(this._yAxis,a);return p.defined(n)?(n.x=r,n.y=s,n):new x.Cartesian2(r,s)}},t.prototype.projectPointsOntoPlane=function(e,n){o.Check.defined("cartesians",e),p.defined(n)||(n=[]);for(var t=0,i=e.length,a=0;a<i;a++){var r=this.projectPointOntoPlane(e[a],n[t]);p.defined(r)&&(n[t]=r,t++)}return n.length=t,n},t.prototype.projectPointToNearestOnPlane=function(e,n){o.Check.defined("cartesian",e),p.defined(n)||(n=new x.Cartesian2);var t=l;t.origin=e,x.Cartesian3.clone(this._plane.normal,t.direction);var i=c.IntersectionTests.rayPlane(t,this._plane,d);p.defined(i)||(x.Cartesian3.negate(t.direction,t.dir
|