473,396 Members | 1,929 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

creation of a set of segments, please help

Hello everybody,

I have an interesting problem for which I still don't have a solution.
Imagine that you're working with points in two-dimesional space, so
the point class should be (simplifying):

class Point {

double x_,y_;

public:

Point(double x, double y) : x_(x), y_(y) {}
// other constructors and member functions
};

Now, imagine that you're also working with segments in 2D. A segment
consists of its endpoints:

class Segment {

Point source_, target_;
public:
Segment(const Point& s, const Point& t) : source_(s), target_(t)
{}
// other constructors and member functions
};
Now, I want to enforce that if I have points P1, P2, the segment P1-P2
is the same as the segment P2-P1. That is, the orientation of the
segment doesn't matter so as long as the endpoints are the same, the
segments are equal. This could be enforced by operator== in the
Segment class:

bool Segment::operator==(const Segment& s)
{ return ((source_ == s.source_ && target_ == s.target_) || (target_
== s.source_ && source_ == s.target_)); }
Now, I would like to create a set of segments. Of course, the segment
does not have to have duplicates. However, sets are defined by using
operator< which is not defined here.

So the question is, how do I create a std::set of segments? Any ideas?
I could just write operator< so that it compares the smaller point
from both segments, but I thought that someone could have a better
solution.

Thank you all,

aa
Nov 13 '08 #1
0 1203

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Bernie Yaeger | last post by:
I'm trying to create a custom control that has 2 listviews, in view smallicon. I'm using these with code that makes them drag/drop controls, so what I am after is a control that does drag/drop...
8
by: Ankit Aneja | last post by:
Hi I have made a windows service in C#.Net Now I want to create a setup of this service http://www.codeproject.com/dotnet/simplewindowsservice.asp I read this article Now my service is also using...
2
by: Garry Jones | last post by:
I have several seperate individual php segment which make up my website. To check what each segment actuallt displays I am linking my css style to each and every segment in a wysiwyg program. ...
8
by: karthik.infoguy | last post by:
Any one just let me know what are the different segments in a compiler and what data are stored in different segments????
5
by: pavi | last post by:
Hi, I want to understand how the C's executable a.out is organised into segments. Which segments the varibles are put into according to their declarations. which Linux commands are used to check...
1
by: phantom2850 | last post by:
hello friends, I recently attended 3 interviews, all three had similar questions... Where is const stored? what are diff segments? what is heap? where is it on RAM/ROM? what is stored in...
7
by: kr | last post by:
Hi All, Suppose I consider a sample program as given below:- #include<stdio.h> #include<stdlib.h> int i; int main() { char *test(int i); char *tmp = NULL;
2
by: =?Utf-8?B?am9obnByZW1p?= | last post by:
Hi there, I have a web app that adds user into w2k3 server and adds it to the administrator group. The code snippet is something like this: try { DirectoryEntry AD = new...
4
by: timmg | last post by:
I have an application were users evaluate records and based on the amount of money involved answer between 17 and a 120 questions on one of three response forms. I have a master list of question...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.