# ScopeDOPE — iOS

Self-contained workspace for the **ScopeDOPE iPhone app**. Everything required to build
the iOS app is sourced **independently inside this `iOS/` folder**. This project does **not**
modify, include, submodule, or build-depend on any file outside `iOS/` — in particular it
does not rely on the sibling `scopedope-android-main/` or `scopedope-shared-main/` trees.
Those were used only as read-only references; any code needed here was copied in and is
maintained as an independent vendored copy.

> Product requirements remain governed by the ScopeDOPE SPEC (the four files under
> `ScopeDOPE/04_-_Highly_Confidential/SPEC/`). The SPEC is a **reference** for what to
> build; it is not a build-time dependency of anything in this folder.

## Layout

```
iOS/
├── README.md                     ← this file
├── ScopeDOPE_iOS_BUILD_PLAN.md   ← phased implementation plan (start here)
└── engine/                       ← self-contained Kotlin Multiplatform ballistics engine
    ├── settings.gradle.kts       ← standalone build (rootProject "scopedope-ballistics-ios")
    ├── build.gradle.kts
    ├── gradle.properties
    ├── gradlew / gradlew.bat
    ├── gradle/
    │   ├── libs.versions.toml
    │   └── wrapper/              ← Gradle 8.13 wrapper
    └── ballistics/
        ├── build.gradle.kts      ← KMP: jvm() + iosArm64/iosX64/iosSimulatorArm64 → XCFramework
        └── src/
            ├── commonMain/.../ballistics/
            │   ├── BallisticsEngine.kt   ← vendored copy, iOS-readiness fixes applied
            │   ├── BcModel.kt
            │   ├── TwistDirection.kt
            │   └── UnitConversion.kt
            └── commonTest/.../ballistics/
                └── MultiZoneBcTest.kt    ← pure unit sanity test (no external data)
```

## The engine (`engine/`)

This is an **independent copy** of the ScopeDOPE `:ballistics` engine with the two
changes required to make it build for iOS (Kotlin/Native), neither of which touches the
original sources:

1. **`java.lang.Math` removed.** `Math.toRadians(...)` (JVM/Android-only, absent on
   Kotlin/Native) is replaced by a multiplatform `toRadians(deg)` helper backed by
   `kotlin.math.PI`. All 7 call sites updated; the numeric result is identical.
2. **iOS targets + XCFramework added.** `ballistics/build.gradle.kts` declares
   `iosArm64`, `iosX64`, and `iosSimulatorArm64` and packages them as the
   `ScopeDopeBallistics` XCFramework. `androidTarget()` and the Android SDK dependency
   were dropped so the module builds with only the Kotlin toolchain; `jvm()` is kept for
   fast headless validation.

The drag tables, atmosphere model, RK4 integrator, secondary effects, and DOPE-Blend
logic are otherwise byte-for-byte the reference engine, preserving cross-platform output
parity (SPEC requires < 0.01 mil vs. the Android/JVM engine).

### Build (requires macOS for the XCFramework)

```bash
cd engine
./gradlew :ballistics:jvmTest                              # headless sanity test (any OS)
./gradlew :ballistics:assembleScopeDopeBallisticsXCFramework   # XCFramework (macOS only)
```

The assembled framework lands in `engine/ballistics/build/XCFrameworks/`. The Swift app
(added in a later phase, also inside this folder) links it directly — no remote artifact,
no external project reference.

## Status

- [x] Phase 0 (engine): vendored, iOS-readiness fixes applied, standalone build configured.
- [x] Phase 1 (partial): built-in ammo data vendored to `assets/ammo/` (DB + CSV + build
      script + Room v4 schema). See `assets/ammo/README.md`.
- [ ] Everything else: see `ScopeDOPE_iOS_BUILD_PLAN.md`. The Swift app, `.dope` Codable
      layer, BLE/printer drivers, and UI all live under `iOS/` as they land.

---
© 2026 Cold Bore Ballistics LLC. Proprietary and Confidential.
