-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Gradient #136
Conversation
I still think that users should not need to change between As a concrete proposal: can we have the I haven't tried this. I think it provides semantics for backends that don't handle gradients, without requiring duplicate code in every backend. (I know we debated those questions in #9). |
import Data.Semigroup | ||
|
||
-- | A stop is (color, proportion, opacity) | ||
type GradientStop = (SomeColor, Double, Double) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a) Can this be a real type instead of an alias?
b) Do we really need SomeColor
? Would AlphaColor
work as well?
c) Since SomeColor
/ AlphaColor
already has opacity, do we need another double about opacity?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a) Do you mean data GradientStop = GradientStop SomeColor Double Double
? Any reason for the preference?
@byorgey suggested b & c as well I don't have a strong preference either way. My intention was to be consistent with FillColor
and LineColor
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC, type
doesn't provide any type safety; any (SomeColor, Double, Double)
will do. Untyped Double
s make me nervous---they could reperesent anything.
I don't understand the SomeColor
in FillColor
either. :)
@bergey re: |
|
||
----------------------------------------------------------------------------- | ||
-- | | ||
-- Module : Diagrams.Attributes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be: "Module : Diagrams.TwoD.Attributes".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, thanks
You mention supporting backends that do not support gradients. Can you elaborate on what API we would end up with if we went ahead and broke all backends? Is there a clean way to have attributes that do not care what vector-space they live in work together with attributes that do? Textures appear to me to carry the meaning of functions from some space to a color ( |
If we broke all backends, then |
@jeffreyrosenbluth , please correct me if I'm wrong. If we completely replace I thought the point of implementing gradients is that backend libraries already support them. That is, SVG can represent them directly, and cairo does something sensible (?). I agree that In R3 it's worse. I think POVRay (our only 3D Backend right now) only supports 2D textures surface mapped (not sure how) to the objects. That's pretty common, I think, especially for non-raytracing implementations. Parametric 3D textures are really nice, but what backend would we target? I'd love to have a native Haskell raytracer or a custom OpenGL shader, but I think either is a long way off. |
It's been a long time since I've used POVRay, but I'm quite sure it has support for "solid", i.e. parametric 3D, textures. |
@byorgey Ooh. I'll look harder in the docs, then. Thanks! |
Specifically I think the breaking change is replacing
With a I'm pretty sure PovRay can handle a 3d texture and not just a texture as a surface, I'll look into it. |
@bergey is right about the Backends needing to change if we completely replace @fryguybob Re, generalizing from |
I do like the solution of having e.g. |
If someone would put this through some tests with cairo and svg then we can add some documentation and merge. |
@@ -77,6 +77,7 @@ module Diagrams.TwoD | |||
, strokeLocTrail, strokeLocT, strokeLocLine, strokeLocLoop | |||
, FillRule(..), fillRule | |||
, StrokeOpts(..), vertexNames, queryFillRule | |||
, splitFills |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the reason for re-exporting this from Diagrams.TwoD
? I think I intentionally did not re-export it because it is useful only to backend writers, who can import Diagrams.TwoD.Attributes
if they need it; there's no need to export it from Diagrams.Prelude
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your right, I'll take it out
This is looking good to me. |
data FillLoops v = FillLoops | ||
|
||
instance Typeable v => SplitAttribute (FillLoops v) where | ||
type AttrType (FillLoops v) = FillColor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh, I think this now needs to consider both FillColor
and FillTexture
, but the way I have it set up it can only handle doing one at a time. =(
One solution I suppose would be to make a second function akin to splitFills
but acting on FillTexture
. It's just a bit annoying to have to do two passes, but it should only be a few extra lines of code (copy lines 551-566 here and change a few things).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I don't have better answers to some of the line notes. Some of this
code was written as long as 6 months ago, so I don't remember exactly what
I was thinking at the time. I'll try to look into some the your questions
more deeply this weekend.
On Thu, Apr 17, 2014 at 10:17 PM, Brent Yorgey notifications@github.comwrote:
In src/Diagrams/TwoD/Attributes.hs:
+-- | A synonym for 'fillColor', specialized to @'Colour' Double@
+-- (i.e. opaque colors). See comment after 'fillColor' about backends.
+fc :: (HasStyle a, V a ~ R2) => Colour Double -> a -> a
+fc = fillColor
+
+-- | A synonym for 'fillColor', specialized to @'AlphaColour' Double@
+-- (i.e. colors with transparency). See comment after 'fillColor' about backends.
+fcA :: (HasStyle a, V a ~ R2) => AlphaColour Double -> a -> a
+fcA = fillColor
+------------------------------------------------------------
+
+data FillLoops v = FillLoops
+
+instance Typeable v => SplitAttribute (FillLoops v) where
- type AttrType (FillLoops v) = FillColor
Ugh, I think this now needs to consider both FillColor and FillTexture,
but the way I have it set up it can only handle doing one at a time. =(One solution I suppose would be to make a second function akin to
splitFills but acting on FillTexture. It's just a bit annoying to have to
do two passes, but it should only be a few extra lines of code (copy lines
551-566 here and change a few things).—
Reply to this email directly or view it on GitHubhttps://github.com//pull/136/files#r11762174
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries. I may have some time to help out as well.
I think this gradient branches are ready to merge |
+1 |
I think this and the other gradient branches are ready to merge.