This repository has been archived on 2025-03-02. You can view files and clone it, but cannot push or open issues or pull requests.
neofx-zoomedit/Line.h

44 lines
1.1 KiB
C++

#ifndef LINE_H_
#define LINE_H_
#include "Vertex.h"
#include <math.h>
#define INTERSECTION_ERROR -1
#define INTERSECTION_NONE 0
#define INTERSECTION_IDENTICAL 1
#define INTERSECTION_LINE 2
#define INTERSECTION_LINE_LINE 2
#define INTERSECTION_LINE_SEGMENT 3
#define INTERSECTION_SEGMENT_LINE 6
#define INTERSECTION_SEGMENT_SEGMENT 7
class Line {
private:
Vertex v1, v2;
public:
Line() {}
Line(const Vertex& vertex1, const Vertex& vertex2) :
v1(vertex1), v2(vertex2) {}
Line(float x1, float y1, float x2, float y2) :
v1(x1, y1), v2(x2, y2) {}
Vertex &getVertex1() {return v1;}
const Vertex &getVertex1() const {return v1;}
void setVertex1(const Vertex &v) {v1 = v;}
Vertex &getVertex2() {return v2;}
const Vertex &getVertex2() const {return v2;}
void setVertex2(const Vertex &v) {v2 = v;}
float lengthSq() const {return v1.distanceSq(v2);}
float length() const {return sqrtf(lengthSq());}
bool contains(const Vertex &v) const;
int intersects(const Line &l, Vertex *v) const;
};
#endif /*LINE_H_*/