@@ -285,63 +285,136 @@ public extension TwoDimensional where Length: SignedNumeric {
285285// MARK: - Operators
286286
287287public extension TwoDimensional where Length: AdditiveArithmetic {
288- static func + ( multiplier: Length , value: Self ) -> Self {
288+ /// Add the given scalar value to both dimensions of the 2D value
289+ ///
290+ /// ```
291+ /// 11 + CGPoint(x: 7, y: 12) == CGPoint(x: 18, y: 23)
292+ /// ```
293+ ///
294+ /// - Parameters:
295+ /// - augend: This will be added to both dimensions of `addend`
296+ /// - addend: The dimensions here will have `augend` added to each
297+ static func + ( augend: Length , addend: Self ) -> Self {
289298 . init(
290- measurementX: multiplier + value . measurementX,
291- measurementY: multiplier + value . measurementY
299+ measurementX: augend + addend . measurementX,
300+ measurementY: augend + addend . measurementY
292301 )
293302 }
294303
295304
296- static func + ( value: Self , multiplier: Length ) -> Self {
297- multiplier + value
305+ /// Add the given scalar value to both dimensions of the 2D value
306+ ///
307+ /// ```
308+ /// CGPoint(x: 7, y: 12) + 11 == CGPoint(x: 18, y: 23)
309+ /// ```
310+ ///
311+ /// - Parameters:
312+ /// - augend: The dimensions here will have `augend` added to each
313+ /// - addend: This will be added to both dimensions of `addend`
314+ static func + ( augend: Self , addend: Length ) -> Self {
315+ addend + augend
298316 }
299317
300318
301- static func - ( multiplier: Length , value: Self ) -> Self {
319+ /// Subtracts both dimensions of the 2D value from the given scalar value and returns the result as that same 2D type
320+ ///
321+ /// ```
322+ /// 11 - CGPoint(x: 7, y: 12) == CGPoint(x: 4, y: -1)
323+ /// ```
324+ ///
325+ /// - Parameters:
326+ /// - minuend: This will have each dimension of `subtrahend` subtracted from it
327+ /// - subtrahend: Each dimension of this will be subtracted from `minuend`
328+ static func - ( minuend: Length , subtrahend: Self ) -> Self {
302329 . init(
303- measurementX: multiplier - value . measurementX,
304- measurementY: multiplier - value . measurementY
330+ measurementX: minuend - subtrahend . measurementX,
331+ measurementY: minuend - subtrahend . measurementY
305332 )
306333 }
307334
308335
309- static func - ( value: Self , multiplier: Length ) -> Self {
336+ /// Subtracts the given scalar value from both dimensions of the 2D value and returns the result as that same 2D type
337+ ///
338+ /// ```
339+ /// CGPoint(x: 7, y: 12) - 11 == CGPoint(x: -4, y: 1)
340+ /// ```
341+ ///
342+ /// - Parameters:
343+ /// - minuend: Each dimension of this will be subtracted from `minuend`
344+ /// - subtrahend: This will have `minuend` subtracted from each dimension of it
345+ static func - ( minuend: Self , subtrahend: Length ) -> Self {
310346 . init(
311- measurementX: value . measurementX - multiplier ,
312- measurementY: value . measurementY - multiplier
347+ measurementX: minuend . measurementX - subtrahend ,
348+ measurementY: minuend . measurementY - subtrahend
313349 )
314350 }
315351}
316352
317353
318354
319355public extension TwoDimensional where Length: MultiplicativeArithmetic {
320- static func * ( multiplier: Length , value: Self ) -> Self {
356+
357+ /// Multiplies the given scalar value by both dimensions of the 2D value
358+ ///
359+ /// ```
360+ /// 2 * CGPoint(x: 7, y: 12) == CGPoint(x: 14, y: 24)
361+ /// ```
362+ ///
363+ /// - Parameters:
364+ /// - multiplier: This will be multiplied by both dimensions of `multiplicand`
365+ /// - multiplicand: The dimensions here will have `multiplier` multiplied by each
366+ static func * ( multiplier: Length , multiplicand: Self ) -> Self {
321367 . init(
322- measurementX: multiplier * value . measurementX,
323- measurementY: multiplier * value . measurementY
368+ measurementX: multiplier * multiplicand . measurementX,
369+ measurementY: multiplier * multiplicand . measurementY
324370 )
325371 }
326372
327-
328- static func * ( value: Self , multiplier: Length ) -> Self {
329- multiplier * value
373+ /// Multiplies both dimensions of the given 2D value by the scalar value
374+ ///
375+ /// ```
376+ /// CGPoint(x: 7, y: 12) * 2 == CGPoint(x: 14, y: 24)
377+ /// ```
378+ ///
379+ /// - Parameters:
380+ /// - multiplier: The dimensions here will have `multiplier` multiplied by each
381+ /// - multiplicand: This will be multiplied by both dimensions of `multiplicand`
382+ static func * ( multiplier: Self , multiplicand: Length ) -> Self {
383+ multiplicand * multiplier
330384 }
331385
332386
333- static func / ( multiplier: Length , value: Self ) -> Self {
387+ /// Divides the given scalar value by both dimensions of the 2D value and returns the result as that same 2D type
388+ ///
389+ /// ```
390+ /// 2 / CGPoint(x: 7, y: 12) == CGPoint(x: 2/7, y: 0.125)
391+ /// ```
392+ ///
393+ /// - Parameters:
394+ /// - numerator: This be divided by each dimension of `denominator`
395+ /// - denominator: Each dimension of this will be divided into `numerator`
396+ // CGPoint(x: 7, y: 12) / 2 == CGPoint(x: 3.5 y: 6)
397+ static func / ( numerator: Length , denominator: Self ) -> Self {
334398 . init(
335- measurementX: multiplier / value . measurementX,
336- measurementY: multiplier / value . measurementY
399+ measurementX: numerator / denominator . measurementX,
400+ measurementY: numerator / denominator . measurementY
337401 )
338402 }
339403
340404
341- static func / ( value: Self , multiplier: Length ) -> Self {
405+ /// Divides both dimensions of the given 2D value by the scalar value and returns the result as that same 2D type
406+ ///
407+ /// ```
408+ /// CGPoint(x: 7, y: 12) / 2 == CGPoint(x: 3.5 y: 6)
409+ /// ```
410+ ///
411+ /// - Parameters:
412+ /// - numerator: Each dimension of this be divided by `denominator`
413+ /// - denominator: This will be divided into each dimension of `numerator`
414+ static func / ( numerator: Self , denominator: Length ) -> Self {
342415 . init(
343- measurementX: value . measurementX / multiplier ,
344- measurementY: value . measurementY / multiplier
416+ measurementX: numerator . measurementX / denominator ,
417+ measurementY: numerator . measurementY / denominator
345418 )
346419 }
347420}
0 commit comments