forked from SuperMap/iClient-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSize.js
More file actions
98 lines (84 loc) · 2.44 KB
/
Size.js
File metadata and controls
98 lines (84 loc) · 2.44 KB
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
import SuperMap from '../SuperMap';
/**
* @class SuperMap.Size
* @classdesc 此类描绘一对高宽值的实例。
* @param w -{number} 宽度,默认值为0.0
* @param h -{number} 高度 ,默认值为0.0
*
* @example
* var size = new SuperMap.Size(31,46);
*/
export default class Size {
/**
* @member SuperMap.Size.prototype.w -{number}
* @description 宽,默认值为0.0
*/
w = 0.0;
/**
* @member SuperMap.Size.prototype.h -{number}
* @description 高,默认值为0.0
*/
h = 0.0;
constructor(w, h) {
this.w = w ? parseFloat(w) : this.w;
this.h = w ? parseFloat(h) : this.h;
}
/**
* @function SuperMap.Size.prototype.toString
* @description 返回此对象的字符串形式
* @example
* var size = new SuperMap.Size(10,5);
* var str = size.toString();
* @returns {string} 例如:"w=10,h=5"
*/
toString() {
return ("w=" + this.w + ",h=" + this.h);
}
/**
* @function SuperMap.Size.prototype.clone
* @description 克隆当前size对象.
* @example
* var size = new SuperMap.Size(31,46);
* var size2 = size.clone();
*
* @returns {SuperMap.Size} 返回一个新的与当前size对象有相同宽、高的Size对象。
*/
clone() {
return new Size(this.w, this.h);
}
/**
*
* @function SuperMap.Size.prototype.equals
* @description 比较两个size对象是否相等。
* @example
* var size = new SuperMap.Size(31,46);
* var size2 = new SuperMap.Size(31,46);
* var isEquals = size.equals(size2);
*
* @param sz -{SuperMap.Size} 用于比较相等的Size对象。
* @returns {Boolean} 传入的size和当前size高宽相等,注意:如果传入的size为空则返回false
*
*/
equals(sz) {
var equals = false;
if (sz != null) {
equals = ((this.w === sz.w && this.h === sz.h) ||
(isNaN(this.w) && isNaN(this.h) && isNaN(sz.w) && isNaN(sz.h)));
}
return equals;
}
/**
*
* @function SuperMap.Size.prototype.destroy
* @description 销毁此对象。销毁后此对象的所有属性为null,而不是初始值。
* @example
* var size = new SuperMap.Size(31,46);
* size.destroy();
*/
destroy() {
this.w = null;
this.h = null;
}
CLASS_NAME = "SuperMap.Size"
}
SuperMap.Size = Size;