Fix copy-paste bug in BumpMapEffect::ComputeTangent#151
Open
CodeReclaimers wants to merge 1 commit intodavideberly:masterfrom
Open
Fix copy-paste bug in BumpMapEffect::ComputeTangent#151CodeReclaimers wants to merge 1 commit intodavideberly:masterfrom
CodeReclaimers wants to merge 1 commit intodavideberly:masterfrom
Conversation
Length(deltaPos1) is tested twice on line 168; second check should test Length(deltaPos2). Without this, a zero-length deltaPos2 is not detected and the function proceeds with a degenerate tangent frame. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
Author
Test program#include <Mathematics/Vector3.h>
#include <Mathematics/Vector2.h>
#include <cstdlib>
#include <iostream>
using namespace gte;
static bool DetectDegenerate_Buggy(
Vector3<float> const& position0,
Vector3<float> const& position1,
Vector3<float> const& position2)
{
Vector3<float> deltaPos1 = position1 - position0;
Vector3<float> deltaPos2 = position2 - position0;
float const epsilon = 1e-08f;
if (Length(deltaPos1) <= epsilon || Length(deltaPos1) <= epsilon)
return true;
return false;
}
static bool DetectDegenerate_Fixed(
Vector3<float> const& position0,
Vector3<float> const& position1,
Vector3<float> const& position2)
{
Vector3<float> deltaPos1 = position1 - position0;
Vector3<float> deltaPos2 = position2 - position0;
float const epsilon = 1e-08f;
if (Length(deltaPos1) <= epsilon || Length(deltaPos2) <= epsilon)
return true;
return false;
}
int main()
{
Vector3<float> p0 = { 0.0f, 0.0f, 0.0f };
Vector3<float> p1 = { 1.0f, 0.0f, 0.0f };
Vector3<float> p2 = { 0.0f, 0.0f, 0.0f }; // same as p0
bool buggyDetected = DetectDegenerate_Buggy(p0, p1, p2);
bool fixedDetected = DetectDegenerate_Fixed(p0, p1, p2);
if (!fixedDetected || buggyDetected)
{
std::cerr << "FAIL" << std::endl;
return EXIT_FAILURE;
}
std::cout << "PASS: fixed version correctly detects zero-length deltaPos2" << std::endl;
return EXIT_SUCCESS;
}Before fix: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Length(deltaPos1)is tested twice on line 168; second check should testLength(deltaPos2). Without this, a zero-lengthdeltaPos2is not detected and the function proceeds with a degenerate tangent frame.Note: This is a compiled Graphics source file, so a standalone header-only test is not feasible.