davideberly / GeometricTools

A collection of source code for computing in the fields of mathematics, geometry, graphics, image analysis and physics.
Boost Software License 1.0
1.08k stars 202 forks source link

compile problem - have to cast (double) for all std::sqrt(...) #90

Closed owai1980 closed 1 month ago

owai1980 commented 1 month ago

Hello,

I use GeometricTools mainly with Segment2, Arc2, Line2, Circle, Ray2, ... objects.

Until now, everything was ok, but i have some precision problems, so I want to switch from the standard double to gte::BSRational<gte::UIntegerAP32>

so now i use:

gte::Vector2< gte::BSRational<gte::UIntegerAP32> >;
gte::Segment2<  gte::BSRational<gte::UIntegerAP32> >;
gte::Ray2<  gte::BSRational<gte::UIntegerAP32> >;
gte::Arc2<  gte::BSRational<gte::UIntegerAP32> >;
gte::Line2<  gte::BSRational<gte::UIntegerAP32> >;
gte::Circle2<  gte::BSRational<gte::UIntegerAP32> >;

But for every use of std::sqrt() or std::fabs() i had +- 23 compilation problems in these files:

GTE/Mathematics/Arc2.h
GTE/Mathematics/DistPoint2Arc2.h
GTE/Mathematics/DistPoint2Circle2.h
GTE/Mathematics/DistPointLine.h
GTE/Mathematics/DistPointSegment.h
GTE/Mathematics/IntrCircle2Circle2.h
GTE/Mathematics/IntrLine2Circle2.h
GTE/Mathematics/IntrLine2Line2.h
GTE/Mathematics/IntrRay2Segment2.h
GTE/Mathematics/IntrSegment2Segment2.h
GTE/Mathematics/Vector.h

examples (from various files):

T root = std::sqrt(discr);

result.distance = std::sqrt(sqrLength0);

return std::sqrt(Dot(v, v));

if (std::fabs(length - radius) <= epsilon)

I always have to insert a cast (double) to be allowed to compile:

T root = std::sqrt((double)discr);

result.distance = std::sqrt((double)sqrLength0);

return std::sqrt((double)Dot(v, v));

if (std::fabs((double)(length - radius)) <= (double)epsilon)

I use embarcadero c++ builder 12 (lastest version with all patches)

after patching all your files to allow compile, my app compiles and works well, pretty fast, and more precise! (just a little bug in arc2, but i think it's my fault).

these are the typical headers that i include:

#include <Mathematics/Segment.h>
#include <Mathematics/Arc2.h>
#include <Mathematics/Hypersphere.h>

#include <Mathematics/FIQuery.h>
#include <Mathematics/TIQuery.h>
#include <Mathematics/DistPointLine.h>
#include <Mathematics/DistPointSegment.h>
#include <Mathematics/DistPoint2Arc2.h>
#include <Mathematics/ContAlignedBox2Arc2.h>

//#include "Mathematics/IntrLine2Line2.h"
#include "Mathematics/IntrArc2Arc2.h"
#include "Mathematics/IntrSegment2Arc2.h"
#include "Mathematics/IntrSegment2Segment2.h"
#include "Mathematics/IntrRay2Segment2.h"
#include "Mathematics/IntrRay2Arc2.h"
#include "Mathematics/IntrRay2Circle2.h"
#include "Mathematics/IntrLine2Segment2.h"
#include "Mathematics/IntrLine2Arc2.h"
#include "Mathematics/IntrLine2Circle2.h"

Do you have any clue? maybe a problem of namespace? or the path i use to include your files?

thank you!

johan

davideberly commented 1 month ago

include the ArbitraryPrecision.h before all your other header files in the source files that use rational numbers. The problem is how the compiler processes the symbols (uses a two-pass system).

owai1980 commented 1 month ago

It works prefect! Thank you! 👍 👍

Le mer. 5 juin 2024 à 23:36, David Eberly @.***> a écrit :

include the ArbitraryPrecision.h before all your other header files in

the source files that use rational numbers. The problem is how the compiler processes the symbols (uses a two-pass system).

— Reply to this email directly, view it on GitHub https://github.com/davideberly/GeometricTools/issues/90#issuecomment-2151002492, or unsubscribe https://github.com/notifications/unsubscribe-auth/AG3BAQNLR4XKIHATDEHU2W3ZF6AGTAVCNFSM6AAAAABI264SPSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNJRGAYDENBZGI . You are receiving this because you authored the thread.Message ID: @.***>

davideberly commented 1 month ago

Closing this because problem solved.