@@ -17,9 +17,106 @@ public struct Edges: Compound, RelativeCompoundEquality, RelativeCompoundInequal
1717 public let properties : [ Property ]
1818
1919 internal init ( _ context: Context , _ properties: [ Property ] ) {
20+ guard properties. count == 4 else {
21+ fatalError ( " No valid edges were used " )
22+ }
23+
2024 self . context = context
2125 self . properties = properties
2226 }
27+
28+ /// Insets all edges individually.
29+ ///
30+ /// - parameter top: The amount by which to inset the top edge, in points.
31+ /// - parameter leading: The amount by which to inset the leading edge, in points.
32+ /// - parameter bottom: The amount by which to inset the bottom edge, in points.
33+ /// - parameter trailing: The amount by which to inset the trailing edge, in points.
34+ ///
35+ /// - returns: A new expression with the inseted edges.
36+ ///
37+ public func inseted( top: CGFloat , leading: CGFloat , bottom: CGFloat , trailing: CGFloat ) -> Expression < Edges > {
38+ return Expression (
39+ self ,
40+ [
41+ Coefficients ( 1 , top) ,
42+ Coefficients ( 1 , leading) ,
43+ Coefficients ( 1 , - bottom) ,
44+ Coefficients ( 1 , - trailing)
45+ ]
46+ )
47+ }
48+
49+ /// Insets all horizontal and vertical edges.
50+ ///
51+ /// - parameter horizontally: The amount by which to inset the leading and trailing edges, in points.
52+ /// - parameter vertically: The amount by which to inset the top and bottom edges, in points.
53+ ///
54+ /// - returns: A new expression with the inseted edges.
55+ ///
56+ public func inseted( horizontally: CGFloat , vertically: CGFloat ) -> Expression < Edges > {
57+ return self . inseted (
58+ top: vertically,
59+ leading: horizontally,
60+ bottom: vertically,
61+ trailing: horizontally
62+ )
63+ }
64+
65+ /// Insets all horizontal edges.
66+ ///
67+ /// - parameter horizontally: The amount by which to inset the leading and trailing edges, in points.
68+ ///
69+ /// - returns: A new expression with the inseted edges.
70+ ///
71+ public func inseted( horizontally: CGFloat ) -> Expression < Edges > {
72+ return self . inseted (
73+ horizontally: horizontally,
74+ vertically: 0
75+ )
76+ }
77+
78+ /// Insets all vertical edges.
79+ ///
80+ /// - parameter vertically: The amount by which to inset the top and bottom edges, in points.
81+ ///
82+ /// - returns: A new expression with the inseted edges.
83+ ///
84+ public func inseted( vertically: CGFloat ) -> Expression < Edges > {
85+ return self . inseted (
86+ horizontally: 0 ,
87+ vertically: vertically
88+ )
89+ }
90+
91+ /// Insets all edges by a single value.
92+ ///
93+ /// - parameter by: The amount by which to inset the top and bottom edges, in points.
94+ ///
95+ /// - returns: A new expression with the inseted edges.
96+ ///
97+ public func inseted( by value: CGFloat ) -> Expression < Edges > {
98+ return self . inseted (
99+ horizontally: value,
100+ vertically: value
101+ )
102+ }
103+
104+ #if os(iOS) || os(tvOS)
105+ /// Insets all edges individually using an existing UIEdgeInsets.
106+ ///
107+ /// - parameter by: The UIEdgeInsets to use as a base value.
108+ ///
109+ /// - returns: A new expression with the inseted edges.
110+ ///
111+ public func inseted( by insets: UIEdgeInsets ) -> Expression < Edges > {
112+ return self . inseted (
113+ top: insets. top,
114+ leading: insets. left,
115+ bottom: insets. bottom,
116+ trailing: insets. right
117+ )
118+ }
119+ #endif
23120}
24121
25122/// Insets all edges.
@@ -30,7 +127,7 @@ public struct Edges: Compound, RelativeCompoundEquality, RelativeCompoundInequal
30127/// - returns: A new expression with the inset edges.
31128///
32129public func inset( _ edges: Edges , _ all: CGFloat ) -> Expression < Edges > {
33- return inset ( edges, all , all , all , all)
130+ return edges. inseted ( by : all)
34131}
35132
36133/// Insets the horizontal and vertical edges.
@@ -44,7 +141,31 @@ public func inset(_ edges: Edges, _ all: CGFloat) -> Expression<Edges> {
44141/// - returns: A new expression with the inset edges.
45142///
46143public func inset( _ edges: Edges , _ horizontal: CGFloat , _ vertical: CGFloat ) -> Expression < Edges > {
47- return inset ( edges, vertical, horizontal, vertical, horizontal)
144+ return edges. inseted ( horizontally: horizontal, vertically: vertical)
145+ }
146+
147+ /// Insets the horizontal edges.
148+ ///
149+ /// - parameter edges: The edges to inset.
150+ /// - parameter horizontally: The amount by which to inset the horizontal edges, in
151+ /// points.
152+ ///
153+ /// - returns: A new expression with the inset edges.
154+ ///
155+ public func inset( _ edges: Edges , horizontally horizontal: CGFloat ) -> Expression < Edges > {
156+ return edges. inseted ( horizontally: horizontal)
157+ }
158+
159+ /// Insets the vertical edges.
160+ ///
161+ /// - parameter edges: The edges to inset.
162+ /// - parameter vertically: The amount by which to inset the vertical edges, in
163+ /// points.
164+ ///
165+ /// - returns: A new expression with the inset edges.
166+ ///
167+ public func inset( _ edges: Edges , vertically vertical: CGFloat ) -> Expression < Edges > {
168+ return edges. inseted ( vertically: vertical)
48169}
49170
50171/// Insets edges individually.
@@ -58,12 +179,7 @@ public func inset(_ edges: Edges, _ horizontal: CGFloat, _ vertical: CGFloat) ->
58179/// - returns: A new expression with the inset edges.
59180///
60181public func inset( _ edges: Edges , _ top: CGFloat , _ leading: CGFloat , _ bottom: CGFloat , _ trailing: CGFloat ) -> Expression < Edges > {
61- return Expression ( edges, [
62- Coefficients ( 1 , top) ,
63- Coefficients ( 1 , leading) ,
64- Coefficients ( 1 , - bottom) ,
65- Coefficients ( 1 , - trailing)
66- ] )
182+ return edges. inseted ( top: top, leading: leading, bottom: bottom, trailing: trailing)
67183}
68184
69185#if os(iOS) || os(tvOS)
@@ -75,6 +191,6 @@ public func inset(_ edges: Edges, _ top: CGFloat, _ leading: CGFloat, _ bottom:
75191/// - returns: A new expression with the inset edges.
76192///
77193public func inset( _ edges: Edges , _ insets: UIEdgeInsets ) -> Expression < Edges > {
78- return inset ( edges, insets . top , insets. left , insets . bottom , insets . right )
194+ return edges. inseted ( by : insets)
79195}
80196#endif
0 commit comments