Skip to content

Conversation

@Audatic07
Copy link
Contributor

@Audatic07 Audatic07 commented Feb 2, 2026

Addresses 1 gate migration for #908

Describe the changes you have made in this PR -

Created AndGate.ts files in v0 and v1, using OrGate.ts as reference, deleted AndGate.js files in the process.

Screenshots of the UI changes (If any) -


Code Understanding and AI Usage

Did you use AI assistance (ChatGPT, Claude, Copilot, etc.) to write any part of this code?

  • No, I wrote all the code myself
  • Yes, I used AI assistance (continue below)

If you used AI assistance:

  • I have reviewed every single line of the AI-generated code
  • I can explain the purpose and logic of each function/component I added
  • I have tested edge cases and understand how the code handles them
  • I have modified the AI output to follow this project's coding standards and conventions

Explain your implementation approach:
Using the provided reference of OrGate.ts, I modified AndGate.js into AndGate.ts, ensuring that I stick to the reference strictly.
Here are the changes:

  1. Added private properties at class
  2. Typed Constructors
  3. Added Null Safety to ctx in customDraw()
  4. Added return type to customSave() and generateVerilog()
  5. Rearraged parts of code to match the format of OrGate.ts

Checklist before requesting a review

  • I have added proper PR title and linked to the issue
  • I have performed a self-review of my code
  • I can explain the purpose of every function, class, and logic block I added
  • I understand why my changes work and have tested them thoroughly
  • I have considered potential edge cases and how my code handles them
  • If it is a core feature, I have added thorough tests
  • My code follows the project's style guidelines and conventions

Note: Please check Allow edits from maintainers if you would like us to assist in the PR.

Summary by CodeRabbit

  • Refactor
    • AND gate rewritten in TypeScript: now a parameterizable multi-input AND with configurable input count and bit width; visual rendering, simulation behavior, and Verilog output preserved.
  • Chores
    • OR gate save format extended for backward compatibility and minor drawing refinements.

@netlify
Copy link

netlify bot commented Feb 2, 2026

Deploy Preview for circuitverse ready!

Name Link
🔨 Latest commit b5f09ce
🔍 Latest deploy log https://app.netlify.com/projects/circuitverse/deploys/6983918d18b9b60008b1f7b0
😎 Deploy Preview https://deploy-preview-917--circuitverse.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 46 (🔴 down 1 from production)
Accessibility: 73 (no change from production)
Best Practices: 92 (no change from production)
SEO: 82 (no change from production)
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 2, 2026

Walkthrough

The AndGate implementation was removed from its JavaScript locations and added as new TypeScript modules: deleted src/.../AndGate.js and v1/.../AndGate.js, and added src/.../AndGate.ts and v1/.../AndGate.ts. The new TypeScript classes reintroduce multi-input wiring, resolve logic, drawing, serialization (including legacy constructorParamaters alias), and Verilog generation, and expose inp, inputSize, and output1 as public members. Additionally, OrGate had inp, inputSize, and output1 changed from private to public and its customSave serialization updated.

Possibly related PRs

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: converting AndGate from JavaScript to TypeScript across multiple directories.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@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: 2

🤖 Fix all issues with AI agents
In `@v1/src/simulator/src/modules/AndGate.ts`:
- Around line 1-52: The class AndGate currently declares inp, inputSize, and
output1 as private which breaks external helpers like changeInputSize—make these
properties public (change private inp/inputSize/output1 to public) so
changeInputSize and other modules can access them; replace any remaining var
declarations in this module with const (e.g., loop variables) for TS
consistency; and locate any usage or declaration of the misspelled identifier
constructorParamaters and either correct it to constructorParameters or
confirm/backfill the legacy alias (keep a tolerant alias if backward
compatibility is required) so callers do not break.
- Around line 124-125: Update the v1 helplink constant for the AndGate by
replacing AndGate.prototype.helplink's old URL
'https://docs.circuitverse.org/#/chapter4/4gates?id=and-gate' with the new src
format 'https://docs.circuitverse.org/chapter4/chapter4-gates#and-gate'; apply
the same URL-format change to other gate modules (e.g.,
OrGate.prototype.helplink) so all v1 modules match the primary src helplink
pattern.
🧹 Nitpick comments (2)
src/simulator/src/modules/AndGate.ts (2)

55-59: Consider reordering isResolvable() check before accessing input values.

The current order initializes result from this.inp[0].value before checking isResolvable(). While the || 0 fallback prevents crashes, checking resolvability first is cleaner and avoids unnecessary value access when the gate cannot resolve.

This appears to match the original JS implementation, so it's a minor suggestion.

♻️ Suggested reordering
     resolve() {
+        if (this.isResolvable() === false) {
+            return;
+        }
         let result = this.inp[0].value || 0;
-        if (this.isResolvable() === false) {
-            return;
-        }
         for (let i = 1; i < this.inputSize; i++) {

68-68: Use const instead of var for TypeScript consistency.

For TypeScript best practices, prefer const (or let if reassignment is needed) over var.

♻️ Proposed fix
     customDraw() {
-        var ctx = simulationArea.context;
+        const ctx = simulationArea.context;

@Audatic07
Copy link
Contributor Author

As stated by coderabbit, should I modify the OrGate.ts help link too? And, please tell me if I can proceed to rewrite the rest of the modules, if the current format is satisfactory. Thanks for your time :)

@Audatic07
Copy link
Contributor Author

@shoryabansalgithub please check and confirm if changes to the reference OrGate suggested by Coderabbit must be made or not, since they seem valid and reasonable to me. Can I proceed with redoing AndGate and then refactor the rest of the gates accordingly too?

@shoryabansalgithub
Copy link

@Audatic07 yes you can do it

Copy link
Contributor

@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: 1

🤖 Fix all issues with AI agents
In `@v1/src/simulator/src/modules/AndGate.ts`:
- Around line 29-39: The logic in AndGate.ts that builds input Nodes uses raw
division (inputLength / 2) which yields floats for odd counts and produces
incorrect indices and y-positions; update the three loops that create Nodes to
use integer bounds like Math.floor(inputLength / 2) (mirroring OrGate.ts) so
indices are integers—e.g., compute half = Math.floor(inputLength/2) and use
loops with half-1, 0..half-1, and half..inputLength-1 (adjusting the y-position
expressions to use integer i and half) when constructing new Node(...) and
pushing to this.inp.
🧹 Nitpick comments (1)
v1/src/simulator/src/modules/AndGate.ts (1)

40-49: Consider aligning even-input logic with OrGate for consistency.

While the even-input case produces mathematically correct node positions, the iteration pattern differs from OrGate:

  • AndGate: forward iteration, nodes pushed in order -10, -20, 10, 20
  • OrGate: backward then forward iteration, nodes in order -20, -10, 10, 20

This difference in inp[] array ordering may not affect functionality but could cause subtle issues if code elsewhere relies on a specific ordering.

@Audatic07 Audatic07 force-pushed the migrate-logic-gate#908 branch from 9ea62b1 to b5f09ce Compare February 4, 2026 18:35
@Audatic07
Copy link
Contributor Author

@Nihal4777 please review :)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants