rokitna
2019-4-24 09:34:24

I’m interested in whatever is going on here too.

I don’t know if this is the same thing, while back I think I observed that I could rebind #\| to be my own reader macro, but that as long as it appeared inside a list, it acted like a comment syntax again.

My best guess is that sometimes the reader takes an “ignore whitespace and comments” step that isn’t followed by reading an s-expression, so it can’t be implemented as a recursive call to read and hence can’t take user-defined reader macros into account. Maybe in your examples it’s acting differently because it’s at the beginning of the stream?


wortham29176
2019-4-24 12:35:53

@wortham29176 has joined the channel


lexi.lambda
2019-4-24 15:42:41

Is there any way with racket/draw to convert a piece of text to a dc-path%, or is that just fundamentally impossible (either due to how Cairo works or because it just isn’t exposed through the Racket API)?


mflatt
2019-4-24 16:08:04

dc-path% has a text-outline method. Is that what you’re looking for?


lexi.lambda
2019-4-24 16:09:35

Aha, thanks! Not sure how I missed that.


lexi.lambda
2019-4-24 17:53:28

@mflatt Is it intentional that the draw-rectangle method of dc<%> aligns its coordinates when drawing the stroke but not when drawing the fill? And if so, why? (If no, I can open a PR to fix it, but based on the way the code is structured, it seems intended.)


mflatt
2019-4-24 17:57:22

Maybe I’m not looking at the same place, but I think it does align for the fill. Both cairo_rectangle calls use ax and ay.


mflatt
2019-4-24 17:58:34

Oh, the width and height are not aligned for the fill… I’m not immediately sure


lexi.lambda
2019-4-24 17:59:09

lexi.lambda
2019-4-24 17:59:28

Maybe it gets overridden somewhere else that I’m not looking at, though.


mflatt
2019-4-24 18:00:54

No, I’m misreading the code. Probably because ax is bound outside the first draw_rectangle, I read the x and ax.


mflatt
2019-4-24 18:02:25

It does seem like those should be aligned according to the docs, but it also does look intentional. And I agree about other methods. Just for reference, let me see what the older code did…


lexi.lambda
2019-4-24 18:02:51

It seems like some of the drawing functions take care not to align the fill coordinates, but others don’t (e.g. draw-polygon), and I’m not sure why.


lexi.lambda
2019-4-24 18:05:39

Looking at the git history, it looks like that code’s been there since it was first added in this commit: https://github.com/racket/draw/commit/b2f8e97e10dc0e515ce68d63d43c47aa803e1e96


lexi.lambda
2019-4-24 18:06:50

But maybe there’s some other history prior to that that git doesn’t know about, I don’t know.


alexknauth
2019-4-24 18:09:36

The function-like one would display its parameters as #<procedure> #<procedure> though, which isn’t very helpful.


mflatt
2019-4-24 18:09:48

I mean the C++ version, and I see that it did apply alignment. So, probably brush alignments just got lost. I worry about what will happen to existing programs when we change things (back), but it seems like we should try it.


lexi.lambda
2019-4-24 18:10:22

Okay, maybe I’ll give it a try and write some tests, and we can see what happens.


lexi.lambda
2019-4-24 18:11:51

It’s curious, though, that the code appears to be careful about not aligning the coordinates for the fill, even including the comment. But if you don’t know why, then I don’t imagine anyone does.


mflatt
2019-4-24 18:11:59

In case you haven’t discovered it already, you may want to start with tests/racket/draw/draw


lexi.lambda
2019-4-24 18:12:49

I saw it, though it looked intimidating, and I didn’t look at it very closely. :) But I’ll take another look.


lexi.lambda
2019-4-24 19:39:42

@mflatt I am trying to understand this sentence in the documentation for set-smoothing: > For line drawing, coordinates are further shifted based on the pen width and the alignment scale, where the shift corresponds to half of the pen width (reduced to a value such that its multiplication times the alignment scale times two produces an integer). After looking at the code that does this and re-reading, I now understand what it does, but I’m not sure it’s actually the right thing to do. IIUC it means it adds (* 0.5 alignment-scale) to the coordinates when drawing a stroke iff (quotient pen-width alignment-scale) is an odd number, which at first sounds reasonable: it avoids a line being drawn on a “pixel boundary” when the pen width is odd. The problem is that this doesn’t really do the right thing for the 'aligned smoothing mode, since it adjusts x and y, which means that when the line is perfectly horizontal, it can cause the x coordinate to go out of alignment, and vice-versa for the y coordinate when the line is vertical. For lines that are neither perfectly horizontal nor perfectly vertical, it seems like neither adjustment is really right.


lexi.lambda
2019-4-24 19:40:10

Here are some visual aids, blown up with a pixel grid overlaid.


lexi.lambda
2019-4-24 19:40:12

mflatt
2019-4-24 19:41:04

Does the output depend on the pen cap?


lexi.lambda
2019-4-24 19:41:30

Yes, it does. Is the issue that this assumes a 'round cap?


lexi.lambda
2019-4-24 19:43:06

Or, I guess it’s probably actually more relevant for a 'projecting cap.


mflatt
2019-4-24 19:43:14

I think that 'aligned makes only a certain amount of sense. If the current calculation does the right thing for rectangular frames and the broad side of lines, then that’s probably as far as we tried to refine it.


lexi.lambda
2019-4-24 19:45:31

Alright, I guess that’s fine. Though the docs do recommend it: “For most applications that draw to the screen or bitmaps, 'aligned mode is the best choice.” Are you saying that’s not true, or just that there are caveats?


mflatt
2019-4-24 19:46:51

Well, it’s not that other drawing modes are better. But, in the past, we didn’t figure out how to solve all problems with 'aligned.


lexi.lambda
2019-4-24 19:48:38

I see. So maybe it just needs to do something smarter here? I wasn’t thinking about the pen cap, but now that you’ve mentioned it, that makes sense. Maybe it could avoid applying the adjustment when the cap is 'butt except in the obviously-correct cases for perfectly horizontal/vertical lines.


mflatt
2019-4-24 19:51:10

That sounds plausible, though complex. The correct adjustment would depend on the slope of the line, right?


lexi.lambda
2019-4-24 19:55:13

Well, I’m not sure if it makes sense to do any adjustment at all if the line isn’t perfectly horizontal or perfectly vertical (after coordinate alignment), since aliasing will happen, anyway, in those cases. But I guess there could be some way for it to be minimized more generally, which would take into account the slope of the line… but I’d have to think harder about it.


mflatt
2019-4-24 19:56:33

Ok, I agree that it potentially makes sense to special-case horizontal and vertical lines, taking into account the pen cap. To minimize changes, I’d keep the current adjustment in place for other lines.


lexi.lambda
2019-4-24 19:57:29

Alright, I’ll give that a try for now, and if I come up with something better in the meantime then I’ll try that, instead.


massung
2019-4-24 21:45:42

@massung has joined the channel