1+ require ( '../../../../src/common/commontypes/geometry/LineString' ) ;
2+
3+ describe ( 'common_LineString Test' , function ( ) {
4+ var roadLine ;
5+ beforeEach ( function ( ) {
6+ var points = [ new SuperMap . Geometry . Point ( 4933.319287022352 , - 3337.3849141502124 ) ,
7+ new SuperMap . Geometry . Point ( 4960.9674060199022 , - 3349.3316322355736 ) ,
8+ new SuperMap . Geometry . Point ( 5075.3145648369318 , - 3378.0037556404409 ) ,
9+ new SuperMap . Geometry . Point ( 5006.0235999418364 , - 3358.8890067038628 ) ,
10+ new SuperMap . Geometry . Point ( 5305.19551436013 , - 3376.9669111768926 ) ] ;
11+ roadLine = new SuperMap . Geometry . LineString ( points ) ;
12+ } ) ;
13+
14+ it ( 'constructor test' , function ( ) {
15+ expect ( roadLine ) . not . toBeNull ( ) ;
16+ expect ( roadLine . components . length ) . toEqual ( 5 ) ;
17+ } ) ;
18+
19+ it ( 'removeComponent test' , function ( ) {
20+ var removePoint = new SuperMap . Geometry . Point ( 4960.9674060199022 , - 3349.3316322355736 ) ;
21+ var removed = roadLine . removeComponent ( removePoint ) ;
22+ expect ( removed ) . toBeTruthy ( ) ;
23+ } ) ;
24+
25+ it ( 'getSortedSegments test' , function ( ) {
26+ var segments = roadLine . getSortedSegments ( ) ;
27+ expect ( segments ) . not . toBeNull ( ) ;
28+ expect ( segments . length ) . toEqual ( 4 ) ;
29+ expect ( segments [ 0 ] . x1 ) . toBeLessThan ( segments [ 0 ] . x2 ) ;
30+ expect ( segments [ 1 ] . x1 ) . toBeLessThan ( segments [ 1 ] . x2 ) ;
31+ expect ( segments [ 2 ] . x1 ) . toBeLessThan ( segments [ 2 ] . x2 ) ;
32+ expect ( segments [ 3 ] . x1 ) . toBeLessThan ( segments [ 3 ] . x2 ) ;
33+
34+ } ) ;
35+
36+ it ( 'getVertices test' , function ( ) {
37+ var vertices1 , vertices2 , vertices3 ;
38+ //nodes = true
39+ vertices1 = roadLine . getVertices ( true ) ;
40+ expect ( vertices1 ) . not . toBeNull ( ) ;
41+ expect ( vertices1 . length ) . toEqual ( 2 ) ;
42+ //nodes = false
43+ vertices2 = roadLine . getVertices ( false ) ;
44+ expect ( vertices2 ) . not . toBeNull ( ) ;
45+ expect ( vertices2 . length ) . toEqual ( 3 ) ;
46+ //nodes = ""
47+ vertices3 = roadLine . getVertices ( ) ;
48+ expect ( vertices3 ) . not . toBeNull ( ) ;
49+ expect ( vertices3 . length ) . toEqual ( 5 ) ;
50+ } ) ;
51+
52+ it ( 'calculateCircle' , function ( ) {
53+ var points1 = [ ] , points2 = [ ] , points3 = [ ] ;
54+ //两点:
55+ points1 . push ( new SuperMap . Geometry . Point ( - 50 , 30 ) ) ;
56+ points1 . push ( new SuperMap . Geometry . Point ( - 30 , 50 ) ) ;
57+ var circle1 = SuperMap . Geometry . LineString . calculateCircle ( points1 ) ;
58+ expect ( circle1 . length ) . toEqual ( 2 ) ;
59+
60+ //三点p1.x != p3.x:
61+ points2 . push ( new SuperMap . Geometry . Point ( - 50 , 30 ) ) ;
62+ points2 . push ( new SuperMap . Geometry . Point ( - 30 , 50 ) ) ;
63+ points2 . push ( new SuperMap . Geometry . Point ( - 20 , 60 ) ) ;
64+ var circle2 = SuperMap . Geometry . LineString . calculateCircle ( points2 ) ;
65+ expect ( circle2 . length ) . toEqual ( 3 ) ;
66+
67+ //三点p1.x == p3.x:
68+ points3 . push ( new SuperMap . Geometry . Point ( - 50 , 30 ) ) ;
69+ points3 . push ( new SuperMap . Geometry . Point ( - 30 , 50 ) ) ;
70+ points3 . push ( new SuperMap . Geometry . Point ( - 50 , 60 ) ) ;
71+ var circle3 = SuperMap . Geometry . LineString . calculateCircle ( points3 ) ;
72+ expect ( circle3 . length ) . toBeGreaterThan ( 3 ) ;
73+
74+ } ) ;
75+
76+ it ( 'createLineEPS test' , function ( ) {
77+ var points = [ ] ;
78+ points . push ( new SuperMap . Geometry . Point ( - 50 , 30 ) ) ;
79+ points . push ( new SuperMap . Geometry . Point ( - 30 , 50 , "LTypeArc" ) ) ;
80+ points . push ( new SuperMap . Geometry . Point ( 2 , 60 ) ) ;
81+ points . push ( new SuperMap . Geometry . Point ( 8 , 20 ) ) ;
82+
83+ var lineEPS = SuperMap . Geometry . LineString . createLineEPS ( points ) ;
84+ expect ( lineEPS . length ) . toEqual ( 74 ) ;
85+
86+ var points1 = [ ] ;
87+ points1 . push ( new SuperMap . Geometry . Point ( - 50 , 30 ) ) ;
88+ points1 . push ( new SuperMap . Geometry . Point ( - 30 , 50 , "LTypeCurve" ) ) ;
89+ points1 . push ( new SuperMap . Geometry . Point ( 2 , 60 ) ) ;
90+ points1 . push ( new SuperMap . Geometry . Point ( 8 , 20 ) ) ;
91+
92+ var lineEPS1 = SuperMap . Geometry . LineString . createLineEPS ( points1 ) ;
93+ expect ( lineEPS1 . length ) . toEqual ( 4 ) ;
94+ } ) ;
95+
96+ it ( 'createLineArc test' , function ( ) {
97+ var lineArc1 , lineArc2 , lineArc3 ;
98+ var list = [ ] , i , len , points = [ ] ;
99+ points . push ( new SuperMap . Geometry . Point ( - 50 , 30 ) ) ;
100+ points . push ( new SuperMap . Geometry . Point ( - 30 , 50 , "LTypeArc" ) ) ;
101+ points . push ( new SuperMap . Geometry . Point ( 2 , 60 ) ) ;
102+ points . push ( new SuperMap . Geometry . Point ( 8 , 20 ) ) ;
103+
104+ //i = 0;
105+ i = 0 ; len = 2 ;
106+ lineArc1 = SuperMap . Geometry . LineString . createLineArc ( list , i , len , points ) ;
107+ expect ( lineArc1 [ 0 ] . length ) . toEqual ( 2 ) ;
108+ //i = len -1;
109+ i = 1 ; len = 2 ;
110+ lineArc2 = SuperMap . Geometry . LineString . createLineArc ( list , i , len , points ) ;
111+ expect ( lineArc2 [ 0 ] . length ) . toEqual ( 4 ) ;
112+ //i = "";
113+ i = 1 ; len = 4 ;
114+ lineArc3 = SuperMap . Geometry . LineString . createLineArc ( list , i , len , points ) ;
115+ expect ( lineArc3 [ 0 ] . length ) . toEqual ( 76 ) ;
116+ } ) ;
117+
118+ it ( 'addPointEPS test' , function ( ) {
119+ var pointEPS1 , pointEPS2 , pointEPS3 ;
120+ var type = "LTypeArc" , i , len , points = [ ] ;
121+ points . push ( new SuperMap . Geometry . Point ( - 50 , 30 ) ) ;
122+ points . push ( new SuperMap . Geometry . Point ( - 30 , 50 , "LTypeArc" ) ) ;
123+ points . push ( new SuperMap . Geometry . Point ( 2 , 60 ) ) ;
124+ points . push ( new SuperMap . Geometry . Point ( 8 , 20 ) ) ;
125+
126+ //i = 0;
127+ i = 0 ; len = 2 ;
128+ pointEPS1 = SuperMap . Geometry . LineString . addPointEPS ( points , i , len , type ) ;
129+ expect ( pointEPS1 [ 0 ] . length ) . toEqual ( 2 ) ;
130+ //i = len -1;
131+ i = 1 ; len = 2 ;
132+ pointEPS2 = SuperMap . Geometry . LineString . addPointEPS ( points , i , len , type ) ;
133+ expect ( pointEPS2 [ 0 ] . length ) . toEqual ( 2 ) ;
134+ //i = "";
135+ i = 1 ; len = 4 ;
136+ pointEPS3 = SuperMap . Geometry . LineString . addPointEPS ( points , i , len , type ) ;
137+ expect ( pointEPS3 [ 0 ] . length ) . toEqual ( 73 ) ;
138+ } ) ;
139+ } ) ;
0 commit comments