]> git.tdb.fi Git - r2c2.git/commitdiff
Snap to segments in both directions
authorMikko Rasa <tdb@tdb.fi>
Sat, 25 May 2013 22:59:11 +0000 (01:59 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 25 May 2013 22:59:11 +0000 (01:59 +0300)
Choose whichever is closer to the current rotation.

source/libr2c2/object.cpp

index e9e58abf97041c44351a7becd185895e95f79304..d7c7db25e68beaeac81923f5eb2e6258b10e2e7d 100644 (file)
@@ -45,9 +45,15 @@ bool Object::snap_to(const Object &other, float limit, SnapType what)
                Snap ssn = sn;
                if(other.snap(ssn, limit, what))
                {
-                       set_rotation(rotation+ssn.rotation-sn.rotation-Angle::half_turn());
+                       if(what==SNAP_NODE)
+                               set_rotation(rotation+ssn.rotation-sn.rotation-Angle::half_turn());
+                       else
+                       {
+                               Angle adiff = wrap_balanced((ssn.rotation-sn.rotation)*2.0f)/2.0f;
+                               set_rotation(rotation+adiff);
+                       }
                        sn = get_snap_node(i);
-                       position += ssn.position-sn.position;
+                       set_position(position+ssn.position-sn.position);
                        return true;
                }
        }