* @return Pointer to the first bisector created or NULL if no bisectors
* were created.
*/
-RS_Line* RS_Creation::createBisector(const Vector& coord1,
- const Vector& coord2,
- double length,
- int num,
- RS_Line* l1,
- RS_Line* l2) {
+RS_Line * RS_Creation::createBisector(const Vector & coord1, const Vector & coord2,
+ double length, int num, RS_Line * l1, RS_Line * l2)
+{
+ // check given entities:
+ if (!l1 || !l2 || l1->rtti() != RS2::EntityLine || l2->rtti() != RS2::EntityLine)
+ return NULL;
- VectorSolutions sol;
+ // intersection between entities:
+ VectorSolutions sol = RS_Information::getIntersection(l1, l2, false);
+ Vector inters = sol.get(0);
- // check given entities:
- if (l1==NULL || l2==NULL ||
- l1->rtti()!=RS2::EntityLine || l2->rtti()!=RS2::EntityLine) {
- return NULL;
- }
+ if (!inters.valid)
+ return NULL;
- // intersection between entities:
- sol = RS_Information::getIntersection(l1, l2, false);
- Vector inters = sol.get(0);
- if (inters.valid==false) {
- return NULL;
- }
+ double angle1 = inters.angleTo(l1->getNearestPointOnEntity(coord1));
+ double angle2 = inters.angleTo(l2->getNearestPointOnEntity(coord2));
+ double angleDiff = RS_Math::getAngleDifference(angle1, angle2);
- double angle1 = inters.angleTo(l1->getNearestPointOnEntity(coord1));
- double angle2 = inters.angleTo(l2->getNearestPointOnEntity(coord2));
- double angleDiff = RS_Math::getAngleDifference(angle1, angle2);
- if (angleDiff>M_PI) {
- angleDiff = angleDiff - 2*M_PI;
- }
- RS_Line* ret = NULL;
+ if (angleDiff > M_PI)
+ angleDiff = angleDiff - 2 * M_PI;
- if (document!=NULL && handleUndo) {
- document->startUndoCycle();
- }
+ RS_Line * ret = NULL;
- for (int n=1; n<=num; ++n) {
+ if (document && handleUndo)
+ document->startUndoCycle();
- double angle = angle1 +
- (angleDiff / (num+1) * n);
+ for(int n=1; n<=num; n++)
+ {
+ double angle = angle1 + (angleDiff / (num + 1) * n);
+ Vector v;
+ v.setPolar(length, angle);
+ RS_LineData d = RS_LineData(inters, inters + v);
+ RS_Line * newLine = new RS_Line(container, d);
- RS_LineData d;
- Vector v;
+ if (container)
+ {
+ newLine->setLayerToActive();
+ newLine->setPenToActive();
+ container->addEntity(newLine);
+ }
- Vector c;
- v.setPolar(length, angle);
- d = RS_LineData(inters, inters + v);
+ if (document && handleUndo)
+ document->addUndoable(newLine);
- RS_Line* newLine = new RS_Line(container, d);
- if (container!=NULL) {
- newLine->setLayerToActive();
- newLine->setPenToActive();
- container->addEntity(newLine);
- }
- if (document!=NULL && handleUndo) {
- document->addUndoable(newLine);
- }
- if (graphicView!=NULL) {
- graphicView->drawEntity(newLine);
- }
- if (ret==NULL) {
- ret = newLine;
- }
- }
- if (document!=NULL && handleUndo) {
- document->endUndoCycle();
- }
+ if (graphicView)
+ graphicView->drawEntity(newLine);
- return ret;
+ if (!ret)
+ ret = newLine;
+ }
+
+ if (document && handleUndo)
+ document->endUndoCycle();
+
+ return ret;
}