On 03/05/2010 07:04 PM, Dr. David Kirkby wrote:
I just got a doc test failure on Solaris.


File
"/export/home/drkirkby/32/sage-4.3.4.alpha0/devel/sage/sage/plot/colors.py",
line 660:
sage: gold / pi + yellow * e
Expected:
RGB color (0.51829585732141792, 0.49333037605210095, 0.0)
Got:
RGB color (0.51829585732141814, 0.49333037605210117, 0.0)


Looking at the doc test I see this:


--------------------------------------
EXAMPLES::

sage: from __future__ import division
sage: from sage.plot.colors import yellow, gold
sage: yellow / 4
RGB color (0.25, 0.25, 0.0)
sage: yellow.__truediv__(4)
RGB color (0.25, 0.25, 0.0)
sage: gold / pi + yellow * e
RGB color (0.51829585732141792, 0.49333037605210095, 0.0)
----------------------------------------------

The is absolutely no justification given in the doc test for this
result, so how do we know it's right?

Printing the values of 'yellow' and 'gold' I get:

sage: print yellow
RGB color (1.0, 1.0, 0.0)
sage: print gold
RGB color (1.0, 0.84313725490196079, 0.0)
sage:

I personally don't understand how one can divide one colour by another,
but I'm not disputing that there can be some logic in this. I tried in
Mathematica to just divide the these as lists

In[44]:= yellow={1,1,0}

Out[44]= {1, 1, 0}

In[45]:= gold={1.0,0.84313725490196079, 0.0}

In[46]:= gold/Pi + yellow E

Out[46]= {3.03659, 2.98666, 0.}

With no idea what this division is supposed to do, I tried.

In[47]:= Normalize[%]

Out[47]= {0.712944, 0.701221, 0.}

but that gives totally different numbers.

So I'm none the wiser. Of course, I could create a ticket to check the
expected value to be

0.51829585732141..., 0.49333037605210...,0.0

but I'd have no justification for this.

Perhaps someone can enlighten me how one divides /multiples colours, and
can show me a high precision value for the result.

This is just one of several examples I've seen in Sage where the numeric
result from a doc test is not obvious. The "Expected" value is probably
what someone got on their computer. I "Got" a different value on my
computer. But who knows what the result should be? Without some
justification, I find it hard to believe this doc test achieves very
much. I've just waisted an hour trying to work out how I might reproduce
this, but can't


I assume we are talking about the patches up at #5601?

First, note that colors are multiplied by scalars, not by other colors. The documentation for the multiplication and division methods talk about what a multiplication or division means---scale the RGB values by the scalar.

sage: colors.yellow
RGB color (1.0, 1.0, 0.0)
sage: colors.yellow/2
RGB color (0.5, 0.5, 0.0)
sage: colors.yellow*0.3
RGB color (0.29999999999999999, 0.29999999999999999, 0.0)

This makes some sort of sense, at least numerically. However, what does not make sense is when a resulting component is more than one, the fractional part is taken as the value. Therefore,

sage: colors.red*2
RGB color (0.0, 0.0, 0.0)

I think this is a problem (and missed this when I reviewed the colors patch, so this getting in is partially my fault!) At least explains what colors*scalar is. I think this ought to be changed to make more sense when a resulting component is outside of [0,1] (maybe cap the values, instead of just take the fractional part). The problem here is in the rgbcolor() function when it creates a color from a tuple.

The addition of two colors is documented in the function for addition, and says there that it uses the blend function. The documentation for blend says

        Return a color blended with the given ``color`` by a given
        ``fraction``.  The algorithm interpolates linearly between the
        colors' corresponding R, G, and B coordinates.

This is so that colors.red+colors.blue is approximately purple (though not exactly colors.purple, since colors.purple is a specifically defined value according to HTML standards). colors.yellow+colors.red is approximately colors.orange, etc.

Thanks,

Jason

--
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org

Reply via email to