kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #00951
Re: Patch: improved magnetism
-
To:
kicad-devel@xxxxxxxxxxxxxxx
-
From:
Werner Almesberger <werner@...>
-
Date:
Mon, 4 Feb 2008 06:13:45 -0800
-
In-reply-to:
<20080204075656.GH19839@...>
--XWOWbaMNXpFDWE00 Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Oops, I think there's quite a lot of 64-bit-isms in my patch, causing
overflows in multiplications. This patch should fix that. Sorry.
- Werner
---------------------------------- Changes ------------------------------------
pcbnew/controle.cpp (Join, Project), pcbnew/class_track.cpp (HitTest): force 64
bit arithmetic where coordinates are multiplied with other coordinates
--XWOWbaMNXpFDWE00 Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="kicad-magnet-overflow.patch"
--- pcbnew/controle.cpp.orig 2008-02-04 10:36:45.000000000 -0300
+++ pcbnew/controle.cpp 2008-02-04 10:41:44.000000000 -0300
@@ -234,11 +234,11 @@
b1 -= b0;
b0 -= a0;
- denom = b1.y*a1.x-b1.x*a1.y;
+ denom = (int64_t) b1.y*a1.x - (int64_t) b1.x*a1.y;
if (!denom)
return false; // parallel
- t = (b1.y*b0.x-b1.x*b0.y)/(double) denom;
+ t = ((int64_t) b1.y*b0.x - (int64_t) b1.x*b0.y)/(double) denom;
t = min(max(t, 0.0), 1.0);
res.x = (int) round(a0.x+t*a1.x);
@@ -261,8 +261,9 @@
return false;
vec = track->m_End-track->m_Start;
- t = (on_grid.x-track->m_Start.x)*vec.x+(on_grid.y-track->m_Start.y)*vec.y;
- t /= vec.x*vec.x+vec.y*vec.y;
+ t = (int64_t) (on_grid.x-track->m_Start.x)*vec.x +
+ (int64_t) (on_grid.y-track->m_Start.y)*vec.y;
+ t /= (int64_t) vec.x*vec.x + (int64_t) vec.y*vec.y;
t = min(max(t, 0.0), 1.0);
res.x = (int) round(track->m_Start.x+t*vec.x);
--- pcbnew/class_track.cpp.orig 2008-02-04 10:41:55.000000000 -0300
+++ pcbnew/class_track.cpp 2008-02-04 10:42:32.000000000 -0300
@@ -886,7 +886,8 @@
if( Type() == TYPEVIA ) /* VIA rencontree */
{
- return spot_cX*spot_cX+spot_cY*spot_cY <= l_piste*l_piste;
+ return (int64_t) spot_cX*spot_cX + (int64_t) spot_cY*spot_cY <=
+ (int64_t) l_piste*l_piste;
}
else
{
--XWOWbaMNXpFDWE00--
Follow ups
References