From Theory to action
After all this talk lets make it happen. Breath deep and lets jump into finding the actual points that our dot is between.
Video Transcript
00:00So my X is changing that means is X or you know what let's call it
00:05Let's do it with the with the Y. Well, let's do it the X is X for us will mean that
00:11This is what's not moving is X is what's not moving. Okay. Now if is X is not true. That means the Y is moving
00:18All right
00:18So now we know what direction we're going the last thing that's left for us is the last thing that is left for us
00:24It's to cycle through the corners to search for the actual actually for the dot that hasn't that is the dot that's being changed
00:31Alright, so let's see how that is gonna roll. So first of all, I want to go to my corners that was just created and
00:39I want to run through and I just go back down here into our get line first want to create my length
00:48Which is an integer could get the length then we're gonna loop through
00:52I'm going to loop through the corners
00:58Now the reason why I'm putting the length inside of a separate variable is because the length is the function
01:05We started learning about getters and setters. So now that we know that length is the function our loop is going to call that function a
01:13Lot of times now if I just put into a variable now, I don't have to call a function that takes less on the system
01:20Automatically, I just saved some for my system. So this is really just about her keeping this keeping our code more efficient
01:27All right, so I'm in my for loop. Now the next step for me is I could ask here if
01:32Our is X is true. Then what do we want to do?
01:35We want to test to see if our X has changed if our Y is true
01:40Then we want to test if our Y has changed now, we could use an if statement or we could use a
01:46Different mythology, but let's start with the let's start using an if and then we might change it, right?
01:51So with an if statement, what would we put in our if so we have your our dot which is our new?
01:55The corners I we're in a specific dot right now
01:59What do we want to know because we know that the X is not changing. We want to know if they're if our X
02:08Correlates to the X inside of our application. So if I take that X I could ask it if it equals to my
02:16Point dot X we could trace that out
02:23Just so we could see it. Let me just put here a little comma here
02:29So we could look at it
02:30So we're only testing X because now we know that it's going to be X true
02:35Hopefully and let's see. Let's just fix any errors we have here
02:39Expecting a semicolon because we didn't put here an equal
02:42Run it one more time. Alright, so let's see how it works. So if we stop this just for a second
02:49So first of all, we're let's let's see what's going on here
02:51First of all, we're testing the wrong thing right because we need the Y and we're testing the X
02:57So so our logic is is some sort of some issue in our our is X
03:02Is not the right thing, right? So we basically wanted to do this only
03:06What we wanted to do if it is the X we wanted to test the Y
03:10So we're gonna do that to the Y instead. That was our mistake
03:13so if our X is not changing we want to change we want to check if our we want to check our Y and
03:22Here we go. So
03:24There we go. So first of all
03:26We have here a false false and then we have a true and a true
03:29Why do we have a true and a true because our Y?
03:33478 is true both here and here now
03:37That's so far so good, but that doesn't really give us our dots
03:42Right because even though our Y is 478 or maybe it does right if we look at our application currently at this second
03:48It does but that that's not gonna fly
03:51the reason is that the reason why this is not going to fly is because
03:56Currently when we have only a square and we got those two dots. We got C and D here. It's true right now
04:02We are really here and we are really between C and D
04:07Unfortunately as our application gets more
04:10You know more built and we have already a square here. And if I try to start from here
04:16I'm still gonna get true for this and I'm still gonna get true for this
04:20So it's not good enough. It is good. Definitely. We're in a good shape
04:24We were definitely in a good place that we know that our X is definitely
04:28Probably is probably between these two points is probably between our Y
04:35Are between our Y and X between 2 and 3 18
04:40Unfortunately for us though, we don't know if it's a guaranteed slam dunk
04:45Alright, so the next step for us is actually to confirm also our X position to confirm that our position is really between those two dots
04:53And there aren't any other well
04:56we don't even have to worry about other dots because if we go through the cycle and our dot is our X is between
05:03This value and that value if it's between this and that value then I don't really care. There's others
05:09Now if it's not between those two values, then I do care
05:13So my next test my next question would have to be if my X 155 is between 2 and 3 18
05:21How are we gonna do that?
05:22So the easiest way to do it because we know that if our dot is true
05:27We could assume that the next dot is true as well. If there is a next dot now
05:32If there isn't an X dot then we have a problem, but because our loop will complete before the length is over
05:39We could almost make an assumption, but not really where we're very close to making assumptions show
05:45Assumption, but one thing that we could do just to make our lives easier instead of adding here extra logic
05:50We could go back into our application and just add one extra dot of virtual dot that doesn't really exist
05:57This virtual that will be just the initial dot that we started with that way even if we do find a dot
06:03That's like towards the end such as let's say this is going to be zero
06:07There's gonna be between between these two dots between this dot and that dot
06:11But we don't we didn't have a relationship here because our array was ended our vector is over
06:18So we just lended the dot that is just going to be there because it makes our life easier
06:22So it's kind of an overlapping dot
06:24It's the same that as the first one and the reason why we're doing that is because we want to keep our our code
06:29We want to keep our function right here that we're working on the get line
06:33We want to keep it simple now in our scenario back to our code
06:37We know that y and y are true the next thing that we want to ask we want to make sure that end
06:43We want to make sure what we want to make sure that our dot is between those two dots now. How could we do that?
06:50The best way we could do that is we could probably first of all
06:55We want to align them based on the right order right so we if we're gonna if we're gonna take a value
07:00And this value is let's say this is 50 is 30 and we're at 40
07:06now we might ask if 50 is greater than 30 and
07:11is smaller than 80
07:14Or another way around it could be either either this either
07:18It's bigger than this and smaller than that or smaller than that and equal to that so it has to be in this range
07:24basically
07:26To be able to find a range the best way for us is instead of doing this calculation is we could say this is our
07:32Find the smaller number the smaller number is going to be our starting point
07:37We'll subtract the two values will subtract the value from the highest worse if this is 30
07:44We'll subtract 30 from C 30 from our middle number, and then we'll just make sure that our number is smaller than C
07:51Because that would that would probably be the easiest way for us to solve this without adding a without creating a complicated if statement
07:58All right, so let's try this now. You might have a better solution, which I obviously strongly recommend that you
08:05Put it up and show and show it to us, but let's see what we're doing so first of all what I want to do is
08:10I'm going to create a variable just as we said and a variable is going to be a really simple
08:17integer a simple number, so it's going to be an
08:20Number and that number is going to be a math
08:27floor no math
08:30min
08:31Where in math min is going to we're going to take two values or?
08:35our v Corners X or
08:40our v Corners I plus one and now because we know and we probably need to make sure now that we're going through the length
08:46That will go through length minus one because we added one item that we don't want to cross
08:51Okay, and that will enable us to make sure that we never get an error
08:55So we want to make sure that we want to take our X. We want to take our Y. We're sorry X in the
09:00current point and the next point and
09:06When we take these two points we want to end and by the way we also
09:11Going back to this we want to make sure that if our Y here is true
09:14But not only that is a true that and is a true also for the next one right because that's what we just did
09:20When we're showing in the sample, so we only want to take only want to take the point when it's true on both directions
09:26Not only we want to take it when it's true on both those directions
09:29We want to take it also when the value is between those two digits that we're going to see in a second
09:34alright, so and
09:37We have our minimum value, so we got ourselves that little minimum now. We could trace on top of that put your little
09:46What do we want to trace on top of that?
09:47We want to take our current point, and we want to ask is our current point in the range of our?
10:00two dots, but sorry for
10:04Scrambling there for a second, okay, so let's see how this works
10:06So we already know the smallest number
10:09Now we just have to take the biggest number subtract the biggest from the smallest then we have our range
10:14After we have our range we could subtract the smallest number and just make sure that we're still inside of that range now because our
10:21Values are always positive inside of our flash because we're in the positive area
10:27We don't have to worry about negatives at all because there aren't negatives everything everything in our application starts from zero zero
10:34And it's always positive the negatives are outside of my screen
10:37So I don't have to worry about negatives which makes my life easier, so I don't even have to worry about negatives
10:42So the next value here is I want to take my I'm just going to break it down because I make it easier
10:46So this is going to be a top about top value
10:50Just going to be a number as well. What do I want to do? I want to take my
10:56Max number for the same two here, and I could subtract from that max the number which is the number that we've just got here
11:06Now I have my range because I now I have the number where it started from and I have my my
11:12range of numbers last step that I have left is actually to take my current
11:20Last step that I have left is to take my current x-position in my point so I could take my point there px and
11:28then what I want to do is I want to check to see if it's
11:32smaller or equal
11:35to that range
11:37This price should call this range if it's smaller or equal to range then we're good. We're completely good. So let's let's see this just
11:47running so we're on our application just one more time, and let's see what's going on here, so first of all
11:57We first test to see if our dot and we're seeing this in our trees first of all
12:01We're testing to see if we're in between the two dots that are
12:050 2 and 3 18 no are we between 3 18 and 3 18 no are we between 3 18?
12:12478 and 478 yes, we are
12:16Okay
12:16So this now, let's just condense all this what we just created here
12:20So now that we could condense all this we really want to ask a simple question
12:24our simple question basically is if
12:28if we if we are true to this and we are true to that
12:35Then we're then we're rolling right so we don't really even need to do this if that's not true
12:40So we can even just start here if that is true
12:45All right, so if that is true
12:47and we could probably hear another if statement if
12:55The range is true
13:00If that is true
13:01Let's just trace out just quickly something and we will fix it later on if that is true
13:06Then what do we want to trace out? We want to trace out the two dots that were in between
13:10So we want to trace out I and I plus plus
13:14High plus one we don't want to upgrade I so let's see this
13:18Run our application one more time and here we go
13:22So now we got the values that we care about now
13:24We know that we're between the two dots two and three zero one two three. So we know we're between dots two and three
13:30That's where we're starting
