//
//  AlgebraicProduct3+SwiftUIConditionalConformances.swift
//

import Foundation
import SwiftUI
import HDXLCommonUtilities

// -------------------------------------------------------------------------- //
// MARK: AlgebraicProduct3 - AdditiveArithmetic
// -------------------------------------------------------------------------- //

public extension AlgebraicProduct3
  where
  A:AdditiveArithmetic,
  B:AdditiveArithmetic,
  C:AdditiveArithmetic {
 
  @inlinable
  static var zero: Self {
    get {
      return Self(
        A.zero,
        B.zero,
        C.zero
      )
    }
  }

  @inlinable
  static func +(
    lhs: Self,
    rhs: Self) -> Self {
    return Self(
      lhs.a + rhs.a,
      lhs.b + rhs.b,
      lhs.c + rhs.c
    )
  }
  
//  @inlinable
//  static func +=(
//    lhs: inout Self,
//    rhs: Self) {
//    lhs.a += rhs.a
//    lhs.b += rhs.b
//    lhs.c += rhs.c
//  }
  
  @inlinable
  static func -(
    lhs: Self,
    rhs: Self) -> Self {
    return Self(
      lhs.a - rhs.a,
      lhs.b - rhs.b,
      lhs.c - rhs.c
    )
  }
  
//  @inlinable
//  static func -=(
//    lhs: inout Self,
//    rhs: Self) {
//    lhs.a -= rhs.a
//    lhs.b -= rhs.b
//    lhs.c -= rhs.c
//  }
  
}

// -------------------------------------------------------------------------- //
// MARK: AlgebraicProduct3 - VectorArithmetic
// -------------------------------------------------------------------------- //

public extension AlgebraicProduct3
  where
  A:VectorArithmetic,
  B:VectorArithmetic,
  C:VectorArithmetic {
  
  @inlinable
  var magnitudeSquared: Double {
    get {
      return (
        self.a.magnitudeSquared
        +
        self.b.magnitudeSquared
        +
        self.c.magnitudeSquared
      )
    }
  }
  
  @inlinable
  mutating func scale(by factor: Double) {
    self.a.scale(by: factor)
    self.b.scale(by: factor)
    self.c.scale(by: factor)
  }

}

