Search in sources :

Example 1 with TransformRotate

use of de.neemann.digital.draw.graphics.TransformRotate in project Digital by hneemann.

the class ModifyMoveSelected method rotateElements.

/**
 * Rotates the given elements
 *
 * @param elements the elements to rotate
 * @param center   the center position
 */
public static void rotateElements(ArrayList<Movable> elements, Vector center) {
    Transform transform = new TransformRotate(center, 1) {

        @Override
        public Vector transform(Vector v) {
            return super.transform(v.sub(center));
        }

        @Override
        public VectorFloat transform(VectorFloat v) {
            return super.transform(v.sub(center));
        }
    };
    for (Movable m : elements) {
        if (m instanceof VisualElement) {
            VisualElement ve = (VisualElement) m;
            ve.rotate();
            ve.setPos(transform.transform(ve.getPos()));
        } else if (m instanceof Wire) {
            Wire w = (Wire) m;
            w.p1 = transform.transform(w.p1);
            w.p2 = transform.transform(w.p2);
        } else {
            Vector p = m.getPos();
            Vector t = transform.transform(p);
            m.move(t.sub(p));
        }
    }
}
Also used : TransformRotate(de.neemann.digital.draw.graphics.TransformRotate) Movable(de.neemann.digital.draw.elements.Movable) VisualElement(de.neemann.digital.draw.elements.VisualElement) Transform(de.neemann.digital.draw.graphics.Transform) Wire(de.neemann.digital.draw.elements.Wire) Vector(de.neemann.digital.draw.graphics.Vector) VectorFloat(de.neemann.digital.draw.graphics.VectorFloat)

Aggregations

Movable (de.neemann.digital.draw.elements.Movable)1 VisualElement (de.neemann.digital.draw.elements.VisualElement)1 Wire (de.neemann.digital.draw.elements.Wire)1 Transform (de.neemann.digital.draw.graphics.Transform)1 TransformRotate (de.neemann.digital.draw.graphics.TransformRotate)1 Vector (de.neemann.digital.draw.graphics.Vector)1 VectorFloat (de.neemann.digital.draw.graphics.VectorFloat)1