Skip to content

Conversation

@mateuszJS
Copy link
Owner

@mateuszJS mateuszJS commented Jul 22, 2025

Summary by CodeRabbit

  • New Features

    • Introduced interactive camera controls with panning and zooming using mouse, keyboard, wheel, and touch gestures.
    • Added a visible project boundary around the canvas for clearer workspace demarcation.
  • Improvements

    • Visual elements such as borders and UI handles now scale proportionally with zoom for consistent appearance.
    • Canvas rendering and pointer interactions now accurately reflect camera position and zoom level.
    • Enhanced touch support for zoom gestures.
    • Render scale updates dynamically with canvas size and camera zoom for improved visual consistency.
  • Bug Fixes

    • Improved pointer coordinate calculations to account for canvas scaling and camera transforms.
    • Disabled browser overscroll effects on the main interface for a smoother user experience.

@coderabbitai
Copy link

coderabbitai bot commented Jul 22, 2025

"""

Walkthrough

This update introduces a camera system with panning and zooming capabilities, affecting pointer handling, rendering logic, and UI scaling. The render scale is now dynamically updated based on camera zoom and canvas size, with corresponding changes in Zig rendering code to scale line widths and UI elements. A project boundary is also visually rendered.

Changes

File(s) Change Summary
integration-tests/template.html Added overscroll-behavior: none; to the body style to disable scroll chaining and overscroll effects.
src/WebGPU/pick.ts Switched from canvas.clientWidth/Height to canvas.width/height for matrix calculations.
src/WebGPU/pointer.ts Added camera system with pan/zoom; pointer events now update camera and adjust coordinates accordingly.
src/getCanvasMatrix.ts Camera transforms (pan/zoom) applied to the canvas matrix; imports camera state.
src/index.ts Render scale now updates with camera zoom and canvas size; initial camera offset set; logic refactored.
src/logic/index.d.ts Added update_render_scale function to Zig module declarations.
src/logic/index.zig Added render_scale to state; scales line widths/UI; draws project boundary; updates rendering logic.
src/logic/transform_ui.zig Added render_scale parameter to UI transform functions; all geometry and thicknesses now scale.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Canvas
    participant PointerController
    participant Camera
    participant ZigLogic

    User->>Canvas: Mouse/Touch/Keyboard event
    Canvas->>PointerController: Event handler
    PointerController->>Camera: Update pan/zoom state
    PointerController->>PointerController: Adjust pointer coords for camera
    PointerController->>ZigLogic: Forward adjusted pointer event
    Camera->>Canvas: (On zoom/pan) Triggers render scale update
    Canvas->>ZigLogic: Call update_render_scale(render_scale)
    ZigLogic->>Canvas: Render with updated scale and camera transform
Loading

Estimated code review effort

4 (~90 minutes)

Possibly related PRs

Suggested labels

released on @next

Poem

Hopping through code with a zoom and a pan,
The camera now moves just like a rabbit can!
Lines grow and shrink, the canvas expands,
Boundaries appear, drawn by steady hands.
With scale and with style,
We render and smile—
This code’s now a magical, zoomable land! 🐇✨
"""

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

npm error Exit handler never called!
npm error This is an error with npm itself. Please report this error at:
npm error https://github.com/npm/cli/issues
npm error A complete log of this run can be found in: /.npm/_logs/2025-07-22T12_28_55_251Z-debug-0.log


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f7886d5 and 4344420.

📒 Files selected for processing (4)
  • src/index.ts (4 hunks)
  • src/logic/index.d.ts (1 hunks)
  • src/logic/index.zig (9 hunks)
  • src/logic/transform_ui.zig (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/index.ts
  • src/logic/index.zig
  • src/logic/index.d.ts
  • src/logic/transform_ui.zig
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🔭 Outside diff range comments (1)
src/index.ts (1)

193-193: Inconsistent coordinate system usage in asset loading.

This line still uses canvas.clientWidth and canvas.clientHeight instead of projectWidth and projectHeight, which creates inconsistency with the new coordinate system used elsewhere.

Apply this fix for consistency:

-                points: getDefaultPoints(width, height, canvas.clientWidth, canvas.clientHeight),
+                points: getDefaultPoints(width, height, projectWidth, projectHeight),
🧹 Nitpick comments (2)
src/WebGPU/pointer.ts (2)

159-159: Remove outdated comment.

This comment appears to reference old code and should be removed.

-  // pointer.zoom = clamp(pointer.zoom + event.deltaY * 0.01, 0.1, 100)

180-198: Consider using pinch gesture for more natural touch zoom.

The current implementation uses vertical movement of one finger. A pinch gesture using the distance between two fingers would be more intuitive.

Here's an improved implementation:

-  let lastTouchY: number
+  let lastTouchDistance: number

  canvas.addEventListener('touchstart', (event) => {
    if (event.touches.length === 2) {
      event.preventDefault()

-      lastTouchY = event.touches[0].clientY
+      const dx = event.touches[0].clientX - event.touches[1].clientX
+      const dy = event.touches[0].clientY - event.touches[1].clientY
+      lastTouchDistance = Math.sqrt(dx * dx + dy * dy)
    }
  })

  canvas.addEventListener('touchmove', (event) => {
    if (event.touches.length === 2) {
      event.preventDefault()

-      const delta = lastTouchY - event.touches[0].clientY
-      lastTouchY = event.touches[0].clientY
+      const dx = event.touches[0].clientX - event.touches[1].clientX
+      const dy = event.touches[0].clientY - event.touches[1].clientY
+      const distance = Math.sqrt(dx * dx + dy * dy)
+      const delta = (lastTouchDistance - distance) * 0.01
+      lastTouchDistance = distance

      camera.zoom = clamp(camera.zoom - delta * 0.01, 0.1, 20)
      onZoom()
    }
  })
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c797780 and 315841c.

📒 Files selected for processing (8)
  • integration-tests/template.html (1 hunks)
  • src/WebGPU/pick.ts (1 hunks)
  • src/WebGPU/pointer.ts (5 hunks)
  • src/getCanvasMatrix.ts (1 hunks)
  • src/index.ts (4 hunks)
  • src/logic/index.d.ts (1 hunks)
  • src/logic/index.zig (9 hunks)
  • src/logic/transform_ui.zig (5 hunks)
🧬 Code Graph Analysis (4)
src/getCanvasMatrix.ts (2)
src/utils/mat4.ts (1)
  • ortho (36-58)
src/WebGPU/pointer.ts (1)
  • camera (20-24)
src/WebGPU/pick.ts (1)
src/WebGPU/pointer.ts (1)
  • pointer (26-35)
src/index.ts (4)
src/logic/index.d.ts (2)
  • init_state (21-21)
  • update_render_scale (31-31)
src/WebGPU/pointer.ts (2)
  • camera (20-24)
  • initMouseController (37-199)
src/WebGPU/canvasSizeObserver.ts (1)
  • canvasSizeObserver (11-42)
src/utils/getDefaultPoints.ts (1)
  • getDefaultPoints (3-21)
src/WebGPU/pointer.ts (2)
src/logic/index.d.ts (2)
  • on_pointer_move (29-29)
  • on_pointer_down (27-27)
src/utils/clamp.ts (1)
  • clamp (1-3)
🧰 Additional context used
🧬 Code Graph Analysis (4)
src/getCanvasMatrix.ts (2)
src/utils/mat4.ts (1)
  • ortho (36-58)
src/WebGPU/pointer.ts (1)
  • camera (20-24)
src/WebGPU/pick.ts (1)
src/WebGPU/pointer.ts (1)
  • pointer (26-35)
src/index.ts (4)
src/logic/index.d.ts (2)
  • init_state (21-21)
  • update_render_scale (31-31)
src/WebGPU/pointer.ts (2)
  • camera (20-24)
  • initMouseController (37-199)
src/WebGPU/canvasSizeObserver.ts (1)
  • canvasSizeObserver (11-42)
src/utils/getDefaultPoints.ts (1)
  • getDefaultPoints (3-21)
src/WebGPU/pointer.ts (2)
src/logic/index.d.ts (2)
  • on_pointer_move (29-29)
  • on_pointer_down (27-27)
src/utils/clamp.ts (1)
  • clamp (1-3)
🔇 Additional comments (14)
integration-tests/template.html (1)

23-23: Good addition to prevent scroll interference with canvas interactions.

The overscroll-behavior: none; property appropriately prevents browser default scroll behaviors from interfering with the new camera panning and zooming functionality.

src/logic/index.d.ts (1)

31-31: Correct type declaration for the new render scale function.

The function signature appropriately declares the update_render_scale function that takes a numeric render scale parameter.

src/WebGPU/pick.ts (1)

88-92: Good alignment with pixel-based coordinate system.

Using canvas.width and canvas.height instead of canvas.clientWidth and canvas.clientHeight correctly aligns the picking matrix calculations with the actual pixel dimensions used in the rendering pipeline, ensuring accurate coordinate mapping with the new camera system.

src/getCanvasMatrix.ts (2)

2-2: Appropriate import for camera integration.

The camera import correctly brings in the camera state needed for the matrix transformations.


5-16: Well-implemented camera transformation integration.

The matrix transformation sequence is correct: first create the orthographic projection, then apply camera translation, and finally apply zoom scaling. The comments provide helpful context about the design decision to handle zoom at the matrix level rather than per-effect.

src/index.ts (6)

15-17: Appropriate imports for camera integration.

The new imports correctly bring in the render scale update function and camera object needed for the enhanced functionality.


64-67: Good setup of project dimensions for camera system.

Using half the canvas client dimensions for project size creates an appropriate coordinate space for the camera system with panning and zooming capabilities.


80-82: Well-implemented render scale calculation.

The updateRenderScale function correctly computes the scale factor based on the ratio of actual canvas pixels to client pixels, adjusted by camera zoom. This ensures consistent rendering across different device pixel ratios and zoom levels.


84-92: Proper camera offset initialization and scale updates.

The initial camera offset setup centers the view appropriately, and the render scale update ensures consistent scaling behavior during canvas resizing.


96-96: Correct integration with mouse controller.

Passing updateRenderScale as a callback to the mouse controller enables dynamic render scale updates during zoom operations.


150-150: Consistent use of project dimensions for new images.

Using projectWidth and projectHeight for default points calculation aligns with the new coordinate system.

src/logic/transform_ui.zig (3)

150-206: LGTM: Consistent scaling implementation for UI transform lines.

The render_scale parameter is properly applied to all geometric calculations while maintaining proportional relationships between corner lines, straight lines, and the rotation icon distance.


211-259: LGTM: Comprehensive scaling implementation for transform UI rendering.

All UI elements are consistently scaled including line thicknesses, icon sizes, positioning offsets, and the outer line border. The function signature update and parameter passing to get_points_of_line is correct.


262-272: LGTM: Picking functionality properly scaled to match rendering.

The scaling implementation maintains consistency between the render and pick functions, using the same thickness values and border calculations. Function signature and parameter passing are correct.

@mateuszJS mateuszJS merged commit dc53c07 into next Jul 22, 2025
5 checks passed
@github-actions
Copy link

🎉 This PR is included in version 0.1.0-next.18 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants