map

J

Joy Maitland

I have an imageID and a pair of (X,Y) coordinate

how can I map( X,Y) coordinate as a key to imageID?

for example

(1,1) -> image1
(2,1) -> image5
(5,4) -> image12
(1,9) -> image8
.... etc

what Class object i should use?
any example code ?
 
K

Kai-Uwe Bux

Joy said:
I have an imageID and a pair of (X,Y) coordinate

how can I map( X,Y) coordinate as a key to imageID?

for example

(1,1) -> image1
(2,1) -> image5
(5,4) -> image12
(1,9) -> image8
... etc

what Class object i should use?
[snip]

What about:

typedef int x_coordinate;
typedef int y_coordinate;

typedef std::pair< x_coordinate, y_coordinate > cartesian_2d;
typedef std::map< cartesian_2d, imageID > image_map;



Best

Kai-Uwe Bux
 
J

Joy Maitland

Joy said:
I have an imageID and a pair of (X,Y) coordinate

how can I map( X,Y) coordinate as a key to imageID?

for example

(1,1) -> image1
(2,1) -> image5
(5,4) -> image12
(1,9) -> image8
... etc

what Class object i should use?
[snip]

What about:

typedef int x_coordinate;
typedef int y_coordinate;

typedef std::pair< x_coordinate, y_coordinate > cartesian_2d;
typedef std::map< cartesian_2d, imageID > image_map;

do i use these template lke this:

cartesian_2d coord1 = (1,2);
cartesian_2d coord2 = (3,2);

image_map map1;
map1.add(coord1, 1);
map1.add(coord2, 3);
 
E

Erik Wikström

Joy said:
I have an imageID and a pair of (X,Y) coordinate

how can I map( X,Y) coordinate as a key to imageID?

for example

(1,1) -> image1
(2,1) -> image5
(5,4) -> image12
(1,9) -> image8
... etc

what Class object i should use?
[snip]

What about:

typedef int x_coordinate;
typedef int y_coordinate;

typedef std::pair< x_coordinate, y_coordinate > cartesian_2d;
typedef std::map< cartesian_2d, imageID > image_map;

do i use these template lke this:

cartesian_2d coord1 = (1,2);
cartesian_2d coord2 = (3,2);

No, you have to use the make_pair() function:

cartesian_2d coord1 = make_pair(1,2);
cartesian_2d coord2 = make_pair(3,2);
 
J

Juha Nieminen

Erik said:
cartesian_2d coord1 = make_pair(1,2);
cartesian_2d coord2 = make_pair(3,2);

What's wrong with:

cartesian_2d coord1(1, 2);
cartesian_2d coord2(3, 2);

?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,167
Messages
2,570,910
Members
47,453
Latest member
MadelinePh

Latest Threads

Top