spdegabrielle
2019-9-5 10:29:36

Summer picture competition community choice

You don’t have to choose - you can vote for as many favourites as you want!

Vote early, vote often, because voting ends Sunday afternoon uk time.

https://forms.gle/G9r8saiQXqjirkAi8


spdegabrielle
2019-9-5 12:28:09

I forgot to mention the prize is a limited edition racketeer cap. As far as I know racketeer caps are the most popular and desirable swag. ‘Rare as hens teeth’. Priceless maybe.


dasheng523
2019-9-5 12:29:49

@dasheng523 has joined the channel


samth
2019-9-5 14:54:47

@mflatt apropos of your recent change to parameters on racketcs, I had contemplated a different idea, and I wonder if you thought about it: trying to determine in schemify if a value was a parameter and then explicitly introducing the code to access the parameter value. I suppose that could still be done in schemify, although it’s a little tricky with the closure representation for default values.


mflatt
2019-9-5 14:59:27

Yes, that could work. I can imagine changing the application of a parameter to be a call to unsafe-parameter-ref and still avoid a jump or two that way. Probably a smaller additional effect than the representation change, but possibly worthwhile. I’ll put that on my list of things to try.


mflatt
2019-9-5 16:48:37

Nice idea, but doesn’t seem to speed up a microbenchmark that just accesses a parameter.


samth
2019-9-5 16:52:59

Can you share the branch that tried this out? I’m interested in looking at the generated code


mflatt
2019-9-5 16:56:40

mflatt
2019-9-5 16:57:05

Technically not complete, since I didn’ update “http://internal.ss\|internal.ss” and “built-in-symbol.rkt”, but close enough.


mflatt
2019-9-5 16:58:23

I think all the time is in parameter-cell and thread-cell-ref, but I could be wrong.


notjack
2019-9-5 18:16:30

I finally published a basic transducers API! https://docs.racket-lang.org/rebellion/Transducers.html


spdegabrielle
2019-9-5 18:47:48

Summer picture competition community choice

You don’t have to choose - you can vote for as many favourites as you want!

Vote early, vote often, because voting ends Sunday afternoon uk time.

https://forms.gle/G9r8saiQXqjirkAi8


spdegabrielle
2019-9-5 18:48:29

Votes needed


soegaard2
2019-9-5 19:43:55

I have a problem that could need a couple of new eyes.


soegaard2
2019-9-5 19:44:41

In MetaPict bezier curves are represented as (bez p0 p1 p2 p3) . The curve goes from p0 to p3 and the control points are p1 and p2.


soegaard2
2019-9-5 19:45:29

The function bez-intersection-point-and-time calculates an intersection point between two bezier curves b1 and b2.


soegaard2
2019-9-5 19:46:12

It works in most cases - but I have found an edge case, where I get an infinite loop.


soegaard2
2019-9-5 19:46:31
#lang racket
(require metapict)

(define b1
  (bez (pt -4.999999999999893 2989.799999999806)
       (pt -4.999999999999893 2989.7999999998056)
       (pt -4.999999999999893 2989.7999999998056)
       (pt -4.999999999999893 2989.7999999998056)))
(define b2
  (bez (pt -4.999999999999893 2989.799999999806)
       (pt -4.999999999999893 2989.799999999806)
       (pt -4.999999999999893 2989.799999999806)
       (pt -4.999999999999893 2989.799999999806)))

(bez-intersection-point-and-times b1 b2)

soegaard2
2019-9-5 19:47:39

The bezier curve b2 has p0=p1=p2=p3 which means it represents a point.


soegaard2
2019-9-5 19:48:01

The other bezier curve b1 is almost the same point.


soegaard2
2019-9-5 19:48:22

The function is defined here:



notjack
2019-9-5 19:48:48

quick idea: switch to #lang exact-decimal racket and see what happens


soegaard2
2019-9-5 19:50:25

Is the effect of exact-decimal to make the reader turn floating points numbers into exact numbers?


notjack
2019-9-5 19:52:00

yes, it makes 4.999999999999893 read as that exact value instead of reading as the base–2 floating point value that most closely approximates it


samth
2019-9-5 19:53:00

I also see no performance improvement. I was, however, motivated to look at what parameters are used a lot; turns out current-namespace and current-locale are called many many times. I’ll try to post the numbers later.


soegaard2
2019-9-5 19:57:47

I don’t think there will be an effect: > (read (open-input-string "-4.999999999999893")) -4.999999999999893


soegaard2
2019-9-5 19:58:49

Also the first thing the function bez-intersection-point-and-times does is to convert into inexact numbers in order to avoid exact fractions (which have a tendency to grow very large).


notjack
2019-9-5 19:59:23

ah so probably not gonna do anything useful then


soegaard2
2019-9-5 19:59:45

Let me attempt to explain the algorithm.


notjack
2019-9-5 20:00:24

reading through that function, I don’t see any recursion or looping constructs


notjack
2019-9-5 20:00:47

Oh wait, now I see - you aliased the function to again


soegaard2
2019-9-5 20:01:06

The parameter t belongs to b1 and runs from 0 to 1, which corresponds to the beginning point p0 and the end point p3 respectively.


soegaard2
2019-9-5 20:01:26

Yes.


soegaard2
2019-9-5 20:02:08

During the search the interval becomes smaller and smaller and goes from t- to t+.


soegaard2
2019-9-5 20:02:26

Likewise the interval for the second curve is from u- to u+.


soegaard2
2019-9-5 20:03:36

First the bounding boxes (non-tight) of b1 and b2 are computed.


soegaard2
2019-9-5 20:03:58

If the bounding boxes doesn’t overlap, then the curves have no intersection, and #f is returned.


soegaard2
2019-9-5 20:05:04

If the bounding boxes overlap and are very small (practically a point), then the point in the center is returned and we have found an intersection point.


soegaard2
2019-9-5 20:05:48

If the bounding boxes overlap but aren’t small, then the two curves are split in two halves.


soegaard2
2019-9-5 20:06:01

b1 is split into b11 and b12


soegaard2
2019-9-5 20:06:08

b2 is split into b21 and b22


soegaard2
2019-9-5 20:06:59

Then the search continues for intersection points between the four possibilities.


soegaard2
2019-9-5 20:08:02

The idea is of course that the curves gets smaller.


notjack
2019-9-5 20:10:14

My approach to debugging it would be to gut it by splitting it up into smaller functions, maybe adding some structs to bundle together related values, and replacing the recursion with something easier for my brain to statically analyze. As is I have no idea why it loops forever.


soegaard2
2019-9-5 20:12:01

It “looks” correct, but I must be missing something.


notjack
2019-9-5 20:15:58

Could you add some comparison functions that explicitly take a tolerance param, to make it easier to verify that that’s being handled correctly? Like these:

(define (fuzzy=? x y #:tolerance [tolerance <very small default value>])
  (define delta (abs (- x y)))
  (<= delta tolerance))

(define (fuzzy<? x y #:tolerance [tolerance ...]) ...)
... similar for >, <=, >=, etc. ...

Then you could 1) unit test the hell out of them, and 2) run them through Herbie (https://herbie.uwplse.org) to check that floating point isn’t doing something weird.


soegaard2
2019-9-5 20:17:32

I did try the above approach but I couldn’t find the right spot.


soegaard2
2019-9-5 20:18:26

I need to step though all the temporary results and see if they match what I expect.


soegaard2
2019-9-5 20:20:21

I have found one odd thing. The bounding box for b1 in the examples is not small.


soegaard2
2019-9-5 20:20:35
bez.rkt> (define b1
  (bez (pt -4.999999999999893 2989.799999999806)
       (pt -4.999999999999893 2989.7999999998056)
       (pt -4.999999999999893 2989.7999999998056)
       (pt -4.999999999999893 2989.7999999998056)))
bez.rkt> (bez-large-bounding-box b1)
(window
 -4.999999999999893
 -4.999999999999893
 2989.7999999998056
 2989.799999999806)
bez.rkt> (def ε 1e-15)
bez.rkt> (define (very-small? w)
    (defm (window x- x+ y- y+) w)
    (and (<= (- x+ x-) ε)
         (<= (- y+ y-) ε)))
bez.rkt> (very-small? (bez-large-bounding-box b1))
#f

soegaard2
2019-9-5 20:22:27

In this edge case b1 is an vertical line and b2 is a point.


soegaard2
2019-9-5 20:22:59

Maybe I should special case points and vertical/horizontal lines?


soegaard2
2019-9-5 20:25:36

Or perhaps I should make sure that the split curves b11 and b12 actually are different from b1.


notjack
2019-9-5 20:26:09

¯_(ツ)_/¯


jaz
2019-9-5 20:26:38

> Or perhaps I should make sure that the split curves b11 and b12 actually are different from b1.


jaz
2019-9-5 20:26:45

That’s what I was going to suggest


jaz
2019-9-5 20:27:35

In this case, b11 is the same as b1


notjack
2019-9-5 20:29:03

@soegaard2 what’s defm do?


soegaard2
2019-9-5 20:29:16

That’s short for define-match.


soegaard2
2019-9-5 20:29:25

defv is short for define-values


soegaard2
2019-9-5 20:29:30

def is short for define


notjack
2019-9-5 20:30:03

ahh


notjack
2019-9-5 20:30:17

So is window a struct somewhere then?


jaz
2019-9-5 20:30:32

structs.rkt


soegaard2
2019-9-5 20:30:39

(struct window (minx maxx miny maxy))


notjack
2019-9-5 20:33:57

Poking around structs.rkt now out of curiosity


soegaard2
2019-9-5 20:35:54

After inserting checks and displays I see that: b11=b1 b21=b2 b22=b2


soegaard2
2019-9-5 20:36:23

So the first of the four recursive calls uses b11 and b21 which are the same as b1 and b2.


soegaard2
2019-9-5 20:36:37

So only the times are changed.


jaz
2019-9-5 20:38:07

what if you change small-bb1? and small-bb2? to check both very-small? and splittable??


jaz
2019-9-5 20:39:06

I mean: (or (very-small? x) (unsplittable? x))


jaz
2019-9-5 20:39:32

where the latter is true if splitting the argument results in a box that’s equal to the argument.


soegaard2
2019-9-5 20:40:05

Sounds like the right place to make a change.


soegaard2
2019-9-5 20:40:41

Let’s see. The place where a point is found is:

(or (and small-bb1? small-bb2?
                (<= (+ (area bb1) (area bb2)) ε)
                (list (window-center bb1) ; point
                      ; todo : instead of the center, find
                      ; the intersection of lines
                      (/ (+ t- t+) 2)     ; time on original b1
                      (/ (+ u- u+) 2)))   ; time on original b2

soegaard2
2019-9-5 20:41:21

So can we ever be in a situation where there is an intersection point, but the curves are splittable?


soegaard2
2019-9-5 20:42:02

Yes… that’s taken care of by very-small?.


soegaard2
2019-9-5 20:42:06

I think it will work.


soegaard2
2019-9-5 20:52:08

And after some testing - it seems to work.


soegaard2
2019-9-5 20:52:14

Thank you both.


soegaard2
2019-9-5 20:53:29

I did this: (defv (b11 b12) (split-bez b1 1/2)) (defv (b21 b22) (split-bez b2 1/2)) (def small-bb1? (or (very-small? bb1) (equal? b11 b1))) (def small-bb2? (or (very-small? bb2) (equal? b21 b2)))


soegaard2
2019-9-5 20:53:39

It bothers me it isn’t symmetrical.


notjack
2019-9-5 20:55:18

thank you too, for a totally unrelated reason: metapict’s structs are a good use case for me to consider for rebellion/type


soegaard2
2019-9-5 20:59:40

I did use quite a few features of struct in that file.


notjack
2019-9-5 21:00:39

do you have any other files in other projects where you define tons and tons of structs?


soegaard2
2019-9-5 21:03:05

Not quite as many, but there are few in remacs: https://github.com/soegaard/remacs/blob/master/representation.rkt


soegaard2
2019-9-5 21:10:59

If you need examples with many structs, scribble has one: https://github.com/racket/scribble/blob/master/scribble-lib/scribble/struct.rkt


markus.pfeiffer
2019-9-5 21:16:50

:exploding_head: NO NOT TWO REMACSES.

which one is older?


soegaard2
2019-9-5 21:17:23

Are you referring to the Rust one?


markus.pfeiffer
2019-9-5 21:17:29

yes


soegaard2
2019-9-5 21:17:46

Then this one is older - but it is a horrible name.


soegaard2
2019-9-5 21:18:29

If (and I doubt it) it ever becomes good enough to use for others than me, then it needs a better name.


soegaard2
2019-9-5 21:19:27

There is also rmacs.


markus.pfeiffer
2019-9-5 21:20:09

Just in case it wasn’t confusing enough :wink:


soegaard2
2019-9-5 21:20:48

I like “Sublime Text”.


soegaard2
2019-9-5 21:21:24

Simple and clear.


notjack
2019-9-5 21:39:36

@soegaard2 both great examples! added to a list https://github.com/jackfirth/rebellion/wiki