meltedlilacs / ben

Bright Enough to Navigate
Other
0 stars 0 forks source link

List doesn't work when the same object is added multiple times #1

Closed meltedlilacs closed 10 years ago

meltedlilacs commented 10 years ago

Because at this point the pointer is stored in the same object as the data (Node), if the same object is added twice in a row, there is an infinite pointer loop when attempting to add a third object, causing the program to crash. This would also be an issue if the List was longer, with the same object inserted twice, as it would cause jumps in the linked list, and it would no longer be linear.

Possible fixes:

meltedlilacs commented 10 years ago

I think creating a Data class and inheriting from it is not the best design, since the Data class would add no useful methods or variables to the class, it would simply be trying to replicate the behavior of a template. So I think the template method is probably the better one.

metaporia commented 10 years ago

just do the template thing. i don't see why our original list design doesn't work but... k

metaporia commented 10 years ago

can you just put a clause in that prevents adding the same object? i think that would be easier since it would avoid using the template while not adding superfluous code (like a data class) k

On Thu, Jun 26, 2014 at 4:02 PM, Keane Yahn-Krafft < thisaintforuruse@gmail.com> wrote:

just do the template thing. i don't see why our original list design doesn't work but... k

meltedlilacs commented 10 years ago

But what if a Square was scanned twice from the same position? We would want the probability weighted more towards the number of Square's in both of those scans, so preventing duplicates would throw off the probability.

metaporia commented 10 years ago

since the position is based on the position of each sensor, more than one scan from a given position is pointless because that will make it even more precise (we should add a tag that specifies which sensor is was scanned by so if it is triggered by another after a partial rotation it registers). or better yet, have the list of postion's scanned from be a separate type of list that is a pointer to a Square and a sensor number

On Thu, Jun 26, 2014 at 5:24 PM, Gabriel Damon notifications@github.com wrote:

But what if a Square was scanned twice from the same position? We would want the probability weighted more towards the number of Square's in both of those scans, so preventing duplicates would throw off the probability.

— Reply to this email directly or view it on GitHub https://github.com/GabrielD42/ben/issues/1#issuecomment-47296018.

meltedlilacs commented 10 years ago

Yeah, so if we used a template class, it would be a pointer to a template object (in this case a Square). I'm confused why we need the sensor number, though.

metaporia commented 10 years ago

using a new struct for the scannedFrom list would eliminate having a list of squares, and the sensor number would help specify the location of each scan and allow for us to eliminate adding duplicate scans while keeping scans from the same center point of teh robot, but from a different angle with a different sensor. the class would have: pointer to square sensor number

On Thu, Jun 26, 2014 at 8:55 PM, Gabriel Damon notifications@github.com wrote:

Yeah, so if we used a template class, it would be a pointer to a template object (in this case a Square). I'm confused why we need the sensor number, though.

— Reply to this email directly or view it on GitHub https://github.com/GabrielD42/ben/issues/1#issuecomment-47305659.

metaporia commented 10 years ago

and (append this to the class): pointer to next part of the list (i'm hesitant to say node because that would be a different class)

On Fri, Jun 27, 2014 at 10:50 AM, Keane Yahn-Krafft < thisaintforuruse@gmail.com> wrote:

using a new struct for the scannedFrom list would eliminate having a list of squares, and the sensor number would help specify the location of each scan and allow for us to eliminate adding duplicate scans while keeping scans from the same center point of teh robot, but from a different angle with a different sensor. the class would have: pointer to square sensor number

On Thu, Jun 26, 2014 at 8:55 PM, Gabriel Damon notifications@github.com wrote:

Yeah, so if we used a template class, it would be a pointer to a template object (in this case a Square). I'm confused why we need the sensor number, though.

— Reply to this email directly or view it on GitHub https://github.com/GabrielD42/ben/issues/1#issuecomment-47305659.

meltedlilacs commented 10 years ago

How would the sensor number be any more specific then simply knowing where the sensor was when it took the reading? Although something we do have to consider is recording two sensor positions: where it was when it sent out hte pulse and where it was when it received it.

metaporia commented 10 years ago

because the location of the robot is a pointer to a square which wouldn't give any information about which side the scan was coming from. it wouldn't be more specific than knowing whee the sensor was at the time of the scan, but doing the calculation for the sensors location before hand, and creating a new struct with it, would avoid the duplicate Square problem

On Fri, Jun 27, 2014 at 11:56 AM, Gabriel Damon notifications@github.com wrote:

How would the sensor number be any more specific then simply knowing where the sensor was when it took the reading? Although something we do have to consider is recording two sensor positions: where it was when it sent out hte pulse and where it was when it received it.

— Reply to this email directly or view it on GitHub https://github.com/GabrielD42/ben/issues/1#issuecomment-47387369.

meltedlilacs commented 10 years ago

I was thinking of having the list of Square's scanned from being the Square each sensor was currently above.

meltedlilacs commented 10 years ago

Ok, so we will create a child class of List that will only store 1 of each object in it. To accomplish this it will use comparison operators to order the list, meaning that Square should override the equality operators.

meltedlilacs commented 10 years ago

I guess I shouldn't close it until we fix the issue

meltedlilacs commented 10 years ago

List no longer fails when the same object is added twice, because each node is different, and points to the same data