ShopGun-GenericGeometry 0.3.0

ShopGun-GenericGeometry 0.3.0

Laurie Hufford 维护。



📐通用几何形状

Swift 5 Build Status Cocoapods License

你曾需要创建一个不包含 CGFloat 的 CGSize 吗?或者一个枚举值 Points?边框值为可选的吗?

所有这些,以及更多,都可以通过 通用几何形状 实现。

包括以下类型

  • Point
  • Size
  • Rect
  • Edges
  • Corners

这允许您执行如下操作

let maybeSize: Size<Int?> = Size(width: nil, height: 15)
// w: nil, h: Optional(15)

let concreteSize: Size<Int> = maybeSize.unwrapped(or: Size(999))
// w: 999, h: 15

let stringSize: Size<String> = concreteSize.map(String.init)
// w: "999", h: "15"

let scaledSize = concreteSize.multipling(by: Size<Int>(width: 10, height: 100))
// w: 9990, h: 1500

let boolPoint: Point<Bool> = Point(x: true, y: false)
// x: true, y: false

let tuplePoint: Point<(Bool, Int)> = boolPoint.zip(Point<Int>(5))
// x:(true, 5), y:(false, 5)

let mappedPoint: Point<Double> = tuplePoint.map { $0 ? Double($1) * 2 : Double($1) / 2 }
// x:10.0, y:2.5

类型

Point

表示在 2D 坐标系中的一个 x/y 点。

  • init(x: Value, y: Value) / init(Value)
  • zero
  • map / zip / zipWith
  • == (当 Value: Equatable 时)
  • init(cgPoint: CGPoint) / cgPoint / withCGFloats

Size

代表一个宽度和高度配合,表示 2D 坐标系中的大小。

Rect<>Value>

Point和Size的组合,表示2维坐标系统中的一个矩形。originsize使用相同的底层Value类型。

  • init(origin: Point<>Value>, size: Size<>Value>) / init(x: Value, y: Value, width: Value, height: Value)
  • zero
  • map / zip / zipWith
  • == (当 Value: Equatable 时)
  • cornerPoints: Corners<>Point<>Value>
  • inset(by: Edges<>Value>) / inset(by: Value)
  • outset(by: Edges<>Value>) / outset(by: Value)
  • init(cgRect: CGRect) / cgRect / withCGFloats

Edges<>Value>

包含矩形4条边的值。

  • init(top: Value, left: Value, bottom: Value, right: Value) / init(Value)
  • zero
  • map / zip / zipWith
  • == / isUniform (当Value: Equatable时)
  • 否定
  • adding(Value) / adding(Edges)
  • cgRectEdges: [CGRectEdge: Value] / value(forEdge: CGRectEdge) / withCGFloats
  • uiEdgeInsets

Corners<>Value>

包含矩形4个角的值。

  • init(topLeft: Value, topRight: Value, bottomLeft: Value, bottomRight: Value) / init(Value)
  • zero
  • map / zip / zipWith
  • == / isUniform (当Value: Equatable时)
  • withCGFloats