bagherilab / ARCADE

ARCADE: Agent-based model of heterogeneous cell populations in dynamic microenvironments
Other
9 stars 1 forks source link

Add unit tests for Colors in core utilities #59

Closed cainja closed 3 weeks ago

cainja commented 1 month ago

Colors is missing unit tests

cainja commented 1 month ago

@jessicasyu

I am a little confused about the desired functionality in the Colors class, as this method touches a lot of UI functionality.

How should the colors be interpolated when given nonlinear values?

Specific proposed unit test in question:


    @Test
    public void getRGB_NonlinearColorsCalledBetweenMinAndMax_returnsInterpolatedColor() {
        Colors colors = new Colors(new Color[] {
            new Color(0, 0, 0, 0),
            new Color(100, 100, 100, 0),
            new Color(200, 200, 200, 200),
        }, new double[] { 0, 0.1, 1});

        assertEquals(new Color(0, 0, 0, 0).getRGB(), colors.getRGB(0));

        assertEquals(new Color(50, 50, 50, 0).getRGB(), colors.getRGB(0.05));
        assertEquals(new Color(100, 100, 100, 0).getRGB(), colors.getRGB(0.1));
        assertEquals(new Color(200, 200, 200, 125).getRGB(), colors.getRGB(0.55));

        assertEquals(new Color(200, 200, 200, 200).getRGB(), colors.getRGB(1));
    }

1) Should colors.getColor(0.1) return Color(100, 100, 100, 0)? 2) Should the other colors be interpolated linearly between the specified values in the double array?

jessicasyu commented 1 month ago

Yeah, if I remember correctly, this class is an implementation of MASON's ColorMap that allowed for multiple colors in the gradient. I think the more effective solution is replacing it with the new CompositeColorMap (which doesn't exist in the version of MASON we are using). We might want to update to MASON 22, but that is probably a separate issue.

To answer your questions:

  1. Yes, I think colors.getColor(0.1) should return Color(100, 100, 100, 0)
  2. Interpolation is linear between values in the double array