Repository navigation
feat: add Earth day/night terminator visualization - #99
Conversation
🤖 CodeAnt AI — Review Status
Updated in place by CodeAnt AI · last 5 reviews |
📝 WalkthroughWalkthroughSatellite illumination is calculated with Cesium geometry, then used to adjust satellite point transparency. Cesium globe lighting is enabled during viewer initialization. ChangesSatellite illumination visualization
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant EarthTwin
participant isSatelliteSunlit
participant CesiumGlobe
EarthTwin->>isSatelliteSunlit: provide satellite position and Julian date
isSatelliteSunlit->>CesiumGlobe: test Sun ray against WGS84 ellipsoid
CesiumGlobe-->>isSatelliteSunlit: return intersection result
isSatelliteSunlit-->>EarthTwin: return sunlit status
EarthTwin->>CesiumGlobe: apply point color and outline alpha
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
| const nowJulian = Cesium.JulianDate.now(); | ||
| const sunlit = isSatelliteSunlit(cartPos, nowJulian, viewer.scene.globe); |
There was a problem hiding this comment.
Suggestion: JulianDate.now() is called inside the per-satellite loop, so you recalculate time thousands of times per refresh and get slightly different timestamps across entities in one render pass. Compute the timestamp once before iterating and reuse it for every satellite in that update. [performance]
Severity Level: Major ⚠️
- ⚠️ Extra CPU per refresh for every catalog object.
- ⚠️ Slightly inconsistent sunlit state within one refresh.
- ⚠️ Reduced performance headroom for larger satellite counts.Steps of Reproduction ✅
1. In `frontend/src/components/EarthTwin.tsx` lines 150–170, `populateEntities` is defined
as a `useCallback` that fetches `objects` and then iterates them with `objects.forEach(obj
=> { ... })` (verified via BulkRead and Grep).
2. Inside this loop at lines 193–195, the code computes `cartPos` and then calls `const
nowJulian = Cesium.JulianDate.now();` followed by `const sunlit =
isSatelliteSunlit(cartPos, nowJulian, viewer.scene.globe);`, so `JulianDate.now()` is
executed once per satellite.
3. Further down in the same file, at lines 360–365 (Grep result), the Cesium viewer
initialization logic calls `populateEntities(viewer);` once after setup and again inside a
`setInterval(() => { if (viewerRef.current && !viewerRef.current.isDestroyed()) {
populateEntities(viewerRef.current); } }, …);`, so this per-satellite loop runs on every
refresh.
4. With thousands of catalog objects, each refresh of `populateEntities` calls
`Cesium.JulianDate.now()` thousands of times in rapid succession inside a single update
cycle, instead of computing it once per refresh and reusing it.
5. Because `JulianDate.now()` advances slightly between calls, satellites in the same
frame end up using slightly different `julianDate` values for `isSatelliteSunlit`,
creating avoidable overhead and small illumination inconsistencies across entities in a
single render pass.(Use Cmd/Ctrl + Click for best experience)
Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** frontend/src/components/EarthTwin.tsx
**Line:** 194:195
**Comment:**
*Performance: `JulianDate.now()` is called inside the per-satellite loop, so you recalculate time thousands of times per refresh and get slightly different timestamps across entities in one render pass. Compute the timestamp once before iterating and reuse it for every satellite in that update.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix| globe: Cesium.Globe | ||
| ): boolean { | ||
| // Compute Sun position in the Earth‑Centered Inertial (ECI) frame. | ||
| const sunPosInertial = new Cesium.Cartesian3(); | ||
| Cesium.Simon1994PlanetaryPositions.computeSunPositionInEarthInertialFrame(julianDate, sunPosInertial); | ||
|
|
||
| // Convert Sun position to Earth‑Fixed frame. | ||
| const temeToFixed = Cesium.Transforms.computeTemeToPseudoFixedMatrix(julianDate); | ||
| const sunPosFixed = Cesium.Matrix4.multiplyByPoint(temeToFixed, sunPosInertial, new Cesium.Cartesian3()); | ||
|
|
||
| // Vector from satellite to Sun. | ||
| const satToSun = Cesium.Cartesian3.subtract(sunPosFixed, position, new Cesium.Cartesian3()); | ||
| const direction = Cesium.Cartesian3.normalize(satToSun, new Cesium.Cartesian3()); | ||
|
|
||
| // Ray from satellite toward the Sun. | ||
| const ray = new Cesium.Ray(position, direction); | ||
|
|
||
| // Test intersection with Earth's ellipsoid (WGS84). | ||
| const intersection = Cesium.IntersectionTests.rayEllipsoid(ray, Cesium.Ellipsoid.WGS84); |
There was a problem hiding this comment.
Suggestion: The function contract says the globe argument is used for ellipsoid reference, but the implementation ignores it and hardcodes Ellipsoid.WGS84. This mismatch makes the API misleading and breaks correctness if the scene ellipsoid differs from WGS84; use globe.ellipsoid (or remove the parameter and docs if intentionally fixed). [docstring mismatch]
Severity Level: Major ⚠️
- ⚠️ API suggests configurable ellipsoid but always uses WGS84.
- ⚠️ Misleads callers reusing function for non-Earth globes.
- ⚠️ Harder to adapt illumination logic to custom ellipsoids.Steps of Reproduction ✅
1. In `frontend/src/utils/illumination.ts` lines 7–10, the JSDoc for `isSatelliteSunlit`
states `@param globe - The Cesium Globe instance (used for ellipsoid reference).`,
documenting that the `globe` parameter controls which ellipsoid is used.
2. The function signature at lines 11–15 is `export function isSatelliteSunlit(position:
Cesium.Cartesian3, julianDate: Cesium.JulianDate, globe: Cesium.Globe): boolean {`,
clearly accepting a `globe` argument.
3. Inside the function body, the only ellipsoid reference occurs at line 32: `const
intersection = Cesium.IntersectionTests.rayEllipsoid(ray, Cesium.Ellipsoid.WGS84);`, which
hardcodes `Cesium.Ellipsoid.WGS84` instead of using `globe.ellipsoid`.
4. Grep results for `isSatelliteSunlit` show no other use of `globe` within this file
beyond the parameter and doc comment, confirming that the passed-in `globe` is completely
ignored in the implementation.
5. As a result, callers such as `frontend/src/components/EarthTwin.tsx` line 195
(`isSatelliteSunlit(cartPos, nowJulian, viewer.scene.globe)`) cannot actually influence
the ellipsoid used by the intersection test, and if a non-WGS84 globe were ever passed,
the function would still assume WGS84, contradicting its documented contract.(Use Cmd/Ctrl + Click for best experience)
Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** frontend/src/utils/illumination.ts
**Line:** 14:32
**Comment:**
*Docstring Mismatch: The function contract says the `globe` argument is used for ellipsoid reference, but the implementation ignores it and hardcodes `Ellipsoid.WGS84`. This mismatch makes the API misleading and breaks correctness if the scene ellipsoid differs from WGS84; use `globe.ellipsoid` (or remove the parameter and docs if intentionally fixed).
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fixThere was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@frontend/src/components/EarthTwin.tsx`:
- Around line 193-202: Update the satellite styling flow around
isSatelliteSunlit and the entity created in populateEntities so point color and
outlineColor react to the current Cesium clock time. Recompute sunlit state on
clock ticks or use time-varying Cesium properties, while preserving the existing
lit and shadow color values and avoiding dependence on the five-minute entity
rebuild.
In `@frontend/src/utils/illumination.ts`:
- Around line 20-22: Update the Sun-position conversion in the illumination
utility to use the inertial-frame transform matching sunPosInertial, and apply
it with the corresponding Matrix3/vector multiplication API; replace the
TEME-specific computeTemeToPseudoFixedMatrix and Matrix4.multiplyByPoint usage
while preserving the resulting fixed-frame Cartesian3.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 29e5e189-d89f-451f-b729-af995e3dd1e3
📒 Files selected for processing (2)
frontend/src/components/EarthTwin.tsxfrontend/src/utils/illumination.ts
| const cartPos = Cesium.Cartesian3.fromDegrees(pos.lon, pos.lat, pos.alt * 1000); | ||
| const nowJulian = Cesium.JulianDate.now(); | ||
| const sunlit = isSatelliteSunlit(cartPos, nowJulian, viewer.scene.globe); | ||
|
|
||
| const entity = viewer.entities.add({ | ||
| position: Cesium.Cartesian3.fromDegrees(pos.lon, pos.lat, pos.alt * 1000), | ||
| position: cartPos, | ||
| point: { | ||
| pixelSize, | ||
| color: colorConfig.cesium.withAlpha(0.85), | ||
| outlineColor: colorConfig.cesium.withAlpha(0.4), | ||
| color: sunlit ? colorConfig.cesium.withAlpha(0.85) : colorConfig.cesium.withAlpha(0.3), | ||
| outlineColor: sunlit ? colorConfig.cesium.withAlpha(0.4) : colorConfig.cesium.withAlpha(0.1), |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Inspect the relevant component around the reported lines and nearby update logic.
file="frontend/src/components/EarthTwin.tsx"
wc -l "$file"
sed -n '150,260p' "$file"
printf '\n---\n'
sed -n '320,390p' "$file"Repository: 7-Blocks/Kepler
Length of output: 6501
🏁 Script executed:
#!/bin/bash
set -euo pipefail
file="frontend/src/components/EarthTwin.tsx"
wc -l "$file"
sed -n '150,260p' "$file"
printf '\n---\n'
sed -n '320,390p' "$file"Repository: 7-Blocks/Kepler
Length of output: 6501
🏁 Script executed:
#!/bin/bash
set -euo pipefail
file="frontend/src/components/EarthTwin.tsx"
rg -n "isSatelliteSunlit|onTick|clock|entity\.point|withAlpha\(0\.(85|3|4|1)\)" "$file"Repository: 7-Blocks/Kepler
Length of output: 654
🏁 Script executed:
#!/bin/bash
set -euo pipefail
file="frontend/src/components/EarthTwin.tsx"
printf '--- matching lines ---\n'
rg -n "isSatelliteSunlit|onTick|clock|setInterval|populateEntities|withAlpha" "$file"
printf '\n--- surrounding isSatelliteSunlit usage ---\n'
sed -n '180,220p' "$file"
printf '\n--- surrounding any clock/onTick setup ---\n'
sed -n '400,520p' "$file"Repository: 7-Blocks/Kepler
Length of output: 244
🏁 Script executed:
#!/bin/bash
set -euo pipefail
file="frontend/src/components/EarthTwin.tsx"
rg -n "isSatelliteSunlit|onTick|clock|setInterval|populateEntities|withAlpha" "$file"
printf '\n--- lines 180-220 ---\n'
sed -n '180,220p' "$file"
printf '\n--- lines 400-520 ---\n'
sed -n '400,520p' "$file"Repository: 7-Blocks/Kepler
Length of output: 9985
🏁 Script executed:
#!/bin/bash
set -euo pipefail
file="frontend/src/components/EarthTwin.tsx"
sed -n '280,325p' "$file"Repository: 7-Blocks/Kepler
Length of output: 1670
Make satellite shadow styling time-varying. The lit/shadow colors are computed only when entities are rebuilt, so satellites can stay in the wrong state for up to five minutes between refreshes. Drive the point colors from the clock or update existing entities on tick instead of waiting for the next populateEntities run.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@frontend/src/components/EarthTwin.tsx` around lines 193 - 202, Update the
satellite styling flow around isSatelliteSunlit and the entity created in
populateEntities so point color and outlineColor react to the current Cesium
clock time. Recompute sunlit state on clock ticks or use time-varying Cesium
properties, while preserving the existing lit and shadow color values and
avoiding dependence on the five-minute entity rebuild.
|
Hii @Ayush-0918, Please attach screenshots of the updates/changes along with your PR. Thanks! |
|
Thanks for the reminder @krishkhinchi ! I’ll attach screenshots demonstrating the feature shortly. |
krishkhinchi
left a comment
There was a problem hiding this comment.
Thank you for this effort, LGTM!!
|
Hi @Ayush-0918, your PR deployment has failed on Vercel. Could you please check the deployment logs and fix the issue? Thanks!
|

User description
Description
This PR adds a real-time Earth day/night terminator visualization to the Cesium globe.
Changes
illumination.tsutility to determine whether a satellite is sunlit or inside Earth's shadow.Related Issue
Fixes #92
Checklist
I have read the contributing guidelines
My code follows the project guidelines
I have completed testing of my changes
Documentation has been updated (if applicable)
Screenshots / Screen Recordings
Breaking Changes
No breaking changes.
ECSoC26 Submission
ECSoC26-L1– BeginnerECSoC26-L2– IntermediateECSoC26-L3– AdvancedCodeAnt-AI Description
Make satellites dim when they pass into Earth’s shadow and show a lit day/night globe
What Changed
Impact
✅ Clearer Earth day/night view✅ Easier to spot shadowed satellites✅ More realistic globe lighting💡 Usage Guide
Checking Your Pull Request
Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.
Talking to CodeAnt AI
Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:
This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.
Example
Preserve Org Learnings with CodeAnt
You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:
This helps CodeAnt AI learn and adapt to your team's coding style and standards.
Example
Retrigger review
Ask CodeAnt AI to review the PR again, by typing:
Check Your Repository Health
To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.
Summary by CodeRabbit
Greptile Summary
This PR adds real-time Earth day/night terminator visualization by enabling Cesium globe lighting and introducing
illumination.ts, which computes per-satellite shadow status via a sun-position / ellipsoid ray-intersection test.Matrix4vsMatrix3API, unusedglobeparameter,JulianDate.now()inside the loop) are all resolved in this revision.computeSunPositionInEarthInertialFrameandcomputeTemeToPseudoFixedMatrixare called once per satellite per frame rather than once per frame, repeating identical work for every object in the scene.Confidence Score: 5/5
Safe to merge; the illumination logic is geometrically correct and all blocking issues from earlier reviews have been addressed.
The shadow-detection algorithm is sound: the Matrix3 API is used correctly, the globe ellipsoid is referenced through the parameter rather than hardcoded, the import is present, and JulianDate allocation is hoisted outside the per-satellite loop. Remaining feedback is about a redundant per-satellite sun-position recomputation and a formatting inconsistency, neither of which affects correctness.
No files require special attention beyond the optional refactor in illumination.ts to hoist sun-position computation out of per-satellite calls.
Important Files Changed
Sequence Diagram
%%{init: {'theme': 'neutral'}}%% sequenceDiagram participant ET as EarthTwin.tsx participant IL as illumination.ts participant CES as Cesium APIs ET->>ET: JulianDate.now() [once per frame] loop for each satellite ET->>ET: "keplerToLatLonAlt(obj) → {lat,lon,alt}" ET->>ET: Cartesian3.fromDegrees(lon,lat,alt) ET->>IL: isSatelliteSunlit(cartPos, nowJulian, globe) IL->>CES: Simon1994.computeSunPositionInEarthInertialFrame(julianDate) IL->>CES: Transforms.computeTemeToPseudoFixedMatrix(julianDate) IL->>CES: Matrix3.multiplyByVector(teme, sunInertial) → sunPosFixed IL->>CES: IntersectionTests.rayEllipsoid(ray, ellipsoid) IL-->>ET: boolean (sunlit) ET->>CES: "viewer.entities.add({ color based on sunlit })" end%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%% sequenceDiagram participant ET as EarthTwin.tsx participant IL as illumination.ts participant CES as Cesium APIs ET->>ET: JulianDate.now() [once per frame] loop for each satellite ET->>ET: "keplerToLatLonAlt(obj) → {lat,lon,alt}" ET->>ET: Cartesian3.fromDegrees(lon,lat,alt) ET->>IL: isSatelliteSunlit(cartPos, nowJulian, globe) IL->>CES: Simon1994.computeSunPositionInEarthInertialFrame(julianDate) IL->>CES: Transforms.computeTemeToPseudoFixedMatrix(julianDate) IL->>CES: Matrix3.multiplyByVector(teme, sunInertial) → sunPosFixed IL->>CES: IntersectionTests.rayEllipsoid(ray, ellipsoid) IL-->>ET: boolean (sunlit) ET->>CES: "viewer.entities.add({ color based on sunlit })" endComments Outside Diff (1)
frontend/src/components/EarthTwin.tsx, line 175-194 (link)Cesium.JulianDate.now()is called insideobjects.forEach, allocating a new object per satellite. With 500 objects this is 500 allocations. Moving it above the loop matches the stated intent and eliminates the redundancy.Prompt To Fix With AI
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Reviews (2): Last reviewed commit: "fix: address review feedback" | Re-trigger Greptile