Adding new wxCanvas
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@8790 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
f90fbcc192
commit
84fba40bea
@ -13,9 +13,9 @@ LIBVERSION_AGE=0
|
||||
HEADER_PATH=$(top_srcdir)/contrib/include/wx
|
||||
HEADER_SUBDIR=canvas
|
||||
|
||||
HEADERS=canvas.h
|
||||
HEADERS=canvas.h bbox.h liner.h polygon.h
|
||||
|
||||
OBJECTS=canvas.o
|
||||
OBJECTS=canvas.o bbox.o liner.o polygon.o
|
||||
|
||||
APPEXTRADEFS=-I$(top_srcdir)/contrib/include
|
||||
|
||||
|
369
contrib/src/canvas/bbox.cpp
Normal file
369
contrib/src/canvas/bbox.cpp
Normal file
@ -0,0 +1,369 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: bbox.cpp
|
||||
// Author: Klaas Holwerda
|
||||
// Created: XX/XX/XX
|
||||
// Copyright: 2000 (c) Klaas Holwerda
|
||||
// Licence: wxWindows Licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "bbox.cpp"
|
||||
#endif
|
||||
|
||||
// For compilers that support precompilation, includes "wx/wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "bbox.h"
|
||||
|
||||
wxBoundingBox::wxBoundingBox()
|
||||
{
|
||||
m_minx = m_miny = m_maxx = m_maxy = 0.0;
|
||||
m_validbbox = FALSE;
|
||||
}
|
||||
|
||||
|
||||
wxBoundingBox::wxBoundingBox(wxBoundingBox &other)
|
||||
{
|
||||
m_minx = other.m_minx;
|
||||
m_miny = other.m_miny;
|
||||
m_maxx = other.m_maxx;
|
||||
m_maxy = other.m_maxy;
|
||||
m_validbbox= other.m_validbbox;
|
||||
}
|
||||
|
||||
|
||||
wxBoundingBox::wxBoundingBox(const wxPoint2DDouble& a)
|
||||
{
|
||||
m_minx = a.m_x;
|
||||
m_maxx = a.m_x;
|
||||
m_miny = a.m_y;
|
||||
m_maxy = a.m_y;
|
||||
m_validbbox = TRUE;
|
||||
}
|
||||
|
||||
wxBoundingBox::wxBoundingBox(double xmin, double ymin, double xmax, double ymax)
|
||||
{
|
||||
m_minx = xmin;
|
||||
m_miny = ymin;
|
||||
m_maxx = xmax;
|
||||
m_maxy = ymax;
|
||||
m_validbbox = TRUE;
|
||||
}
|
||||
|
||||
// This function checks if two bboxes intersect
|
||||
bool wxBoundingBox::And(wxBoundingBox *_bbox, double Marge)
|
||||
{
|
||||
assert (m_validbbox == TRUE);
|
||||
assert (_bbox->GetValid());
|
||||
m_minx = wxMax(m_minx, _bbox->m_minx);
|
||||
m_maxx = wxMin(m_maxx, _bbox->m_maxx);
|
||||
m_miny = wxMax(m_miny, _bbox->m_miny);
|
||||
m_maxy = wxMin(m_maxy, _bbox->m_maxy);
|
||||
return (bool)
|
||||
(
|
||||
((m_minx - Marge) < (m_maxx + Marge)) &&
|
||||
((m_miny - Marge) < (m_maxy + Marge))
|
||||
);
|
||||
}
|
||||
|
||||
// Shrink the boundingbox with the given marge
|
||||
void wxBoundingBox::Shrink(const double Marge)
|
||||
{
|
||||
assert (m_validbbox == TRUE);
|
||||
|
||||
m_minx += Marge;
|
||||
m_maxx -= Marge;
|
||||
m_miny += Marge;
|
||||
m_maxy -= Marge;
|
||||
}
|
||||
|
||||
|
||||
// Expand the boundingbox with another boundingbox
|
||||
void wxBoundingBox::Expand(const wxBoundingBox &other)
|
||||
{
|
||||
if (!m_validbbox)
|
||||
{
|
||||
*this=other;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_minx = wxMin(m_minx, other.m_minx);
|
||||
m_maxx = wxMax(m_maxx, other.m_maxx);
|
||||
m_miny = wxMin(m_miny, other.m_miny);
|
||||
m_maxy = wxMax(m_maxy, other.m_maxy);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Expand the boundingbox with a point
|
||||
void wxBoundingBox::Expand(const wxPoint2DDouble& a_point)
|
||||
{
|
||||
if (!m_validbbox)
|
||||
{
|
||||
m_minx = m_maxx = a_point.m_x;
|
||||
m_miny = m_maxy = a_point.m_y;
|
||||
m_validbbox=TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_minx = wxMin(m_minx, a_point.m_x);
|
||||
m_maxx = wxMax(m_maxx, a_point.m_x);
|
||||
m_miny = wxMin(m_miny, a_point.m_y);
|
||||
m_maxy = wxMax(m_maxy, a_point.m_y);
|
||||
}
|
||||
}
|
||||
|
||||
// Expand the boundingbox with a point
|
||||
void wxBoundingBox::Expand(double x,double y)
|
||||
{
|
||||
if (!m_validbbox)
|
||||
{
|
||||
m_minx = m_maxx = x;
|
||||
m_miny = m_maxy = y;
|
||||
m_validbbox=TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_minx = wxMin(m_minx, x);
|
||||
m_maxx = wxMax(m_maxx, x);
|
||||
m_miny = wxMin(m_miny, y);
|
||||
m_maxy = wxMax(m_maxy, y);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Expand the boundingbox with two points
|
||||
void wxBoundingBox::Expand(const wxPoint2DDouble& a, const wxPoint2DDouble& b)
|
||||
{
|
||||
Expand(a);
|
||||
Expand(b);
|
||||
}
|
||||
|
||||
// Enlarge the boundingbox with the given marge
|
||||
void wxBoundingBox::EnLarge(const double marge)
|
||||
{
|
||||
if (!m_validbbox)
|
||||
{
|
||||
m_minx = m_maxx = marge;
|
||||
m_miny = m_maxy = marge;
|
||||
m_validbbox=TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_minx -= marge;
|
||||
m_maxx += marge;
|
||||
m_miny -= marge;
|
||||
m_maxy += marge;
|
||||
}
|
||||
}
|
||||
|
||||
// Calculates if two boundingboxes intersect. If so, the function returns _ON.
|
||||
// If they do not intersect, two scenario's are possible:
|
||||
// other is outside this -> return _OUT
|
||||
// other is inside this -> return _IN
|
||||
OVERLAP wxBoundingBox::Intersect(wxBoundingBox &other, double Marge)
|
||||
{
|
||||
assert (m_validbbox == TRUE);
|
||||
|
||||
// other boundingbox must exist
|
||||
assert (&other);
|
||||
|
||||
if (((m_minx - Marge) > (other.m_maxx + Marge)) ||
|
||||
((m_maxx + Marge) < (other.m_minx - Marge)) ||
|
||||
((m_maxy + Marge) < (other.m_miny - Marge)) ||
|
||||
((m_miny - Marge) > (other.m_maxy + Marge)))
|
||||
return _OUT;
|
||||
|
||||
// Check if other.bbox is inside this bbox
|
||||
if ((m_minx <= other.m_minx) &&
|
||||
(m_maxx >= other.m_maxx) &&
|
||||
(m_maxy >= other.m_maxy) &&
|
||||
(m_miny <= other.m_miny))
|
||||
return _IN;
|
||||
|
||||
// Boundingboxes intersect
|
||||
return _ON;
|
||||
}
|
||||
|
||||
|
||||
// Checks if a line intersects the boundingbox
|
||||
bool wxBoundingBox::LineIntersect(const wxPoint2DDouble& begin, const wxPoint2DDouble& end )
|
||||
{
|
||||
assert (m_validbbox == TRUE);
|
||||
|
||||
return (bool)
|
||||
!(((begin.m_y > m_maxy) && (end.m_y > m_maxy)) ||
|
||||
((begin.m_y < m_miny) && (end.m_y < m_miny)) ||
|
||||
((begin.m_x > m_maxx) && (end.m_x > m_maxx)) ||
|
||||
((begin.m_x < m_minx) && (end.m_x < m_minx)));
|
||||
}
|
||||
|
||||
|
||||
// Is the given point in the boundingbox ??
|
||||
bool wxBoundingBox::PointInBox(double x, double y, double Marge)
|
||||
{
|
||||
assert (m_validbbox == TRUE);
|
||||
|
||||
if ( x >= (m_minx - Marge) && x <= (m_maxx + Marge) &&
|
||||
y >= (m_miny - Marge) && y <= (m_maxy + Marge) )
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Is the given point in the boundingbox ??
|
||||
//
|
||||
bool wxBoundingBox::PointInBox(const wxPoint2DDouble& a, double Marge)
|
||||
{
|
||||
assert (m_validbbox == TRUE);
|
||||
|
||||
return PointInBox(a.m_x, a.m_y, Marge);
|
||||
}
|
||||
|
||||
|
||||
wxPoint2DDouble wxBoundingBox::GetMin()
|
||||
{
|
||||
assert (m_validbbox == TRUE);
|
||||
|
||||
return wxPoint2DDouble(m_minx, m_miny);
|
||||
}
|
||||
|
||||
|
||||
wxPoint2DDouble wxBoundingBox::GetMax()
|
||||
{
|
||||
assert (m_validbbox == TRUE);
|
||||
|
||||
return wxPoint2DDouble(m_maxx, m_maxy);
|
||||
}
|
||||
|
||||
bool wxBoundingBox::GetValid() const
|
||||
{
|
||||
return m_validbbox;
|
||||
}
|
||||
|
||||
void wxBoundingBox::SetMin(double px, double py)
|
||||
{
|
||||
m_minx = px;
|
||||
m_miny = py;
|
||||
if (!m_validbbox)
|
||||
{
|
||||
m_maxx = px;
|
||||
m_maxy = py;
|
||||
m_validbbox = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
void wxBoundingBox::SetMax(double px, double py)
|
||||
{
|
||||
m_maxx = px;
|
||||
m_maxy = py;
|
||||
if (!m_validbbox)
|
||||
{
|
||||
m_minx = px;
|
||||
m_miny = py;
|
||||
m_validbbox = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
void wxBoundingBox::SetValid(bool value)
|
||||
{
|
||||
m_validbbox = value;
|
||||
}
|
||||
|
||||
// adds an offset to the boundingbox
|
||||
// usage : a_boundingbox.Translate(a_point);
|
||||
void wxBoundingBox::Translate(wxPoint2DDouble& offset)
|
||||
{
|
||||
assert (m_validbbox == TRUE);
|
||||
|
||||
m_minx += offset.m_x;
|
||||
m_maxx += offset.m_x;
|
||||
m_miny += offset.m_y;
|
||||
m_maxy += offset.m_y;
|
||||
}
|
||||
|
||||
|
||||
// clears the bounding box settings
|
||||
void wxBoundingBox::Reset()
|
||||
{
|
||||
m_minx = 0.0;
|
||||
m_maxx = 0.0;
|
||||
m_miny = 0.0;
|
||||
m_maxy = 0.0;
|
||||
m_validbbox = FALSE;
|
||||
}
|
||||
|
||||
|
||||
void wxBoundingBox::SetBoundingBox(const wxPoint2DDouble& a_point)
|
||||
{
|
||||
m_minx = a_point.m_x;
|
||||
m_maxx = a_point.m_x;
|
||||
m_miny = a_point.m_y;
|
||||
m_maxy = a_point.m_y;
|
||||
}
|
||||
|
||||
|
||||
// Expands the boundingbox with the given point
|
||||
// usage : a_boundingbox = a_boundingbox + pointer_to_an_offset;
|
||||
wxBoundingBox& wxBoundingBox::operator+(wxBoundingBox &other)
|
||||
{
|
||||
assert (m_validbbox == TRUE);
|
||||
assert (other.GetValid());
|
||||
|
||||
Expand(other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
// makes a boundingbox same as the other
|
||||
wxBoundingBox& wxBoundingBox::operator=( const wxBoundingBox &other)
|
||||
{
|
||||
assert (other.GetValid());
|
||||
|
||||
m_minx = other.m_minx;
|
||||
m_maxx = other.m_maxx;
|
||||
m_miny = other.m_miny;
|
||||
m_maxy = other.m_maxy;
|
||||
m_validbbox = other.m_validbbox;
|
||||
return *this;
|
||||
}
|
||||
|
||||
void wxBoundingBox::MapBbox( const wxTransformMatrix& matrix)
|
||||
{
|
||||
assert (m_validbbox == TRUE);
|
||||
|
||||
double x1,y1,x2,y2,x3,y3,x4,y4;
|
||||
|
||||
matrix.TransformPoint( m_minx, m_miny, x1, y1 );
|
||||
matrix.TransformPoint( m_minx, m_maxy, x2, y2 );
|
||||
matrix.TransformPoint( m_maxx, m_maxy, x3, y3 );
|
||||
matrix.TransformPoint( m_maxx, m_miny, x4, y4 );
|
||||
|
||||
double xmin = wxMin(x1,x2);
|
||||
xmin = wxMin(xmin,x3);
|
||||
xmin = wxMin(xmin,x4);
|
||||
|
||||
double xmax = wxMax( x1, x2);
|
||||
xmax = wxMax(xmax,x3);
|
||||
xmax = wxMax(xmax,x4);
|
||||
|
||||
double ymin = wxMin(y1, y2);
|
||||
ymin = wxMin(ymin,y3);
|
||||
ymin = wxMin(ymin,y4);
|
||||
|
||||
double ymax = wxMax(y1,y2);
|
||||
ymax = wxMax(ymax,y3);
|
||||
ymax = wxMax(ymax,y4);
|
||||
|
||||
// Use these min and max values to set the new boundingbox
|
||||
m_minx = xmin;
|
||||
m_miny = ymin;
|
||||
m_maxx = xmax;
|
||||
m_maxy = ymax;
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
653
contrib/src/canvas/liner.cpp
Normal file
653
contrib/src/canvas/liner.cpp
Normal file
@ -0,0 +1,653 @@
|
||||
/*
|
||||
Program wxLine.CPP
|
||||
Purpose Mainly used for calculating crossings
|
||||
Last Update 05-12-1995
|
||||
*/
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "liner.cpp"
|
||||
#endif
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "liner.h"
|
||||
|
||||
wxLine::wxLine( double x1, double y1, double x2, double y2 )
|
||||
{
|
||||
m_AA = 0.0;
|
||||
m_BB = 0.0;
|
||||
m_CC = 0.0;
|
||||
|
||||
m_a=wxPoint2DDouble(x1,y1);
|
||||
m_b=wxPoint2DDouble(x2,y2);
|
||||
if (m_a==m_b)
|
||||
assert(0);
|
||||
|
||||
m_valid_parameters = FALSE;
|
||||
}
|
||||
|
||||
wxLine::~wxLine()
|
||||
{
|
||||
}
|
||||
|
||||
wxLine::wxLine(const wxPoint2DDouble& a,const wxPoint2DDouble& b)
|
||||
{
|
||||
if (a==b)
|
||||
assert(0);
|
||||
|
||||
m_a=a;
|
||||
m_b=b;
|
||||
m_valid_parameters = FALSE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ActionOnTable1
|
||||
// This function decide which action must be taken, after PointInLine
|
||||
// has given the results of two points in relation to a wxLine. See table 1 in the report
|
||||
//
|
||||
// input Result_beginPoint:
|
||||
// Result_endPoint :
|
||||
// The results can be R_R_LEFT_SIDE, R_R_RIGHT_SIDE, R_R_ON_AREA, R_R_IN_AREA
|
||||
//
|
||||
// return -1: Illegal combination
|
||||
// 0: No action, no crosspoints
|
||||
// 1: Investigate results points in relation to the other wxLine
|
||||
// 2: endPoint is a crosspoint, no further investigation
|
||||
// 3: beginPoint is a crosspoint, no further investigation
|
||||
// 4: beginPoint and endPoint are crosspoints, no further investigation
|
||||
// 5: beginPoint is a crosspoint, need further investigation
|
||||
// 6: endPoint is a crosspoint, need further investigation
|
||||
int wxLine::ActionOnTable1(R_PointStatus Result_beginPoint, R_PointStatus Result_endPoint)
|
||||
{
|
||||
// beginPoint and endPoint are crosspoints
|
||||
if (
|
||||
(Result_beginPoint == R_IN_AREA)
|
||||
&&
|
||||
(Result_endPoint == R_IN_AREA)
|
||||
)
|
||||
return 4;
|
||||
// there are no crosspoints, no action
|
||||
if (
|
||||
(
|
||||
(Result_beginPoint == R_LEFT_SIDE)
|
||||
&&
|
||||
(Result_endPoint == R_LEFT_SIDE)
|
||||
)
|
||||
||
|
||||
(
|
||||
(Result_beginPoint == R_RIGHT_SIDE)
|
||||
&&
|
||||
(Result_endPoint == R_RIGHT_SIDE)
|
||||
)
|
||||
)
|
||||
return 0;
|
||||
// maybe there is a crosspoint, further investigation needed
|
||||
if (
|
||||
(
|
||||
(Result_beginPoint == R_LEFT_SIDE)
|
||||
&&
|
||||
(
|
||||
(Result_endPoint == R_RIGHT_SIDE)
|
||||
||
|
||||
(Result_endPoint == R_ON_AREA)
|
||||
)
|
||||
)
|
||||
||
|
||||
(
|
||||
(Result_beginPoint == R_RIGHT_SIDE)
|
||||
&&
|
||||
(
|
||||
(Result_endPoint == R_LEFT_SIDE)
|
||||
||
|
||||
(Result_endPoint == R_ON_AREA)
|
||||
)
|
||||
)
|
||||
||
|
||||
(
|
||||
(Result_beginPoint == R_ON_AREA)
|
||||
&&
|
||||
(
|
||||
(Result_endPoint == R_LEFT_SIDE)
|
||||
||
|
||||
(Result_endPoint == R_RIGHT_SIDE)
|
||||
||
|
||||
(Result_endPoint == R_ON_AREA)
|
||||
)
|
||||
)
|
||||
)
|
||||
return 1;
|
||||
//there is a crosspoint
|
||||
if (
|
||||
(
|
||||
(Result_beginPoint == R_LEFT_SIDE)
|
||||
||
|
||||
(Result_beginPoint == R_RIGHT_SIDE)
|
||||
)
|
||||
&&
|
||||
(Result_endPoint == R_IN_AREA)
|
||||
)
|
||||
return 2;
|
||||
// there is a crosspoint
|
||||
if (
|
||||
(Result_beginPoint == R_IN_AREA)
|
||||
&&
|
||||
(
|
||||
(Result_endPoint == R_LEFT_SIDE)
|
||||
||
|
||||
(Result_endPoint == R_RIGHT_SIDE)
|
||||
)
|
||||
)
|
||||
return 3;
|
||||
// beginPoint is a crosspoint, further investigation needed
|
||||
if (
|
||||
(Result_beginPoint == R_IN_AREA)
|
||||
&&
|
||||
(Result_endPoint == R_ON_AREA)
|
||||
)
|
||||
return 5;
|
||||
// endPoint is a crosspoint, further investigation needed
|
||||
if (
|
||||
(Result_beginPoint == R_ON_AREA)
|
||||
&&
|
||||
(Result_endPoint == R_IN_AREA)
|
||||
)
|
||||
return 6;
|
||||
// All other combinations are illegal
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
// ActionOnTable2
|
||||
// This function decide which action must be taken, after PointInLine
|
||||
// has given the results of two points in relation to a wxLine. It can only give a
|
||||
// correct decision if first the relation of the points from the wxLine
|
||||
// are investigated in relation to the wxLine wich can be constucted from the points.
|
||||
//
|
||||
// input Result_beginPoint:
|
||||
// Result_endPoint :
|
||||
// The results can be R_LEFT_SIDE, R_RIGHT_SIDE, R_ON_AREA, R_IN_AREA
|
||||
//
|
||||
// return -1: Illegal combination
|
||||
// 0: No action, no crosspoints
|
||||
// 1: Calculate crosspoint
|
||||
// 2: endPoint is a crosspoint
|
||||
// 3: beginPoint is a crosspoint
|
||||
// 4: beginPoint and endPoint are crosspoints
|
||||
int wxLine::ActionOnTable2(R_PointStatus Result_beginPoint, R_PointStatus Result_endPoint)
|
||||
{
|
||||
// beginPoint and eindpoint are crosspoints
|
||||
if (
|
||||
(Result_beginPoint == R_IN_AREA)
|
||||
&&
|
||||
(Result_endPoint == R_IN_AREA)
|
||||
)
|
||||
return 4;
|
||||
// there are no crosspoints
|
||||
if (
|
||||
(
|
||||
(Result_beginPoint == R_LEFT_SIDE)
|
||||
&&
|
||||
(
|
||||
(Result_endPoint == R_LEFT_SIDE)
|
||||
||
|
||||
(Result_endPoint == R_ON_AREA)
|
||||
)
|
||||
)
|
||||
||
|
||||
(
|
||||
(Result_beginPoint == R_RIGHT_SIDE)
|
||||
&&
|
||||
(
|
||||
(Result_endPoint == R_RIGHT_SIDE)
|
||||
||
|
||||
(Result_endPoint == R_ON_AREA)
|
||||
)
|
||||
)
|
||||
||
|
||||
(
|
||||
(Result_beginPoint == R_ON_AREA)
|
||||
&&
|
||||
(
|
||||
(Result_endPoint == R_LEFT_SIDE)
|
||||
||
|
||||
(Result_endPoint == R_RIGHT_SIDE)
|
||||
||
|
||||
(Result_endPoint == R_ON_AREA)
|
||||
)
|
||||
)
|
||||
)
|
||||
return 0;
|
||||
// there is a real intersection, which must be calculated
|
||||
if (
|
||||
(
|
||||
(Result_beginPoint == R_LEFT_SIDE)
|
||||
&&
|
||||
(Result_endPoint == R_RIGHT_SIDE)
|
||||
)
|
||||
||
|
||||
(
|
||||
(Result_beginPoint == R_RIGHT_SIDE)
|
||||
&&
|
||||
(Result_endPoint == R_LEFT_SIDE)
|
||||
)
|
||||
)
|
||||
return 1;
|
||||
// endPoint is a crosspoint
|
||||
if (
|
||||
(
|
||||
(Result_beginPoint == R_LEFT_SIDE)
|
||||
||
|
||||
(Result_beginPoint == R_RIGHT_SIDE)
|
||||
||
|
||||
(Result_beginPoint == R_ON_AREA)
|
||||
)
|
||||
&&
|
||||
(Result_endPoint == R_IN_AREA)
|
||||
)
|
||||
return 2;
|
||||
// beginPoint is a crosspoint
|
||||
if (
|
||||
(Result_beginPoint == R_IN_AREA)
|
||||
&&
|
||||
(
|
||||
(Result_endPoint == R_LEFT_SIDE)
|
||||
||
|
||||
(Result_endPoint == R_RIGHT_SIDE)
|
||||
||
|
||||
(Result_endPoint == R_ON_AREA)
|
||||
)
|
||||
)
|
||||
return 3;
|
||||
// All other combinations are illegal
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Calculate the Y when the X is given
|
||||
double wxLine::Calculate_Y(double X)
|
||||
{
|
||||
CalculateLineParameters();
|
||||
if (m_AA != 0)
|
||||
return -(m_AA * X + m_CC) / m_BB;
|
||||
else
|
||||
// horizontal wxLine
|
||||
return m_a.m_y;
|
||||
}
|
||||
|
||||
void wxLine::Virtual_Point(wxPoint2DDouble& a_point,double distance) const
|
||||
{
|
||||
assert(m_valid_parameters);
|
||||
|
||||
//calculate the distance using the slope of the wxLine
|
||||
//and rotate 90 degrees
|
||||
|
||||
a_point.m_y=a_point.m_y + (distance * -m_BB);
|
||||
a_point.m_x=a_point.m_x - (distance * m_AA );
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Calculate the lineparameters for the wxLine if nessecary
|
||||
//
|
||||
void wxLine::CalculateLineParameters()
|
||||
{
|
||||
// if not valid_parameters calculate the parameters
|
||||
if (!m_valid_parameters)
|
||||
{
|
||||
double length;
|
||||
|
||||
// bp AND ep may not be the same
|
||||
if (m_a == m_b)
|
||||
assert (0);
|
||||
|
||||
m_AA = (m_b.m_y - m_a.m_y); // A = (Y2-Y1)
|
||||
m_BB = (m_a.m_x - m_b.m_x); // B = (X1-X2)
|
||||
|
||||
// the parameters A end B can now be normalized
|
||||
length = sqrt(m_AA*m_AA + m_BB*m_BB);
|
||||
|
||||
assert(length !=0);
|
||||
|
||||
m_AA = (m_AA / length);
|
||||
m_BB = (m_BB / length);
|
||||
|
||||
m_CC = -((m_AA * m_a.m_x) + (m_a.m_y * m_BB));
|
||||
|
||||
m_valid_parameters = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Checks if a wxLine intersect with another wxLine
|
||||
// inout wxLine : another wxLine
|
||||
// Marge: optional, standard on MARGE (declared in MISC.CPP)
|
||||
//
|
||||
// return true : wxLines are crossing
|
||||
// false: wxLines are not crossing
|
||||
//
|
||||
bool wxLine::CheckIntersect (wxLine& lijn, double Marge)
|
||||
{
|
||||
double distance=0;
|
||||
|
||||
// bp AND ep may not be the same
|
||||
if (m_a == m_b)
|
||||
assert (0);
|
||||
|
||||
int Take_Action1, Take_Action2;
|
||||
bool Total_Result=FALSE;
|
||||
R_PointStatus Result_beginPoint,Result_endPoint;
|
||||
|
||||
Result_beginPoint = PointInLine(lijn.m_a,distance,Marge);
|
||||
Result_endPoint = PointInLine(lijn.m_b,distance,Marge);
|
||||
Take_Action1 = ActionOnTable1(Result_beginPoint,Result_endPoint);
|
||||
switch (Take_Action1)
|
||||
{
|
||||
case 0: Total_Result = FALSE ; break;
|
||||
case 1: {
|
||||
Result_beginPoint = lijn.PointInLine(m_a,distance,Marge);
|
||||
Result_endPoint = lijn.PointInLine(m_b,distance,Marge);
|
||||
Take_Action2 = ActionOnTable2(Result_beginPoint,Result_endPoint);
|
||||
switch (Take_Action2)
|
||||
{
|
||||
case 0: Total_Result = FALSE; break;
|
||||
case 1: case 2: case 3: case 4: Total_Result = TRUE; break;
|
||||
}
|
||||
}; break; // This break belongs to the switch(Take_Action1)
|
||||
case 2: case 3: case 4: case 5: case 6: Total_Result = TRUE; break;
|
||||
}
|
||||
return Total_Result; //This is the final decision
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Get the beginPoint from the wxLine
|
||||
// usage: Point aPoint = a_line.GetBeginPoint()
|
||||
//
|
||||
wxPoint2DDouble wxLine::GetBeginPoint()
|
||||
{
|
||||
return m_a;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Get the endPoint from the wxLine
|
||||
// usage: Point aPoint = a_line.GetEndPoint()
|
||||
//
|
||||
wxPoint2DDouble wxLine::GetEndPoint()
|
||||
{
|
||||
return m_b;
|
||||
}
|
||||
|
||||
// Intersects two wxLines
|
||||
// input wxLine : another wxLine
|
||||
// Marge: optional, standard on MARGE
|
||||
//
|
||||
// return 0: If there are no crossings
|
||||
// 1: If there is one crossing
|
||||
// 2: If there are two crossings
|
||||
int wxLine::Intersect(wxLine& lijn, wxPoint2DDouble& c1 ,wxPoint2DDouble& c2 , double Marge)
|
||||
{
|
||||
double distance=0;
|
||||
|
||||
// bp AND ep may not be the same
|
||||
if (m_a == m_b)
|
||||
assert (0);
|
||||
|
||||
R_PointStatus Result_beginPoint,Result_endPoint;
|
||||
int Take_Action1, Take_Action2, Number_of_Crossings = 0;
|
||||
|
||||
Result_beginPoint = PointInLine(lijn.m_a,distance,Marge);
|
||||
Result_endPoint = PointInLine(lijn.m_b,distance,Marge);
|
||||
|
||||
Take_Action1 = ActionOnTable1(Result_beginPoint,Result_endPoint);
|
||||
// 0: No action, no crosspoints
|
||||
// 1: Investigate results points in relation to the other wxLine
|
||||
// 2: endPoint is a crosspoint, no further investigation
|
||||
// 3: beginPoint is a crosspoint, no further investigation
|
||||
// 4: beginPoint and endPoint are crosspoints, no further investigation
|
||||
// 5: beginPoint is a crosspoint, need further investigation
|
||||
// 6: endPoint is a crosspoint, need further investigation
|
||||
|
||||
// The first switch will insert a crosspoint immediatly
|
||||
switch (Take_Action1)
|
||||
{
|
||||
case 2: case 6: c1=lijn.m_b;
|
||||
Number_of_Crossings = 1;
|
||||
break;
|
||||
case 3: case 5: c1=lijn.m_a;
|
||||
Number_of_Crossings = 1;
|
||||
break;
|
||||
case 4: c1=lijn.m_a;
|
||||
c2=lijn.m_b;
|
||||
Number_of_Crossings = 2;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// This switch wil investigate the points of this wxLine in relation to lijn
|
||||
// 1: Investigate results points in relation to the other wxLine
|
||||
// 5: beginPoint is a crosspoint, need further investigation
|
||||
// 6: endPoint is a crosspoint, need further investigation
|
||||
switch (Take_Action1)
|
||||
{
|
||||
case 1: case 5: case 6:
|
||||
{
|
||||
Result_beginPoint = lijn.PointInLine(m_a,distance,Marge);
|
||||
Result_endPoint = lijn.PointInLine(m_b,distance,Marge);
|
||||
Take_Action2 = ActionOnTable2(Result_beginPoint,Result_endPoint);
|
||||
// return -1: Illegal combination
|
||||
// 0: No action, no crosspoints
|
||||
// 1: Calculate crosspoint
|
||||
// 2: endPoint is a crosspoint
|
||||
// 3: beginPoint is a crosspoint
|
||||
// 4: beginPoint and endPoint are crosspoints
|
||||
switch (Take_Action2)
|
||||
{
|
||||
// for the cases see the returnvalue of ActionTable2
|
||||
case 1: { // begin of scope to calculate the intersection
|
||||
double X, Y, Denominator;
|
||||
CalculateLineParameters();
|
||||
Denominator = (m_AA * lijn.m_BB) - (lijn.m_AA * m_BB);
|
||||
// Denominator may not be 0
|
||||
assert(Denominator != 0.0);
|
||||
// Calculate intersection of both linesegments
|
||||
X = ((m_BB * lijn.m_CC) - (lijn.m_BB * m_CC)) / Denominator;
|
||||
Y = ((lijn.m_AA * m_CC) - (m_AA * lijn.m_CC)) / Denominator;
|
||||
|
||||
c1.m_x=X;
|
||||
c1.m_y=Y;
|
||||
}
|
||||
Number_of_Crossings++;
|
||||
break;
|
||||
case 2: c2=m_a;
|
||||
Number_of_Crossings++;
|
||||
break;
|
||||
case 3: c2=m_b;
|
||||
Number_of_Crossings++;
|
||||
break;
|
||||
case 4: c1=m_a;
|
||||
c2=m_b;
|
||||
Number_of_Crossings = 2;
|
||||
break;
|
||||
}
|
||||
};
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return Number_of_Crossings; //This is de final number of crossings
|
||||
}
|
||||
|
||||
//
|
||||
// test if a point lies in the linesegment. If the point isn't on the wxLine
|
||||
// the function returns a value that indicates on which side of the
|
||||
// wxLine the point is (in linedirection from first point to second point
|
||||
//
|
||||
// returns R_LEFT_SIDE, when point lies on the left side of the wxLine
|
||||
// R_RIGHT_SIDE, when point lies on the right side of the wxLine
|
||||
// R_ON_AREA, when point lies on the infinite wxLine within a range
|
||||
// R_IN_AREA, when point lies in the area of the linesegment
|
||||
// the returnvalues are declared in (wxLine.H)
|
||||
R_PointStatus wxLine::PointInLine(const wxPoint2DDouble& a_Point, double& Distance,double Marge)
|
||||
{
|
||||
Distance=0;
|
||||
|
||||
// Point may not be the same
|
||||
assert(m_a != m_b);
|
||||
|
||||
int Result_ofm_BBox=FALSE;
|
||||
R_PointStatus Result_of_Online;
|
||||
|
||||
//quick test if point is begin or endpoint
|
||||
if (a_Point == m_a || a_Point == m_b)
|
||||
return R_IN_AREA;
|
||||
|
||||
// Checking if point is in bounding-box with marge
|
||||
double xmin=wxMin(m_a.m_x,m_b.m_x);
|
||||
double xmax=wxMax(m_a.m_x,m_b.m_x);
|
||||
double ymin=wxMin(m_a.m_y,m_b.m_y);
|
||||
double ymax=wxMax(m_a.m_y,m_b.m_y);
|
||||
|
||||
if ( a_Point.m_x >= (xmin - Marge) && a_Point.m_x <= (xmax + Marge) &&
|
||||
a_Point.m_y >= (ymin - Marge) && a_Point.m_y <= (ymax + Marge) )
|
||||
Result_ofm_BBox=TRUE;
|
||||
|
||||
// Checking if point is on the infinite wxLine
|
||||
Result_of_Online = PointOnLine(a_Point, Distance, Marge);
|
||||
|
||||
// point in boundingbox of the wxLine and is on the wxLine then the point is R_IN_AREA
|
||||
if ((Result_ofm_BBox) && (Result_of_Online == R_ON_AREA))
|
||||
return R_IN_AREA;
|
||||
else
|
||||
return Result_of_Online;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// test if a point lies on the wxLine. If the point isn't on the wxLine
|
||||
// the function returns a value that indicates on which side of the
|
||||
// wxLine the point is (in linedirection from first point to second point
|
||||
//
|
||||
// returns R_LEFT_SIDE, when point lies on the left side of the wxLine
|
||||
// R_ON_AREA, when point lies on the infinite wxLine within a range
|
||||
// R_RIGHT_SIDE, when point lies on the right side of the wxLine
|
||||
// R_LEFT_SIDE , R_RIGHT_SIDE , R_ON_AREA
|
||||
R_PointStatus wxLine::PointOnLine(const wxPoint2DDouble& a_Point, double& Distance, double Marge)
|
||||
{
|
||||
Distance=0;
|
||||
// Point may not be queal
|
||||
assert(m_a!=m_b);
|
||||
|
||||
//quick test if point is begin or endpoint
|
||||
if (a_Point == m_a || a_Point == m_b)
|
||||
return R_ON_AREA;
|
||||
|
||||
CalculateLineParameters();
|
||||
// calculate the distance of a_Point in relation to the wxLine
|
||||
Distance = (m_AA * a_Point.m_x)+(m_BB * a_Point.m_y) + m_CC;
|
||||
|
||||
if (Distance < -Marge)
|
||||
return R_LEFT_SIDE;
|
||||
else
|
||||
{
|
||||
if (Distance > Marge)
|
||||
return R_RIGHT_SIDE;
|
||||
else
|
||||
return R_ON_AREA;
|
||||
}
|
||||
}
|
||||
|
||||
// makes a wxLine same as these
|
||||
// usage : wxLine1 = wxLine2;
|
||||
wxLine& wxLine::operator=(const wxLine& a_line)
|
||||
{
|
||||
m_AA = a_line.m_AA;
|
||||
m_BB = a_line.m_BB;
|
||||
m_CC = a_line.m_CC;
|
||||
|
||||
m_a= a_line.m_a;
|
||||
m_b= a_line.m_b;
|
||||
m_valid_parameters = a_line.m_valid_parameters;
|
||||
return *this;
|
||||
}
|
||||
|
||||
void wxLine::OffsetContour(const wxLine& nextline,double factor,wxPoint2DDouble& offsetpoint) const
|
||||
{
|
||||
wxPoint2DDouble offs_begin(m_a);
|
||||
wxPoint2DDouble offs_end(m_b);
|
||||
|
||||
wxPoint2DDouble offs_bgn_next(nextline.m_a);
|
||||
wxPoint2DDouble offs_end_next(nextline.m_b);
|
||||
// make a wxPoint2DDouble from this point
|
||||
|
||||
Virtual_Point(offs_begin,factor);
|
||||
Virtual_Point(offs_end,factor);
|
||||
wxLine offs_currentline(offs_begin,offs_end);
|
||||
|
||||
nextline.Virtual_Point(offs_bgn_next,factor);
|
||||
nextline.Virtual_Point(offs_end_next,factor);
|
||||
wxLine offs_nextline(offs_bgn_next, offs_end_next);
|
||||
|
||||
offs_nextline.CalculateLineParameters();
|
||||
offs_currentline.CalculateLineParameters();
|
||||
offs_currentline.Intersect(offs_nextline,offsetpoint);
|
||||
}
|
||||
|
||||
// Return the position of the second wxLine compared to this wxLine
|
||||
// Result = IS_ON | IS_LEFT | IS_RIGHT
|
||||
// Here Left and Right is defined as being left or right from
|
||||
// the this wxLine towards the center (common) node
|
||||
// direction of vetors taken as begin to endpoint with end of this at
|
||||
// begin of wxLine two
|
||||
OUTPRODUCT wxLine::OutProduct(const wxLine& two,double accur)
|
||||
{
|
||||
R_PointStatus uitp;
|
||||
double distance;
|
||||
if (two.m_a==two.m_b)
|
||||
assert(0);
|
||||
if (m_a==m_b)
|
||||
assert(0);
|
||||
|
||||
uitp=PointOnLine(two.m_b, distance, accur);
|
||||
|
||||
|
||||
/*double uitp= (_x - first._x) * (third._y - _y) -
|
||||
(_y - first._y) * (third._x - _x);
|
||||
if (uitp>0) return IS_LEFT;
|
||||
if (uitp<0) return IS_RIGHT;
|
||||
return IS_ON;*/
|
||||
|
||||
//depending on direction of this link (going to or coming from centre)
|
||||
if (uitp==R_LEFT_SIDE)
|
||||
return R_IS_LEFT;
|
||||
if (uitp==R_RIGHT_SIDE)
|
||||
return R_IS_RIGHT;
|
||||
return R_IS_ON;
|
||||
}
|
||||
|
||||
// Intersects two lines if a crossing return TRUE
|
||||
// else FALSE
|
||||
bool wxLine::Intersect(wxLine& lijn,wxPoint2DDouble& crossing)
|
||||
{
|
||||
// lijn must exist
|
||||
assert(m_valid_parameters);
|
||||
assert(lijn.m_valid_parameters);
|
||||
|
||||
double X, Y, Denominator;
|
||||
Denominator = (m_AA * lijn.m_BB) - (lijn.m_AA * m_BB);
|
||||
// Denominator may not be 0
|
||||
if (Denominator == 0.0)
|
||||
return FALSE;
|
||||
// Calculate intersection of both linesegments
|
||||
X = ((m_BB * lijn.m_CC) - (lijn.m_BB * m_CC)) / Denominator;
|
||||
Y = ((lijn.m_AA * m_CC) - (m_AA * lijn.m_CC)) / Denominator;
|
||||
|
||||
crossing.m_x=X;
|
||||
crossing.m_y=Y;
|
||||
return TRUE;
|
||||
}
|
||||
|
1453
contrib/src/canvas/polygon.cpp
Normal file
1453
contrib/src/canvas/polygon.cpp
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user