GraphPoint

Twitter: @richardpiazza

笛卡尔坐标系的 Swift 实现。

安装

GraphPoint 通过 Swift Package Manager 发行。要将其安装到项目中,请将其作为依赖项添加到您的 Package.swift 清单中

let package = Package(
    ...
    dependencies: [
        .package(url: "https://github.com/richardpiazza/GraphPoint.git", from: "4.0.0")
    ],
    ...
)

然后在您想要使用它的任何地方导入 GraphPoint

import GraphPoint

依赖项

GraphPoint 严重依赖 Swift2D 库,该库以跨平台、非 Foundation 依赖的方式重新实现了 RectSizePoint

弃用

CoreGraphics 别名已被弃用,并被其 Cartesian 对等项取代。这些类型别名和 GraphPointUI 将在未来版本中移除。

用法

使用 GraphPoint 时,有几个关键方面需要理解。

笛卡尔平面

笛卡尔平面由两条互相垂直的数轴定义:水平的 x 轴和垂直的 y 轴。使用这些轴,我们可以用一对有序数字来描述平面中的任何点。

GraphPoint 中,每个矩形都是一个笛卡尔平面,原点位于中心。

笛卡尔框架

一个 Rect 包含在 CartesianPlane 中,其 origin 相对于平面的 cartesianOrigin。例如

// Visualize graph paper with axes extending 50 points in all four directions from the center of the paper.
let plane = CartesianPlan(size: Size(width: 100, height: 100))
// A 10x10 piece of paper is placed on top of the graph paper; placed 40 points from both the top and left edges. 
let rect = Rect(origin: Point(x: 40, y: 40), size: Size(width: 10, height: 10))
// In relation to the graph, the smaller rectangle would have an 'origin' at (-10, 10).
let cartesianFrame = plane.rect(for: rect)
cartesianFrame == Rect(origin: Point(x: -10, y: 10), size: Size(width: 10, height: 10))

笛卡尔点

CartesianPlane 中的一个点。CartesianPoint 的 x 和 y 坐标表示相对于平面 '原点' (0, 0) 的偏移量。