Package nodebox.graphics

Examples of nodebox.graphics.Point


        return true;
    }

    @Override
    public boolean mouseMoved(Point pt) {
        Point center = getCenter();
        double x = center.x;
        double y = center.y;
        double radius = getRadius();
        float d = (float) Geometry.distance(x, y, pt.x, pt.y);
        if (radius - 4 <= d && d <= radius + 4) {
            float a = (float) Geometry.angle(x, y, pt.x, pt.y);
            double[] xy;
            xy = Geometry.coordinates(x, y, radius, a);
            this.pt = new Point((float) xy[0], (float) xy[1]);
        } else {
            this.pt = null;
        }
        updateHandle();
        return true;
View Full Code Here


        if (shouldWriteAttribute(node, Node.Attribute.HANDLE))
            el.setAttribute("handle", node.getHandle());

        // Write position
        if (shouldWriteAttribute(node, Node.Attribute.POSITION)) {
            Point position = node.getPosition();
            el.setAttribute("position", String.valueOf(position));
        }

        // Write rendered child
        if (shouldWriteAttribute(node, Node.Attribute.RENDERED_CHILD_NAME))
View Full Code Here

    public void testPortSerialization() {
        assertPortSerialization(Port.intPort("int", 42));
        assertPortSerialization(Port.floatPort("float", 33.3));
        assertPortSerialization(Port.stringPort("string", "hello"));
        assertPortSerialization(Port.colorPort("color", Color.BLACK));
        assertPortSerialization(Port.pointPort("point", new Point(11, 22)));
        assertPortSerialization(Port.customPort("geometry", "nodebox.graphics.Geometry"));
    }
View Full Code Here

        Locale.setDefault(Locale.GERMAN);
        try {
            // We use points for the position and for the input port.
            Node originalRoot = Node.ROOT
                    .withName("root")
                    .withPosition(new Point(12, 34))
                    .withInputAdded(Port.pointPort("point", new Point(12, 34)));
            NodeLibrary originalLibrary = NodeLibrary.create("test", originalRoot);
            NodeLibrary library = NodeLibrary.load("test", originalLibrary.toXml(), NodeRepository.of());
            Node root = library.getRoot();
            assertPointEquals(root.getPosition(), 12.0, 34.0);
            assertPointEquals(root.getInput("point").pointValue(), 12.0, 34.0);
View Full Code Here

        UpgradeResult result = NodeLibraryUpgrades.upgrade(version1File);
        assertTrue("Result should contain updated position: " + result.getXml(), result.getXml().contains("position=\"12.00,2.00\""));
        NodeLibrary upgradedLibrary = result.getLibrary(version1File, NodeRepository.of());
        Node root = upgradedLibrary.getRoot();
        Node alpha = root.getChild("alpha");
        assertEquals(new Point(12, 2), alpha.getPosition());
    }
View Full Code Here

    public Rectangle2D getBounds(Iterable<?> objects) {
        Rectangle2D.Double bounds = new Rectangle2D.Double();
        for (Object o : objects) {
            if (o instanceof Point) {
                Point pt = (Point) o;
                bounds.add(pt.toPoint2D());
            } else if (o instanceof Iterable) {
                bounds.add(getBounds((Iterable<?>) o));
            }
        }
        bounds.x -= 5;
View Full Code Here

            @Override
            public void apply(Element e) {
                if (!e.getTagName().equals("node")) return;
                Attr position = e.getAttributeNode("position");
                if (position == null) return;
                Point pt = Point.valueOf(position.getValue());
                Point reversedPoint = new Point(pt.y, pt.x);
                Point gridPoint = new Point(Math.round(reversedPoint.x / GRID_CELL_SIZE) * 3, Math.round(reversedPoint.y / GRID_CELL_SIZE));
                position.setValue(String.valueOf(gridPoint));
            }

            @Override
            public void end(Element root) {
View Full Code Here

        assertConversion(Port.TYPE_INT, Port.TYPE_INT, 42L, 42L);
        assertConversion(Port.TYPE_INT, Port.TYPE_FLOAT, 42L, 42.0);
        assertConversion(Port.TYPE_INT, Port.TYPE_STRING, 42L, "42");
        assertConversion(Port.TYPE_INT, Port.TYPE_BOOLEAN, 42L, true);
        assertConversion(Port.TYPE_INT, Port.TYPE_COLOR, 255L, Color.WHITE);
        assertConversion(Port.TYPE_INT, Port.TYPE_POINT, 42L, new Point(42, 42));

        assertConversion(Port.TYPE_FLOAT, Port.TYPE_INT, 42.0, 42L);
        assertConversion(Port.TYPE_FLOAT, Port.TYPE_FLOAT, 42.0, 42.0);
        assertConversion(Port.TYPE_FLOAT, Port.TYPE_STRING, 42.0, "42.0");
        assertConversion(Port.TYPE_FLOAT, Port.TYPE_BOOLEAN, 0.0, false);
        assertConversion(Port.TYPE_FLOAT, Port.TYPE_COLOR, 0.0, Color.BLACK);
        assertConversion(Port.TYPE_FLOAT, Port.TYPE_POINT, 42.0, new Point(42, 42));

        assertConversion(Port.TYPE_STRING, Port.TYPE_INT, "42", 42L);
        assertConversion(Port.TYPE_STRING, Port.TYPE_FLOAT, "42", 42.0);
        assertConversion(Port.TYPE_STRING, Port.TYPE_STRING, "hello", "hello");
        assertConversion(Port.TYPE_STRING, Port.TYPE_BOOLEAN, "true", true);
        assertConversion(Port.TYPE_STRING, Port.TYPE_BOOLEAN, "not-a-boolean", false);
        assertConversion(Port.TYPE_STRING, Port.TYPE_COLOR, "#ff0000ff", new Color(1, 0, 0));
        assertConversion(Port.TYPE_STRING, Port.TYPE_POINT, "4,2", new Point(4, 2));

        assertConversion(Port.TYPE_BOOLEAN, Port.TYPE_INT, true, 1L);
        assertConversion(Port.TYPE_BOOLEAN, Port.TYPE_INT, false, 0L);
        assertConversion(Port.TYPE_BOOLEAN, Port.TYPE_FLOAT, true, 1.0);
        assertConversion(Port.TYPE_BOOLEAN, Port.TYPE_STRING, true, "true");
        assertConversion(Port.TYPE_BOOLEAN, Port.TYPE_STRING, false, "false");
        assertConversion(Port.TYPE_BOOLEAN, Port.TYPE_BOOLEAN, false, false);
        assertConversion(Port.TYPE_BOOLEAN, Port.TYPE_COLOR, true, Color.WHITE);
        assertConversion(Port.TYPE_BOOLEAN, Port.TYPE_COLOR, false, Color.BLACK);

        assertConversion(Port.TYPE_COLOR, Port.TYPE_STRING, new Color(0, 1, 0), "#00ff00ff");
        assertConversion(Port.TYPE_COLOR, Port.TYPE_COLOR, Color.WHITE, Color.WHITE);

        assertConversion(Port.TYPE_POINT, Port.TYPE_STRING, new Point(4, 2), "4.00,2.00");
        assertConversion(Port.TYPE_POINT, Port.TYPE_POINT, new Point(4, 2), new Point(4, 2));
    }
View Full Code Here

    @Test
    public void testGeometryToPointsConversion() {
        Node line = Node.ROOT
                .withName("line")
                .withFunction("corevector/line")
                .withInputAdded(Port.pointPort("point1", new Point(10, 20)))
                .withInputAdded(Port.pointPort("point2", new Point(30, 40)))
                .withInputAdded(Port.intPort("points", 2));
        Node point = Node.ROOT
                .withName("point")
                .withFunction("corevector/point")
                .withInputAdded(Port.pointPort("value", Point.ZERO));
        Node net = Node.NETWORK
                .withChildAdded(line)
                .withChildAdded(point)
                .withRenderedChild(point)
                .connect("line", "point", "value");
        assertResultsEqual(net, new Point(10, 20), new Point(30, 40));
    }
View Full Code Here

    }

    private void setValueFromControl() {
        double x = xNumber.getValue();
        double y = yNumber.getValue();
        setPortValue(new Point(x, y));
    }
View Full Code Here

TOP

Related Classes of nodebox.graphics.Point

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.