02Geek HTML5 and JavaScript, TypeScript, React, Flash, ActionScript online School
Previous VideoNext Video

Reverse

Digging deeper into our traces we are almost ready to stitch together our temporary corners into our main corners vector. In this video we first take care of our first issue that some times the order of the dots don't match our main vector.

Video Transcript

00:00Now the big question is now what should come first now if we're looking at our application
00:06We know that our value is growing or getting smaller
00:09But that's currently true only because we're between two dots that are getting smaller if our two dots are getting bigger
00:16Then we would expect the first dot and just to make this easier on the aisle
00:21So if we have your zero on one end and we have your 100 on the other end
00:26And now we have your two dots one dot that has well, you know, let's put here a big number
00:31So it's uh, you know, so it's in our real range of numbers. Let's get 600
00:35And now we're putting inside into this range. We're putting two numbers. We're putting one 16
00:41And we're putting the number 155 and the big question is is who comes in first
00:46Because if I already take if I'm taking the first slice and it is important for you to organize it in the right order
00:52Because if I don't then everything is gonna fall apart
00:55So what I really need to do to know is first I need to know what is my direction
01:00after I know my direction I need to know basically if I need to flip or I don't need a flip and
01:06Based on my direction then I could choose to flip or not to flip now
01:10How do we know our direction our direction is really based on that a and B points?
01:14so if a and B if we already know the direction which we do because we stored that information in our in our
01:23Var in our variable there in our a line if I even just do a trace here. I'm just going to trace here the direction
01:31so if we're tracing out our O line and
01:35We're going to trace out our direction. We should be getting here that direction where we're we're heading
01:41In other words, if we it right here for going out of why our real direction and we're really going out of the Y line
01:48So we're leaving the Y
01:50But really the the line that we care about is the X we don't care about the direction what we really care about right now is
01:56The opposite of the direction so it's good that we store that as well. That's our O P Z
02:01and
02:02Our O P Z enables us to then now that we know what our line O P Z is
02:07We could then go to the two different dots and basically ask if we are if our first dot is
02:15Greater in size than our next dot then also our
02:20Point should have a greater
02:23That in the first one should be greater than the last one
02:26On the other hand if it's not then flip it
02:30All right, so let's see how this works. So we're gonna have your we're gonna have to trace this if statement now
02:35so we're gonna ask if
02:38if our
02:39Current line position a so I'm gonna go there to I'm gonna go to that lines
02:44I'm gonna go right into my current corner. So V corners
02:49Want to go into into lock o line dot a that means I'm going to line a which is to our scenario
02:57And I'm gonna ask if our line a
03:02Dot what dot our op line O P Z if our line a in whatever direction
03:09That we're now heading to ours that we're working with if our line is greater
03:15then
03:17the exact same thing only for
03:19the new line
03:21Now this logic I'm even though we're building in this logic isn't really needed in a scenario of when it's the exact same
03:29Doubt but we're building it anyways because we're gonna reuse it
03:32When our dot is not the same dot. Oh actually
03:35Right now we could have just let's just joke step by step. So first of all, we're gonna go to O line B
03:40So we're gonna go to line B and
03:42Basically ask the same question. So we're taking the value in
03:47Line a in the point a we're taking the value 600
03:51This is that the value is you're asking is 600 greater than zero. Okay, so it's 600 is greater than zero
03:58That's good
04:00Now we're gonna ask if that if all of this if all this equation that we just did here if all that equals to what?
04:08to the same relationship with our element, so if a is first and B a second and
04:18We know that we're going that our number basically if it's bigger. That means our number is going downwards
04:26We out we want to ask the same question. So we're gonna ask if our first point in our path points in our V path
04:35if our V path at position zero is
04:39Greater than V path in the last position of V path
04:47Wasn't that complicated right?
04:48so basically what we're doing here basically asking in the more abstract visual way is if 600 is greater than zero and
04:57155 is greater than 116 then probably don't do anything if
05:03This is not true then flip this value. So it will be true
05:07So that way even if this is starting at zero and this is 600 as long as this is bigger if this
05:13First side is bigger than the second side
05:15The first side is second bigger than the second side then they're in we're in the right direction
05:19If it's not both if they're both not the same then flip this one and then they will be the same
05:24So basically this statement this if statement is exactly the opposite of what we want
05:30So we could even say here if it's not equal. That means it's not it's just not and if it's not
05:36Then let's flip it
05:39so if it's not we could just go into our our
05:43Little we could go right back to in our V paths
05:49We could say V paths from now on you equal V paths only in reverse
05:54All right, so let's see this one more time. Let's see our application. Let's see if it's really doing what we're hoping it will do
06:00So first of all if we run our if we run forwards and our number is getting smaller
06:06that means our X value is
06:0998 and
06:11In the end of it. It's a hundred and fifty five
06:16That means the number is getting bigger, so it seems like it flipped even though. We don't really want it to flip
06:20Let's see if they really did flip you run this one more time
06:24Yeah, it definitely did flip so if so basically our flip here didn't really happen the way we wanted to so let's see
06:33Let's see why all right, so
06:35All right, so if our corner
06:39in its current position is
06:42Greater and you know the easiest thing to do in these type of scenarios is let's just trace it all out because then it's easier to
06:49Digest this because it is a lot of a lot of kind of like
06:53Variables and top of variables, so this is our first variable. Let's put here our second variable as well
06:58And we'll put here our
07:03Corners variable as well. You know it's been in a separate line
07:06Trace
07:08It's always the easiest way to solve these type of stuff is always break it apart into another line
07:14Just so you could grab all the information that you need out of it
07:18Oh, so first of all you already I can see a problem first of all I already found my problem even before we did the
07:23Trace, but I'm going to continue onwards
07:24And this is really just the beauty of traces were just by looking again at your variables you find your issue
07:30All right, so first of all my issue is that I didn't actually approach a specific point
07:34I actually wanted to approach that OPZ also at my in these two points
07:38But if I run it
07:39I'll be able to see now that my issue was again that I basically traced out the whole but the whole
07:45the whole point instead of the X only or the Y only
07:50so we could solve that quite easily by just going in here and
07:54adding here that
07:56Y position to the first part and or Y or X it could be either and to the second place as well
08:03So now we have the right now. We have the right relationship now. We probably should keep it at you know if it's not the same
08:11And we could we could probably comment all this out now that we found that issue
08:16and let's see so first of all if we're going forwards that shouldn't flip and
08:21It didn't our X is still bigger than our last X now on the other hand if we're going in the wrong direction
08:29Now what we're hoping is that it will flip if we look at it again
08:32We'll see yep
08:33It is flipping our bigger is always on the top here because our bigger is always on the top here
08:39perfect

Ready to Level Up Your Skills?

Join thousands of learners on 02GEEK and start your journey to becoming a coding expert today!

Enroll Now for Free!