bool QgsMeshDatasetValue::operator==( const QgsMeshDatasetValue &other ) const { bool equal = std::isnan( mX ) == std::isnan( other.x() ); equal &= std::isnan( mY ) == std::isnan( other.y() ); if ( equal ) { if ( std::isnan( mY ) ) { equal &= qgsDoubleNear( other.x(), mX, 1E-8 ); } else { equal &= qgsDoubleNear( other.x(), mX, 1E-8 ); equal &= qgsDoubleNear( other.y(), mY, 1E-8 ); } } return equal; }
QgsMeshDatasetValue QgsMeshLayer::datasetValue( const QgsMeshDatasetIndex &index, const QgsPointXY &point ) const { QgsMeshDatasetValue value; if ( mTriangularMesh && dataProvider() && dataProvider()->isValid() && index.isValid() ) { int faceIndex = mTriangularMesh->faceIndexForPoint( point ) ; if ( faceIndex >= 0 ) { int nativeFaceIndex = mTriangularMesh->trianglesToNativeFaces().at( faceIndex ); if ( dataProvider()->isFaceActive( index, nativeFaceIndex ) ) { if ( dataProvider()->datasetGroupMetadata( index ).dataType() == QgsMeshDatasetGroupMetadata::DataOnFaces ) { int nativeFaceIndex = mTriangularMesh->trianglesToNativeFaces().at( faceIndex ); value = dataProvider()->datasetValue( index, nativeFaceIndex ); } else { const QgsMeshFace &face = mTriangularMesh->triangles()[faceIndex]; const int v1 = face[0], v2 = face[1], v3 = face[2]; const QgsPoint p1 = mTriangularMesh->vertices()[v1], p2 = mTriangularMesh->vertices()[v2], p3 = mTriangularMesh->vertices()[v3]; const QgsMeshDatasetValue val1 = dataProvider()->datasetValue( index, v1 ); const QgsMeshDatasetValue val2 = dataProvider()->datasetValue( index, v2 ); const QgsMeshDatasetValue val3 = dataProvider()->datasetValue( index, v3 ); const double x = QgsMeshLayerUtils::interpolateFromVerticesData( p1, p2, p3, val1.x(), val2.x(), val3.x(), point ); double y = std::numeric_limits<double>::quiet_NaN(); bool isVector = dataProvider()->datasetGroupMetadata( index ).isVector(); if ( isVector ) y = QgsMeshLayerUtils::interpolateFromVerticesData( p1, p2, p3, val1.y(), val2.y(), val3.y(), point ); value = QgsMeshDatasetValue( x, y ); } } } } return value; }