Skip to content

Fix missing negEnd0 radius comparison in ContCapsule3 MergeContainers#118

Open
CodeReclaimers wants to merge 1 commit intodavideberly:masterfrom
CodeReclaimers:fix/cont-capsule3-merge-radius
Open

Fix missing negEnd0 radius comparison in ContCapsule3 MergeContainers#118
CodeReclaimers wants to merge 1 commit intodavideberly:masterfrom
CodeReclaimers:fix/cont-capsule3-merge-radius

Conversation

@CodeReclaimers
Copy link
Contributor

In MergeContainers, the negEnd0 distance+radius is computed (line 171) but never compared against the running radius maximum before being overwritten by the posEnd1 computation (line 174). If negEnd0 is the farthest endpoint from the merge axis, the merged capsule is too narrow.

Fix: add the missing if (tmp > radius) { radius = tmp; } block, matching the pattern used for the other three endpoints.

Test (CMakeLists.txt)
cmake_minimum_required(VERSION 3.14)
project(test_issue_5_1 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(GTE_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../../GTE")
add_executable(test_issue_5_1 test_issue_5_1.cpp)
target_include_directories(test_issue_5_1 PRIVATE "${GTE_ROOT}")
Test (test_issue_5_1.cpp)
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <Mathematics/ContCapsule3.h>

static bool test_asymmetric_capsules()
{
    using Real = double;
    using Vec3 = gte::Vector3<Real>;

    // Capsule0: long segment from (-10,-8,0) to (2,0,0), radius 2.
    gte::Segment3<Real> seg0(Vec3{-10.0,-8.0,0.0}, Vec3{2.0,0.0,0.0});
    gte::Capsule3<Real> capsule0(seg0, 2.0);

    // Capsule1: short segment near origin, radius 1.
    gte::Segment3<Real> seg1(Vec3{-1.0,0.0,0.0}, Vec3{1.0,0.0,0.0});
    gte::Capsule3<Real> capsule1(seg1, 1.0);

    gte::Capsule3<Real> merge;
    gte::MergeContainers(capsule0, capsule1, merge);

    // Merged capsule must contain capsule0's negative end sphere.
    gte::Sphere3<Real> negEnd0Sphere(seg0.p[0], capsule0.radius);
    return gte::InContainer<Real>(negEnd0Sphere, merge);
}

int main()
{
    return test_asymmetric_capsules() ? EXIT_SUCCESS : EXIT_FAILURE;
}

The negEnd0 distance+radius was computed but never compared against
the running maximum, so the merged capsule could be too narrow.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

1 participant