csColor GetPixel (float coord_x, float coord_y) { // Scale the texture coordinates. coord_x *= textureScale.x; coord_y *= textureScale.y; // Calculate the material coordinates. float matcoord_x_f = (coord_x * img_w); float matcoord_y_f = (coord_y * img_h); int matcoord_x = int (matcoord_x_f); int matcoord_y = int (matcoord_y_f); // Bilinearly filter from material. csColor p00 (GetPixelWrap (img, img_w, img_h, matcoord_x, matcoord_y)); csColor p01 (GetPixelWrap (img, img_w, img_h, matcoord_x, matcoord_y+1)); csColor p11 (GetPixelWrap (img, img_w, img_h, matcoord_x+1, matcoord_y+1)); csColor p10 (GetPixelWrap (img, img_w, img_h, matcoord_x+1, matcoord_y)); float f1 = matcoord_x_f - matcoord_x; float f2 = matcoord_y_f - matcoord_y; return csLerp (csLerp (p00, p10, f1), csLerp (p01, p11, f1), f2); }
/** * @brief * Calculate the intersection point of a line segment and the two triangles making a the cell of a height map terrain */ dFloat BodyTerrain::RayCastCell(int xIndex0, int zIndex0, const Vector3 &p0, const Vector3 &dp, Vector3 &normalOut) { dFloat t; // Clamp x if (xIndex0 < 0) xIndex0 = 0; if (xIndex0 >= static_cast<int>(m_nWidth)-1) xIndex0 = m_nWidth-2; // Clamp z if (zIndex0 < 0) zIndex0 = 0; if (zIndex0 >= static_cast<int>(m_nHeight)-1) zIndex0 = m_nHeight-2; // Get the 3d point at the corner of the cell Vector3 p00((xIndex0 + 0)*m_vScale.x, HEIGHFIELD(zIndex0+0, xIndex0+0), (zIndex0 + 0)*m_vScale.z); Vector3 p10((xIndex0 + 1)*m_vScale.x, HEIGHFIELD(zIndex0+0, xIndex0+1), (zIndex0 + 0)*m_vScale.z); Vector3 p11((xIndex0 + 1)*m_vScale.x, HEIGHFIELD(zIndex0+1, xIndex0+1), (zIndex0 + 1)*m_vScale.z); // Clip line again first triangle Vector3 e0 = p10 - p00; Vector3 e1 = p11 - p00; t = RayCastTriangle(p0, dp, p00, e0, e1); if (t < 1.0f) { return t; } // Clip line against second triangle Vector3 p01((xIndex0 + 0)*m_vScale.x, HEIGHFIELD(zIndex0+1, xIndex0+0), (zIndex0 + 1)*m_vScale.z); Vector3 e2 = p01 - p00; return RayCastTriangle(p0, dp, p00, e1, e2); }
void Bezier::split(double t, Bezier & left, Bezier & right) const { // http://processingjs.nihongoresources.com/bezierinfo/sketchsource.php?sketch=CubicDeCasteljau // interpolate from 4 to 3 points QPointF p5((1-t)*m_endpoint0.x() + t*m_cp0.x(), (1-t)*m_endpoint0.y() + t*m_cp0.y()); QPointF p6((1-t)*m_cp0.x() + t*m_cp1.x(), (1-t)*m_cp0.y() + t*m_cp1.y()); QPointF p7((1-t)*m_cp1.x() + t*m_endpoint1.x(), (1-t)*m_cp1.y() + t*m_endpoint1.y()); // interpolate from 3 to 2 points QPointF p8((1-t)*p5.x() + t*p6.x(), (1-t)*p5.y() + t*p6.y()); QPointF p9((1-t)*p6.x() + t*p7.x(), (1-t)*p6.y() + t*p7.y()); // interpolate from 2 points to 1 point QPointF p10((1-t)*p8.x() + t*p9.x(), (1-t)*p8.y() + t*p9.y()); // we now have all the values we need to build the subcurves left.m_endpoint0 = m_endpoint0; left.m_cp0 = p5; left.m_cp1 = p8; right.m_endpoint0 = left.m_endpoint1 = p10; right.m_cp0 = p9; right.m_cp1 = p7; right.m_endpoint1 = m_endpoint1; left.m_isEmpty = right.m_isEmpty = false; }
int lenn(long int n){ int l; l=ceil(log10(n)); long int pp; pp=p10(l); if(pp==n){ l=l+1; } return l; }
int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); QQmlApplicationEngine engine; Player p1("Emma", 4); Player p2("Emma", 4); Player p3("Emma", 4); Player p4("Emma", 4); Player p5("Emma", 4); Player p6("Emma", 4); Player p7("Emma", 4); Player p8("Emma", 4); Player p9("Emma", 4); Player p10("Emma", 4); Player p11("Emma", 4); Player p12("Emma", 4); Match m(3); engine.rootContext()->setContextProperty("player1", &p1); engine.rootContext()->setContextProperty("player2", &p2); engine.rootContext()->setContextProperty("player3", &p3); engine.rootContext()->setContextProperty("player4", &p4); engine.rootContext()->setContextProperty("player5", &p5); engine.rootContext()->setContextProperty("player6", &p6); engine.rootContext()->setContextProperty("player7", &p7); engine.rootContext()->setContextProperty("player8", &p8); engine.rootContext()->setContextProperty("player9", &p9); engine.rootContext()->setContextProperty("player10", &p10); engine.rootContext()->setContextProperty("player11", &p11); engine.rootContext()->setContextProperty("player12", &p12); engine.rootContext()->setContextProperty("match", &m); QCoreApplication::setApplicationName("Lab2"); QCoreApplication::setOrganizationName("EMMA"); QCoreApplication::setOrganizationDomain(".fourThompson"); engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); return app.exec(); }
void setup(MeshType & mesh, viennagrid::hexahedron_tag) { typedef typename viennagrid::result_of::point<MeshType>::type PointType; typedef typename viennagrid::result_of::vertex_handle<MeshType>::type VertexHandleType; PointType p0(0.0, 0.0, 0.0); PointType p1(1.0, 0.0, 0.0); PointType p2(1.0, 1.0, 0.0); PointType p3(0.0, 1.0, 0.0); PointType p4(0.0, 0.0, 1.0); PointType p5(1.0, 0.0, 1.0); PointType p6(1.0, 1.0, 1.0); PointType p7(0.0, 1.0, 1.0); PointType p8(2.0, 0.0, 0.0); PointType p9(2.0, 1.0, 0.0); PointType p10(2.0, 0.0, 1.0); PointType p11(2.0, 1.0, 1.0); std::cout << "Adding vertices to segment:" << std::endl; VertexHandleType vh0 = viennagrid::make_vertex( mesh, p0 ); VertexHandleType vh1 = viennagrid::make_vertex( mesh, p1 ); VertexHandleType vh2 = viennagrid::make_vertex( mesh, p2 ); VertexHandleType vh3 = viennagrid::make_vertex( mesh, p3 ); VertexHandleType vh4 = viennagrid::make_vertex( mesh, p4 ); VertexHandleType vh5 = viennagrid::make_vertex( mesh, p5 ); VertexHandleType vh6 = viennagrid::make_vertex( mesh, p6 ); VertexHandleType vh7 = viennagrid::make_vertex( mesh, p7 ); VertexHandleType vh8 = viennagrid::make_vertex( mesh, p8 ); VertexHandleType vh9 = viennagrid::make_vertex( mesh, p9 ); VertexHandleType vh10 = viennagrid::make_vertex( mesh, p10 ); VertexHandleType vh11 = viennagrid::make_vertex( mesh, p11 ); viennagrid::make_hexahedron( mesh, vh0, vh1, vh3, vh2, vh4, vh5, vh7, vh6 ); viennagrid::make_hexahedron( mesh, vh1, vh8, vh2, vh9, vh5, vh10, vh6, vh11 ); }
int main(int argc, char **argv) { plan_tests(92); // test constructor GeoPoint p1(Angle::Degrees(345.32), Angle::Degrees(-6.332)); ok1(p1.IsValid()); ok1(equals(p1, -6.332, 345.32)); // test normalize() p1.Normalize(); ok1(p1.IsValid()); ok1(equals(p1, -6.332, -14.68)); // test parametric() GeoPoint p2(Angle::Degrees(2), Angle::Degrees(1)); GeoPoint p3 = p1.Parametric(p2, 5); ok1(p2.IsValid()); ok1(p3.IsValid()); ok1(equals(p3, -1.332, -4.68)); // test interpolate GeoPoint p4 = p1.Interpolate(p3, 0.5); ok1(p4.IsValid()); ok1(equals(p4, -3.832, -9.68)); GeoPoint p5 = p1.Interpolate(p3, 0.25); ok1(p5.IsValid()); ok1(equals(p5, -5.082, -12.18)); // test * GeoPoint p6 = p2 * 3.5; ok1(p6.IsValid()); ok1(equals(p6, 3.5, 7)); // test + p6 = p6 + p2; ok1(p6.IsValid()); ok1(equals(p6, 4.5, 9)); // test += p6 += p2; ok1(p6.IsValid()); ok1(equals(p6, 5.5, 11)); // test - p6 = p6 - p2; ok1(p6.IsValid()); ok1(equals(p6, 4.5, 9)); // for large and short distance testing GeoPoint p11(Angle::Degrees(0.00001), Angle::Degrees(0.00001)); GeoPoint p12(Angle::Degrees(179), Angle::Degrees(0)); p11 += p1; p12 += p1; ok1(p11.IsValid()); ok1(equals(p11, -6.33199, -14.67999)); ok1(p12.IsValid()); ok1(equals(p12, -6.332, 164.32)); // test sort() ok1(!p1.Sort(p3)); ok1(p3.Sort(p1)); ok1(!p1.Sort(p4)); ok1(p4.Sort(p1)); ok1(!p1.Sort(p5)); ok1(p5.Sort(p1)); ok1(!p4.Sort(p3)); ok1(p3.Sort(p4)); ok1(!p5.Sort(p3)); ok1(p3.Sort(p5)); ok1(!p5.Sort(p4)); ok1(p4.Sort(p5)); // test distance() // // note: distance between p1 and p4 and between p3 and p4 is not // the same due to linear interpolation instead of real geographic // intermediate point calculation ok1(equals(p2.Distance(p6), 869146.334126)); ok1(equals(p6.Distance(p2), 869146.334126)); ok1(equals(p1.Distance(p5), 309506.275043)); ok1(equals(p1.Distance(p4), 619486.719361)); ok1(equals(p1.Distance(p3), 1240403.22926)); ok1(equals(p3.Distance(p4), 620924.169000)); ok1(equals(p1.Distance(p11), 1.561761)); ok1(equals(p1.Distance(p12), 18599361.600)); ok1(equals(p2.DistanceS(p6), 869326.653160)); ok1(equals(p6.DistanceS(p2), 869326.653160)); ok1(equals(p1.DistanceS(p5), 309562.219016)); ok1(equals(p1.DistanceS(p4), 619603.149273)); ok1(equals(p1.DistanceS(p3), 1240649.267606)); ok1(equals(p3.DistanceS(p4), 621053.760625)); ok1(equals(p1.DistanceS(p11), 1.568588)); ok1(equals(p1.DistanceS(p12), 18602548.701)); // test bearing() // // note: the bearings p1 -> p5, p5 -> p4 and so on are not the same due to // linear interpolation instead of real geographic intermediate point // calculation ok1(equals(p2.Bearing(p6), 63.425773)); ok1(equals(p6.Bearing(p2), 243.762198)); ok1(equals(p1.Bearing(p5), 63.601900)); ok1(equals(p1.Bearing(p4), 63.735395)); ok1(equals(p1.Bearing(p3), 63.937616)); ok1(equals(p5.Bearing(p4), 63.619712)); ok1(equals(p5.Bearing(p3), 63.799336)); ok1(equals(p4.Bearing(p3), 63.694155)); ok1(equals(p5.Bearing(p6), 66.126880)); ok1(equals(p2.Bearing(p3), 250.886912)); ok1(equals(p2.BearingS(p6), 63.272424)); ok1(equals(p6.BearingS(p2), 243.608847)); ok1(equals(p1.BearingS(p5), 63.449343)); ok1(equals(p1.BearingS(p4), 63.582620)); ok1(equals(p1.BearingS(p3), 63.784526)); ok1(equals(p5.BearingS(p4), 63.466726)); ok1(equals(p5.BearingS(p3), 63.646072)); ok1(equals(p4.BearingS(p3), 63.540756)); ok1(equals(p5.BearingS(p6), 65.982854)); ok1(equals(p2.BearingS(p3), 250.786774)); // test distance_bearing() // note: should be the same output as bearing() and distance() GeoVector v = p2.DistanceBearing(p6); ok1(equals(v.distance, 869146.334126)); ok1(equals(v.bearing, 63.425773)); v = p2.DistanceBearingS(p6); ok1(equals(v.distance, 869326.653160)); ok1(equals(v.bearing, 63.272424)); // test intermediate_point() GeoPoint p7(Angle::Zero(), Angle::Zero()); ok1(p7.IsValid()); GeoPoint p8 = p7.IntermediatePoint(p2, 100000); ok1(p8.IsValid()); ok1(equals(p8, 0.402361, 0.804516)); ok1(equals(p8.Distance(p7), 100000)); GeoPoint p9 = p7.IntermediatePoint(p2, 100000000); ok1(p9.IsValid()); ok1(equals(p9, p2)); // test projected_distance() ok1(equals(p8.ProjectedDistance(p7, p2), 100000)); ok1(equals(p4.ProjectedDistance(p1, p3), 619494.517917)); ok1(equals((p2 * 2).ProjectedDistance(p2, p6), 248511.833322)); // Tests moved here from test_fixed.cpp GeoPoint l1(Angle::Zero(), Angle::Zero()); ok1(l1.IsValid()); GeoPoint l2(Angle::Degrees(-0.3), Angle::Degrees(1.0)); ok1(l2.IsValid()); GeoPoint l3(Angle::Degrees(0.00001), Angle::Zero()); ok1(l3.IsValid()); GeoPoint l4(Angle::Degrees(10), Angle::Zero()); ok1(l4.IsValid()); l4.SetInvalid(); ok1(!l4.IsValid()); bool find_lat_lon_okay = true; for (Angle bearing = Angle::Zero(); bearing < Angle::FullCircle(); bearing += Angle::Degrees(5)) { GeoPoint p_test = FindLatitudeLongitude(p1, bearing, 50000); find_lat_lon_okay = equals(p_test.Distance(p1), 50000) && find_lat_lon_okay; } ok1(find_lat_lon_okay); v = l1.DistanceBearing(l2); // 116090 @ 343 v = l1.DistanceBearing(l3); ok(v.distance > 0 && v.distance < 2, "earth distance short", 0); GeoPoint p10(GeoPoint::Invalid()); ok1(!p10.IsValid()); return exit_status(); }
void LLSurfacePatch::calcNormal(const U32 x, const U32 y, const U32 stride) { U32 patch_width = mSurfacep->mPVArray.mPatchWidth; U32 surface_stride = mSurfacep->getGridsPerEdge(); const F32 mpg = mSurfacep->getMetersPerGrid() * stride; S32 poffsets[2][2][2]; poffsets[0][0][0] = x - stride; poffsets[0][0][1] = y - stride; poffsets[0][1][0] = x - stride; poffsets[0][1][1] = y + stride; poffsets[1][0][0] = x + stride; poffsets[1][0][1] = y - stride; poffsets[1][1][0] = x + stride; poffsets[1][1][1] = y + stride; const LLSurfacePatch *ppatches[2][2]; // LLVector3 p1, p2, p3, p4; ppatches[0][0] = this; ppatches[0][1] = this; ppatches[1][0] = this; ppatches[1][1] = this; U32 i, j; for (i = 0; i < 2; i++) { for (j = 0; j < 2; j++) { if (poffsets[i][j][0] < 0) { if (!ppatches[i][j]->getNeighborPatch(WEST)) { poffsets[i][j][0] = 0; } else { poffsets[i][j][0] += patch_width; ppatches[i][j] = ppatches[i][j]->getNeighborPatch(WEST); } } if (poffsets[i][j][1] < 0) { if (!ppatches[i][j]->getNeighborPatch(SOUTH)) { poffsets[i][j][1] = 0; } else { poffsets[i][j][1] += patch_width; ppatches[i][j] = ppatches[i][j]->getNeighborPatch(SOUTH); } } if (poffsets[i][j][0] >= (S32)patch_width) { if (!ppatches[i][j]->getNeighborPatch(EAST)) { poffsets[i][j][0] = patch_width - 1; } else { poffsets[i][j][0] -= patch_width; ppatches[i][j] = ppatches[i][j]->getNeighborPatch(EAST); } } if (poffsets[i][j][1] >= (S32)patch_width) { if (!ppatches[i][j]->getNeighborPatch(NORTH)) { poffsets[i][j][1] = patch_width - 1; } else { poffsets[i][j][1] -= patch_width; ppatches[i][j] = ppatches[i][j]->getNeighborPatch(NORTH); } } } } LLVector3 p00(-mpg,-mpg, *(ppatches[0][0]->mDataZ + poffsets[0][0][0] + poffsets[0][0][1]*surface_stride)); LLVector3 p01(-mpg,+mpg, *(ppatches[0][1]->mDataZ + poffsets[0][1][0] + poffsets[0][1][1]*surface_stride)); LLVector3 p10(+mpg,-mpg, *(ppatches[1][0]->mDataZ + poffsets[1][0][0] + poffsets[1][0][1]*surface_stride)); LLVector3 p11(+mpg,+mpg, *(ppatches[1][1]->mDataZ + poffsets[1][1][0] + poffsets[1][1][1]*surface_stride)); LLVector3 c1 = p11 - p00; LLVector3 c2 = p01 - p10; LLVector3 normal = c1; normal %= c2; normal.normVec(); *(mDataNorm + surface_stride * y + x) = normal; }
void onInitialization( ) { glViewport(0, 0, screenWidth, screenHeight); srand(42); Mat gold; gold.ka=Color(0.24725, 0.1995, 0.0745); gold.kd=Color(0.75164, 0.60648, 0.22648); gold.ks=Color(0.628281, 0.555802, 0.366065); gold.shine=0.4 * 128; gold.n=Color(0.17, 0.35, 1.5); gold.k=Color(3.1, 2.7, 1.9); gold.reflective=true; gold.refractive=false; Mat brown; brown.ka=Color(0.1,0.1,0.1); brown.kd=Color(0.58, 0.294, 0); brown.ks=Color(0,0,0); brown.shine=0; brown.reflective=false; brown.refractive=false; double gn=1.5; Mat glass; glass.ka=Color(0.1,0.1,0.1); glass.kd=Color(0.2,0.2,0.2); glass.ks=Color(1,1,1); glass.shine=120; glass.reflective=true; glass.refractive=true; glass.n=Color(gn,gn,gn); glass.k=Color(0,0,0); Mat glass2=glass; glass2.n=Color(1/gn, 1/gn, 1/gn); add(new Sphere(glass2, Vector(0,0,0), 0.4)); add(new Torus(gold, 0.25, 0.1)); double z=-0.65; Vector p00(-2,-2,z); Vector p10(2,-2,z); Vector p01(-2,2,z); Vector p11(2,2,z); Vector n(0,0,1); add(new Triangle(brown, p00, p10, p01, n,n,n)); add(new Triangle(brown, p11, p01, p10, n,n,n)); int cube[12][3][3]={ { {-1, -1, -1}, {1, -1, -1}, {1, -1, 1} }, { {-1, -1, 1}, {-1, -1, -1}, {1, -1, 1} }, { {-1, 1, -1}, {1, 1, 1}, {1, 1, -1} }, { {-1, 1, 1}, {1, 1, 1}, {-1, 1, -1} }, { {-1, -1, -1}, {-1, 1, 1}, {-1, 1, -1} }, { {-1, 1, 1}, {-1, -1, -1}, {-1, -1, 1} }, { {1, -1, -1}, {1, 1, -1}, {1, 1, 1} }, { {1, 1, 1}, {1, -1, 1}, {1, -1, -1} }, { {-1, 1, -1}, {1, 1, -1}, {-1, -1, -1} }, { {1, -1, -1}, {-1, -1, -1}, {1, 1, -1} }, { {-1, 1, 1}, {-1, -1, 1}, {1, 1, 1}, }, { {1, -1, 1}, {1, 1, 1}, {-1, -1, 1} }}; double a=0.5,b=0.5,c=0.5; for(int i=0;i<12;i++){ Vector p1(cube[i][0][0]*a, cube[i][0][1]*b, cube[i][0][2]*c); Vector p2(cube[i][1][0]*a, cube[i][1][1]*b, cube[i][1][2]*c); Vector p3(cube[i][2][0]*a, cube[i][2][1]*b, cube[i][2][2]*c); Vector n=((p2-p1)%(p3-p1)).unit(); add(new Triangle(glass, p1, p2, p3, n, n, n)); } gen(phLim); render(); tone(); for(int i=0;i<objSize;i++){ delete obj[i]; } }
/** @SYMTestCaseID SYSLIB-SQL-CT-1628 @SYMTestCaseDesc GetFirstSqlStmt() test Tests the GetFirstSqlStmt() behaviour with a set of various SQL statements. @SYMTestPriority High @SYMTestActions GetFirstSqlStmt() test @SYMTestExpectedResults Test must not fail @SYMREQ REQ5792 REQ5793 */ void TestGetFirstSqlStmt() { TPtrC res; TBuf<1> b2; b2.Append(TChar(0)); TPtr p2(PTR_ARG(b2)); res.Set(GetFirstSqlStmt(p2)); //Expected result: res = "\x0", p2 is NULL TEST(res == b2); TEST(!p2.Ptr()); TBuf<2> b3; b3.Append(TChar(' ')); b3.Append(TChar(0)); TPtr p3(PTR_ARG(b3)); res.Set(GetFirstSqlStmt(p3)); //Expected result: res = " \x0", p3 is NULL TEST(res == b3); TEST(!p3.Ptr()); TBuf<7> b4(_L(";; ; ")); b4.Append(TChar(0)); TPtr p4(PTR_ARG(b4)); res.Set(GetFirstSqlStmt(p4)); //Expected result: res = "\x0", p4 = "; ; \x0" TEST(res.Length() == 1 && (TInt)res[0] == 0); TInt accLen = res.Length(); TEST(p4 == b4.Right(b4.Length() - accLen)); res.Set(GetFirstSqlStmt(p4)); //Expected result: res = "\x0", p4 = " ; \x0" TEST(res.Length() == 1 && (TInt)res[0] == 0); accLen += res.Length(); TEST(p4 == b4.Right(b4.Length() - accLen)); res.Set(GetFirstSqlStmt(p4)); //Expected result: res = " \x0", p4 = " \x0" TEST((TInt)res[0] == (TInt)TChar(' ') && (TInt)res[1] == 0); accLen += res.Length(); TEST(p4 == b4.Right(b4.Length() - accLen)); res.Set(GetFirstSqlStmt(p4)); //Expected result: res = " \x0", p4 is NULL TEST((TInt)res[0] == (TInt)TChar(' ') && (TInt)res[1] == (TInt)TChar(' ') && (TInt)res[2] == 0); TEST(!p4.Ptr()); TBuf<20> b5(_L("SELECT * FROM A")); b5.Append(TChar(0)); TPtr p5(PTR_ARG(b5)); res.Set(GetFirstSqlStmt(p5)); //Expected result: res = "SELECT * FROM A\x0", p5 is NULL TEST(res == b5); TEST(!p5.Ptr()); TBuf<20> b6(_L("SELECT * FROM A;")); b6.Append(TChar(0)); TPtr p6(PTR_ARG(b6)); res.Set(GetFirstSqlStmt(p6)); //Expected result: res = "SELECT * FROM A\x0", p6 = "\x0" TEST(res == b6.Left(b6.Length() - 1)); TEST(p6.Length() == 1 && p6[0] == 0); TBuf<40> b7(_L("/** Comment */ SELECT * FROM A;")); b7.Append(TChar(0)); TPtr p7(PTR_ARG(b7)); res.Set(GetFirstSqlStmt(p7)); //Expected result: res = "/** Comment */ SELECT * FROM A\x0", p7 = "\x0" TEST(res == b7.Left(b7.Length() - 1)); TEST(p7.Length() == 1 && p7[0] == 0); TBuf<40> b8(_L(" SELECT * FROM --Comment \r\n A;")); b8.Append(TChar(0)); TPtr p8(PTR_ARG(b8)); res.Set(GetFirstSqlStmt(p8)); //Expected result: res = " SELECT * FROM --Comment \r\n A\x0", p8 = "\x0" TEST(res == b8.Left(b8.Length() - 1)); TEST(p8.Length() == 1 && p8[0] == 0); TBuf<40> b9(_L("SELECT * FROM A; SELECT * FROM B")); b9.Append(TChar(0)); TPtr p9(PTR_ARG(b9)); res.Set(GetFirstSqlStmt(p9)); //Expected result: res = "SELECT * FROM A\x0", p9 = " SELECT * FROM B\x0" TEST(res.Left(res.Length() - 1) == b9.Left(res.Length() - 1) && (TInt)res[res.Length() - 1] == 0); accLen = res.Length(); TEST(p9 == b9.Right(b9.Length() - accLen)); res.Set(GetFirstSqlStmt(p9)); //Expected result: res = " SELECT * FROM B\x0", p9 is NULL TEST(res == b9.Right(b9.Length() - accLen)); TEST(!p9.Ptr()); //Defect INC113060 TBuf<255> b10(_L("UPDATE Playlist SET Name=';',Time='2007-09-20 12:31:33' WHERE UniqueId=640397473")); TPtr p10(PTR_ARG(b10)); res.Set(GetFirstSqlStmt(p10)); //Expected results: res= original string TEST(res.Compare(b10)==0); TEST(!p10.Ptr()); TBuf<255> firstStmt(_L("SELECT * FROM PlayList"));firstStmt.Append(TChar(0)); TBuf<255> b11(_L("SELECT * FROM PlayList;UPDATE Playlist SET Name=';',Time='2007-09-20 12:31:33' WHERE UniqueId=640397473")); TPtr p11(PTR_ARG(b11)); res.Set(GetFirstSqlStmt(p11)); TEST(res.Compare(firstStmt)==0); TEST(p11.Compare(b10)==0); }
void BigDecimal::fromString(const char *szNumber) { int scale = 0, state = 0, expSign=1; size_t len = strlen(szNumber), pos = 0; int exp=0; std::string s; s.resize(len + 2); for (size_t i = 0; i < len; i++) { char c = szNumber[i]; if (state==0 && c == '-') { state = 1; s[pos] = c; pos++; continue; } if (state == 0 && c >= 48 && c <= 57) { s[pos] = c; pos++; state = 2; continue; } if (state <= 2 && c =='.') { state = 10; continue; } // First digit if (state == 1 && (c < 48 || c > 57)) { throw std::logic_error(szFormatError); } if (state == 1 && c >= 48 && c <= 57) { s[pos] = c; pos++; state = 2; continue; } // Integral part if (state == 2) { if (c >= 48 && c <= 57) { s[pos] = c; pos++; continue; } if (c == 'e' || c == 'E') { state = 3; continue; } if (c == 'e' || c == 'E') { state = 3; exp = 0; continue; } throw std::logic_error(szFormatError); } // Exponent sign if (state == 3) { if (c == '-') { expSign = -1; state = 4; continue; } if (c == '+') { expSign = 1; state = 4; continue; } if (c >= 48 && c <= 57) { exp = exp * 10 + c - 48; state = 4; continue; } throw std::logic_error(szFormatError); } // Exponent sign if (state == 4) { if (c >= 48 && c <= 57) { if (exp >= 100000000) throw std::logic_error(szFormatError); exp = exp * 10 + c - 48; state = 4; continue; } } // Fracture part if (state == 10 && c >= 48 && c <= 57) { scale += 1; s[pos] = c; pos++; continue; } break; } scale_ = scale <= 0 ? 0 : scale; m_.FromString(s.c_str(), 10); if (exp!=0) { if (expSign<0) scale_ = exp; else { vlong p10(10); p10.Pow(10, exp); vlong m(m_); m_.Mul(m_, p10); } } }
void Polyhedron_triangulation::extract_CAT() { std::for_each(cat_cells.begin(), cat_cells.end(), std::mem_fun_ref(&std::list<CAT_facet>::clear)); int *tetra_vtx_ptr = tetra_mesh.tetrahedronlist; int *marker = tetra_mesh.pointmarkerlist; REAL *pnt_tbl = tetra_mesh.pointlist; std::function<Point_3(int)> cgal_pnt = [=](int idx) { return Point_3(pnt_tbl[idx*3], pnt_tbl[idx*3+1], pnt_tbl[idx*3+2]); }; for (int i = 0; i < tetra_mesh.numberoftetrahedra; i++, tetra_vtx_ptr += 4) { std::set<int> group_no; std::multimap<int, int> group_no_vidx; typedef std::multimap<int, int>::const_iterator Iter; for (int j = 0; j < 4; j++) { int vid = tetra_vtx_ptr[j]; int gid = marker[vid]; group_no.insert(gid); group_no_vidx.insert(std::make_pair(gid, vid)); } if (group_no.size() == 2) { std::set<int>::const_iterator gid0 = group_no.begin(), gid1 = group_no.begin(); ++gid1; if (group_no_vidx.count(*gid0) == 1 && group_no_vidx.count(*gid1) == 3) { std::pair<Iter, Iter> i0 = group_no_vidx.equal_range(*gid0); std::pair<Iter, Iter> i1 = group_no_vidx.equal_range(*gid1); std::list<Point_3> mid_tri; for (Iter it = i1.first; it != i1.second; ++it) mid_tri.push_back(CGAL::midpoint(cgal_pnt(i0.first->second), cgal_pnt(it->second))); if (*gid0 >= 0) cat_cells[*gid0].push_back(CAT_facet(cgal_pnt(i0.first->second), mid_tri)); if (*gid1 >= 0) for (Iter it = i1.first; it != i1.second; ++it) cat_cells[*gid1].push_back(CAT_facet(cgal_pnt(it->second), mid_tri)); } else if (group_no_vidx.count(*gid0) == 3 && group_no_vidx.count(*gid1) == 1) { std::pair<Iter, Iter> i0 = group_no_vidx.equal_range(*gid0); std::pair<Iter, Iter> i1 = group_no_vidx.equal_range(*gid1); std::list<Point_3> mid_tri; for (Iter it = i0.first; it != i0.second; ++it) mid_tri.push_back(CGAL::midpoint(cgal_pnt(i1.first->second), cgal_pnt(it->second))); if (*gid1 >= 0) cat_cells[*gid1].push_back(CAT_facet(cgal_pnt(i1.first->second), mid_tri)); if (*gid0 >= 0) for (Iter it = i0.first; it != i0.second; ++it) cat_cells[*gid0].push_back(CAT_facet(cgal_pnt(it->second), mid_tri)); } else { std::pair<Iter, Iter> i0 = group_no_vidx.equal_range(*gid0); std::pair<Iter, Iter> i1 = group_no_vidx.equal_range(*gid1); Iter it = i0.first; Point_3 p00(cgal_pnt(it->second)); ++it; Point_3 p01(cgal_pnt(it->second)); it = i1.first; Point_3 p10(cgal_pnt(it->second)); ++it; Point_3 p11(cgal_pnt(it->second)); Point_3 midpnt[4] = {CGAL::midpoint(p00, p10), CGAL::midpoint(p00, p11), CGAL::midpoint(p01, p10), CGAL::midpoint(p01, p11)}; std::list<Point_3> mid_pm; // the middle parallelogram mid_pm.push_back(midpnt[0]); mid_pm.push_back(midpnt[1]); if (Vector_3(midpnt[0], midpnt[1])*Vector_3(midpnt[2], midpnt[3]) < 0) { mid_pm.push_back(midpnt[2]); mid_pm.push_back(midpnt[3]); } else { mid_pm.push_back(midpnt[3]); mid_pm.push_back(midpnt[2]); } if (*gid0 >= 0) { cat_cells[*gid0].push_back(CAT_facet(p00, mid_pm)); cat_cells[*gid0].push_back(CAT_facet(p01, mid_pm)); } if (*gid1 >= 0) { cat_cells[*gid1].push_back(CAT_facet(p10, mid_pm)); cat_cells[*gid1].push_back(CAT_facet(p11, mid_pm)); } } } else if (group_no.size() == 3) { // the two vertices in the same group int smgp[2]; // the two vertices in the other two different groups int dfgp[2]; int gi, gj, gk; std::vector< std::pair<int, int> > tmpv(group_no_vidx.begin(), group_no_vidx.end()); if (tmpv[0].first == tmpv[1].first) { smgp[0] = tmpv[0].second; smgp[1] = tmpv[1].second; gi = tmpv[0].first; dfgp[0] = tmpv[2].second; dfgp[1] = tmpv[3].second; gj = tmpv[2].first; gk = tmpv[3].first; } else if (tmpv[1].first == tmpv[2].first) { smgp[0] = tmpv[1].second; smgp[1] = tmpv[2].second; gi = tmpv[1].first; dfgp[0] = tmpv[0].second; dfgp[1] = tmpv[3].second; gj = tmpv[0].first; gk = tmpv[3].first; } else { smgp[0] = tmpv[2].second; smgp[1] = tmpv[3].second; gi = tmpv[2].first; dfgp[0] = tmpv[0].second; dfgp[1] = tmpv[1].second; gj = tmpv[0].first; gk = tmpv[1].first; } Point_3 pi[2] = {cgal_pnt(smgp[0]), cgal_pnt(smgp[1])}; Point_3 pj(cgal_pnt(dfgp[0])), pk(cgal_pnt(dfgp[1])); Point_3 tri_cent[2] = {CGAL::centroid(pi[0], pj, pk), CGAL::centroid(pi[1], pj, pk)}; Point_3 edge_mid[5] = {CGAL::midpoint(pi[0], pj), CGAL::midpoint(pi[0], pk), CGAL::midpoint(pi[1], pj), CGAL::midpoint(pi[1], pk), CGAL::midpoint(pj, pk)}; //std::list<Point_3> quad_i0i1j, quad_i0i1k, tri_i0i1jk; std::array<Point_3, 4> quad_i0i1j = {edge_mid[0], edge_mid[2], tri_cent[1], tri_cent[0]}; std::array<Point_3, 4> quad_i0i1k = {edge_mid[1], edge_mid[3], tri_cent[1], tri_cent[0]}; std::array<Point_3, 3> tri_i0i1jk = {edge_mid[4], tri_cent[1], tri_cent[0]}; if (gi >= 0) { cat_cells[gi].push_back(CAT_facet(pi[0], quad_i0i1j.begin(), quad_i0i1j.end())); cat_cells[gi].push_back(CAT_facet(pi[0], quad_i0i1k.begin(), quad_i0i1k.end())); cat_cells[gi].push_back(CAT_facet(pi[1], quad_i0i1j.begin(), quad_i0i1j.end())); cat_cells[gi].push_back(CAT_facet(pi[1], quad_i0i1k.begin(), quad_i0i1k.end())); } if (gj >= 0) { cat_cells[gj].push_back(CAT_facet(pj, quad_i0i1j.begin(), quad_i0i1j.end())); cat_cells[gj].push_back(CAT_facet(pj, tri_i0i1jk.begin(), tri_i0i1jk.end())); } if (gk >= 0) { cat_cells[gk].push_back(CAT_facet(pk, quad_i0i1k.begin(), quad_i0i1k.end())); cat_cells[gk].push_back(CAT_facet(pk, tri_i0i1jk.begin(), tri_i0i1jk.end())); } } else if (group_no.size() == 4) { std::array<Point_3, 4> vs; std::array<int, 4> groupid; for (int j = 0; j < 4; j++) { vs[j] = cgal_pnt(tetra_vtx_ptr[j]); groupid[j] = marker[tetra_vtx_ptr[j]]; } Point_3 tetra_cent = CGAL::centroid(vs.begin(), vs.end(), CGAL::Dimension_tag<0>()); for (int j = 0; j < 4; j++) { if (groupid[j] < 0) continue; for (int k = 0; k < 4; k++) { if (j == k) continue; for (int l = 0; l < 4; l++) { if (l == j || l == k) continue; Point_3 mpnt = CGAL::midpoint(vs[j], vs[k]); int m; for (m = 0; m < 4; m++) if (m != j && m != k && m != l) break; Point_3 tri_cent[2] = { CGAL::centroid(vs[j], vs[k], vs[l]), CGAL::centroid(vs[j], vs[k], vs[m]) }; std::list<Point_3> tri; tri.push_back(mpnt); tri.push_back(tri_cent[0]); tri.push_back(tri_cent[1]); cat_cells[groupid[j]].push_back(CAT_facet(vs[j], tri)); tri.pop_front(); tri.push_back(tetra_cent); cat_cells[groupid[j]].push_back(CAT_facet(vs[j], tri)); } } } } } }
MEM_plotdata * PLOT_scatterellipse( int npt , float xlo,float xhi , float ylo,float yhi , float * x , float * y , float * xsig , float * ysig , float * corr , float pell , char * xlab , char * ylab , char * tlab ) { int ii,jj , np , nnax,mmax , nnay,mmay ; float xbot,xtop , ybot,ytop , pbot,ptop , xobot,xotop,yobot,yotop , xa,xb,ya,yb , dx,dy,dt ; char str[32] ; MEM_plotdata * mp ; float xu,yu , xd,yd ; if( npt < 2 || x == NULL || y == NULL ) return NULL ; if( xsig == NULL || ysig == NULL || corr == NULL ) return NULL ; if( pell <= 0.0 || pell >= 1.0 ) pell = 0.5 ; pell = -2.0 * log(1.0-pell) ; /* find range of data */ xbot = xtop = x[0] ; ybot = ytop = y[0] ; for( ii=0 ; ii < npt ; ii++ ){ xu = x[ii] + pell*xsig[ii] ; xd = x[ii] - pell*xsig[ii] ; if( xd < xbot ) xbot = xd ; if( xu > xtop ) xtop = xu ; yu = y[ii] + pell*ysig[ii] ; yd = y[ii] - pell*ysig[ii] ; if( yd < ybot ) ybot = yd ; if( yu > ytop ) ytop = yu ; } if( xbot >= xtop || ybot >= ytop ){ fprintf(stderr,"*** Data has no range in PLOT_scatterellipse!\n\a"); return NULL ; } if( xlo < xhi ){ xbot = xlo ; xtop = xhi ; } if( ylo < yhi ){ ybot = ylo ; ytop = yhi ; } /*-- push range of x outwards --*/ #if 0 pbot = p10(xbot) ; ptop = p10(xtop) ; if( ptop < pbot ) ptop = pbot ; if( ptop != 0.0 ){ np = (xtop-xbot) / ptop + 0.5 ; switch( np ){ case 1: ptop *= 0.1 ; break ; case 2: ptop *= 0.2 ; break ; case 3: ptop *= 0.25 ; break ; case 4: case 5: ptop *= 0.5 ; break ; } xbot = floor( xbot/ptop ) * ptop ; xtop = ceil( xtop/ptop ) * ptop ; nnax = floor( (xtop-xbot) / ptop + 0.5 ) ; mmax = (nnax < 3) ? 10 : (nnax < 6) ? 5 : 2 ; } else { nnax = 1 ; mmax = 10 ; } #else nnax = 1 ; mmax = 10 ; #endif /*-- push range of y outwards --*/ #if 0 pbot = p10(ybot) ; ptop = p10(ytop) ; if( ptop < pbot ) ptop = pbot ; if( ptop != 0.0 ){ np = (ytop-ybot) / ptop + 0.5 ; switch( np ){ case 1: ptop *= 0.1 ; break ; case 2: ptop *= 0.2 ; break ; case 3: ptop *= 0.25 ; break ; case 4: case 5: ptop *= 0.5 ; break ; } ybot = floor( ybot/ptop ) * ptop ; ytop = ceil( ytop/ptop ) * ptop ; nnay = floor( (ytop-ybot) / ptop + 0.5 ) ; mmay = (nnay < 3) ? 10 : (nnay < 6) ? 5 : 2 ; } else { nnay = 1 ; mmay = 10 ; } #else nnay = 1 ; mmay = 10 ; #endif /*-- setup to plot --*/ create_memplot_surely( "SellPlot" , 1.3 ) ; set_color_memplot( 0.0 , 0.0 , 0.0 ) ; set_thick_memplot( 0.0 ) ; /*-- plot labels, if any --*/ xobot = 0.15 ; xotop = 1.27 ; /* set objective size of plot */ yobot = 0.1 ; yotop = 0.95 ; if( STGOOD(tlab) ){ yotop -= 0.02 ; yobot -= 0.01 ; } /* x-axis label? */ if( STGOOD(xlab) ) plotpak_pwritf( 0.5*(xobot+xotop) , yobot-0.06 , xlab , 16 , 0 , 0 ) ; /* y-axis label? */ if( STGOOD(ylab) ) plotpak_pwritf( xobot-0.12 , 0.5*(yobot+yotop) , ylab , 16 , 90 , 0 ) ; /* label at top? */ if( STGOOD(tlab) ) plotpak_pwritf( xobot+0.01 , yotop+0.01 , tlab , 18 , 0 , -2 ) ; /* plot axes */ plotpak_set( xobot,xotop , yobot,yotop , xbot,xtop , ybot,ytop , 1 ) ; plotpak_periml( nnax,mmax , nnay,mmay ) ; /* plot data */ #define NELL 64 /* should be divisible by 4 */ #define DTH (2.0*PI/NELL) for( ii=0 ; ii < npt ; ii++ ){ dx = pell * xsig[ii] ; dy = pell * ysig[ii] ; dt = asin(corr[ii]) ; xb = x[ii] + dx ; yb = y[ii] + dy*sin(dt) ; for( jj=1 ; jj <= NELL ; jj++ ){ xa = xb ; ya = yb ; xb = x[ii] + dx*cos(jj*DTH) ; yb = y[ii] + dy*sin(jj*DTH+dt) ; plotpak_line( xa,ya , xb,yb ) ; } } set_color_memplot( 1.0 , 0.0 , 0.0 ) ; for( ii=0 ; ii < npt-1 ; ii++ ) plotpak_line( x[ii],y[ii] , x[ii+1],y[ii+1] ) ; #define DSQ 0.005 dx = DSQ*(xtop-xbot) ; dy = DSQ*(ytop-ybot) * (xotop-xobot)/(yotop-yobot) ; set_color_memplot( 0.0 , 0.0 , 1.0 ) ; for( ii=0 ; ii < npt ; ii++ ){ xa = x[ii] - dx ; xb = x[ii] + dx ; ya = y[ii] - dy ; yb = y[ii] + dy ; plotpak_line( xa,ya , xa,yb ) ; plotpak_line( xa,yb , xb,yb ) ; plotpak_line( xb,yb , xb,ya ) ; plotpak_line( xb,ya , xa,ya ) ; } set_color_memplot( 0.0 , 0.0 , 0.0 ) ; mp = get_active_memplot() ; return mp ; }
void CContainers::prepareMemBuffers() { memout=new CMemoryBuffer(); std::pair<std::string,CMemoryBuffer*> p("!data",memout); memmap.insert(p); memout_words=new CMemoryBuffer(); std::pair<std::string,CMemoryBuffer*> p2("!!!words",memout_words); memmap.insert(p2); memout_letters=new CMemoryBuffer(); std::pair<std::string,CMemoryBuffer*> p3("!!letters",memout_letters); memmap.insert(p3); memout_num=new CMemoryBuffer(); std::pair<std::string,CMemoryBuffer*> p4("!num",memout_num); memmap.insert(p4); memout_year=new CMemoryBuffer(); std::pair<std::string,CMemoryBuffer*> p5("!year",memout_year); memmap.insert(p5); memout_date=new CMemoryBuffer(); std::pair<std::string,CMemoryBuffer*> p6("!date",memout_date); memmap.insert(p6); memout_words2=new CMemoryBuffer(); std::pair<std::string,CMemoryBuffer*> p7("!!!words2",memout_words2); memmap.insert(p7); memout_words3=new CMemoryBuffer(); std::pair<std::string,CMemoryBuffer*> p8("!!!words3",memout_words3); memmap.insert(p8); memout_words4=new CMemoryBuffer(); std::pair<std::string,CMemoryBuffer*> p9("!!!words4",memout_words4); memmap.insert(p9); memout_pages=new CMemoryBuffer(); std::pair<std::string,CMemoryBuffer*> p10("!pages",memout_pages); memmap.insert(p10); memout_num2=new CMemoryBuffer(); std::pair<std::string,CMemoryBuffer*> p11("!num2",memout_num2); memmap.insert(p11); memout_num3=new CMemoryBuffer(); std::pair<std::string,CMemoryBuffer*> p12("!num3",memout_num3); memmap.insert(p12); memout_num4=new CMemoryBuffer(); std::pair<std::string,CMemoryBuffer*> p13("!num4",memout_num4); memmap.insert(p13); memout_remain=new CMemoryBuffer(); std::pair<std::string,CMemoryBuffer*> p14("!remain",memout_remain); memmap.insert(p14); memout_date2=new CMemoryBuffer(); std::pair<std::string,CMemoryBuffer*> p15("!date2",memout_date2); memmap.insert(p15); memout_date3=new CMemoryBuffer(); std::pair<std::string,CMemoryBuffer*> p16("!date3",memout_date3); memmap.insert(p16); memout_num2b=new CMemoryBuffer(); std::pair<std::string,CMemoryBuffer*> p17("!num2b",memout_num2b); memmap.insert(p17); memout_num3b=new CMemoryBuffer(); std::pair<std::string,CMemoryBuffer*> p18("!num3b",memout_num3b); memmap.insert(p18); memout_num4b=new CMemoryBuffer(); std::pair<std::string,CMemoryBuffer*> p19("!num4b",memout_num4b); memmap.insert(p19); memout_numb=new CMemoryBuffer(); std::pair<std::string,CMemoryBuffer*> p20("!numb",memout_numb); memmap.insert(p20); memout_num2c=new CMemoryBuffer(); std::pair<std::string,CMemoryBuffer*> p21("!num2c",memout_num2c); memmap.insert(p21); memout_num3c=new CMemoryBuffer(); std::pair<std::string,CMemoryBuffer*> p22("!num3c",memout_num3c); memmap.insert(p22); memout_num4c=new CMemoryBuffer(); std::pair<std::string,CMemoryBuffer*> p23("!num4c",memout_num4c); memmap.insert(p23); memout_numc=new CMemoryBuffer(); std::pair<std::string,CMemoryBuffer*> p24("!numc",memout_numc); memmap.insert(p24); memout_time=new CMemoryBuffer(); std::pair<std::string,CMemoryBuffer*> p25("!time",memout_time); memmap.insert(p25); memout_remain2=new CMemoryBuffer(); std::pair<std::string,CMemoryBuffer*> p26("!remain2",memout_remain2); memmap.insert(p26); memout_ip=new CMemoryBuffer(); std::pair<std::string,CMemoryBuffer*> p27("!ip",memout_ip); memmap.insert(p27); memout_hm=new CMemoryBuffer(); std::pair<std::string,CMemoryBuffer*> p28("!hm",memout_hm); memmap.insert(p28); memout_hms=new CMemoryBuffer(); std::pair<std::string,CMemoryBuffer*> p29("!hms",memout_hms); memmap.insert(p29); }
void test_RT() { typedef RT Cls; // _test_cls_regular_3( Cls() ); typedef traits::Bare_point Point; typedef traits::Weighted_point Weighted_point; typedef typename Cls::Vertex_handle Vertex_handle; typedef typename Cls::Cell_handle Cell_handle; typedef typename Cls::Facet Facet; typedef typename Cls::Edge Edge; typedef std::list<Weighted_point> list_point; typedef typename Cls::Finite_cells_iterator Finite_cells_iterator; // temporary version int n, m; int count = 0; // For dimension 0, we need to check that the point of highest weight is the // one that finally ends up in the vertex. std::cout << " test dimension 0 " << std::endl; Cls T0; T0.insert(Weighted_point( Point (0,0,0), 0) ); T0.insert(Weighted_point( Point (0,0,0), 1) ); T0.insert(Weighted_point( Point (0,0,0), -1) ); assert(T0.dimension() == 0); assert(T0.number_of_vertices() == 1); assert(T0.finite_vertices_begin()->point().weight() == 1); std::cout << " test dimension 1 " << std::endl; Cls T1; std::cout << " number of inserted points : " ; Weighted_point p[5]; for ( m=0; m<5; m++) { if ( (m%2)== 0 ) p[m] = Weighted_point( Point( 2*m,0,0 ), 2 ); else p[m] = Weighted_point( Point( -2*m+1,0,0 ), 2 ); T1.insert( p[m] ); count++; if (count <10) std::cout << count << '\b' ; else if (count < 100) std::cout << count << '\b' << '\b' ; else std::cout << count << '\b' << '\b' << '\b' ; std::cout.flush(); } assert( T1.is_valid() ); std::cout << std::endl << " number of vertices : " << T1.number_of_vertices() << std::endl; std::cout << " number of inserted points : " ; Weighted_point q[5]; for ( m=0; m<5; m++) { if ( (m%2)== 0 ) q[m] = Weighted_point( Point( 2*m+1,0,0 ), 5 ); else q[m] = Weighted_point( Point( -2*m+1,0,0 ), 5 ); T1.insert( q[m] ); count++; if (count <10) std::cout << count << '\b' ; else if (count < 100) std::cout << count << '\b' << '\b' ; else std::cout << count << '\b' << '\b' << '\b' ; std::cout.flush(); } assert( T1.is_valid() ); std::cout << std::endl << " number of vertices : " << T1.number_of_vertices() << std::endl; std::cout << " number of inserted points : " ; Weighted_point r[10]; for ( m=0; m<10; m++) { if ( (m%2)== 0 ) r[m] = Weighted_point( Point( m,0,0 ), 1 ); else r[m] = Weighted_point( Point( -m,0,0 ), 1 ); T1.insert( r[m] ); count++; if (count <10) std::cout << count << '\b' ; else if (count < 100) std::cout << count << '\b' << '\b' ; else std::cout << count << '\b' << '\b' << '\b' ; std::cout.flush(); } assert( T1.is_valid() ); std::cout << std::endl << " number of vertices : " << T1.number_of_vertices() << std::endl; assert( T1.dimension()==1 ); // The following is distilled from a bug report by Wulue Zhao // ([email protected]), a student of Tamal Dey. Point pt0(0,0,0); Point pt1( 1,0,0), pt2(2,0,0), pt3(3,0,0); Point pt4(-1,0,0), pt5(-2,0,0), pt6(-3,0,0); Weighted_point wp0(pt0,10.0); Weighted_point wp1(pt1,0.0), wp2(pt2,0.0), wp3(pt3,0.0); Weighted_point wp4(pt4,0.0), wp5(pt5,0.0), wp6(pt6,0.0); Cls T11; T11.insert(wp0); T11.insert(wp1); T11.insert(wp2); T11.insert(wp3); T11.insert(wp4); T11.insert(wp5); T11.insert(wp6); assert(T11.is_valid()); // And another distilled bug report from the same guy. { Point p1(-0.07, 0.04, 0.04); Point p2(0.09, 0.04, 0.04); Point p3(0.09, -0.05, 0.04); Point p4(0.05, -0.05, 0.04); Point p5(0.05, 0.0, 0.04); Point p6(-0.07, 0.0, 0.04); Point p7(-0.07, 0.04, -0.04); Point p8(0.09, 0.04, -0.04); Point p9(0.09, -0.05, -0.04); Point p10(0.05, -0.05, -0.04); Point p11(0.05, 0.0, -0.04); Point p12(-0.07, 0.0, -0.04); Weighted_point wp1(p1,0); Weighted_point wp2(p2,0); Weighted_point wp3(p3,0); Weighted_point wp4(p4,0); Weighted_point wp5(p5,0); Weighted_point wp6(p6,0); Weighted_point wp7(p7,0); Weighted_point wp8(p8,0); Weighted_point wp9(p9,0); Weighted_point wp10(p10,0); Weighted_point wp11(p11,0); Weighted_point wp12(p12,0); Weighted_point wp13(p3,0.3); // wp13 has the same coordinates with wp3 Cls T111; T111.insert(wp1); T111.insert(wp2); T111.insert(wp3); T111.insert(wp13); // it doesnot work inserting wp13 here T111.insert(wp4); T111.insert(wp5); T111.insert(wp6); T111.insert(wp7); T111.insert(wp8); T111.insert(wp9); T111.insert(wp10); T111.insert(wp11); T111.insert(wp12); assert(T111.is_valid()); } std::cout << " test dimension 2 " << std::endl; std::cout << " number of inserted points : " ; Cls T2; count = 0 ; int px=1, py=1; int qx=-1, qy=2; Weighted_point s[400]; for (m=0; m<10; m++) for (n=0; n<10; n++) { s[m+20*n] = Weighted_point( Point(m*px+n*qx, m*py+n*qy, 0), 1 ); T2.insert( s[m+20*n] ); count++; if (count <10) std::cout << count << '\b' ; else if (count < 100) std::cout << count << '\b' << '\b' ; else std::cout << count << '\b' << '\b' << '\b' ; std::cout.flush(); } for (m=10; m<20; m++) for (n=0; n<10; n++) { s[m+20*n] = Weighted_point( Point(m*px+n*qx, m*py+n*qy, 0), -1 ); T2.insert( s[m+20*n] ); count++; if (count <10) std::cout << count << '\b' ; else if (count < 100) std::cout << count << '\b' << '\b' ; else std::cout << count << '\b' << '\b' << '\b' ; std::cout.flush(); } for (m=0; m<10; m++) for (n=10; n<20; n++) { s[m+20*n] = Weighted_point( Point(m*px+n*qx, m*py+n*qy, 0), -2 ); T2.insert( s[m+20*n] ); count++; if (count <10) std::cout << count << '\b' ; else if (count < 100) std::cout << count << '\b' << '\b' ; else std::cout << count << '\b' << '\b' << '\b' ; std::cout.flush(); } for (m=10; m<20; m++) for (n=10; n<20; n++) { s[m+20*n] = Weighted_point( Point(m*px+n*qx, m*py+n*qy, 0), 5 ); T2.insert( s[m+20*n] ); count++; if (count <10) std::cout << count << '\b' ; else if (count < 100) std::cout << count << '\b' << '\b' ; else std::cout << count << '\b' << '\b' << '\b' ; std::cout.flush(); } std::cout << std::endl << " number of vertices : " << T2.number_of_vertices() << std::endl; assert( T2.dimension()==2 ); assert( T2.is_valid() ); // dimension 3 std::cout << " test dimension 3" << std::endl; Cls T; list_point lp; int a, b, d; for (a=0;a!=10;a++) // for (b=0;b!=10;b++) for (b=0;b!=5;b++) // for (d=0;d!=10;d++) for (d=0;d!=5;d++) lp.push_back(Weighted_point( Point(a*b-d*a + (a-b)*10 +a , a-b+d +5*b, a*a-d*d+b), a*b-a*d) ); list_point::iterator it; count = 0 ; std::cout << " number of inserted points : " ; for (it=lp.begin(); it!=lp.end(); ++it){ count++; T.insert(*it); if (count <10) std::cout << count << '\b' ; else if (count < 100) std::cout << count << '\b' << '\b' ; else if (count < 1000) std::cout << count << '\b' << '\b' << '\b' ; else std::cout << count << std::endl; std::cout.flush(); } std::cout << std::endl; std::cout << " number of vertices : " << T.number_of_vertices() << std::endl; assert(T.is_valid()); assert(T.dimension()==3); T.clear(); std::cout << " test iterator range insert" << std::endl; T.insert (lp.begin(), lp.end()); std::cout << " number of vertices : " << T.number_of_vertices() << std::endl; assert(T.is_valid()); assert(T.dimension()==3); //test nearest_power_vertex std::cout << " test nearest_power_vertex " << std::endl; Point pp1(0.0, 0.0, 0.0); Point pp2(1.0, 0.0, 0.0); Point pp3(0.0, 1.0, 0.0); Point pp4(0.0, 0.0, 1.0); Point pp5(1.0, 1.0, 0.0); Point pp6(0.0, 1.0, 1.0); Point pp7(1.0, 0.0, 1.0); Point pp8(1.0, 1.0, 1.0); Weighted_point wpp1(pp1, 1.0); Weighted_point wpp2(pp2, 2.0); Weighted_point wpp3(pp3, 1.0); Weighted_point wpp4(pp4, 4.0); Weighted_point wpp5(pp5, 1.0); Weighted_point wpp6(pp6, 1.0); Weighted_point wpp7(pp7, 1.0); Weighted_point wpp8(pp8, 8.0); Cls T3; T3.insert(wpp1); Vertex_handle v2 = T3.insert(wpp2); assert( T3.nearest_power_vertex(Point(0.5,0.5,0.5)) == v2); T3.insert(wpp3); Vertex_handle v4 = T3.insert(wpp4); assert( T3.nearest_power_vertex(Point(0.5,0.5,0.5)) == v4); T3.insert(wpp5); T3.insert(wpp6); T3.insert(wpp7); // Avoid inserting the same point twice, now that hidden points are handled, // insert (existing_point) returns Vertex_handle(). // T3.insert(wpp8); Vertex_handle v8 = T3.insert(wpp8); Point query(0.5,0.5,0.5); assert(T3.nearest_power_vertex(query) == v8); assert(T3.nearest_power_vertex(Weighted_point(query,1.0)) == v8 ); assert(T3.nearest_power_vertex_in_cell(query ,v8->cell()) == v8); // test dual std::cout << " test dual member functions" << std::endl; Finite_cells_iterator fcit = T3.finite_cells_begin(); for( ; fcit != T3.finite_cells_end(); ++fcit) { Point cc = T3.dual(fcit); Vertex_handle ncc = T3.nearest_power_vertex(cc); assert(fcit->has_vertex(ncc)); } // test Gabriel std::cout << " test is_Gabriel " << std::endl; Point q0(0.,0.,0.); Point q1(2.,0.,0.); Point q2(0.,2.,0.); Point q3(0.,0.,2.); Weighted_point wq0(q0,0.); Weighted_point wq1(q1,0.); Weighted_point wq2(q2,0.); Weighted_point wq3(q3,0.); Weighted_point wq01(q0,2.); Cls T4; Vertex_handle v0 = T4.insert(wq0); Vertex_handle v1 = T4.insert(wq1); v2 = T4.insert(wq2); Vertex_handle v3 = T4.insert(wq3); Cell_handle c; int i,j,k,l; assert(T4.is_facet(v0,v1,v2,c,j,k,l)); i = 6 - (j+k+l); Facet f = std::make_pair(c,i); assert(T4.is_Gabriel(c,i)); assert(T4.is_Gabriel(f)); assert(T4.is_facet(v1,v2,v3,c,j,k,l)); i = 6 - (j+k+l); assert(!T4.is_Gabriel(c,i)); assert(T4.is_edge(v0,v1,c,i,j)); assert(T4.is_Gabriel(c,i,j)); Edge e = make_triple(c,i,j); assert(T4.is_Gabriel(e)); assert(T4.is_edge(v2,v3,c,i,j)); assert(T4.is_Gabriel(c,i,j)); Vertex_handle v01 = T4.insert(wq01); (void) v01; // kill warning assert(T4.is_edge(v2,v3,c,i,j)); assert(!T4.is_Gabriel(c,i,j)); Weighted_point wwq0(q0,0.); Weighted_point wwq1(q1,0.); Weighted_point wwq2(q2,0.); Weighted_point wwq3(q3,5.); Cls T5; v0 = T5.insert(wwq0); v1 = T5.insert(wwq1); v2 = T5.insert(wwq2); v3 = T5.insert(wwq3); assert(T5.nearest_power_vertex(v3->point().point()) == v3); assert(T5.nearest_power_vertex(v0->point().point()) == v3); assert(T5.is_Gabriel(v3)); assert(!T5.is_Gabriel(v0)); }
int main(int argc, char **argv) { plan_tests(66); // test constructor GeoPoint p1(Angle::Degrees(345.32), Angle::Degrees(-6.332)); ok1(p1.IsValid()); ok1(equals(p1, -6.332, 345.32)); // test normalize() p1.Normalize(); ok1(p1.IsValid()); ok1(equals(p1, -6.332, -14.68)); // test parametric() GeoPoint p2(Angle::Degrees(2), Angle::Degrees(1)); GeoPoint p3 = p1.Parametric(p2, fixed(5)); ok1(p2.IsValid()); ok1(p3.IsValid()); ok1(equals(p3, -1.332, -4.68)); // test interpolate GeoPoint p4 = p1.Interpolate(p3, fixed(0.5)); ok1(p4.IsValid()); ok1(equals(p4, -3.832, -9.68)); GeoPoint p5 = p1.Interpolate(p3, fixed(0.25)); ok1(p5.IsValid()); ok1(equals(p5, -5.082, -12.18)); // test * GeoPoint p6 = p2 * fixed(3.5); ok1(p6.IsValid()); ok1(equals(p6, 3.5, 7)); // test + p6 = p6 + p2; ok1(p6.IsValid()); ok1(equals(p6, 4.5, 9)); // test += p6 += p2; ok1(p6.IsValid()); ok1(equals(p6, 5.5, 11)); // test - p6 = p6 - p2; ok1(p6.IsValid()); ok1(equals(p6, 4.5, 9)); // test sort() ok1(!p1.Sort(p3)); ok1(p3.Sort(p1)); ok1(!p1.Sort(p4)); ok1(p4.Sort(p1)); ok1(!p1.Sort(p5)); ok1(p5.Sort(p1)); ok1(!p4.Sort(p3)); ok1(p3.Sort(p4)); ok1(!p5.Sort(p3)); ok1(p3.Sort(p5)); ok1(!p5.Sort(p4)); ok1(p4.Sort(p5)); // test distance() // // note: distance between p1 and p4 and between p3 and p4 is not // the same due to linear interpolation instead of real geographic // intermediate point calculation ok1(equals(p2.Distance(p6), 869326.653160)); ok1(equals(p6.Distance(p2), 869326.653160)); ok1(equals(p1.Distance(p5), 309562.219016)); ok1(equals(p1.Distance(p4), 619603.149273)); ok1(equals(p1.Distance(p3), 1240649.267606)); ok1(equals(p3.Distance(p4), 621053.760625)); // test bearing() // // note: the bearings p1 -> p5, p5 -> p4 and so on are not the same due to // linear interpolation instead of real geographic intermediate point // calculation ok1(equals(p2.Bearing(p6), 63.272424)); ok1(equals(p6.Bearing(p2), 243.608847)); ok1(equals(p1.Bearing(p5), 63.449343)); ok1(equals(p1.Bearing(p4), 63.582620)); ok1(equals(p1.Bearing(p3), 63.784526)); ok1(equals(p5.Bearing(p4), 63.466726)); ok1(equals(p5.Bearing(p3), 63.646072)); ok1(equals(p4.Bearing(p3), 63.540756)); ok1(equals(p5.Bearing(p6), 65.982854)); ok1(equals(p2.Bearing(p3), 250.786774)); // test distance_bearing() // note: should be the same output as bearing() and distance() GeoVector v = p2.DistanceBearing(p6); ok1(equals(v.distance, 869326.653160)); ok1(equals(v.bearing, 63.272424)); // test intermediate_point() GeoPoint p7(Angle::Zero(), Angle::Zero()); ok1(p7.IsValid()); GeoPoint p8 = p7.IntermediatePoint(p2, fixed(100000)); ok1(p8.IsValid()); ok1(equals(p8, 0.402274, 0.804342)); ok1(equals(p8.Distance(p7), 100000)); GeoPoint p9 = p7.IntermediatePoint(p2, fixed(100000000)); ok1(p9.IsValid()); ok1(equals(p9, p2)); // test projected_distance() ok1(equals(p8.ProjectedDistance(p7, p2), 100000)); ok1(equals(p4.ProjectedDistance(p1, p3), 619599.304393)); ok1(equals((p2 * fixed(2)).ProjectedDistance(p2, p6), 248567.832772)); // Tests moved here from test_fixed.cpp GeoPoint l1(Angle::Zero(), Angle::Zero()); ok1(l1.IsValid()); GeoPoint l2(Angle::Degrees(-0.3), Angle::Degrees(1.0)); ok1(l2.IsValid()); GeoPoint l3(Angle::Degrees(0.00001), Angle::Zero()); ok1(l3.IsValid()); GeoPoint l4(Angle::Degrees(10), Angle::Zero()); ok1(l4.IsValid()); l4.SetInvalid(); ok1(!l4.IsValid()); bool find_lat_lon_okay = true; for (Angle bearing = Angle::Zero(); bearing < Angle::FullCircle(); bearing += Angle::Degrees(5)) { GeoPoint p_test = FindLatitudeLongitude(p1, bearing, fixed(50000)); find_lat_lon_okay = equals(p_test.Distance(p1), 50000) && find_lat_lon_okay; } ok1(find_lat_lon_okay); v = l1.DistanceBearing(l2); printf("Dist %g bearing %d\n", FIXED_DOUBLE(v.distance), FIXED_INT(v.bearing.Degrees())); // 116090 @ 343 v = l1.DistanceBearing(l3); printf("Dist %g bearing %d\n", FIXED_DOUBLE(v.distance), FIXED_INT(v.bearing.Degrees())); ok(positive(v.distance) && v.distance < fixed(2), "earth distance short", 0); v = l1.DistanceBearing(l4); printf("Dist %g bearing %d\n", FIXED_DOUBLE(v.distance), FIXED_INT(v.bearing.Degrees())); GeoPoint p10(GeoPoint::Invalid()); ok1(!p10.IsValid()); return exit_status(); }
TEST(FloatRectTest, SquaredDistanceToTest) { // // O--x // | // y // // FloatRect.x() FloatRect.maxX() // | | // 1 | 2 | 3 // ======+==========+====== --FloatRect.y() // 4 | 5(in) | 6 // ======+==========+====== --FloatRect.maxY() // 7 | 8 | 9 // FloatRect r1(100, 100, 250, 150); // `1` case FloatPoint p1(80, 80); EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p1), 800.f); FloatPoint p2(-10, -10); EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p2), 24200.f); FloatPoint p3(80, -10); EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p3), 12500.f); // `2` case FloatPoint p4(110, 80); EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p4), 400.f); FloatPoint p5(150, 0); EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p5), 10000.f); FloatPoint p6(180, -10); EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p6), 12100.f); // `3` case FloatPoint p7(400, 80); EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p7), 2900.f); FloatPoint p8(360, -10); EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p8), 12200.f); // `4` case FloatPoint p9(80, 110); EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p9), 400.f); FloatPoint p10(-10, 180); EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p10), 12100.f); // `5`(& In) case FloatPoint p11(100, 100); EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p11), 0.f); FloatPoint p12(150, 100); EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p12), 0.f); FloatPoint p13(350, 100); EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p13), 0.f); FloatPoint p14(350, 150); EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p14), 0.f); FloatPoint p15(350, 250); EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p15), 0.f); FloatPoint p16(150, 250); EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p16), 0.f); FloatPoint p17(100, 250); EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p17), 0.f); FloatPoint p18(100, 150); EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p18), 0.f); FloatPoint p19(150, 150); EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p19), 0.f); // `6` case FloatPoint p20(380, 150); EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p20), 900.f); // `7` case FloatPoint p21(80, 280); EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p21), 1300.f); FloatPoint p22(-10, 300); EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p22), 14600.f); // `8` case FloatPoint p23(180, 300); EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p23), 2500.f); // `9` case FloatPoint p24(450, 450); EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p24), 50000.f); }
void BuildTreeDoubleYShape(Node *node[], Tree &tree) { const KDL::Vector unitx(1,0,0); const KDL::Vector unity(0,1,0); const KDL::Vector unitz(0,0,1); const KDL::Vector unit1(sqrt(14.0)/8.0, 1.0/8.0, 7.0/8.0); const KDL::Vector zero = KDL::Vector::Zero(); KDL::Vector p0(0.0f, -1.5f, 0.0f); KDL::Vector p1(0.0f, -1.0f, 0.0f); KDL::Vector p2(0.0f, -0.5f, 0.0f); KDL::Vector p3(0.5f*Root2Inv, -0.5+0.5*Root2Inv, 0.0f); KDL::Vector p4(0.5f*Root2Inv+0.5f*HalfRoot3, -0.5+0.5*Root2Inv+0.5f*0.5, 0.0f); KDL::Vector p5(0.5f*Root2Inv+1.0f*HalfRoot3, -0.5+0.5*Root2Inv+1.0f*0.5, 0.0f); KDL::Vector p6(0.5f*Root2Inv+1.5f*HalfRoot3, -0.5+0.5*Root2Inv+1.5f*0.5, 0.0f); KDL::Vector p7(0.5f*Root2Inv+0.5f*HalfRoot3, -0.5+0.5*Root2Inv+0.5f*HalfRoot3, 0.0f); KDL::Vector p8(0.5f*Root2Inv+1.0f*HalfRoot3, -0.5+0.5*Root2Inv+1.0f*HalfRoot3, 0.0f); KDL::Vector p9(0.5f*Root2Inv+1.5f*HalfRoot3, -0.5+0.5*Root2Inv+1.5f*HalfRoot3, 0.0f); KDL::Vector p10(-0.5f*Root2Inv, -0.5+0.5*Root2Inv, 0.0f); KDL::Vector p11(-0.5f*Root2Inv-0.5f*HalfRoot3, -0.5+0.5*Root2Inv+0.5f*HalfRoot3, 0.0f); KDL::Vector p12(-0.5f*Root2Inv-1.0f*HalfRoot3, -0.5+0.5*Root2Inv+1.0f*HalfRoot3, 0.0f); KDL::Vector p13(-0.5f*Root2Inv-1.5f*HalfRoot3, -0.5+0.5*Root2Inv+1.5f*HalfRoot3, 0.0f); KDL::Vector p14(-0.5f*Root2Inv-0.5f*HalfRoot3, -0.5+0.5*Root2Inv+0.5f*0.5, 0.0f); KDL::Vector p15(-0.5f*Root2Inv-1.0f*HalfRoot3, -0.5+0.5*Root2Inv+1.0f*0.5, 0.0f); KDL::Vector p16(-0.5f*Root2Inv-1.5f*HalfRoot3, -0.5+0.5*Root2Inv+1.5f*0.5, 0.0f); node[0] = new Node(p0, unit1, 0.08, JOINT, RADIAN(-180.), RADIAN(180.), RADIAN(30.)); tree.InsertRoot(node[0]); node[1] = new Node(p1, unitx, 0.08, JOINT, RADIAN(-180.), RADIAN(180.), RADIAN(30.)); tree.InsertLeftChild(node[0], node[1]); node[2] = new Node(p1, unitz, 0.08, JOINT, RADIAN(-180.), RADIAN(180.), RADIAN(30.)); tree.InsertLeftChild(node[1], node[2]); node[3] = new Node(p2, unitz, 0.08, JOINT, RADIAN(-180.), RADIAN(180.), RADIAN(30.)); tree.InsertLeftChild(node[2], node[3]); node[4] = new Node(p2, unitz, 0.08, JOINT, RADIAN(-180.), RADIAN(180.), RADIAN(30.)); tree.InsertRightSibling(node[3], node[4]); node[5] = new Node(p3, unity, 0.08, JOINT, RADIAN(-180.), RADIAN(180.), RADIAN(30.)); tree.InsertLeftChild(node[3], node[5]); node[6] = new Node(p3, unity, 0.08, JOINT, RADIAN(-180.), RADIAN(180.), RADIAN(30.)); tree.InsertRightSibling(node[5], node[6]); node[7] = new Node(p3, unitx, 0.08, JOINT, RADIAN(-180.), RADIAN(180.), RADIAN(30.)); tree.InsertLeftChild(node[5], node[7]); node[8] = new Node(p4, unitz, 0.08, JOINT, RADIAN(-180.), RADIAN(180.), RADIAN(30.)); tree.InsertLeftChild(node[7], node[8]); node[9] = new Node(p5, unitx, 0.08, JOINT, RADIAN(-180.), RADIAN(180.), RADIAN(30.)); tree.InsertLeftChild(node[8], node[9]); node[10] = new Node(p5, unity, 0.08, JOINT, RADIAN(-180.), RADIAN(180.), RADIAN(30.)); tree.InsertLeftChild(node[9], node[10]); node[11] = new Node(p6, zero, 0.08, EFFECTOR); tree.InsertLeftChild(node[10], node[11]); node[12] = new Node(p3, unitx, 0.08, JOINT, RADIAN(-180.), RADIAN(180.), RADIAN(30.)); tree.InsertLeftChild(node[6], node[12]); node[13] = new Node(p7, unitz, 0.08, JOINT, RADIAN(-180.), RADIAN(180.), RADIAN(30.)); tree.InsertLeftChild(node[12], node[13]); node[14] = new Node(p8, unitx, 0.08, JOINT, RADIAN(-180.), RADIAN(180.), RADIAN(30.)); tree.InsertLeftChild(node[13], node[14]); node[15] = new Node(p8, unity, 0.08, JOINT, RADIAN(-180.), RADIAN(180.), RADIAN(30.)); tree.InsertLeftChild(node[14], node[15]); node[16] = new Node(p9, zero, 0.08, EFFECTOR); tree.InsertLeftChild(node[15], node[16]); node[17] = new Node(p10, unity, 0.08, JOINT, RADIAN(-180.), RADIAN(180.), RADIAN(30.)); tree.InsertLeftChild(node[4], node[17]); node[18] = new Node(p10, unitx, 0.08, JOINT, RADIAN(-180.), RADIAN(180.), RADIAN(30.)); tree.InsertLeftChild(node[17], node[18]); node[19] = new Node(p10, unity, 0.08, JOINT, RADIAN(-180.), RADIAN(180.), RADIAN(30.)); tree.InsertRightSibling(node[17], node[19]); node[20] = new Node(p11, unitz, 0.08, JOINT, RADIAN(-180.), RADIAN(180.), RADIAN(30.)); tree.InsertLeftChild(node[18], node[20]); node[21] = new Node(p12, unitx, 0.08, JOINT, RADIAN(-180.), RADIAN(180.), RADIAN(30.)); tree.InsertLeftChild(node[20], node[21]); node[22] = new Node(p12, unity, 0.08, JOINT, RADIAN(-180.), RADIAN(180.), RADIAN(30.)); tree.InsertLeftChild(node[21], node[22]); node[23] = new Node(p13, zero, 0.08, EFFECTOR); tree.InsertLeftChild(node[22], node[23]); node[24] = new Node(p10, unitx, 0.08, JOINT, RADIAN(-180.), RADIAN(180.), RADIAN(30.)); tree.InsertLeftChild(node[19], node[24]); node[25] = new Node(p14, unitz, 0.08, JOINT, RADIAN(-180.), RADIAN(180.), RADIAN(30.)); tree.InsertLeftChild(node[24], node[25]); node[26] = new Node(p15, unitx, 0.08, JOINT, RADIAN(-180.), RADIAN(180.), RADIAN(30.)); tree.InsertLeftChild(node[25], node[26]); node[27] = new Node(p15, unity, 0.08, JOINT, RADIAN(-180.), RADIAN(180.), RADIAN(30.)); tree.InsertLeftChild(node[26], node[27]); node[28] = new Node(p16, zero, 0.08, EFFECTOR); tree.InsertLeftChild(node[27], node[28]); }
int main() { Point p1(-253.357, -123.36); Point p2(-190.03, 216.606); Point p3(-343.349, 286.6); Point p4(141.604, 279.934); Point p5(276.591, -46.7012); Point p6(251.593, -263.347); Point p7(-3.38184, -343.339); Point p8(-380.012, -173.355); Point p9(-98.3726, 39.957); Point p10(133.271, 124.949); Point p11(289.923, 301.598); Point p12(421.577, 23.292); Point p13(79.9434, -93.3633); Point p14(-40.0449, 366.592); Point p15(311.587, 374.924); Point p16(431.576, 214.94); Point p17(426.576, -131.693); Point p18(-265.023, -285.011); Point p19(369.915, 89.9521); Point p20(368.249, -15.0376); Point p21(484.904, 18.2925); Point p22(-411.675, 283.267); Point p23(-250.024, 124.949); Point p24(-80.041, -78.3647); Point p25(-360.014, 31.6245); Point p26(-305.019, 356.593); // built Delaunay triangulation PS.insert(p1); PS.insert(p2); PS.insert(p3); PS.insert(p4); PS.insert(p5); PS.insert(p6); PS.insert(p7); PS.insert(p8); PS.insert(p9); PS.insert(p10); PS.insert(p11); PS.insert(p12); PS.insert(p13); PS.insert(p14); PS.insert(p15); PS.insert(p16); PS.insert(p17); PS.insert(p18); PS.insert(p19); PS.insert(p20); PS.insert(p21); PS.insert(p22); PS.insert(p23); PS.insert(p24); PS.insert(p25); PS.insert(p26); std::list<Vertex_handle> LV; bool correct = true; // circle emptiness check Circle cs1(Point(-23.3799, 108.284), 1124.78); check_empty checker(cs1); CGAL::range_search(PS,cs1,std::back_inserter(LV),checker,true); if (checker.get_result()) { std::cout << "circle not empty !\n"; std::cout << "this is an error !\n"; correct=false; } else std::cout << "circle was empty !\n"; Circle cs2(Point(-255.024, -100.029), 23551); check_empty checker2(cs2); CGAL::range_search(PS,cs2,std::back_inserter(LV),checker2,true); if (checker2.get_result()) std::cout << "circle not empty !\n"; else { std::cout << "circle was empty !\n"; std::cout << "this is an error !\n"; correct=false; } // triangle check Triangle t1(Point(-21.7134, -123.36), Point(84.9429, 74.9536), Point(209.931, -161.69)); Triangle t2(Point(-61.7095, 164.945), Point(-88.3735, 101.618), Point(49.9463, 101.618)); check_empty_triangle tchecker1(t1); CGAL::range_search(PS,t1.vertex(0),t1.vertex(1),t1.vertex(2),std::back_inserter(LV),tchecker1,true); if (tchecker1.get_result()) std::cout << "triangle not empty !\n"; else { std::cout << "triangle was empty !\n"; std::cout << "this is an error !\n"; correct=false; } check_empty_triangle tchecker2(t2); CGAL::range_search(PS,t2.vertex(0),t2.vertex(1),t2.vertex(2),std::back_inserter(LV),tchecker2,true); if (tchecker2.get_result()) { std::cout << "triangle not empty !\n"; std::cout << "this is an error !\n"; correct=false; } else std::cout << "triangle was empty !\n"; // rectangle check Rectangle_2 r1(-290.021, -175.022, -125.037, -35.0356); Rectangle_2 r2(-48.3774, 136.614, -23.3799, 251.603); check_empty_rectangle rchecker1(r1); CGAL::range_search(PS,r1.vertex(0),r1.vertex(1),r1.vertex(2),r1.vertex(3),std::back_inserter(LV),rchecker1,true); if (rchecker1.get_result()) std::cout << "rectangle not empty !\n"; else { std::cout << "rectangle was empty !\n"; std::cout << "this is an error !\n"; correct=false; } check_empty_rectangle rchecker2(r2); CGAL::range_search(PS,r2.vertex(0),r2.vertex(1),r2.vertex(2),r2.vertex(3),std::back_inserter(LV),rchecker2,true); if (rchecker2.get_result()) { std::cout << "rectangle not empty !\n"; std::cout << "this is an error !\n"; correct=false; } else std::cout << "rectangle was empty !\n"; if (correct) return 0; return 1; }
int main( int argc, char* argv[]) { // create some points in the plane Point p1(1,2), p2(4,2); Point p3(2,1), p4(4,3); Point p5(2,2), p6(6,2); Point p7(1,4), p8(2,3); Point p9(3,2), p10(5,0); // create some segments Segment s1(p1, p2); Segment s2(p3, p4); Segment s3(p5, p6); Segment s4(p7, p8); Segment s5(p9, p10); // test with predicate functions echo("*****************************************************************"); echo("Segment 1 and 2, they should intersect at point (3,2)"); printSegments(s1, s2); testForIntersectionAndPrint(s1, s2); doIntersectionAndPrint(s1, s2); newline(); echo("Segment 1 and 3, they should intersect at segment (2,2), (4,2)"); printSegments(s1, s3); testForIntersectionAndPrint(s1, s3); doIntersectionAndPrint(s1, s3); newline(); echo("Segment 1 and 4, they should not intersect"); printSegments(s1, s4); testForIntersectionAndPrint(s1, s4); doIntersectionAndPrint(s1, s4); newline(); echo("Segment 2 and 5, they should intersect at point (3,2)"); printSegments(s2, s5); testForIntersectionAndPrint(s2, s5); doIntersectionAndPrint(s2, s5); newline(); echo("Segment 2 and 2, they should intersect at segment (2,1), (4,3)"); printSegments(s2, s2); testForIntersectionAndPrint(s2, s2); doIntersectionAndPrint(s2, s2); newline(); // test with non-predicate functions echo("*****************************************************************"); echo("Segment 1 and 2, they should intersect at point (3,2)"); printSegments(s1, s2); testForIntersectionAndPrint2(s1, s2); doIntersectionAndPrint2(s1, s2); newline(); echo("Segment 1 and 3, they should intersect at segment (2,2), (4,2)"); printSegments(s1, s3); testForIntersectionAndPrint2(s1, s3); doIntersectionAndPrint2(s1, s3); newline(); echo("Segment 1 and 4, they should not intersect"); printSegments(s1, s4); testForIntersectionAndPrint2(s1, s4); doIntersectionAndPrint2(s1, s4); newline(); echo("Segment 2 and 5, they should intersect at point (3,2)"); printSegments(s2, s5); testForIntersectionAndPrint2(s2, s5); doIntersectionAndPrint2(s2, s5); newline(); echo("Segment 2 and 2, they should intersect at segment (2,1), (4,3)"); printSegments(s2, s2); testForIntersectionAndPrint2(s2, s2); doIntersectionAndPrint2(s2, s2); newline(); return 0; }
void Render(DemoEntityManager* const scene) { NewtonCollision* const deformableCollision = NewtonBodyGetCollision(m_body); dAssert((NewtonCollisionGetType(deformableCollision) == SERIALIZE_ID_CLOTH_PATCH) || (NewtonCollisionGetType(deformableCollision) == SERIALIZE_ID_DEFORMABLE_SOLID)); const dFloat* const particles = NewtonDeformableMeshGetParticleArray(deformableCollision); int stride = NewtonDeformableMeshGetParticleStrideInBytes(deformableCollision) / sizeof (dFloat); // calculate vertex skinning for (int i = 0; i < m_vertexCount; i++) { int index = m_indexMap[i] * stride; m_vertex[i * 3 + 0] = particles[index + 0]; m_vertex[i * 3 + 1] = particles[index + 1]; m_vertex[i * 3 + 2] = particles[index + 2]; // clear the normal for next loop m_normal[i * 3 + 0] = 0.0f; m_normal[i * 3 + 1] = 0.0f; m_normal[i * 3 + 2] = 0.0f; } // calculate vertex normals int normalStride = 3; for (DemoMesh::dListNode* segmentNode = GetFirst(); segmentNode; segmentNode = segmentNode->GetNext()) { const DemoSubMesh& subSegment = segmentNode->GetInfo(); for (int i = 0; i < subSegment.m_indexCount; i += 3) { int i0 = subSegment.m_indexes[i + 0] * normalStride; int i1 = subSegment.m_indexes[i + 1] * normalStride; int i2 = subSegment.m_indexes[i + 2] * normalStride; dVector p0(m_vertex[i0], m_vertex[i0 + 1], m_vertex[i0 + 2], 0.0f); dVector p1(m_vertex[i1], m_vertex[i1 + 1], m_vertex[i1 + 2], 0.0f); dVector p2(m_vertex[i2], m_vertex[i2 + 1], m_vertex[i2 + 2], 0.0f); dVector p10(p1 - p0); dVector p20(p2 - p0); dVector normal(p10.CrossProduct(p20)); normal = normal.Scale(1.0f / dSqrt(normal.DotProduct3(normal))); m_normal[i0 + 0] += normal.m_x; m_normal[i0 + 1] += normal.m_y; m_normal[i0 + 2] += normal.m_z; m_normal[i1 + 0] += normal.m_x; m_normal[i1 + 1] += normal.m_y; m_normal[i1 + 2] += normal.m_z; m_normal[i2 + 0] += normal.m_x; m_normal[i2 + 1] += normal.m_y; m_normal[i2 + 2] += normal.m_z; } } // normalize all the normals for (int i = 0; i < m_vertexCount; i++) { dVector n(m_normal[i * 3 + 0], m_normal[i * 3 + 1], m_normal[i * 3 + 2], 0.0f); n = n.Scale(1.0f / dSqrt(n.DotProduct3(n))); m_normal[i * 3 + 0] = n.m_x; m_normal[i * 3 + 1] = n.m_y; m_normal[i * 3 + 2] = n.m_z; } glDisable(GL_CULL_FACE); DemoMesh::Render(scene); glEnable(GL_CULL_FACE); }
MEM_topshell_data * plot_strip_init( Display * dpy , int nx , float dx , int ny , float ybot , float ytop , char * lab_xxx , char * lab_yyy , char * lab_top , char ** nam_yyy , void_func * killfunc ) { int ii , jj , np , nnax,nnay , mmax,mmay , yall ; float pbot,ptop , xobot,xotop,yobot,yotop , yll,yhh ; char str[32] ; float *ud ; MEM_topshell_data * mp ; MEM_plotdata * mplot ; /*-- sanity check --*/ if( dpy == NULL || ny == 0 || nx < 9 || ybot >= ytop ) return NULL ; if( dx <= 0.0 ) dx = 1.0 ; yall = (ny > 0) ; if( !yall ) ny = -ny ; if( ny == 1 ) yall = 1 ; /*-- data ranges --*/ ptop = p10(nx) ; nnax = rint(nx/ptop) ; if( nnax == 1 ) nnax = 10 ; mmax = (nnax < 3) ? 10 : (nnax < 6) ? 5 : 2 ; pbot = p10(ybot) ; ptop = p10(ytop) ; if( ptop < pbot ) ptop = pbot ; nnay = rint((ytop-ybot)/ptop) ; if( nnay == 1 ) nnay = 10 ; mmay = (nnay < 3) ? 10 : (nnay < 6) ? 5 : 2 ; /*-- setup to plot --*/ create_memplot_surely( "Striplot" , 1.3 ) ; set_color_memplot( 0.0 , 0.0 , 0.0 ) ; set_thick_memplot( 0.0 ) ; mplot = get_active_memplot() ; /*-- plot labels, if any --*/ xobot = 0.15 ; xotop = 1.27 ; /* set objective size of plot */ yobot = 0.1 ; yotop = 0.95 ; if( STGOOD(lab_top) ){ yotop -= 0.02 ; yobot -= 0.01 ; } if( nam_yyy != NULL ){ xotop -= 0.16 ; xobot -= 0.02 ; } /* x-axis label? */ if( STGOOD(lab_xxx) ) plotpak_pwritf( 0.5*(xobot+xotop) , yobot-0.06 , lab_xxx , 16 , 0 , 0 ) ; /* y-axis label? */ if( STGOOD(lab_yyy) ) plotpak_pwritf( xobot-0.10 , 0.5*(yobot+yotop) , lab_yyy , 16 , 90 , 0 ) ; /* label at top? */ if( STGOOD(lab_top) ) plotpak_pwritf( xobot+0.01 , yotop+0.01 , lab_top , 18 , 0 , -2 ) ; /*-- plot all on same vertical scale --*/ if( yall ){ /* do name labels at right? */ if( nam_yyy != NULL ){ float yv = yotop ; int sz ; for( jj=0 ; jj < ny ; jj++ ){ if( STGOOD(nam_yyy[jj]) ){ set_color_memplot( ccc[jj%NCLR][0] , ccc[jj%NCLR][1] , ccc[jj%NCLR][2] ) ; set_thick_memplot( 2*THIK ) ; plotpak_line( xotop+0.008 , yv , xotop+0.042 , yv ) ; set_thick_memplot( 0.0 ) ; set_color_memplot( 0.0 , 0.0 , 0.0 ) ; sz = (strlen(nam_yyy[jj]) <= 10) ? 12 : 10 ; plotpak_pwritf( xotop+0.048 , yv , nam_yyy[jj] , sz , 0 , -1 ) ; yv -= 0.05 ; } } } /* plot axes */ plotpak_set( xobot,xotop , yobot,yotop , 0.0,nx*dx , ybot,ytop , 1 ) ; plotpak_periml( nnax,mmax , nnay,mmay ) ; } else { /*-- plot each on separate vertical scale --*/ float dyo = (yotop-yobot) / ( (1.0+SY) * ny - SY ) ; /* name labels at right? */ if( nam_yyy != NULL ){ float yv = yotop ; int sz ; for( jj=0 ; jj < ny ; jj++ ){ yll = yobot + jj*(1.0+SY)*dyo ; yhh = yll + dyo ; if( STGOOD(nam_yyy[jj]) ){ set_color_memplot( ccc[jj%NCLR][0] , ccc[jj%NCLR][1] , ccc[jj%NCLR][2] ) ; set_thick_memplot( 2*THIK ) ; yv = 0.7*yhh + 0.3*yll ; plotpak_line( xotop+0.008 , yv , xotop+0.042 , yv ) ; set_thick_memplot( 0.0 ) ; set_color_memplot( 0.0 , 0.0 , 0.0 ) ; sz = (strlen(nam_yyy[jj]) <= 10) ? 12 : 10 ; plotpak_pwritf( xotop+0.048 , yv , nam_yyy[jj] , sz , 0 , -1 ) ; } } } /* data each in its own box */ nnay = 1 ; pbot = p10(ybot) ; ptop = p10(ytop) ; if( ptop > pbot && pbot > 0.0 ) ptop = pbot ; if( ptop != 0.0 ) mmay = floor( (ytop-ybot) / ptop + 0.5 ) ; else mmay = 5 ; /* shouldn't happen */ if( mmay == 1 ) mmay = 5 ; else if( mmay == 2 ) mmay = 4 ; else if( mmay == 3 ) mmay = 6 ; for( jj=ny-1 ; jj >= 0 ; jj-- ){ yll = yobot + jj*(1.0+SY)*dyo ; yhh = yll + dyo ; plotpak_set( xobot,xotop , yll,yhh , 0.0,nx*dx , ybot,ytop , 1 ) ; plotpak_perimm( nnax,mmax , nnay,mmay , (jj==0) ? 1 : 3 ) ; if( ybot < 0.0 && ytop > 0.0 ){ plotpak_setlin(5) ; plotpak_line( 0.0,0.0 , nx*dx,0.0 ) ; plotpak_setlin(1) ; } } } /*-- open display for this plot --*/ mp = memplot_to_topshell( dpy , mplot , killfunc ) ; if( mp == NULL ) return NULL ; /*-- auxiliary data needed by addto --*/ ud = (float *) calloc( (12+ny) , sizeof(float) ) ; ud[0] = xobot ; ud[1] = xotop ; ud[2] = yobot ; ud[3] = yotop ; ud[4] = 0.0 ; ud[5] = nx ; ud[6] = ybot ; ud[7] = ytop ; ud[8] = ny ; ud[9] = yall ; ud[10] = MEMPLOT_NLINE(mplot) ; /* number of init lines */ ud[11] = -1 ; /* current x position */ mp->userdata = ud ; /*-- plot invalid lines, to be replaced later with valid lines --*/ /* line connecting ii to ii+1 at the jj-th y level is number ud[10] + ii + jj*nx in the memplot structure */ for( jj=0 ; jj < ny ; jj++ ) for( ii=0 ; ii < nx ; ii++ ) ADDTO_MEMPLOT( mplot , 0.0,0.0,0.0,0.0,0.0,-THCODE_INVALID ) ; /* and two more for each y (an X at the current point): X for the jj-th y level is the two lines numbered ud[10] + nx*ny + 2*jj and ud[10] + nx*ny + 2*jj+1 */ for( jj=0 ; jj < 2*ny ; jj++ ) ADDTO_MEMPLOT( mplot , 0.0,0.0,0.0,0.0,0.0,-THCODE_INVALID ) ; /*-- exit, stage left --*/ return mp ; }