bool RenderSVGShape::strokeContains(const FloatPoint& point, bool requiresStroke) { if (!strokeBoundingBox().contains(point)) return false; Color fallbackColor; if (requiresStroke && !RenderSVGResource::strokePaintingResource(this, style(), fallbackColor)) return false; const SVGRenderStyle* svgStyle = style()->svgStyle(); for (size_t i = 0; i < m_zeroLengthLinecapLocations.size(); ++i) { ASSERT(style()->svgStyle()->hasStroke()); float strokeWidth = this->strokeWidth(); if (style()->svgStyle()->capStyle() == SquareCap) { if (zeroLengthSubpathRect(m_zeroLengthLinecapLocations[i], strokeWidth).contains(point)) return true; } else { ASSERT(style()->svgStyle()->capStyle() == RoundCap); FloatPoint radiusVector(point.x() - m_zeroLengthLinecapLocations[i].x(), point.y() - m_zeroLengthLinecapLocations[i].y()); if (radiusVector.lengthSquared() < strokeWidth * strokeWidth * .25f) return true; } } if (!svgStyle->strokeDashArray().isEmpty() || svgStyle->strokeMiterLimit() != svgStyle->initialStrokeMiterLimit() || svgStyle->joinStyle() != svgStyle->initialJoinStyle() || svgStyle->capStyle() != svgStyle->initialCapStyle()) { if (!m_path) RenderSVGShape::createShape(); return RenderSVGShape::shapeDependentStrokeContains(point); } return shapeDependentStrokeContains(point); }
bool RenderSVGPath::shapeDependentStrokeContains(const FloatPoint& point) { if (RenderSVGShape::shapeDependentStrokeContains(point)) return true; const SVGRenderStyle& svgStyle = style().svgStyle(); for (size_t i = 0; i < m_zeroLengthLinecapLocations.size(); ++i) { ASSERT(svgStyle.hasStroke()); float strokeWidth = this->strokeWidth(); if (svgStyle.capStyle() == SquareCap) { if (zeroLengthSubpathRect(m_zeroLengthLinecapLocations[i], strokeWidth).contains(point)) return true; } else { ASSERT(svgStyle.capStyle() == RoundCap); FloatPoint radiusVector(point.x() - m_zeroLengthLinecapLocations[i].x(), point.y() - m_zeroLengthLinecapLocations[i].y()); if (radiusVector.lengthSquared() < strokeWidth * strokeWidth * .25f) return true; } } return false; }
int CXXCircle::isSomewhereInsideSphere(const CXXCoord ¢re, const double radius) const{ //This can be checked by looking at any point on the circle rj and evaluating //if it is within the sphere CXXCoord xAxis(1.0, 0.0, 0.0); CXXCoord yAxis(0.0, 1.0, 0.0); //Need a vector orthogonal to centreToCircle. Get this by crossing CXXCoord radiusVector(0.,0.,0.); if (fabs(theNormal*xAxis)<0.9999999) radiusVector = xAxis ^ theNormal; else radiusVector = yAxis ^ theNormal; radiusVector.normalise(); radiusVector *= radiusOfCircle; CXXCoord pointOnCircle = getCentreOfCircle() + radiusVector; CXXCoord vectorToSphere = pointOnCircle - centre; double distanceToSphereSq = vectorToSphere.get3DLengthSq(); if (distanceToSphereSq < radius*radius){ return 1; } else { return 0; } }
void PluginCameraCalibration::detectEdgesOnSingleArc( const GVector::vector3d<double>& center, double radius, double theta1, double theta2, int numPoints) { int threshold(20); double distToLine = camera_parameters.additional_calibration_information->line_search_corridor_width->getDouble() / 2.0; CameraParameters::CalibrationData calData; calData.straightLine = false; calData.radius = radius; calData.center = center; calData.theta1 = theta1; calData.theta2 = theta2; for(int i=1;i<=numPoints;i++){ double alpha = 1.0 - ((double) i)/((double) numPoints + 1.0); double theta = alpha*theta1+(1.0-alpha)*theta2; GVector::vector3d<double> radiusVector(cos(theta),sin(theta),0.0); GVector::vector3d<double> posInWorld = center+radius*radiusVector; GVector::vector3d<double> worldStart = center+(radius-distToLine)*radiusVector; GVector::vector3d<double> worldEnd = center+(radius+distToLine)*radiusVector; GVector::vector2d<double> imgStart, imgEnd; camera_parameters.field2image(worldStart,imgStart); camera_parameters.field2image(worldEnd,imgEnd); sanitizeSobel(grey_image,imgStart); sanitizeSobel(grey_image,imgEnd); GVector::vector2d<double> arcPoint; bool centerFound; Sobel::centerOfLine(*grey_image, imgStart.x, imgEnd.x, imgStart.y, imgEnd.y, arcPoint, centerFound, threshold); calData.imgPts.push_back(std::make_pair(arcPoint,centerFound)); calData.alphas.push_back(alpha); } camera_parameters.calibrationSegments.push_back(calData); }
/* ============= SetPointList Точки необходимо задавать обходя по часовой стрелке ============= */ void CollisionElementPolygon::SetPointList( const PointList &setPoints ) { if( setPoints.size() < 3 ) { __log.PrintInfo( Filelevel_ERROR, "CollisionElementPolygon::SetPointList => not enough points" ); return; } this->pointsSource = setPoints; this->pointsResult.clear(); this->pointsResult.resize( setPoints.size() + 1 ); //copy src to result int num = 0; PointList::iterator iter, iterEnd = this->pointsSource.end(); for( iter = this->pointsSource.begin(); iter != iterEnd; ++iter, ++num ) { this->pointsResult[ num ] = *iter; } this->pointsResult[ this->pointsResult.size() - 1 ] = this->pointsSource[ 0 ]; Vec2 radiusVector( Vec2Null ); Vec2 edge0, edge1, edge2; num = 0; iterEnd = this->pointsResult.end(); for( iter = this->pointsResult.begin(); iter != iterEnd; ++iter, ++num ) { Point *point = &( *iter ); radiusVector.Set( max( fabs( point->x ), radiusVector.x ), max( fabs( point->y ), radiusVector.y ) ); if( num > 1 ) { //нормальзовать не нужно т.к. нужно не значение, а только знак edge0 = this->pointsResult[ num - 1 ] - this->pointsResult[ num - 2 ]; edge1 = this->pointsResult[ num ] - this->pointsResult[ num - 2 ]; edge1.Rotate90CW(); float sign = edge0.Dot( edge1 ); if( sign > 0 ) { __log.PrintInfo( Filelevel_ERROR, "CollisionElementPolygon::SetPointList => points[%d] is not clockwise", num ); this->pointsResult.clear(); this->pointsSource.clear(); return; } } }//for this->_rect->radius2 = Square( radiusVector.Length() ); //формирования списка разделающих осей Vec2 axis; Vec2 tmpVec2; iterEnd = this->pointsResult.end(); iter = this->pointsResult.begin(); num = 1; for( ++iter; iter != iterEnd; ++iter, ++num ) { tmpVec2 = this->pointsResult[ num ] - this->pointsResult[ num - 1 ]; axis.Set( tmpVec2.x, tmpVec2.y ); axis.Rotate90CW(); if( axis.x < 0 ) { axis *= -1.0f; } else if( axis.y < 0.0f ) { axis *= -1.0f; } axis.Normalize(); if( !this->_IsAxisExists( axis ) ) { this->axes.push_back( axis ); } }//foreach pointsSource }//SetPointList