]> git.tdb.fi Git - r2c2.git/blobdiff - source/libr2c2/object.cpp
Make use of the mspmath library
[r2c2.git] / source / libr2c2 / object.cpp
index 1b48a862ae6b634c499fa49c094e54bc5c41cb05..cc56edeb6af28883f6619dd7953c8e21925d9e15 100644 (file)
@@ -18,8 +18,8 @@ bool Object::snap(Snap &sn, float limit, SnapType what) const
                for(unsigned i=0; i<nsn; ++i)
                {
                        Snap node = get_snap_node(i);
-                       Vector d(sn.position.x-node.position.x, sn.position.y-node.position.y, sn.position.z-node.position.z);
-                       if(d.x*d.x+d.y*d.y<limit*limit)
+                       Vector span = sn.position-node.position;
+                       if(dot(span, span)<limit*limit)
                        {
                                sn = node;
                                return true;
@@ -45,11 +45,9 @@ 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-M_PI);
+                       set_rotation(rotation+ssn.rotation-sn.rotation-Angle::half_turn());
                        sn = get_snap_node(i);
-                       position.x += ssn.position.x-sn.position.x;
-                       position.y += ssn.position.y-sn.position.y;
-                       position.z += ssn.position.z-sn.position.z;
+                       position += ssn.position-sn.position;
                        return true;
                }
        }
@@ -57,4 +55,26 @@ bool Object::snap_to(const Object &other, float limit, SnapType what)
        return false;
 }
 
+Object *Object::get_link(unsigned) const
+{
+       throw out_of_range("Object::get_link");
+}
+
+bool Object::break_link(Object &other)
+{
+       unsigned nls = get_n_link_slots();
+       for(unsigned i=0; i<nls; ++i)
+               if(get_link(i)==&other)
+                       return break_link(i);
+
+       return false;
+}
+
+void Object::break_links()
+{
+       unsigned nls = get_n_link_slots();
+       for(unsigned i=0; i<nls; ++i)
+               break_link(i);
+}
+
 } // namespace R2C2