void EdgeItem::UpdatePath( void ){ // if( points ) // delete []points; points.clear(); QPainterPath m_path; m_path.moveTo(0, 0); QPointF control = MidPoint(); double dist = DistancePoint(QPointF(0, 0) , control) + DistancePoint(control, m_endPoint); int maxPointsCount = 8; pointsCount = (int)(dist / m_selectDistance) + 1; if(pointsCount > maxPointsCount ){ pointsCount = maxPointsCount; } // points = new QPointF[pointsCount]; QPointF point; for (int i = 0; i < pointsCount; i++){ point = BezierValue( (double) i / ( pointsCount - 1), control ); m_path.lineTo( point ); // m_path.addEllipse(point, 3,3); points << point + pos(); } setPath( m_path ); UpdateArrow(); }
void DistanceGrid::fromRgba(const u8 *pImageData) { for (s32 i = 0; i < m_szx * m_szy; ++i) { const u8 r = *pImageData++; const u8 g = *pImageData++; const u8 b = *pImageData++; const u8 a = *pImageData++; if (a < 128) { m_gridInside[i] = DistancePoint(0.0f, 0.0f); m_gridOutside[i] = DistancePoint(1.0f, 1.0f); } else { m_gridInside[i] = DistancePoint(1.0f, 1.0f); m_gridOutside[i] = DistancePoint(0.0f, 0.0f); } } }
qreal EdgeItem::Distance( QPointF point){ // qDebug()<<"Distance point: "<<point<<", pos: "<<pos()<<", end: "<<endPoint(); qreal minDist = 99999; qreal dist; for(int i = 0; i < points.count(); i++){ // qDebug()<<"dist: "<<dist; dist = DistancePoint( points[i], point); if( minDist > dist ){ minDist = dist; // qDebug()<<"min"; } } return minDist; }