Friday, November 18, 2016

Digest for comp.lang.c++@googlegroups.com - 8 updates in 4 topics

Louis Krupp <lkrupp@nospam.pssw.com.invalid>: Nov 18 02:03PM -0700

On Fri, 18 Nov 2016 12:00:12 -0800 (PST), Shivu <rout.jyoti@gmail.com>
wrote:
 
>> Ben.
 
>Thank you Ben. The problem I am facing is, to get the data for all the pedestrians at single point of time. I am receiving them at different time. The vehicles and pedestrians change their positions but its after a certain amount of time, lets say 5 seconds. I want to do this calculation within that time. This procedure would repeat every 5 seconds when they change their positions.
>So I need a container to hold the data for each pedestrian at each event and could able to append the next entries to the container for the next pedestrians in the next events.
 
Do you really need to store all of that data?
 
To see if I understand what you're trying to do, let's walk through
this using pedestrians and vehicles numbered starting at 1. I know
that array indices starting at zero are natural for us programmers,
but if you're going to interface with normal people, it's better to
start at 1.
 
For each vehicle, store the ID of the closest pedestrian and the
distance to that pedestrian. You could use an array (call it va), and
you could initialize each element to pedestrian zero and a very large
distance:
 
va[i].p = 0;
va[i].d = 100000000;
 
for each vehicle ID i.
 
When you get a report that pedestrian p is distance d from vehicle v,
see if va[v].d < d. If it is, set va[v].d to d and set va[v].p to p.
If va[v].d >= d, do nothing.
 
When you have to do your periodic report to the pedestrians, loop
through va and tell whoever needs to know that vehicle v is distance d
from pedestrian p.
 
As Ben said, you should think about what to do if two pedestrians are
the same distance from a vehicle and all other pedestrians are farther
away. I don't have a really good answer to that except to say that if
this is a real-world application in which vehicles will be driven to
pick up the closest pedestrian you'd want to make sure that
pedestrians with, say, higher ID numbers don't consistently get
preempted by people with lower IDs.
 
If you just pick the first pedestrian to report in case of a tie, or
if you pick the one with the most recent report, I think you should
add a comment to reflect the fact that's it's a conscious decision.
 
I have to admit that dealing with a tie isn't something I would have
thought of.
 
Louis
Shivu <rout.jyoti@gmail.com>: Nov 18 03:03PM -0800

On Friday, November 18, 2016 at 10:05:44 PM UTC+1, Louis Krupp wrote:
 
> I have to admit that dealing with a tie isn't something I would have
> thought of.
 
> Louis
 
Thank a lot Louis, I am trying this way.
A small doubt though, distance is a double data type. I did not understand the following part:

va[i].p = 0;
va[i].d = 100000000;
 
Is va a 2-D array? How to initialize pedestrian id and distance as elements in that array?
Ian Collins <ian-news@hotmail.com>: Nov 19 11:46AM +1300

On 11/19/16 10:01 AM, Richard wrote:
> have to steal it from another company". Most of the people I
> interviewed were in the early part of their career and while some
> people answered these questions, most people failed.
 
Most of the people we recruit here are from off-shore. I can only see
that pool of available good talent growing in the light of recent events...
 
--
Ian
Popping mad <rainbow@colition.gov>: Nov 18 09:10PM

On Fri, 18 Nov 2016 12:14:35 -0800, red floyd wrote:
 
> *THINK* he's trying to use an initializer list. I've already told him
> his syntax for that is wrong.
 
no I am not. Nor was I doing that before. I'm building accessory
methods to private data. It happens to be a copy constructor and there
is no initializer list. I did wonder if I could, however, condense this
into an initializer list, in this case, because I am accessing a
parameter and then evaluating its value, which is a class instance, and
calling a member of the class which returns a value with is assigned to a
member of 'this'.
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Nov 18 11:16PM +0100

On 18.11.2016 22:10, Popping mad wrote:
> parameter and then evaluating its value, which is a class instance, and
> calling a member of the class which returns a value with is assigned to a
> member of 'this'.
 
You'd better express that as an initializer list.
 
I.e.
 
Node( Node const& other )
: parent{ other.parent }
, right{ other.right }
, left{ other.left }
, value{ other.value }
, max{ other.max }
{}
 
But this is what the default copy constructor will do, and it will not
forget to copy over some item.
 
So really you should write
 
Node( Node const& other ) = default;
 
Or even better, just not declare any copy constructor at all.
 
Cheers!,
 
- Alf
legalize+jeeves@mail.xmission.com (Richard): Nov 18 09:05PM

[Please do not mail me a copy of your followup]
 
ruben safir <ruben@mrbrklyn.com> spake the secret code
 
>Does anyone know of any sample code for reading PNG files that doesn't
>include using libpng.... just straight direct access.
 
If I were to make a C++ PNG parser/emitter from scratch these days, I
might use Boost.Spirit (parser framework that can handle binary blobs
quite easily). Another approach might be to overlay a chunk iterator
view on top of the raw PNG stream. This would avoid copying of data
and might result in something really fast for reading. For writing,
its just a stream of chunks that are defined according to the things
in them. I don't think there's a way you can avoid at least 1
copying of data into an internal buffer when doing writing. I'm just
brainstorming here, so I could be wrong.
--
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
The Terminals Wiki <http://terminals-wiki.org>
The Computer Graphics Museum <http://computergraphicsmuseum.org>
Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com>
legalize+jeeves@mail.xmission.com (Richard): Nov 18 09:06PM

[Please do not mail me a copy of your followup]
 
Popping mad <rainbow@colition.gov> spake the secret code
 
>On Tue, 15 Nov 2016 12:06:12 -0800, Rick C. Hodgin wrote:
 
>> On Windows
 
>/dev/null
 
Nope, Windows uses NUL:.
--
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
The Terminals Wiki <http://terminals-wiki.org>
The Computer Graphics Museum <http://computergraphicsmuseum.org>
Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com>
legalize+jeeves@mail.xmission.com (Richard): Nov 18 09:07PM

[Please do not mail me a copy of your followup]
 
Popping mad <rainbow@colition.gov> spake the secret code
 
>On Wed, 16 Nov 2016 00:15:06 +0100, Christian Gollwitzer wrote:
 
>> https://github.com/lvandeve/lodepng
 
>ah, that is good. Thank you.
 
Interesting, didn't know about that one.
 
"It's made for C (ISO C90), and has a C++ wrapper with a more
convenient interface on top."
 
Oddly, these days this sort of approach feels backward to me. I'd
rather see a library written in C++ with a C wrapper on top.
--
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
The Terminals Wiki <http://terminals-wiki.org>
The Computer Graphics Museum <http://computergraphicsmuseum.org>
Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com>
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com.

No comments: