Point 点

代表一个点,其 x 和 y 坐标为像素。

使用示例

var point = hnsdk.point(200, 300);

所有接受 Point 对象的Leaflet方法和选项也接受它们的简单数组形式(除非另有说明),所以这些行是等价的:

map.panBy([200, 300]);
map.panBy(hnsdk.point(200, 300));

注意, Point 不继承 hnsdk 的 Class 对象,这意味着新的类不能继承于它,新的方法也不能用 include 函数添加到它。

构造函数说明
hnsdk.point( x, y, round?) 用给定的 xy 坐标创建一个点对象。如果可选的 round 被设置为true,则对 xy 值进行舍入。
hnsdk.point(coords)期待一个形式为 [x, y] 的数组来代替。
hnsdk.point( coords) 期待一个形式为 {x: Number, y: Number} 的普通对象来代替。

Methods 方法

方法名返回值说明
clone()Point

返回当前点的拷贝。

add(otherPoint)Point

返回当前点和给定点的相加结果。

subtract(otherPoint)Point

返回给定点与当前点相减的结果。

divideBy( num)Point

返回当前点除以给定数字的结果。

multiplyBy( num)Point

返回当前点与给定数字相乘的结果。

scaleBy(scale)Point

将当前点的每个坐标与 scale的每个坐标相乘。用线性代数术语来说,就是用点乘以 scale 所定义的 缩放矩阵

unscaleBy(scale)Point

scaleBy的倒数。将当前点的每个坐标除以 scale的每个坐标。

round()Point

返回具有圆角坐标的当前点的拷贝。

floor()Point

返回具有浮动坐标的当前点的拷贝(向下舍入)。

ceil()Point

返回当前点的拷贝,坐标为最高值(四舍五入)。

trunc()Point

返回具有截断坐标的当前点的拷贝(四舍五入为零)。

distanceTo(otherPoint)Number

返回当前点和给定点之间的笛卡尔距离。

equals(otherPoint)Boolean

如果给定的点具有相同的坐标,则返回 true

contains(otherPoint)Boolean

如果给定点的两个坐标都小于相应的当前点坐标(绝对值),则返回 true

toString()String

返回点的字符串表示,用于调试目的。

Properties 属性

属性类型说明
xNumber点的 x 坐标
yNumber点的 y 坐标
Last Updated:
Contributors: 小小志