mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-25 00:58:06 -05:00
New class to represent a simple line composed of two points.
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@2170 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
parent
7346f14a79
commit
2c166e6d19
111
src/qgsline.cpp
Normal file
111
src/qgsline.cpp
Normal file
@ -0,0 +1,111 @@
|
||||
/***************************************************************************
|
||||
qgsline - description
|
||||
A simple line composed of two endpoints
|
||||
-------------------
|
||||
begin : 2004-10-24
|
||||
copyright : (C) 2004 by Gary E.Sherman
|
||||
email : sherman at mrcc.com
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
/* $Id$ */
|
||||
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <qstring.h>
|
||||
#include "qgsline.h"
|
||||
|
||||
QgsLine::QgsLine()
|
||||
{
|
||||
}
|
||||
|
||||
// Create a line from two points
|
||||
QgsLine::QgsLine(QgsPoint &p1, QgsPoint &p2) : mBegin(p1), mEnd(p2)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//! Destructor
|
||||
QgsLine::~QgsLine()
|
||||
{
|
||||
}
|
||||
|
||||
/// Sets the begin point of the line
|
||||
void QgsLine::setBegin(QgsPoint &p1)
|
||||
{
|
||||
mBegin = p1;
|
||||
}
|
||||
/// Sets the end point of the line
|
||||
void QgsLine::setEnd(QgsPoint &p2)
|
||||
{
|
||||
mEnd = p2;
|
||||
}
|
||||
|
||||
/// Get the begin point of the line
|
||||
QgsPoint QgsLine::begin() const
|
||||
{
|
||||
return mBegin;
|
||||
}
|
||||
|
||||
/// Get the end point of the line
|
||||
QgsPoint QgsLine::end() const
|
||||
{
|
||||
return mEnd;
|
||||
}
|
||||
|
||||
//! String representation of the line
|
||||
QString QgsLine::stringRep() const
|
||||
{
|
||||
return QString("Not implemented");
|
||||
}
|
||||
|
||||
//! As above but with precision for string representaton of a line
|
||||
QString QgsLine::stringRep(int thePrecision) const
|
||||
{
|
||||
return QString("Not implemented");
|
||||
}
|
||||
|
||||
/*! Return the well known text representation for the line.
|
||||
* The wkt is created without an SRID.
|
||||
* @return Well known text
|
||||
*/
|
||||
QString QgsLine::wellKnownText()
|
||||
{
|
||||
return QString("Not implemented");
|
||||
}
|
||||
|
||||
|
||||
//! Inequality operator
|
||||
bool QgsLine::operator!=(const QgsLine &other)
|
||||
{
|
||||
// Note this function assumes that "flipped" lines are not equal,
|
||||
// thus preserving the concept of direction
|
||||
if((mBegin != other.begin()) || (mEnd != other.end()))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// Assignment
|
||||
QgsLine & QgsLine::operator=(const QgsLine &other)
|
||||
{
|
||||
if (&other != this)
|
||||
{
|
||||
mBegin = other.begin();
|
||||
mEnd = other.end();
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
126
src/qgsline.h
Normal file
126
src/qgsline.h
Normal file
@ -0,0 +1,126 @@
|
||||
/***************************************************************************
|
||||
qgsline.h - description
|
||||
A simple line composed of two endpoints
|
||||
-------------------
|
||||
begin : 2004-10-24
|
||||
copyright : (C) 2004 by Gary E.Sherman
|
||||
email : sherman at mrcc.com
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
/* $Id$ */
|
||||
|
||||
#ifndef QGSLINE_H
|
||||
#define QGSLINE_H
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <qstring.h>
|
||||
|
||||
#include "qgspoint.h"
|
||||
|
||||
/*! \class QgsLine
|
||||
* \brief A simple line object composed of a begin and end point.
|
||||
*
|
||||
* Comparisons (==, !=) honor the direction of the line. This means that
|
||||
* flipped lines with the same coordinates are not considered to be equal.
|
||||
*
|
||||
* For example, (1,1 2,2) != (2,2 1,1)
|
||||
*/
|
||||
class QgsLine
|
||||
{
|
||||
public:
|
||||
//! Default constructor
|
||||
QgsLine();
|
||||
|
||||
/*! Create a line from two points
|
||||
* @param p1 begin point
|
||||
* @param p2 end point
|
||||
*/
|
||||
QgsLine(QgsPoint &p1, QgsPoint &p2);
|
||||
|
||||
//! Destructor
|
||||
~QgsLine();
|
||||
|
||||
/*! Sets the begin point of the line
|
||||
* @param p1 Beginning point of the line
|
||||
*/
|
||||
void setBegin(QgsPoint &p1);
|
||||
|
||||
/*! Sets the end point of the line
|
||||
* @param p1 End point of the line
|
||||
*/
|
||||
void setEnd(QgsPoint &p2);
|
||||
|
||||
/*! Get the begin point of the line
|
||||
* @return Begin point of the line
|
||||
*/
|
||||
QgsPoint begin() const;
|
||||
|
||||
/*! Get the end point of the line
|
||||
* @return End point of the line
|
||||
*/
|
||||
QgsPoint end() const;
|
||||
|
||||
//! String representation of the line
|
||||
QString stringRep() const;
|
||||
|
||||
//! As above but with precision for string representation of a line
|
||||
QString stringRep(int thePrecision) const;
|
||||
|
||||
/*! Return the well known text representation for the line.
|
||||
* The wkt is created without an SRID.
|
||||
* @return Well known text
|
||||
*/
|
||||
QString wellKnownText();
|
||||
|
||||
//! Equality operator
|
||||
bool operator==(const QgsLine &other);
|
||||
|
||||
//! Inequality operator
|
||||
bool operator!=(const QgsLine &other);
|
||||
|
||||
/// Assignment
|
||||
QgsLine & operator=(const QgsLine &other);
|
||||
|
||||
private:
|
||||
|
||||
//! Begin point
|
||||
QgsPoint mBegin;
|
||||
|
||||
//! End point
|
||||
QgsPoint mEnd;
|
||||
|
||||
}; // class QgsLine
|
||||
|
||||
|
||||
inline bool operator==(const QgsLine &l1, const QgsLine &l2)
|
||||
{
|
||||
// Note this function assumes that "flipped" lines are not equal,
|
||||
// thus preserving the concept of direction
|
||||
if((l1.begin() == l2.begin()) && (l1.end() == l2.end()))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
//! Stream operator for writing the line
|
||||
inline std::ostream& operator << (std::ostream& os, const QgsLine &l)
|
||||
{
|
||||
os << l.stringRep();
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
#endif //QGSLINE_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user