« first day (5 days earlier)    last day (15 days later) » 

Flo
Flo
20:13
Hi @Rob. Do you have few minutes to help me with a function ?
Rob
Rob
20:40
Sure, what’s up?
Hey @Flo!
Flo
Flo
Hello !
Yeeeee !
Rob
Rob
🙂
Flo
Flo
Finally I found you :D
I worked a lot to your functionality and I make it work when I draw outside of the canvas
Rob
Rob
I’m spending time working on a startup and have been crazy busy. So, quickly, what’s up?
Flo
Flo
I replaced all negative values with 0 to avoid all the crash
Now I have a problem with my function which resize back all CGPoints
Rob
Rob
20:44
OK
Flo
Flo
Let's me show you fast
Rob
Rob
FWIW, my idea was to translate the CGPoint in the scribbles from 0.0-1.0 of the bounds so that the scribbles could be rendered regardless of resolution (e.g. you rotate device, you go split screen on iPad, etc.). And then you’d multiply those by 240 for serialization.
Flo
Flo
This is how I serialize the CGPoints
Rob
Rob
Let me take a look.
Flo
Flo
And this is how I deserialise the CGPoints back:
Rob
Rob
20:47
Ok, so what’s the issue, again? You have negative values or exceed bounds.width, for example?
Flo
Flo
After I deserialise the CGPoints back I need to rescale all of them like this (and here is the problem ):
Rob
Rob
I don’t see you scaling the bytes in parseScribbleData` back.
Flo
Flo
Because I didn't knew how to rescale the bytes there
Rob
Rob
I’d expect something like let x = bytes[index] * scale where scale was something like bounds.width / 240.
Flo
Flo
So I created a different function
Rob
Rob
20:50
Whatever scale you multiplied during serialization, you have to divide by during deserialization. (Or vice versa.)
Flo
Flo
How can I do that rescale in the parseScribbleData(_ bytes: [UInt8]) -> [[CGPoint]] function?
In this small project works perfectly: github.com/tygruletz/SelectScribblesUsingBinaryData
Rob
Rob
Pass the bounds as a parameter to that method.
Flo
Flo
But in my main project when I send the canvas from a screen to another screen and at the end I save the report in DB after I get the CGPoints back and rescale the CGPoints, these will be in a different place.
Rob
Rob
In scaleCGPoints you pass the CanvasView (I might just pass the bounds, but it achieves the same thing). I’d do the same thing in parseScribbleData. And I’d do a test where I pass the scribbles, convert to UInt8 with one function and convert back with another function and make sure the values were close (they’re going to be slightly different because that UInt8 structure throws away valuable information, but you’re stuck with that).
But the serialize and deserialize functions should do all of the factor adjustments (not trying to clean it up later).
And multiply by factor in one and divide in the other and confirm that the factor for both was the same.
Now, all of this assumes that the bounds.width, for example, is the same during capture and review.
Flo
Flo
Yes is the same
Rob
Rob
20:58
Or if the image in the table view is a little narrower, for example, then obviously the factor in deserialize would need to be different.
Flo
Flo
Same width and height and also same aspect ratio: 240:127
Rob
Rob
So, when you serialize and deserialize, how do the values of input to serialize and the output from deserialize compare? (Just look at the first few values and any issues should jump out at you.)
This will help you isolate the problem. Is it the serialization/deserialization? Or is it the rendering on the canvas?
Flo
Flo
When I serialize I have this values in array (using only a simple dot somewhere on the screen ):
Stroking true: [(124.33332824707031, 27.0), (124.33332824707031, 27.0)]
Rob
Rob
You said:
> Same width and height and also same aspect ratio: 240:127
Flo
Flo
when I deserialize back I have:
Stroking true: [(123.4375, 26.5625), (123.4375, 26.5625)]
Rob
Rob
21:01
You said:

> Same width and height and also same aspect ratio: 240:127

Fine, same ratio. But is the actual width the same?
OK, those values look like the serialization isn’t likely the issue. So I question whether the actual width of the two canvases (not just the aspect ratios, but the resulting widths) are the same.
Flo
Flo
Here is a capture from the main project: recordit.co/VLbGY41OtD
If I click the row 2 times will refresh the canvas and I will get the CGPoints in almost the same position
But I want that CGPoints to be there from when I review the report.
This is why I think is because I don't rescale the CGPoints in the right place.
Im doing the rescale in a function called in the cellForRowAt
Which is called when the cell is refreshed
Not when the view is loaded.
And all of this because I'm using that canvas parameter to that function. And I don't know how to replace it or to do the rescaling when I deserialise.
Do you think you can help me to rescale the CGPoints here?

func parseScribbleData(_ bytes: [UInt8]) -> [[CGPoint]] {

guard bytes.count % 2 == 0 else {
print("The scribble data is corrupted: odd number of bytes")
return []
}

var result = [Scribble]()
var current: Scribble? = nil
var index = 0

while index <= bytes.count - 2 {
let x = bytes[index]
let y = bytes[index + 1]
let hasMarker = y & Scribble.yMarkerBitmask == Scribble.yMarkerBitmask
let point = CGPoint(x: CGFloat(x), y: CGFloat(y & ~Scribble.yMarkerBitmask))
Rob
Rob
It looks like two problems. One, your initial render is off. Second, even after you click on the second time, they’re not close to where they should be.
So, you’re not applying the factor during this deserialization. You’re probably getting CGPoint that have values between 0 and 240, I would have thought.
Flo
Flo
I know they are not close :( In my small project they are exactly where they should be.
Rob
Rob
You are rescaling in cellForRowAt. But the frame of the cell when it’s first presented won’t be right at that point (not the first time you call it, anyway). Constraints haven’t been applied, IIRC.
In cellForRowAt, print cell.reviewCanvas.bounds. I bet when you call it the first time and when you call it the second time, you’ll have different values.
I bet the first time you call it you’re probably getting whatever size it was in the storyboard (not adjusted for the user’s actual device). But when you select row second time (and it reloads the cell), the constraint has been applied.
Rob
Rob
21:18
So reviewCanvas.bounds is different the first time, right?
Flo
Flo
Yes is different
First time have this values from the Storyboard
After that the size is going crazy
cell.reviewCanvas.bounds: (0.0, 0.0, 414.0, 200.0)
From where that values...
Rob
Rob
Yep, because the first time, constraints have not yet been updated, so it’s assuming 375 wide, later updated to 414.
Flo
Flo
Is possible somehow to do the rescaling directly in the CanvasView ?
To be able to run the app also on iPad ?
Rob
Rob
This is precisely the problem I was thinking I was thinking you could solve by refactoring this so the serialization and deserialization should just multiply and divide by 240, respectively, and then do the subsequent scaling by bounds in the canvas view.
Exactly.
Flo
Flo
Do you think you can help me with this refactoring ?
Will take me 1 month
Rob
Rob
21:24
That way, we don’t care what the bounds is in cellForRowAt.
Flo
Flo
Exactly
I don't need to worry about a lot of parameters
And to care about if the user rotate the screen
Now I locked that ViewController on Portrait mode only just to avoid this issues
Rob
Rob
Give 20 min or so and let me take a look at your latest repo.
Flo
Flo
Thank you !
Rob
Rob
21:50
Take a look
Fixes rendering problem when reviewing, methinks, and plus you can now rotate device, etc.
Flo
Flo
Omg !
Thank you !!!
I check right now !
Rob
Rob
This still hardcodes assumptions about the fact that serialization expects 0-240 for x and 0-127 for y, that the scale of the image view happens to match, that serializer loses precision of touches, etc. All of that is not great. But hopefully it should at least work and you can work on it from here.
Flo
Flo
This is amazing
I don't use anymore that canvas parameter everywhere
Rob
Rob
Yep.
Flo
Flo
Was a nightmare in my project where I had canvasViews for signatures
Rob
Rob
21:57
See you around. Bye.
Flo
Flo
Thank you so much !
Have a great day !

« first day (5 days earlier)    last day (15 days later) »