Index: src/LineSegment.cpp
===================================================================
--- src/LineSegment.cpp	(revision a4e9bb5add6b79d2cf25d14ee0e30aa2f2fd6271)
+++ src/LineSegment.cpp	(revision a4e9bb5add6b79d2cf25d14ee0e30aa2f2fd6271)
@@ -0,0 +1,90 @@
+/*
+ * LineSegment.cpp
+ *
+ *  Created on: Jul 22, 2010
+ *      Author: crueger
+ */
+
+#include "LineSegment.hpp"
+#include "Helpers/Assert.hpp"
+
+#include "Line.hpp"
+#include "vector.hpp"
+
+using namespace std;
+
+LineSegment::LineSegment(const Vector &point1,const Vector &point2){
+  line.reset(new Line(point1,point1-point2));
+  begin.reset(new LinePoint(line->getLinePoint(point1)));
+  end.reset(new LinePoint(line->getLinePoint(point2)));
+}
+
+LineSegment::LineSegment(const LinePoint &lp1,const LinePoint &lp2){
+  ASSERT(lp1.getLine()==lp2.getLine(),"Cannot make a lineSegment with two different lines");
+  line.reset(new Line(lp1.getLine()));
+  begin.reset(new LinePoint(lp1));
+  end.reset(new LinePoint(lp2));
+}
+LineSegment::LineSegment(const LineSegment &src)
+{
+  line.reset(new Line(*src.line));
+  begin.reset(new LinePoint(*src.begin));
+  end.reset(new LinePoint(*src.end));
+}
+LineSegment::~LineSegment(){
+}
+LineSegment &LineSegment::operator=(const LineSegment &src){
+  if(this!=&src){
+    lineptr _line(new Line(*src.line));
+    pointptr _begin(new LinePoint(*src.begin));
+    pointptr _end(new LinePoint(*src.end));
+    line = _line;
+    begin = _begin;
+    end = _end;
+  }
+  return *this;
+}
+
+bool LineSegment::isContained(const Vector &point) const{
+  if(!line->isContained(point)){
+    return false;
+  }
+  LinePoint lp = line->getLinePoint(point);
+  return *begin <= lp && lp <= *end;
+}
+
+bool LineSegment::isContained(const LinePoint &lp) const{
+  ASSERT(lp.getLine()==*line,"Cannot compare Linepoints from different Lines");
+  return *begin <= lp && lp <= *end;
+}
+
+bool LineSegment::overlaps(const LineSegment &lineSeg) const{
+  ASSERT(*lineSeg.line == *line,"Cannot compare Linesegments from different Lines");
+  // mutual comparison of endpoints
+  return lineSeg.isContained(*end) || isContained(*lineSeg.end);
+}
+
+bool LineSegment::hasZeroLength() const{
+  return *begin==*end;
+}
+
+LinePoint LineSegment::getBegin() const{
+  return *begin;
+}
+
+LinePoint LineSegment::getEnd() const{
+  return *end;
+}
+
+Line LineSegment::getLine() const{
+  return *line;
+}
+
+bool operator==(const LineSegment &x,const LineSegment &y){
+  ASSERT(*x.line==*y.line,"Comparison of Linesegments from different lines");
+  return *x.begin == *y.begin && *x.end == *y.end;
+}
+bool operator<(const LineSegment &x,const LineSegment &y){
+  ASSERT(*x.line==*y.line,"Comparison of Linesegments from different lines");
+  return (*x.begin != *y.begin) ? *x.begin<*y.begin:*x.end<*y.end;
+}
Index: src/LineSegment.hpp
===================================================================
--- src/LineSegment.hpp	(revision a4e9bb5add6b79d2cf25d14ee0e30aa2f2fd6271)
+++ src/LineSegment.hpp	(revision a4e9bb5add6b79d2cf25d14ee0e30aa2f2fd6271)
@@ -0,0 +1,48 @@
+/*
+ * LineSegment.hpp
+ *
+ *  Created on: Jul 22, 2010
+ *      Author: crueger
+ */
+
+#ifndef LINESEGMENT_HPP_
+#define LINESEGMENT_HPP_
+
+#include <memory>
+
+class Vector;
+class Line;
+class LinePoint;
+
+class LineSegment
+{
+  friend bool operator==(const LineSegment&,const LineSegment&);
+  friend bool operator<(const LineSegment&,const LineSegment&);
+
+  typedef std::auto_ptr<LinePoint> pointptr;
+  typedef std::auto_ptr<Line> lineptr;
+public:
+  LineSegment(const Vector&,const Vector&);
+  LineSegment(const LinePoint&,const LinePoint&);
+  LineSegment(const LineSegment&);
+  virtual ~LineSegment();
+  LineSegment &operator=(const LineSegment&);
+
+  bool isContained(const Vector &) const;
+  bool isContained(const LinePoint &) const;
+  bool overlaps(const LineSegment&) const;
+  bool hasZeroLength() const;
+  LinePoint getBegin() const;
+  LinePoint getEnd() const;
+  Line getLine() const;
+
+private:
+  pointptr begin;
+  pointptr end;
+  lineptr line;
+};
+
+bool operator==(const LineSegment&,const LineSegment&);
+bool operator<(const LineSegment&,const LineSegment&);
+
+#endif /* LINESEGMENT_HPP_ */
Index: src/Makefile.am
===================================================================
--- src/Makefile.am	(revision 6256f5f31eca13a77c3ab8175d56dc82de37ad35)
+++ src/Makefile.am	(revision a4e9bb5add6b79d2cf25d14ee0e30aa2f2fd6271)
@@ -211,4 +211,5 @@
   leastsquaremin.cpp \
   Line.cpp \
+  LineSegment.cpp \
   linkedcell.cpp \
   log.cpp \
@@ -261,4 +262,5 @@
   leastsquaremin.hpp \
   Line.hpp \
+  LineSegment.hpp \
   linkedcell.hpp \
   lists.hpp \
