Skip to content

Latest commit

 

History

History
78 lines (67 loc) · 3.06 KB

File metadata and controls

78 lines (67 loc) · 3.06 KB

GitHub Copilot Instructions for Mandelbrot Project

This document provides context and guidelines for AI agents working on the Mandelbrot repository.

Project Overview

This is a high-performance C++26 application that renders the Mandelbrot set in real-time. It leverages:

  • Raylib: For windowing, input, and graphics rendering.
  • Intel TBB (Threading Building Blocks): As the backend for parallel algorithms (<execution>).
  • Modern CMake: With vcpkg for package management.
  • Clang 21.1+: Primary compiler for C++26 support.

Architecture

  • Single-File Implementation: The core logic resides entirely in mandelbrot.cpp.
  • Parallel Computation: The calc function uses std::execution::par_unseq to parallelize the Mandelbrot iteration across pixels.
  • Data Flow:
    1. Input: Arrow keys (pan), Numpad +/- (zoom), Numpad 1/2 (fractal exponent).
    2. Calculation: mandelRes computes iterations for a complex coordinate. Results are stored in a std::vector<uint8_t> buffer (heap-allocated).
    3. Rendering: draw converts iteration counts to colors and updates a Raylib Image, which is then drawn to the screen.
  • Coordinate Mapping: scaleX and scaleY transform screen coordinates to the complex plane [-2, 1] x [-1, 1].

Build & Dependencies

The project uses vcpkg in manifest mode (vcpkg.json) and CMake Presets.

Dependencies

  • Raylib: Graphics library.
  • TBB: Parallelism library.

Prerequisites

  • Windows: Clang 21.1+ and Ninja build system.
  • Linux: GCC 14+/Clang 17+ and Ninja (sudo apt install build-essential ninja-build).
  • Common: Git and CMake 3.15+.

Workflow

Windows (Clang)

  1. Configure:
    cmake --preset clang-release
  2. Build:
    cmake --build --preset clang-release
  3. Run:
    ./build/clang-release/Mandelbrot.exe

Linux (Ninja)

  1. Configure:
    cmake --preset ninja-release
  2. Build:
    cmake --build --preset ninja-release
  3. Run:
    ./build/release/Mandelbrot

Note: The first configure step bootstraps vcpkg and builds dependencies (Raylib, TBB).

Development Conventions

  • C++ Standard: The codebase targets C++26 with Clang 21.1+.
  • Types: Use ctype (alias for long double) for high-precision fractal math. Use std::complex<ctype> for complex numbers.
  • Optimization:
    • Valid optimizations are encouraged (e.g., std::norm check).
    • The render loop only recalculates calc() when the state (changed flag) is modified.
  • Memory Management:
    • The pixel buffer (std::vector<uint8_t>) is heap-allocated to avoid stack overflow.
  • Compiler Flags: -Werror -Wall -Wextra -pedantic. Code must be warning-free.

Key Files