yzt
2023-05-26 2f70f6727314edd84d8ec2bfe3ce832803f1ea77
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import { BoundingSphere } from "../../Source/Cesium.js";
import { Cartesian3 } from "../../Source/Cesium.js";
import { ComponentDatatype } from "../../Source/Cesium.js";
import { Ellipsoid } from "../../Source/Cesium.js";
import { Geometry } from "../../Source/Cesium.js";
import { GeometryAttribute } from "../../Source/Cesium.js";
import { GeometryType } from "../../Source/Cesium.js";
import { Math as CesiumMath } from "../../Source/Cesium.js";
import { PrimitiveType } from "../../Source/Cesium.js";
import { Rectangle } from "../../Source/Cesium.js";
 
describe("Core/Geometry", function () {
  it("constructor", function () {
    var attributes = {
      position: new GeometryAttribute({
        componentDatatype: ComponentDatatype.DOUBLE,
        componentsPerAttribute: 3,
        values: new Float64Array([0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0]),
      }),
    };
    var indices = new Uint16Array([0, 1, 2]);
    var boundingSphere = new BoundingSphere(new Cartesian3(0.5, 0.5, 0.0), 1.0);
 
    var geometry = new Geometry({
      attributes: attributes,
      indices: indices,
      primitiveType: PrimitiveType.TRIANGLES,
      boundingSphere: boundingSphere,
      geometryType: GeometryType.TRIANGLES,
    });
 
    expect(geometry.attributes).toBe(attributes);
    expect(geometry.indices).toBe(indices);
    expect(geometry.primitiveType).toEqual(PrimitiveType.TRIANGLES);
    expect(geometry.boundingSphere).toBe(boundingSphere);
    expect(geometry.geometryType).toEqual(GeometryType.TRIANGLES);
  });
 
  it("constructor throws without attributes", function () {
    expect(function () {
      return new Geometry({
        primitiveType: PrimitiveType.TRIANGLES,
      });
    }).toThrowDeveloperError();
  });
 
  it("computeNumberOfVertices", function () {
    var attributes = {
      position: new GeometryAttribute({
        componentDatatype: ComponentDatatype.DOUBLE,
        componentsPerAttribute: 3,
        values: new Float64Array([0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0]),
      }),
      st: new GeometryAttribute({
        componentDatatype: ComponentDatatype.FLOAT,
        componentsPerAttribute: 2,
        values: new Float32Array([0.0, 0.0, 1.0, 0.0, 0.0, 1.0]),
      }),
    };
    var indices = new Uint16Array([0, 1, 2]);
    var boundingSphere = new BoundingSphere(new Cartesian3(0.5, 0.5, 0.0), 1.0);
 
    var geometry = new Geometry({
      attributes: attributes,
      indices: indices,
      primitiveType: PrimitiveType.TRIANGLES,
      boundingSphere: boundingSphere,
    });
 
    expect(Geometry.computeNumberOfVertices(geometry)).toEqual(3);
  });
 
  it("computeNumberOfVertices throws when attributes have different number of vertices", function () {
    var attributes = {
      position: new GeometryAttribute({
        componentDatatype: ComponentDatatype.DOUBLE,
        componentsPerAttribute: 3,
        values: new Float64Array([0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0]),
      }),
      st: new GeometryAttribute({
        componentDatatype: ComponentDatatype.FLOAT,
        componentsPerAttribute: 2,
        values: new Float32Array([0.0, 0.0, 1.0, 0.0]),
      }),
    };
    var indices = new Uint16Array([0, 1, 2]);
    var boundingSphere = new BoundingSphere(new Cartesian3(0.5, 0.5, 0.0), 1.0);
 
    var geometry = new Geometry({
      attributes: attributes,
      indices: indices,
      primitiveType: PrimitiveType.TRIANGLES,
      boundingSphere: boundingSphere,
    });
 
    expect(function () {
      Geometry.computeNumberOfVertices(geometry);
    }).toThrowDeveloperError();
  });
 
  it("computeNumberOfVertices throws without geometry", function () {
    expect(function () {
      Geometry.computeNumberOfVertices();
    }).toThrowDeveloperError();
  });
 
  it("computes textureCoordinateRotationPoints for collections of points", function () {
    var positions = Cartesian3.fromDegreesArrayHeights([
      -10.0,
      -10.0,
      0,
      -10.0,
      10.0,
      0,
      10.0,
      -10.0,
      0,
      10.0,
      10.0,
      0,
    ]);
    var boundingRectangle = Rectangle.fromCartesianArray(positions);
    var textureCoordinateRotationPoints = Geometry._textureCoordinateRotationPoints(
      positions,
      0.0,
      Ellipsoid.WGS84,
      boundingRectangle
    );
    expect(textureCoordinateRotationPoints.length).toEqual(6);
    expect(textureCoordinateRotationPoints[0]).toEqualEpsilon(
      0,
      CesiumMath.EPSILON7
    );
    expect(textureCoordinateRotationPoints[1]).toEqualEpsilon(
      0,
      CesiumMath.EPSILON7
    );
    expect(textureCoordinateRotationPoints[2]).toEqualEpsilon(
      0,
      CesiumMath.EPSILON7
    );
    expect(textureCoordinateRotationPoints[3]).toEqualEpsilon(
      1,
      CesiumMath.EPSILON7
    );
    expect(textureCoordinateRotationPoints[4]).toEqualEpsilon(
      1,
      CesiumMath.EPSILON7
    );
    expect(textureCoordinateRotationPoints[5]).toEqualEpsilon(
      0,
      CesiumMath.EPSILON7
    );
  });
});