|
| 1 | +// |
| 2 | +// LayerTree.Builder.Path.ArcTests.swift |
| 3 | +// SwiftDraw |
| 4 | +// |
| 5 | +// Created by Simon Whitty on 14/2/25. |
| 6 | +// Copyright 2025 Simon Whitty |
| 7 | +// |
| 8 | +// Distributed under the permissive zlib license |
| 9 | +// Get the latest version from here: |
| 10 | +// |
| 11 | +// https://github.com/swhitty/SwiftDraw |
| 12 | +// |
| 13 | +// This software is provided 'as-is', without any express or implied |
| 14 | +// warranty. In no event will the authors be held liable for any damages |
| 15 | +// arising from the use of this software. |
| 16 | +// |
| 17 | +// Permission is granted to anyone to use this software for any purpose, |
| 18 | +// including commercial applications, and to alter it and redistribute it |
| 19 | +// freely, subject to the following restrictions: |
| 20 | +// |
| 21 | +// 1. The origin of this software must not be misrepresented; you must not |
| 22 | +// claim that you wrote the original software. If you use this software |
| 23 | +// in a product, an acknowledgment in the product documentation would be |
| 24 | +// appreciated but is not required. |
| 25 | +// |
| 26 | +// 2. Altered source versions must be plainly marked as such, and must not be |
| 27 | +// misrepresented as being the original software. |
| 28 | +// |
| 29 | +// 3. This notice may not be removed or altered from any source distribution. |
| 30 | +// |
| 31 | + |
| 32 | + |
| 33 | +import XCTest |
| 34 | +@testable import SwiftDraw |
| 35 | + |
| 36 | +final class LayerTreeBuilderPathArcTests: XCTestCase { |
| 37 | + |
| 38 | + func testClamped() { |
| 39 | + XCTAssertEqual(5.clamped(to: 0...10), 5) |
| 40 | + XCTAssertEqual((10.1).clamped(to: 0...10), 10) |
| 41 | + XCTAssertEqual((-1).clamped(to: 0...10), 0) |
| 42 | + XCTAssertEqual(Double.infinity.clamped(to: 0...10), 10) |
| 43 | + XCTAssertEqual((-Double.infinity).clamped(to: 0...10), 0) |
| 44 | + XCTAssertEqual(Double.nan.clamped(to: 0...10), 0) |
| 45 | + XCTAssertEqual((-Double.nan).clamped(to: 0...10), 0) |
| 46 | + } |
| 47 | + |
| 48 | + func testVectorAngle() { |
| 49 | + XCTAssertEqual(vectorAngle(ux: 1, uy: 1, vx: 1, vy: 1), 0) |
| 50 | + XCTAssertEqual(vectorAngle(ux: 1, uy: 1, vx: -1, vy: 1), 1.5707964, accuracy: 0.001) |
| 51 | + XCTAssertEqual(vectorAngle(ux: 1, uy: 1, vx: .nan, vy: 1), 3.1415925, accuracy: 0.001) |
| 52 | + } |
| 53 | +} |
0 commit comments