static bool fillPrimitiveElement(JSContext *cx, JSObject * myObject, const y60::Primitive::Element & theElement, const asl::Matrix4f * theTransformation) { //const y60::VertexData3f::VertexDataVector & myPositions = theElement._myPrimitive->getVertexData(y60::POSITIONS).getVertexDataCast<asl::Vector3f>(); const asl::Ptr<y60::ConstVertexDataAccessor<asl::Vector3f> > myPositionAccessor = theElement._myPrimitive->getConstLockingPositionsAccessor(); const y60::VertexData3f & myPositions = myPositionAccessor->get(); if (theElement._myVertexCount == 3) { const asl::Triangle<float> * myTriangle = asl::asTriangle(&asl::asPoint(myPositions[theElement._myStartVertex])); if (theTransformation) { if (!JS_DefineProperty(cx, myObject, "primitive", as_jsval(cx,*myTriangle * (*theTransformation)), 0,0, JSPROP_ENUMERATE)) return false; } else { if (!JS_DefineProperty(cx, myObject, "primitive", as_jsval(cx,*myTriangle), 0,0, JSPROP_ENUMERATE)) return false; } } if (theElement._myVertexCount == 4) { const asl::Point3f * myPolygonPtr = &asl::asPoint(myPositions[theElement._myStartVertex]); std::vector<asl::Point3f> myPolygon(myPolygonPtr, myPolygonPtr + theElement._myVertexCount); if (theTransformation) { for (unsigned int i = 0; i < theElement._myVertexCount; ++i) { myPolygon[i] = myPolygon[i] * (*theTransformation); } } if (!JS_DefineProperty(cx, myObject, "primitive", as_jsval(cx,myPolygon), 0,0, JSPROP_ENUMERATE)) return false; const asl::Triangle<float> * myFirstTriangle = asl::asTriangle(&myPolygon[0]); jsval myPrimitive; if (!JS_GetProperty(cx, myObject, "primitive", &myPrimitive)) return false; if (!JS_DefineProperty(cx, JSVAL_TO_OBJECT(myPrimitive), "normal", as_jsval(cx,myFirstTriangle->plane().normal), 0,0, JSPROP_ENUMERATE)) return false; } return true; }
bool KDChart::TextLayoutItem::intersects( const TextLayoutItem& other, const QPoint& myPos, const QPoint& otherPos ) const { if ( mAttributes.rotation() != other.mAttributes.rotation() ) { // that's the code for the common case: the rotation angles don't need to match here QPolygon myPolygon( rotatedCorners() ); QPolygon otherPolygon( other.rotatedCorners() ); // move the polygons to their positions myPolygon.translate( myPos ); otherPolygon.translate( otherPos ); // create regions out of it QRegion myRegion( myPolygon ); QRegion otherRegion( otherPolygon ); // now the question - do they intersect or not? return ! myRegion.intersect( otherRegion ).isEmpty(); } else { // and that's the code for the special case: the rotation angles match, which is less time consuming in calculation const qreal angle = mAttributes.rotation() * PI / 180.0; // both sizes const QSizeF mySize( unrotatedSizeHint() ); const QSizeF otherSize( other.unrotatedSizeHint() ); // that's myP1 relative to myPos QPointF myP1( mySize.height() * sin( angle ), 0.0 ); // that's otherP1 to myPos QPointF otherP1 = QPointF( otherSize.height() * sin( angle ), 0.0 ) + otherPos - myPos; // now rotate both points the negative angle around myPos myP1 = QPointF( myP1.x() * cos( -angle ), myP1.x() * sin( -angle ) ); qreal r = sqrt( otherP1.x() * otherP1.x() + otherP1.y() * otherP1.y() ); otherP1 = QPointF( r * cos( -angle ), r * sin( -angle ) ); // finally we look, whether both rectangles intersect or even not const bool res = QRectF( myP1, mySize ).intersects( QRectF( otherP1, otherSize ) ); //qDebug() << res << QRectF( myP1, mySize ) << QRectF( otherP1, otherSize ); return res; } }
void Polygon::draw(QPixmap& pixmap) { QPainter painter(&pixmap); // Apply brush to the painter which draw shape painter.setBrush(_brush); // Apply pen to the painter which draw shape painter.setPen(_pen); if( ! _points.empty() ) { if( !_drawed ) { painter.drawEllipse(_points.at(0), delatEnd, delatEnd); } QPolygon myPolygon( _points ); myPolygon.append( _movPoint ); painter.drawPolygon(myPolygon); } }