Skip to content

get(), set() -- cast double to int #261

@jeremydouglass

Description

@jeremydouglass
  • Typical Processing sketch math involves division to find an index for get()ing or set()ing a pixel.
  • In Java this works fine with integer division and integer modulo, which return an integer.
  • In R / Renjin, however, division or modulo (mod() or %%) of two integers returns double -- and "integer division" also returns a double with an integer value.
  • The result is that passing the result of almost any operation to get() / set() needs to be cast to be safely used, or it crashes the sketch with a signature type error -- this is unexpected for Processing users.
  • The solution, casting with as.integer(), is verbose and not in any of the non-R reference examples because it is not idiomatic in the Processing API, where the normal way of casting is with int() or (int).

The best solution is probably to add a casting signature which converts (double, double) to (int, nit) to BuiltinApplet.java.

src/rprocessing/applet/BuiltinApplet.java

For past examples see #155 , 2f1f865

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions