64bit coordinate support enhanced

- int128 to string support for output
- unit tests
- some compiler issues fixed
This commit is contained in:
Matthias Koefferlein 2018-01-10 22:09:45 +01:00
parent d11e2ed8a6
commit 2de6b691b4
15 changed files with 214 additions and 29 deletions

View File

@ -113,7 +113,7 @@ bool euclidian_near_part_of_edge (bool include_zero, db::Coord d, const db::Edge
// handle the parallel case
if (e.parallel (g)) {
if (abs (e.distance (g.p1 ())) >= d) {
if (std::abs (e.distance (g.p1 ())) >= d) {
return false;
}
} else {
@ -243,7 +243,7 @@ static bool var_near_part_of_edge (bool include_zero, db::Coord d, db::Coord dd,
// handle the parallel case
if (e.parallel (g)) {
if (abs (e.distance (g.p1 ())) >= d) {
if (std::abs (e.distance (g.p1 ())) >= d) {
return false;
}
} else {

View File

@ -26,6 +26,7 @@
#include "dbPolygonTools.h"
#include "dbPolygonGenerators.h"
#include "tlLog.h"
#include "tlInt128Support.h"
#include <algorithm>
#include <cmath>
@ -706,7 +707,7 @@ smooth_contour (db::Polygon::polygon_contour_iterator from, db::Polygon::polygon
}
for (size_t j = pi0; can_drop; ) {
if (abs (db::Edge (p0, p2).distance (org_points [j])) > d) {
if (std::abs (db::Edge (p0, p2).distance (org_points [j])) > d) {
can_drop = false;
}
if (j == pi2) {

View File

@ -176,7 +176,7 @@ TEST(3)
layout_read, top_read, j,
top_org.shapes (xor_layer), db::BooleanOp::Xor, true, false);
EXPECT_EQ (top_org.shapes (xor_layer).size () > 210, true);
sp.size (layout_org, top_org, xor_layer, top_org.shapes (xor_layer), -1, -1);
sp.size (layout_org, top_org, xor_layer, top_org.shapes (xor_layer), db::Coord (-1), db::Coord (-1));
EXPECT_EQ (top_org.shapes (xor_layer).size () == 0, true);
}
}
@ -236,7 +236,7 @@ TEST(4)
sp.boolean (layout_org, top_org, i,
layout_read, top_read, j,
top_org.shapes (xor_layer), db::BooleanOp::Xor, true, false);
sp.size (layout_org, top_org, xor_layer, top_org.shapes (xor_layer), -1, -1);
sp.size (layout_org, top_org, xor_layer, top_org.shapes (xor_layer), db::Coord (-1), db::Coord (-1));
EXPECT_EQ (top_org.shapes (xor_layer).size () == 0, true);
}
}

View File

@ -81,7 +81,7 @@ TEST(1)
sp.boolean (layout_org, top_org, i,
layout_read, top_read, j,
top_org.shapes (xor_layer), db::BooleanOp::Xor, true, false);
sp.size (layout_org, top_org, xor_layer, top_org.shapes (xor_layer), -1, -1);
sp.size (layout_org, top_org, xor_layer, top_org.shapes (xor_layer), db::Coord (-1), db::Coord (-1));
EXPECT_EQ (top_org.shapes (xor_layer).size () == 0, true);
}
}

View File

@ -1026,19 +1026,19 @@ TEST(20)
EXPECT_EQ (poly.to_string (), "(100,100;200,100;200,400;100,400;100,300;400,300;400,400;300,400;300,100;400,100;400,200;100,200)");
poly.assign_hull (pts, pts + sizeof (pts) / sizeof (pts[0]));
poly.size (100, 0);
poly.size (db::Coord (100), db::Coord (0));
EXPECT_EQ (poly.to_string (), "(0,100;0,400;500,400;500,100)");
poly.assign_hull (pts, pts + sizeof (pts) / sizeof (pts[0]));
poly.size (0, 100);
poly.size (db::Coord (0), db::Coord (100));
EXPECT_EQ (poly.to_string (), "(100,0;100,500;400,500;400,0)");
poly.assign_hull (pts, pts + sizeof (pts) / sizeof (pts[0]));
poly.size (-100, 0);
poly.size (db::Coord (-100), db::Coord (0));
EXPECT_EQ (poly.to_string (), "(100,100;200,100;200,400;100,400;400,400;300,400;300,100;400,100)");
poly.assign_hull (pts, pts + sizeof (pts) / sizeof (pts[0]));
poly.size (0, -100);
poly.size (db::Coord (0), db::Coord (-100));
EXPECT_EQ (poly.to_string (), "(100,100;100,400;100,300;400,300;400,400;400,100;400,200;100,200)");
poly.assign_hull (pts, pts + sizeof (pts) / sizeof (pts[0]));

View File

@ -122,7 +122,7 @@ TEST(1)
r.set_merged_semantics (false);
EXPECT_EQ (r.sized (10).to_string (), "(-10,-10;-10,60;60,60;60,-10);(40,40;40,110;110,110;110,40)");
EXPECT_EQ (r.sized (10, 20).to_string (), "(-10,-20;-10,70;60,70;60,-20);(40,30;40,120;110,120;110,30)");
EXPECT_EQ (r.sized (db::Coord (10), db::Coord (20)).to_string (), "(-10,-20;-10,70;60,70;60,-20);(40,30;40,120;110,120;110,30)");
EXPECT_EQ (r.sized (10, 20, 0).to_string (), "(0,-20;-10,0;-10,50;0,70;50,70;60,50;60,0;50,-20);(50,30;40,50;40,100;50,120;100,120;110,100;110,50;100,30)");
r.size (10, 20, 2);
EXPECT_EQ (r.to_string (), "(-10,-20;-10,70;60,70;60,-20);(40,30;40,120;110,120;110,30)");
@ -289,13 +289,13 @@ TEST(8)
EXPECT_EQ (r.sized (10).to_string (), "(-10,-10;-10,210;110,210;110,-10)");
EXPECT_EQ (r.sized (10).is_box (), true);
EXPECT_EQ (r.sized (10).is_merged (), true);
EXPECT_EQ (r.sized (10, 20).to_string (), "(-10,-20;-10,220;110,220;110,-20)");
EXPECT_EQ (r.sized (10, 20).is_box (), true);
EXPECT_EQ (r.sized (10, 20).is_merged (), true);
EXPECT_EQ (r.sized (db::Coord (10), db::Coord (20)).to_string (), "(-10,-20;-10,220;110,220;110,-20)");
EXPECT_EQ (r.sized (db::Coord (10), db::Coord (20)).is_box (), true);
EXPECT_EQ (r.sized (db::Coord (10), db::Coord (20)).is_merged (), true);
r.size (10);
EXPECT_EQ (r.to_string (), "(-10,-10;-10,210;110,210;110,-10)");
r.size (10, 20);
r.size (db::Coord (10), db::Coord (20));
EXPECT_EQ (r.to_string (), "(-20,-30;-20,230;120,230;120,-30)");
}
@ -307,9 +307,9 @@ TEST(9)
EXPECT_EQ (r.sized (10).to_string (), "(-110,-110;-110,410;210,410;210,-110)");
EXPECT_EQ (r.sized (10).is_box (), true);
EXPECT_EQ (r.sized (10).is_merged (), false);
EXPECT_EQ (r.sized (10, 20).to_string (), "(-110,-120;-110,420;210,420;210,-120)");
EXPECT_EQ (r.sized (10, 20).is_box (), true);
EXPECT_EQ (r.sized (10, 20).is_merged (), false);
EXPECT_EQ (r.sized (db::Coord (10), db::Coord (20)).to_string (), "(-110,-120;-110,420;210,420;210,-120)");
EXPECT_EQ (r.sized (db::Coord (10), db::Coord (20)).is_box (), true);
EXPECT_EQ (r.sized (db::Coord (10), db::Coord (20)).is_merged (), false);
}
TEST(10a)
@ -1141,12 +1141,12 @@ TEST(27)
db::Region r;
r.insert (db::Box (db::Point (0, 0), db::Point (100, 200)));
EXPECT_EQ (r.sized (-10, -20).to_string (), "(10,20;10,180;90,180;90,20)");
EXPECT_EQ (r.sized (-50, -20).to_string (), "");
EXPECT_EQ (r.sized (-50, -100).to_string (), "");
EXPECT_EQ (r.sized (-55, -20).to_string (), "");
EXPECT_EQ (r.sized (-10, -105).to_string (), "");
EXPECT_EQ (r.sized (-55, -105).to_string (), "");
EXPECT_EQ (r.sized (db::Coord (-10), db::Coord (-20)).to_string (), "(10,20;10,180;90,180;90,20)");
EXPECT_EQ (r.sized (db::Coord (-50), db::Coord (-20)).to_string (), "");
EXPECT_EQ (r.sized (db::Coord (-50), db::Coord (-100)).to_string (), "");
EXPECT_EQ (r.sized (db::Coord (-55), db::Coord (-20)).to_string (), "");
EXPECT_EQ (r.sized (db::Coord (-10), db::Coord (-105)).to_string (), "");
EXPECT_EQ (r.sized (db::Coord (-55), db::Coord (-105)).to_string (), "");
}
TEST(28)
@ -1159,7 +1159,7 @@ TEST(28)
r2.insert (db::Box (db::Point (100, 100), db::Point (200, 300)));
EXPECT_EQ ((r1 & r2).to_string (), "");
EXPECT_EQ ((r1 & r2.sized (5, 5)).to_string (), "(95,95;95,200;100,200;100,95)");
EXPECT_EQ ((r1 & r2.sized (db::Coord (5), db::Coord (5))).to_string (), "(95,95;95,200;100,200;100,95)");
}
TEST(29)

View File

@ -184,7 +184,7 @@ TEST(10)
EXPECT_EQ (t.is_ortho (), true);
EXPECT_EQ (t.to_string (), recomposed (t).to_string ());
t = db::DCplxTrans (db::ICplxTrans (db::disp_trans<int> (db::Vector (100, -256))));
t = db::DCplxTrans (db::ICplxTrans (db::disp_trans<db::Coord> (db::Vector (100, -256))));
EXPECT_EQ (t.is_unity (), false);
EXPECT_EQ (t.to_string (), "r0 *1 100,-256");
EXPECT_EQ (t.is_ortho (), true);
@ -202,7 +202,7 @@ TEST(10)
EXPECT_EQ (t.to_string (), "r0 *1 -0.5,1.25");
EXPECT_EQ (t.to_string (), recomposed (t).to_string ());
t = db::DCplxTrans (db::DTrans (db::simple_trans<int> (db::FTrans::m135, db::Vector (128, -256))));
t = db::DCplxTrans (db::DTrans (db::simple_trans<db::Coord> (db::FTrans::m135, db::Vector (128, -256))));
EXPECT_EQ (t.is_unity (), false);
EXPECT_EQ (t.to_string (), "m135 *1 128,-256");
EXPECT_EQ (t.to_string (), recomposed (t).to_string ());

View File

@ -66,6 +66,10 @@ ArgType::to_string () const
s += "long long"; break;
case T_ulonglong:
s += "unsigned long long"; break;
#if defined(HAVE_64BIT_COORD)
case T_int128:
s += "int128"; break;
#endif
case T_double:
s += "double"; break;
case T_float:

View File

@ -577,6 +577,10 @@ type_to_s (const gsi::ArgType &a, bool linked, bool for_return)
s += "unsigned short"; break;
case gsi::T_int:
s += "int"; break;
#if defined(HAVE_64BIT_COORD)
case gsi::T_int128:
s += "int128"; break;
#endif
case gsi::T_uint:
s += "unsigned int"; break;
case gsi::T_long:

View File

@ -42,7 +42,8 @@ SOURCES = \
tlWebDAV.cc \
tlArch.cc \
tlCommandLineParser.cc \
tlUnitTest.cc
tlUnitTest.cc \
tlInt128Support.cc
HEADERS = \
tlAlgorithm.h \
@ -90,7 +91,8 @@ HEADERS = \
tlWebDAV.h \
tlArch.h \
tlCommandLineParser.h \
tlUnitTest.h
tlUnitTest.h \
tlInt128Support.h
INCLUDEPATH =
DEPENDPATH =

View File

@ -0,0 +1,67 @@
/*
KLayout Layout Viewer
Copyright (C) 2006-2018 Matthias Koefferlein
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#if defined(HAVE_64BIT_COORD)
#include "tlInt128Support.h"
namespace tl
{
std::string
int128_to_string (__int128 x)
{
std::string r;
// this is the max. power of 10 that can be represented with __int128
__int128 m = (unsigned long long) 0x4b3b4ca85a86c47a;
m <<= 64;
m |= (unsigned long long) 0x98a224000000000;
if (x < 0) {
r = "-";
x = -x;
} else if (x == 0) {
return "0";
}
bool first = true;
while (m > 1) {
int d = 0;
while (x >= m) {
d += 1;
x -= m;
}
if (d > 0 || !first) {
r += char ('0' + d);
first = false;
}
m /= 10;
}
r += char('0' + int(x));
return r;
}
}
#endif

View File

@ -0,0 +1,58 @@
/*
KLayout Layout Viewer
Copyright (C) 2006-2018 Matthias Koefferlein
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef HDR_tlInt128Support
#define HDR_tlInt128Support
#if defined(HAVE_64BIT_COORD)
#include "tlCommon.h"
#include <inttypes.h>
#include <ostream>
namespace tl
{
TL_PUBLIC std::string int128_to_string (__int128 x);
}
namespace std
{
// Provide an implementation for abs(__int128_t) if there isn't one
inline __int128 abs (__int128 x)
{
return x < 0 ? -x : x;
}
// Provide ostream serialization for 128bit values
inline std::ostream &operator<< (std::ostream &os, __int128 x)
{
os << tl::int128_to_string (x);
return os;
}
}
#endif
#endif

View File

@ -27,6 +27,7 @@
#include "tlLog.h"
#include "tlException.h"
#include "tlString.h"
#include "tlInt128Support.h"
#include <string>
#include <vector>

View File

@ -0,0 +1,47 @@
/*
KLayout Layout Viewer
Copyright (C) 2006-2018 Matthias Koefferlein
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#if defined(HAVE_64BIT_COORD)
#include "tlInt128Support.h"
#include "tlUnitTest.h"
#include <cstdio>
TEST(1)
{
EXPECT_EQ (tl::int128_to_string (__int128 (0)), "0");
EXPECT_EQ (tl::int128_to_string (__int128 (42)), "42");
EXPECT_EQ (tl::int128_to_string (__int128 (-42)), "-42");
__int128 x = 1;
for (int i = 0; i < 30; ++i) {
x *= 10;
}
EXPECT_EQ (tl::int128_to_string (x), "1000000000000000000000000000000");
EXPECT_EQ (tl::int128_to_string (-x), "-1000000000000000000000000000000");
EXPECT_EQ (tl::int128_to_string (x + 1), "1000000000000000000000000000001");
EXPECT_EQ (tl::int128_to_string (x - 1), "999999999999999999999999999999");
}
#endif

View File

@ -32,6 +32,7 @@ SOURCES = \
tlVariant.cc \
tlWebDAV.cc \
tlXMLParser.cc \
tlInt128Support.cc
INCLUDEPATH += $$TL_INC
DEPENDPATH += $$TL_INC