欧几里得


Carthage compatible GitHub version Build Status

支持 Swift 5.0

Euclid 是一个用 Swift 编写的跨平台 (iOS, macOS, tvOS, watchOS) 实用工具类,它提供了便捷的方法,使用户可以轻松执行大圆数学计算。

功能


系统要求

用法


欧几里得

该库提供的关键大圆方法是 destination,它可以通过 Euclid 类的静态函数访问。

public static func destination(start: CLLocationCoordinate2D, distance: CLLocationDistance, bearing: Bearing) -> CLLocationCoordinate2D { } // Destination coordinate given start, distance and bearing
let calculatedDestination = Euclid.destination(start: source, distance: 100000, bearing: bearing)

CLLocationCoordinate2D 的扩展

public func distance(from coordinate: CLLocationCoordinate2D) -> CLLocationDistance { }
source.distance(from: destination) // Distance in metres

public func bearing(to coordinate: CLLocationCoordinate2D) -> CLLocationDirection { }
source.bearing(to: destination) // Bearing in range -180 - 180

public func bearing(to coordinate: CLLocationCoordinate2D) -> Bearing { }
source.compassBearing(to: destination) // Bearing in range 0 - 360

有用的常量和类型

Euclid.kEarthRadiusMetres // Radius of the earth in metres used by all calculations (6371e3)

public typealias Bearing = Double // Representing a bearing in the range -180 - 180

除了 Euclid 之外,还有一种额外的 BoundingBox 类型,可用于表示球体上的矩形区域。

public struct BoundingBox : CustomStringConvertible, CustomDebugStringConvertible {
    public let lowerLeft: CLLocationCoordinate2D
    public let upperRight: CLLocationCoordinate2D
    public let diagonal: CLLocationDistance
    public let midpoint: CLLocationCoordinate2D
}

安装


Carthage

要使用 Carthage 将 Euclid 集成到您的 Xcode 项目中,请在您的 Cartfile 中指定它。

github "timsearle/Euclid"

运行 carthage update 来构建框架,并将构建的 Euclid.framework 拖到您的 Xcode 项目中,并根据需要更新您的运行脚本。如需其他支持,请访问 Carthage 文档

使用 Euclid 的应用


我们很想知道您将 Euclid 用于什么,如果您希望您的应用在此处显示,请发送 pull request!

贡献


目前 Euclid 具有最初开发的所有功能,但欧几里得几何的世界要大得多。如果您希望为 Euclid 做出贡献,请 fork 该存储库并发送 pull request。 欢迎随时贡献和提出功能请求,请随时提出带有适当标签的问题,以便任何贡献者都可以看到。

许可证


Euclid 在 MIT 许可证下发布。 有关详细信息,请参阅 LICENSE。