Distance units

Version: 5.x

英文原文地址:Distance units

当我们需要指定距离时(地理位置查询),可以使用一个双精度的数字来表示,它的默认单位是米(meters)。除此之外,也可以使用一个包含数字和单位的字符串(如:"2.72km" )。

NEST 使用 Distance 类型来规范距离,并提供了几种方式来构造这种类型的对象。

Constructor

最直接的方式是使用构造函数来构造 Distance 对象

var unitComposed = new Distance(25);
var unitComposedWithUnits = new Distance(25, Nest.DistanceUnit.Meters);

Distance 对象会被序列化为一个由因子和距离单位构成的字符串。因子是一个双精度的数字,所以序列化时至少保留一位小数

Expect("25.0m")
.WhenSerializing(unitComposed)
.WhenSerializing(unitComposedWithUnits);

Implicit conversion

或者,将一个表示距离的 string 直接赋值给 Distance 变量,内部会执行一次隐式转换,从而构造一个 Distance 实例。如果没有指定 DistanceUnit ,默认单位是米

Distance distanceString = "25";
Distance distanceStringWithUnits = "25m"; Expect(new Distance(25))
.WhenSerializing(distanceString)
.WhenSerializing(distanceStringWithUnits);

Supported units

NEST 支持数个距离单位,从毫米到海里

Metric

mm (Millimeters) 毫米

Expect("2.0mm").WhenSerializing(new Distance(2, Nest.DistanceUnit.Millimeters));

cm (Centimeters) 厘米

Expect("123.456cm").WhenSerializing(new Distance(123.456, Nest.DistanceUnit.Centimeters));

m (Meters) 米

Expect("400.0m").WhenSerializing(new Distance(400, Nest.DistanceUnit.Meters));

km (Kilometers) 千米

Expect("0.1km").WhenSerializing(new Distance(0.1, Nest.DistanceUnit.Kilometers));

Imperial

in (Inches) 英寸

Expect("43.23in").WhenSerializing(new Distance(43.23, Nest.DistanceUnit.Inch));

ft (Feet) 英尺

Expect("3.33ft").WhenSerializing(new Distance(3.33, Nest.DistanceUnit.Feet));

yd (Yards) 码

Expect("9.0yd").WhenSerializing(new Distance(9, Nest.DistanceUnit.Yards));

mi (Miles) 英里

Expect("0.62mi").WhenSerializing(new Distance(0.62, Nest.DistanceUnit.Miles));

nmi or NM (Nautical Miles) 海里

Expect("45.5nmi").WhenSerializing(new Distance(45.5, Nest.DistanceUnit.NauticalMiles));

1 英寸 = 2.54 厘米

1 英尺 = 12 英寸

1 码 = 3 英尺

1 英里 = 1760 码

1 海里 = 1852 米

NEST 中的距离单位的更多相关文章

  1. NEST 中的时间单位

    Time units 英文原文地址:Time units 与 Elasticsearch 交互,我们会遇到需要设定时间段的情况(例如:timeout 参数).为了指定时间段,我们可以使用一个表示时间的 ...

  2. Android中的距离单位

    px 像素:每个px对应屏幕上面的一个点 dip或dp(device independent pixels 设备独立像素):一种基于屏幕密度的抽象单位.在每英寸160点的显示器上,1dip=1px.但 ...

  3. [转] MachingLearning中的距离相似性计算以及python实现

    参考:https://blog.csdn.net/gamer_gyt/article/details/75165842#t16  https://blog.csdn.net/ymlgrss/artic ...

  4. 移动端rem距离单位的使用

    在做移动端开发的时候大家肯定会遇到适配问题,手机的屏幕大小有非常多的类别,使用传统的px距离单位已经无法满足我们的需要,于是rem便横空出世,他与百分比定位是比较像的,但是也是有一定的区别,在这里就跟 ...

  5. .net中判断距离高考多长时间的js函数

    在JS中判断距离高考(此处举例高考)的时间函数 JS中代码: function djs() { var severtime= new Date(); //获取服务器日期 var year=severt ...

  6. Leetcode 863. 二叉树中所有距离为 K 的结点

    863. 二叉树中所有距离为 K 的结点  显示英文描述 我的提交返回竞赛   用户通过次数39 用户尝试次数59 通过次数39 提交次数174 题目难度Medium 给定一个二叉树(具有根结点 ro ...

  7. 【前缀思想】二叉树中所有距离为 K 的结点

    863. 二叉树中所有距离为 K 的结点 class Solution { Map<TreeNode,String>map=new HashMap<>(); String pa ...

  8. Leetcode——863.二叉树中所有距离为 K 的结点

    给定一个二叉树(具有根结点 root), 一个目标结点 target ,和一个整数值 K . 返回到目标结点 target 距离为 K 的所有结点的值的列表. 答案可以以任何顺序返回. 示例 1: 输 ...

  9. CSS3中的rem单位

    一.rem介绍 rem是什么? 它的全称是 font size of the root element (根元素的字体大小) 它是CSS3中新增加的一个尺寸(度量)单位,根节点(html)的font- ...

随机推荐

  1. 【转】gcc命令中参数c和o混合使用的详解

    gcc -c a.c  编译成目标文件a.o  gcc a.c  生成执行文件a.exe  gcc -o a -c a.c    编译成目标文件a  gcc -o a  a.c    生成执行文件a. ...

  2. ES--05

    第四十一讲!分词器内部组成 内置分词器 课程大纲 1.什么是分词器 切分词语,normalization(提升recall召回率) 给你一段句子,然后将这段句子拆分成一个一个的单个的单词,同时对每个单 ...

  3. (常用)os模块

    os.getcwd() 获取当前工作目录,即当前python脚本工作的目录路径os.chdir("dirname")  改变当前脚本工作目录:相当于shell下cdos.curdi ...

  4. 阿里云主机Nginx下配置NodeJS、Express和Forever

    https://cnodejs.org/topic/5059ce39fd37ea6b2f07e1a3 AngularJS中文社区即运行在阿里云主机上,本站使用Nginx引擎,为了AngularJS,我 ...

  5. 使用第三方组件(django-redis)创建连接池

    settings里面: ##redis配置CACHES={ 'default':{ 'BACKEND':'django_redis.cache.RedisCache', 'LOCATION':'red ...

  6. 40)django-常用过滤器

    一.形式:小写 {{ name | lower }} 二.过滤器是可以嵌套的,字符串经过三个过滤器,第一个过滤器转换为小写,第二个过滤器输出首字母,第三个过滤器将首字母转换成大写 标签 {{ str| ...

  7. python numpy中数组.min()

    import numpy as np a = np.array([[1,5,3],[4,2,6]]) print(a.min()) #无参,所有中的最小值 print(a.min(0)) # axis ...

  8. Confluence 6 用户目录图例 - Confluence 内部目录

    上面的图:Confluence 使用内部目录为用户管理. https://www.cwiki.us/display/CONFLUENCEWIKI/Diagrams+of+Possible+Config ...

  9. Android UiAutomator

    UiAutomator是一个做UI测试的自动化框架.<Android自动化测试框架>中已有详细介绍,这里就不再累赘了. 一.首先了解自动化测试流程 自动化需求分析 测试用例设计 自动化框架 ...

  10. maven项目使用log4j

    日志是应用软件中不可缺少的部分,Apache的开源项目 log4j 是一个功能强大的日志组件,提供方便的日志记录. 1.maven项目在pom.xml导入log4j依赖: <dependency ...