jxdnsong
2020-10-24 da0104cede61a05a93e97b96ba0aaa7e222bb7d6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/**
 * Cesium - https://github.com/AnalyticalGraphicsInc/cesium
 *
 * Copyright 2011-2017 Cesium Contributors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Columbus View (Pat. Pend.)
 *
 * Portions licensed separately.
 * See https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md for full licensing details.
 */
define(['exports', './Check-70bec281', './Cartesian2-2cbe6c75', './BoundingSphere-51445700', './OrientedBoundingBox-2b1de35e'], function (exports, Check, Cartesian2, BoundingSphere, OrientedBoundingBox) { 'use strict';
 
    /**
         * @private
         */
        var CoplanarPolygonGeometryLibrary = {};
 
        var scratchIntersectionPoint = new Cartesian2.Cartesian3();
        var scratchXAxis = new Cartesian2.Cartesian3();
        var scratchYAxis = new Cartesian2.Cartesian3();
        var scratchZAxis = new Cartesian2.Cartesian3();
        var obbScratch = new OrientedBoundingBox.OrientedBoundingBox();
 
        CoplanarPolygonGeometryLibrary.validOutline = function(positions) {
            //>>includeStart('debug', pragmas.debug);
            Check.Check.defined('positions', positions);
            //>>includeEnd('debug');
 
            var orientedBoundingBox = OrientedBoundingBox.OrientedBoundingBox.fromPoints(positions, obbScratch);
            var halfAxes = orientedBoundingBox.halfAxes;
            var xAxis = BoundingSphere.Matrix3.getColumn(halfAxes, 0, scratchXAxis);
            var yAxis = BoundingSphere.Matrix3.getColumn(halfAxes, 1, scratchYAxis);
            var zAxis = BoundingSphere.Matrix3.getColumn(halfAxes, 2, scratchZAxis);
 
            var xMag = Cartesian2.Cartesian3.magnitude(xAxis);
            var yMag = Cartesian2.Cartesian3.magnitude(yAxis);
            var zMag = Cartesian2.Cartesian3.magnitude(zAxis);
 
            // If all the points are on a line return undefined because we can't draw a polygon
            return !((xMag === 0 && (yMag === 0 || zMag === 0)) || (yMag === 0 && zMag === 0));
        };
 
        // call after removeDuplicates
        CoplanarPolygonGeometryLibrary.computeProjectTo2DArguments = function(positions, centerResult, planeAxis1Result, planeAxis2Result) {
            //>>includeStart('debug', pragmas.debug);
            Check.Check.defined('positions', positions);
            Check.Check.defined('centerResult', centerResult);
            Check.Check.defined('planeAxis1Result', planeAxis1Result);
            Check.Check.defined('planeAxis2Result', planeAxis2Result);
            //>>includeEnd('debug');
 
            var orientedBoundingBox = OrientedBoundingBox.OrientedBoundingBox.fromPoints(positions, obbScratch);
            var halfAxes = orientedBoundingBox.halfAxes;
            var xAxis = BoundingSphere.Matrix3.getColumn(halfAxes, 0, scratchXAxis);
            var yAxis = BoundingSphere.Matrix3.getColumn(halfAxes, 1, scratchYAxis);
            var zAxis = BoundingSphere.Matrix3.getColumn(halfAxes, 2, scratchZAxis);
 
            var xMag = Cartesian2.Cartesian3.magnitude(xAxis);
            var yMag = Cartesian2.Cartesian3.magnitude(yAxis);
            var zMag = Cartesian2.Cartesian3.magnitude(zAxis);
            var min = Math.min(xMag, yMag, zMag);
 
            // If all the points are on a line return undefined because we can't draw a polygon
            if ((xMag === 0 && (yMag === 0 || zMag === 0)) || (yMag === 0 && zMag === 0)) {
                return false;
            }
 
            var planeAxis1;
            var planeAxis2;
 
            if (min === yMag || min === zMag) {
                planeAxis1 = xAxis;
            }
            if (min === xMag) {
                planeAxis1 = yAxis;
            } else if (min === zMag) {
                planeAxis2 = yAxis;
            }
            if (min === xMag || min === yMag) {
                planeAxis2 = zAxis;
            }
 
            Cartesian2.Cartesian3.normalize(planeAxis1, planeAxis1Result);
            Cartesian2.Cartesian3.normalize(planeAxis2, planeAxis2Result);
            Cartesian2.Cartesian3.clone(orientedBoundingBox.center, centerResult);
            return true;
        };
 
        function projectTo2D(position, center, axis1, axis2, result) {
            var v = Cartesian2.Cartesian3.subtract(position, center, scratchIntersectionPoint);
            var x = Cartesian2.Cartesian3.dot(axis1, v);
            var y = Cartesian2.Cartesian3.dot(axis2, v);
 
            return Cartesian2.Cartesian2.fromElements(x, y, result);
        }
 
        CoplanarPolygonGeometryLibrary.createProjectPointsTo2DFunction = function(center, axis1, axis2) {
            return function(positions) {
                var positionResults = new Array(positions.length);
                for (var i = 0; i < positions.length; i++) {
                    positionResults[i] = projectTo2D(positions[i], center, axis1, axis2);
                }
 
                return positionResults;
            };
        };
 
        CoplanarPolygonGeometryLibrary.createProjectPointTo2DFunction = function(center, axis1, axis2) {
            return function(position, result) {
                return projectTo2D(position, center, axis1, axis2, result);
            };
        };
 
    exports.CoplanarPolygonGeometryLibrary = CoplanarPolygonGeometryLibrary;
 
});