๐ ฟ๏ธVector
swift โฉ type โฉ custom โฉ package โฉ GeometryKit โฉ Vector
// History:
// โข 2024.12.09 - draft
// โข 2024.12.11 - version 1.0
// Inheritance Hierarchy
// โข MetricSpace -> Vector -> Vector2D -> ComplextNumber
// ---------------------
// ๐
ฟ๏ธ Vector
// ---------------------
/// ๅปฃ็พฉๅ้ๅๅฎ
public protocol Vector: Equatable, MetricSpace {
// constants
// zero vector
static var zero: Self { get }
// โญ๏ธ ๅๅ้ใๅ้ๅ ๆธๆณใ็ด้็ฉ
// ---------------------------------------
/// ๅ ๆณๅๅ
็ด : -v
static prefix func - (u: Self) -> Self
/// ๅ้ๅ ๆณ๏ผu + v
static func + (u: Self, v: Self) -> Self
/// ๅ้ๆธๆณ๏ผu - v
static func - (u: Self, v: Self) -> Self
/// ็ด้็ฉ๏ผu * a
/// (a * u: default behavior provided = u * a)
static func * (u: Self, a: Scalar) -> Self
/// ็ด้็ฉ๏ผu / a
/// (default behavior provided = u * (1/a))
static func / (u: Self, a: Scalar) -> Self
}
// -----------------------------------
// ๐ Vector default behaviors
// -----------------------------------
public extension Vector {
// ็ด้็ฉ๏ผa * u
static func * (a: Scalar, u: Self) -> Self {
return u * a
}
// ็ด้็ฉ๏ผu / a
static func / (u: Self, a: Scalar) -> Self {
precondition(a != 0, "โ Division by zero is not allowed.")
return u * (1/a)
}
}
MetricSpace๏ผconformed by Vector
ChatGPT โฉ ่จญ่จ Vector ๅๅฎ
Last updated