Polygon Polygon::intersectIgnoreZ(const Polygon &other) const { // Algorithm: // For every pair<Vertex, Vertex> from other determine the intersection point P with every pair<Vertex, Vertex> from this. // For every Vertex from other check if the Vertex is inside this. // For all resulting Vertices in the overlapping polygon sort vertices to remove all crossings. Polygon resultingPolygon; vector<Point3> thisPolygon = getVertices(); vector<Point3> otherPolygon = other.getVertices(); if ( (thisPolygon.size() > 0) && (otherPolygon.size() > 0) ) { // Modify vertices by adding the first vertex at the end of both lists for closing the polygon. thisPolygon.push_back((*thisPolygon.begin())); otherPolygon.push_back((*otherPolygon.begin())); for(uint32_t i = 0; i < thisPolygon.size() - 1; i++) { Point3 thisA = thisPolygon.at(i); Point3 thisB = thisPolygon.at(i+1); Line thisLine(thisA, thisB); for(uint32_t j = 0; j < otherPolygon.size() - 1; j++) { Point3 otherA = otherPolygon.at(j); Point3 otherB = otherPolygon.at(j+1); Line otherLine(otherA, otherB); Point3 result; if (thisLine.intersectIgnoreZ(otherLine, result)) { // Intersection point found. resultingPolygon.add(result); } } } // Now, check if one vertex from other is within this polygon. for(uint32_t j = 0; j < otherPolygon.size()-1; j++) { Point3 otherVertex = otherPolygon.at(j); if (containsIgnoreZ(otherVertex)) { resultingPolygon.add(otherVertex); } } // Remove crossing lines. resultingPolygon.sort(); } return resultingPolygon; }
std::tuple<unsigned int, unsigned int, unsigned int> detect_aes_in_ecb_mode( std::istream & input) { auto lineNumberOffsetAndRepeatCount = std::make_tuple(0u, 0u, 0u); for (unsigned int lineNumber = 1; input; ++lineNumber) { line_extract_streambuf thisLine(input); std::istream thisLineStream(&thisLine); decode_hex_streambuf hexDecoder(thisLineStream); auto mostRepeats = detect_most_repeats(std::istream(&hexDecoder).seekg(0), 16); if (mostRepeats.second > std::get<2>(lineNumberOffsetAndRepeatCount)) lineNumberOffsetAndRepeatCount = std::make_tuple(lineNumber, (mostRepeats.first - 1 * 2) + 1, mostRepeats.second); } return lineNumberOffsetAndRepeatCount; }
//! returns the dimension of text core::dimension2d<u32> ScalableFont::getDimension(const wchar_t* text) const { assert(Areas.size() > 0); core::dimension2d<u32> dim(0, 0); core::dimension2d<u32> thisLine(0, (int)(MaxHeight*m_scale)); for (const wchar_t* p = text; *p; ++p) { if (*p == L'\r' || // Windows breaks *p == L'\n' ) // Unix breaks { if (*p==L'\r' && p[1] == L'\n') // Windows breaks ++p; dim.Height += thisLine.Height; if (dim.Width < thisLine.Width) dim.Width = thisLine.Width; thisLine.Width = 0; continue; } bool fallback = false; const SFontArea &area = getAreaFromCharacter(*p, &fallback); thisLine.Width += area.underhang; thisLine.Width += getCharWidth(area, fallback); } dim.Height += thisLine.Height; if (dim.Width < thisLine.Width) dim.Width = thisLine.Width; //Log::info("ScalableFont", "ScalableFont::getDimension returns: %d, %d", dim.Width, dim.Height); dim.Width = (int)(dim.Width + 0.9f); // round up dim.Height = (int)(dim.Height + 0.9f); //Log::info("ScalableFont", "After: %d, %d", dim.Width, dim.Height); return dim; }
//! returns the dimension of text core::dimension2d<s32> CGUIFont::getDimension(const wchar_t* text) { core::dimension2d<s32> dim(0, 0); core::dimension2d<s32> thisLine(0, MaxHeight); for (const wchar_t* p = text; *p; ++p) { bool lineBreak=false; if (*p == L'\r') // Mac or Windows breaks { lineBreak = true; if (p[1] == L'\n') // Windows breaks ++p; } else if (*p == L'\n') // Unix breaks { lineBreak = true; } if (lineBreak) { dim.Height += thisLine.Height; if (dim.Width < thisLine.Width) dim.Width = thisLine.Width; thisLine.Width = 0; continue; } SFontArea &area = Areas[getAreaFromCharacter(*p)]; thisLine.Width += area.underhang; thisLine.Width += area.width + area.overhang + GlobalKerningWidth; } dim.Height += thisLine.Height; if (dim.Width < thisLine.Width) dim.Width = thisLine.Width; return dim; }
ol::Collision ol::Shape:: LineStripCollision( const std_container1 &vertices, const std_container2 &otherVertices, const Placement &thisPlacement, const Placement &otherPlacement, bool getResults, bool thisConnectFirstAndLast, bool otherConnectFirstAndLast ) const { if( vertices.size() < 2 || otherVertices.size() < 2 ) { OlError( "An empty shape can't ever collide!" ); return Collision( false ); } Vec2D thisCo = thisPlacement.GetPosition(); Vec2D otherCo = otherPlacement.GetPosition(); Matrix2D thisTransform = thisPlacement.Get2DMatrix(); Matrix2D otherTransform = otherPlacement.Get2DMatrix(); typename std_container1::const_iterator thisIter = vertices.begin(); const Vec2D rotationPivot = thisPlacement.GetRotationPivot(); const Vec2D otherRotationPivot = otherPlacement.GetRotationPivot(); Vec2D thisPrev = thisTransform.Transform( *thisIter - rotationPivot ) + thisCo + rotationPivot; thisIter++; std::vector< LinePair * > segmentLists; // Loop through each vertex // while( true ) { bool breakNow = false; // Test if we've reached the last line segment // if( thisIter == vertices.end() ) { if( !thisConnectFirstAndLast ) { break; } breakNow = true; thisIter = vertices.begin(); } Vec2D thisVertex = thisTransform.Transform( *thisIter - rotationPivot ) + thisCo + rotationPivot; thisIter++; typename std_container2::const_iterator otherIter = otherVertices.begin(); Vec2D otherPrev = otherTransform.Transform( *otherIter - otherRotationPivot ) + otherCo + otherRotationPivot; otherIter++; // Loop through each vertex of the other polygon // while( true ) { bool breakNow = false; // Test if we've reached the last line segment of the other polygon // if( otherIter == otherVertices.end() ) { if( !otherConnectFirstAndLast ) { break; } breakNow = true; otherIter = otherVertices.begin(); } Vec2D otherVertex = otherTransform.Transform( *otherIter - otherRotationPivot ) + otherCo + otherRotationPivot; otherIter++; // Test for collision // if( IsCounterClockwise( thisPrev, thisVertex, otherPrev ) != IsCounterClockwise( thisPrev, thisVertex, otherVertex ) && IsCounterClockwise( otherPrev, otherVertex, thisPrev ) != IsCounterClockwise( otherPrev, otherVertex, thisVertex )) { if( !getResults ) { return Collision( true ); } else { Line thisLine( thisVertex, thisPrev ); Line otherLine( otherVertex, otherPrev ); segmentLists.push_back( new LinePair( thisLine, otherLine )); /* return Collision( thisLine, otherLine );*/ } } // Is last line segment of the other polygon processed? // if( breakNow ) { break; } // Advance to the next vertex of the other polygon // otherPrev = otherVertex; } // Is last line segment processed? // if( breakNow ) { break; } // Advance to the next vertex // thisPrev = thisVertex; } if( !segmentLists.empty() ) { return Collision( segmentLists ); } return Collision( false ); }