Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
kicad-source-mirror
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
Elphel
kicad-source-mirror
Commits
521f428c
Commit
521f428c
authored
Nov 14, 2008
by
charras
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Using the last version (1.9) of kbool, downloaded from the wxArt2D project site.
parent
5d5698d6
Changes
51
Show whitespace changes
Inline
Side-by-side
Showing
51 changed files
with
9563 additions
and
8836 deletions
+9563
-8836
makefile.g95
bitmaps/makefile.g95
+4
-0
change_log.txt
change_log.txt
+11
-0
build_version.h
include/build_version.h
+2
-2
dialog_copper_zones.cpp
pcbnew/dialog_copper_zones.cpp
+30
-22
pcbframe.cpp
pcbnew/pcbframe.cpp
+1
-1
zones_convert_brd_items_to_polygons.cpp
pcbnew/zones_convert_brd_items_to_polygons.cpp
+1
-1
PolyLine.h
polygon/PolyLine.h
+1
-1
CMakeLists.txt
polygon/kbool/CMakeLists.txt
+1
-1
_dl_itr.h
polygon/kbool/include/_dl_itr.h
+0
-405
_lnk_itr.cpp
polygon/kbool/include/_lnk_itr.cpp
+0
-269
_lnk_itr.h
polygon/kbool/include/_lnk_itr.h
+0
-163
booleng.h
polygon/kbool/include/booleng.h
+0
-544
graph.h
polygon/kbool/include/graph.h
+0
-211
graphlst.h
polygon/kbool/include/graphlst.h
+0
-69
_dl_itr.cpp
polygon/kbool/include/kbool/_dl_itr.cpp
+700
-702
_dl_itr.h
polygon/kbool/include/kbool/_dl_itr.h
+405
-0
_lnk_itr.cpp
polygon/kbool/include/kbool/_lnk_itr.cpp
+257
-0
_lnk_itr.h
polygon/kbool/include/kbool/_lnk_itr.h
+159
-0
booleng.h
polygon/kbool/include/kbool/booleng.h
+583
-0
graph.h
polygon/kbool/include/kbool/graph.h
+207
-0
graphlst.h
polygon/kbool/include/kbool/graphlst.h
+65
-0
kboolmod.h
polygon/kbool/include/kbool/kboolmod.h
+15
-0
line.h
polygon/kbool/include/kbool/line.h
+107
-0
link.h
polygon/kbool/include/kbool/link.h
+230
-0
lpoint.h
polygon/kbool/include/kbool/lpoint.h
+60
-0
node.h
polygon/kbool/include/kbool/node.h
+85
-0
record.h
polygon/kbool/include/kbool/record.h
+78
-0
scanbeam.h
polygon/kbool/include/kbool/scanbeam.h
+58
-0
statusb.h
polygon/kbool/include/kbool/statusb.h
+54
-0
valuesvc.h
polygon/kbool/include/kbool/valuesvc.h
+4
-4
kboolmod.h
polygon/kbool/include/kboolmod.h
+0
-15
line.h
polygon/kbool/include/line.h
+0
-111
link.h
polygon/kbool/include/link.h
+0
-234
lpoint.h
polygon/kbool/include/lpoint.h
+0
-64
node.h
polygon/kbool/include/node.h
+0
-89
record.h
polygon/kbool/include/record.h
+0
-82
scanbeam.h
polygon/kbool/include/scanbeam.h
+0
-66
infos_kbool.txt
polygon/kbool/infos_kbool.txt
+7
-0
kboollicense.txt
polygon/kbool/kboollicense.txt
+684
-0
CMakeLists.txt
polygon/kbool/src/CMakeLists.txt
+7
-6
booleng.cpp
polygon/kbool/src/booleng.cpp
+276
-280
graph.cpp
polygon/kbool/src/graph.cpp
+2095
-2104
graphlst.cpp
polygon/kbool/src/graphlst.cpp
+285
-289
instonly.cpp
polygon/kbool/src/instonly.cpp
+14
-14
line.cpp
polygon/kbool/src/line.cpp
+996
-997
link.cpp
polygon/kbool/src/link.cpp
+419
-419
lpoint.cpp
polygon/kbool/src/lpoint.cpp
+81
-85
makefile.include
polygon/kbool/src/makefile.include
+4
-0
node.cpp
polygon/kbool/src/node.cpp
+476
-479
record.cpp
polygon/kbool/src/record.cpp
+251
-256
scanbeam.cpp
polygon/kbool/src/scanbeam.cpp
+850
-851
No files found.
bitmaps/makefile.g95
View file @
521f428c
...
@@ -8,3 +8,7 @@ include makefile.include
...
@@ -8,3 +8,7 @@ include makefile.include
libbitmaps.a
:
$(OBJECTS)
libbitmaps.a
:
$(OBJECTS)
ar ruv
$@
$(OBJECTS)
ar ruv
$@
$(OBJECTS)
ranlib
$@
ranlib
$@
clean
:
rm
-f
*
.o
rm
-f
*
.a
change_log.txt
View file @
521f428c
...
@@ -6,6 +6,17 @@ Please add newer entries at the top, list the date and your name with
...
@@ -6,6 +6,17 @@ Please add newer entries at the top, list the date and your name with
email address.
email address.
2008-Nov-14 UPDATE Jean-Pierre Charras <jean-pierre.charras@inpg.fr>
================================================================================
kbool:
Using the last version (1.9) of kbool, downloaded from the wxArt2D project site
(see www.wxart2d.org)
But the version 1.8 bug still is here.
So using the workaround remains mandatory.
(this is not a problem because thermal shapes are better...)
2008-Nov-14 UPDATE Dick Hollenbeck <dick@softplc.com>
2008-Nov-14 UPDATE Dick Hollenbeck <dick@softplc.com>
================================================================================
================================================================================
+gerview
+gerview
...
...
include/build_version.h
View file @
521f428c
...
@@ -9,7 +9,7 @@ COMMON_GLOBL wxString g_BuildVersion
...
@@ -9,7 +9,7 @@ COMMON_GLOBL wxString g_BuildVersion
# include "config.h"
# include "config.h"
(
wxT
(
KICAD_SVN_VERSION
))
(
wxT
(
KICAD_SVN_VERSION
))
# else
# else
(
wxT
(
"(200811
06
-unstable)"
))
/* main program version */
(
wxT
(
"(200811
14
-unstable)"
))
/* main program version */
# endif
# endif
#endif
#endif
;
;
...
@@ -20,7 +20,7 @@ COMMON_GLOBL wxString g_BuildAboutVersion
...
@@ -20,7 +20,7 @@ COMMON_GLOBL wxString g_BuildAboutVersion
# include "config.h"
# include "config.h"
(
wxT
(
KICAD_ABOUT_VERSION
))
(
wxT
(
KICAD_ABOUT_VERSION
))
# else
# else
(
wxT
(
"(200811
06
-unstable)"
))
/* svn date & rev (normally overridden) */
(
wxT
(
"(200811
14
-unstable)"
))
/* svn date & rev (normally overridden) */
# endif
# endif
#endif
#endif
;
;
...
...
pcbnew/dialog_copper_zones.cpp
View file @
521f428c
...
@@ -189,8 +189,10 @@ void dialog_copper_zone::OnInitDialog( wxInitDialogEvent& event )
...
@@ -189,8 +189,10 @@ void dialog_copper_zone::OnInitDialog( wxInitDialogEvent& event )
m_NetNameFilter
->
SetValue
(
NetNameFilter
);
m_NetNameFilter
->
SetValue
(
NetNameFilter
);
wxArrayString
ListNetName
;
wxArrayString
ListNetName
;
m_Parent
->
m_Pcb
->
ReturnSortedNetnamesList
(
ListNetName
,
m_Parent
->
m_Pcb
->
ReturnSortedNetnamesList
(
m_NetSorting
==
0
?
BOARD
::
ALPHA_SORT
:
BOARD
::
PAD_CNT_SORT
);
ListNetName
,
m_NetSorting
==
0
?
BOARD
::
ALPHA_SORT
:
BOARD
::
PAD_CNT_SORT
);
if
(
m_NetSorting
!=
0
)
if
(
m_NetSorting
!=
0
)
{
{
...
@@ -336,8 +338,10 @@ bool dialog_copper_zone::AcceptOptions( bool aPromptForErrors, bool aUseExportab
...
@@ -336,8 +338,10 @@ bool dialog_copper_zone::AcceptOptions( bool aPromptForErrors, bool aUseExportab
m_Parent
->
m_Parent
->
m_EDA_Config
->
Write
(
ZONE_THERMAL_RELIEF_GAP_STRING_KEY
,
m_Parent
->
m_Parent
->
m_EDA_Config
->
Write
(
ZONE_THERMAL_RELIEF_GAP_STRING_KEY
,
(
long
)
m_Zone_Setting
->
m_ThermalReliefGapValue
);
(
long
)
m_Zone_Setting
->
m_ThermalReliefGapValue
);
m_Parent
->
m_Parent
->
m_EDA_Config
->
Write
(
ZONE_THERMAL_RELIEF_COPPER_WIDTH_STRING_KEY
,
m_Parent
->
m_Parent
->
m_EDA_Config
->
Write
(
(
long
)
m_Zone_Setting
->
m_ThermalReliefCopperBridgeValue
);
ZONE_THERMAL_RELIEF_COPPER_WIDTH_STRING_KEY
,
(
long
)
m_Zone_Setting
->
m_ThermalReliefCopperBridgeValue
);
// If we use only exportable to others zones parameters, exit here:
// If we use only exportable to others zones parameters, exit here:
if
(
aUseExportableSetupOnly
)
if
(
aUseExportableSetupOnly
)
...
@@ -388,8 +392,10 @@ void dialog_copper_zone::OnNetSortingOptionSelected( wxCommandEvent& event )
...
@@ -388,8 +392,10 @@ void dialog_copper_zone::OnNetSortingOptionSelected( wxCommandEvent& event )
wxArrayString
ListNetName
;
wxArrayString
ListNetName
;
m_NetSorting
=
m_NetSortingOption
->
GetSelection
();
m_NetSorting
=
m_NetSortingOption
->
GetSelection
();
m_Parent
->
m_Pcb
->
ReturnSortedNetnamesList
(
ListNetName
,
m_Parent
->
m_Pcb
->
ReturnSortedNetnamesList
(
m_NetSorting
==
0
?
BOARD
::
ALPHA_SORT
:
BOARD
::
PAD_CNT_SORT
);
ListNetName
,
m_NetSorting
==
0
?
BOARD
::
ALPHA_SORT
:
BOARD
::
PAD_CNT_SORT
);
if
(
m_NetSorting
!=
0
)
if
(
m_NetSorting
!=
0
)
{
{
wxString
Filter
=
m_NetNameFilter
->
GetValue
();
wxString
Filter
=
m_NetNameFilter
->
GetValue
();
...
@@ -448,12 +454,14 @@ void dialog_copper_zone::ExportSetupToOtherCopperZones( wxCommandEvent& event )
...
@@ -448,12 +454,14 @@ void dialog_copper_zone::ExportSetupToOtherCopperZones( wxCommandEvent& event )
if
(
!
AcceptOptions
(
true
,
true
)
)
if
(
!
AcceptOptions
(
true
,
true
)
)
return
;
return
;
// Export to others zones:
// Export
settings ( but layer )
to others zones:
BOARD
*
pcb
=
m_Parent
->
m_Pcb
;
BOARD
*
pcb
=
m_Parent
->
m_Pcb
;
for
(
int
ii
=
0
;
ii
<
pcb
->
GetAreaCount
();
ii
++
)
for
(
int
ii
=
0
;
ii
<
pcb
->
GetAreaCount
();
ii
++
)
{
{
ZONE_CONTAINER
*
zone
=
pcb
->
GetArea
(
ii
);
ZONE_CONTAINER
*
zone
=
pcb
->
GetArea
(
ii
);
int
zone_layer
=
zone
->
GetLayer
();
m_Zone_Setting
->
ExportSetting
(
*
zone
);
m_Zone_Setting
->
ExportSetting
(
*
zone
);
zone
->
SetLayer
(
zone_layer
);
m_Parent
->
GetScreen
()
->
SetModify
();
m_Parent
->
GetScreen
()
->
SetModify
();
}
}
}
}
...
...
pcbnew/pcbframe.cpp
View file @
521f428c
...
@@ -12,7 +12,7 @@
...
@@ -12,7 +12,7 @@
#include "protos.h"
#include "protos.h"
#include "id.h"
#include "id.h"
#include "drc_stuff.h"
#include "drc_stuff.h"
#include "kbool/include/booleng.h"
#include "kbool/include/
kbool/
booleng.h"
/*******************************/
/*******************************/
/* class WinEDA_PcbFrame */
/* class WinEDA_PcbFrame */
...
...
pcbnew/zones_convert_brd_items_to_polygons.cpp
View file @
521f428c
...
@@ -464,7 +464,7 @@ void AddThermalReliefPadPolygon( Bool_Engine* aBooleng,
...
@@ -464,7 +464,7 @@ void AddThermalReliefPadPolygon( Bool_Engine* aBooleng,
// Now, add the 4 holes ( each is the pattern, rotated by 0, 90, 180 and 270 deg
// Now, add the 4 holes ( each is the pattern, rotated by 0, 90, 180 and 270 deg
// WARNING: problems with kbool if angle = 0 (in fact when angle < 200):
// WARNING: problems with kbool if angle = 0 (in fact when angle < 200):
// bad filled polygon on some cases, when pads are on a same vertical line
// bad filled polygon on some cases, when pads are on a same vertical line
// this seems a bug in kbool polygon
// this seems a bug in kbool polygon
(exists in 1.9 kbool version)
// angle = 450 (45.0 degrees orientation) seems work fine.
// angle = 450 (45.0 degrees orientation) seems work fine.
// angle = 0 with thermal shapes without angle < 90 deg seems works fine also
// angle = 0 with thermal shapes without angle < 90 deg seems works fine also
angle
=
0
;
angle
=
0
;
...
...
polygon/PolyLine.h
View file @
521f428c
...
@@ -17,7 +17,7 @@
...
@@ -17,7 +17,7 @@
#include <vector>
#include <vector>
#include "kbool/include/booleng.h"
#include "kbool/include/
kbool/
booleng.h"
#include "pad_shapes.h"
#include "pad_shapes.h"
// inflection modes for DS_LINE and DS_LINE_VERTEX, used in math_for_graphics.cpp
// inflection modes for DS_LINE and DS_LINE_VERTEX, used in math_for_graphics.cpp
...
...
polygon/kbool/CMakeLists.txt
View file @
521f428c
project
(
kbool
)
project
(
kbool
)
subdirs
(
src
samples
)
subdirs
(
src
)
polygon/kbool/include/_dl_itr.h
deleted
100644 → 0
View file @
5d5698d6
/*! \file kbool/include/kbool/_dl_itr.h
\author Probably Klaas Holwerda
Copyright: 2001-2004 (C) Probably Klaas Holwerda
Licence: wxWidgets Licence
RCS-ID: $Id: _dl_itr.h,v 1.1 2005/05/24 19:13:35 titato Exp $
*/
//! author="Klaas Holwerda"
/*
* Definitions of classes, for list implementation
* template list and iterator for any list node type
*/
#ifndef _DL_Iter_H
#define _DL_Iter_H
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
#pragma interface
#endif
#include <stdlib.h>
#include "../include/booleng.h"
#ifndef _STATUS_ENUM
#define _STATUS_ENUM
//!<enum Error codes for List and iterator class
enum
Lerror
{
NO_MES
,
/*!<No Message will be generated */
NO_LIST
,
/*!<List is not attached to the iterator*/
NO_LIST_OTHER
,
/*!<no attached list on other iter*/
AC_ITER_LIST_OTHER
,
/*!<iter not allowed on other list */
SAME_LIST
,
/*!<same list not allowed*/
NOT_SAME_LIST
,
/*!<must be same list*/
ITER_GT_1
,
/*!<more then one iteriter at root*/
ITER_GT_0
,
/*!<iter not allowed*/
ITER_HITROOT
,
/*!<iter at root*/
NO_ITEM
,
/*!<no item at current*/
NO_NEXT
,
/*!<no next after current*/
NO_PREV
,
/*!<no prev before current */
EMPTY
,
/*!<list is empty*/
NOT_ALLOW
,
/*!<not allowed*/
ITER_NEG
/*!<to much iters deleted*/
};
#endif
#define SWAP(x,y,t)((t)=(x),(x)=(y),(y)=(t))
#define RT _list->_root
#define HD _list->_root->_next
#define TL _list->_root->_prev
#define NB _list->_nbitems
template
<
class
Dtype
>
class
DL_List
;
template
<
class
Dtype
>
class
DL_Iter
;
template
<
class
Dtype
>
class
DL_SortIter
;
//! Template class DL_Node
template
<
class
Dtype
>
class
DL_Node
{
friend
class
DL_List
<
Dtype
>
;
friend
class
DL_Iter
<
Dtype
>
;
friend
class
DL_SortIter
<
Dtype
>
;
//!Public members
public
:
//!Template constructor no contents
//!Construct a node for a list object
DL_Node
();
//!constructor with init of Dtype
DL_Node
(
Dtype
n
);
//!Destructor
~
DL_Node
();
//!Public members
public
:
//!data in node
Dtype
_item
;
//!pointer to next node
DL_Node
*
_next
;
//!pointer to previous node
DL_Node
*
_prev
;
};
//!Template class DL_List
template
<
class
Dtype
>
class
DL_List
{
friend
class
DL_Iter
<
Dtype
>
;
friend
class
DL_SortIter
<
Dtype
>
;
public
:
//!Constructor
//!Construct a list object
//!!tcarg class | Dtype | list object
DL_List
();
//!destructor
~
DL_List
();
//!Report off List Errors
void
Error
(
const
char
*
function
,
Lerror
a_error
);
//!Number of items in the list
int
count
();
//!Empty List?
bool
empty
();
//!insert the object given at the end of the list, after tail
DL_Node
<
Dtype
>*
insend
(
Dtype
n
);
//!insert the object given at the begin of the list, before head
DL_Node
<
Dtype
>*
insbegin
(
Dtype
n
);
//!remove the object at the begin of the list (head)
void
removehead
();
//! remove the object at the end of the list (tail)
void
removetail
();
//!remove all objects from the list
void
remove_all
(
bool
deleteObject
=
false
);
//!Get the item at the head of the list
Dtype
headitem
();
//!Get the item at the tail of the list
Dtype
tailitem
();
//! to move all objects in a list to this list.
void
takeover
(
DL_List
<
Dtype
>*
otherlist
);
public
:
//!the root node pointer of the list, the first and last node
//! in the list are connected to the root node. The root node is used
//! to detect the end / beginning of the list while traversing it.
DL_Node
<
Dtype
>*
_root
;
//!the number of items in the list, if empty list it is 0
int
_nbitems
;
//!number of iterators on the list, Attaching or instantiating an iterator to list,
//! will increment this member, detaching and
//! destruction of iterator for a list will decrement this number
short
int
_iterlevel
;
};
//! Template class DL_Iter for iterator on DL_List
template
<
class
Dtype
>
class
DL_Iter
{
public
:
//!Construct an iterator object for a given list of type Dtype
DL_Iter
(
DL_List
<
Dtype
>*
newlist
);
//!Constructor of iterator for the same list as another iterator
DL_Iter
(
DL_Iter
*
otheriter
);
//!Constructor without an attached list
DL_Iter
();
//!destructor
~
DL_Iter
();
//!Report off Iterator Errors
void
Error
(
const
char
*
function
,
Lerror
a_error
);
//!This attaches an iterator to a list of a given type.
void
Attach
(
DL_List
<
Dtype
>*
newlist
);
//!This detaches an iterator from a list
void
Detach
();
//!execute given function for each item in the list/iterator
void
foreach_f
(
void
(
*
fp
)
(
Dtype
n
)
);
//! list mutations
//!insert after tail item
DL_Node
<
Dtype
>*
insend
(
Dtype
n
);
//!insert before head item
DL_Node
<
Dtype
>*
insbegin
(
Dtype
n
);
//!insert before current iterator position
DL_Node
<
Dtype
>*
insbefore
(
Dtype
n
);
//!insert after current iterator position
DL_Node
<
Dtype
>*
insafter
(
Dtype
n
);
//!to move all objects in a list to the list of the iterator.
void
takeover
(
DL_List
<
Dtype
>*
otherlist
);
//!to move all objects in a list (using iterator of that list) to the list of the iterator
void
takeover
(
DL_Iter
*
otheriter
);
//! to move maxcount objects in a list (using iterator of that list) to the list of the iterator
void
takeover
(
DL_Iter
*
otheriter
,
int
maxcount
);
//!remove object at current iterator position from the list.
void
remove
();
//!Remove head item
void
removehead
();
//!Remove tail item
void
removetail
();
//!Remove all items
void
remove_all
();
/* void foreach_mf(void (Dtype::*mfp)() ); //call Dtype::mfp for each item */
//!is list empty (contains items or not)?
bool
empty
();
//!is iterator at root node (begin or end)?
bool
hitroot
();
//!is iterator at head/first node?
bool
athead
();
//!is iterator at tail/last node?
bool
attail
();
//!is given item member of the list
bool
has
(
Dtype
otheritem
);
//!Number of items in the list
int
count
();
/* cursor movements */
//!go to last item, if list is empty goto hite
void
totail
();
//!go to first item, if list is empty goto hite
void
tohead
();
//!set the iterator position to the root (empty dummy) object in the list.
void
toroot
();
//! set the iterator position to next object in the list ( can be the root also).
void
operator
++
(
void
);
//!set iterator to next item (pre fix)
void
operator
++
(
int
);
//!set the iterator position to previous object in the list ( can be the root also)(postfix).
void
operator
--
(
void
);
//!set the iterator position to previous object in the list ( can be the root also)(pre fix).
void
operator
--
(
int
);
//!set the iterator position n objects in the next direction ( can be the root also).
void
operator
>>
(
int
);
//!set the iterator position n objects in the previous direction ( can be the root also).
void
operator
<<
(
int
);
//!set the iterator position to next object in the list, if this would be the root object,
//!then set the iterator at the head object
void
next_wrap
();
//!set the iterator position to previous object in the list, if this would be the root object,
//!then set the iterator at the tail object
void
prev_wrap
();
//!move root in order to make the current node the tail
void
reset_tail
();
//!move root in order to make the current node the head
void
reset_head
();
//!put the iterator at the position of the given object in the list.
bool
toitem
(
Dtype
);
//!put the iterator at the same position as the given iterator in the list.
void
toiter
(
DL_Iter
*
otheriter
);
//!put the iterator at the position of the given node in the list.
bool
tonode
(
DL_Node
<
Dtype
>*
);
//!iterate through all items of the list
bool
iterate
(
void
);
//!To get the item at the current iterator position
Dtype
item
();
//! get node at iterator
DL_Node
<
Dtype
>*
node
();
//!sort list with mergesort
void
mergesort
(
int
(
*
fcmp
)
(
Dtype
,
Dtype
));
//!sort list with cocktailsort
/*!
\return number of swaps done.
*/
int
cocktailsort
(
int
(
*
)(
Dtype
,
Dtype
),
bool
(
*
)(
Dtype
,
Dtype
)
=
NULL
);
protected
:
//!sort list with mergesort
void
mergesort_rec
(
int
(
*
fcmp
)(
Dtype
,
Dtype
),
DL_Node
<
Dtype
>
*
RT1
,
int
n
);
//!sort list with mergesort
void
mergetwo
(
int
(
*
fcmp
)(
Dtype
,
Dtype
),
DL_Node
<
Dtype
>
*
RT1
,
DL_Node
<
Dtype
>
*
RT2
);
//!set the iterator position to next object in the list ( can be the root also).
void
next
();
//!set the iterator position to previous object in the list ( can be the root also).
void
prev
();
//!the list for this iterator
DL_List
<
Dtype
>
*
_list
;
//!the current position of the iterator
DL_Node
<
Dtype
>
*
_current
;
};
//! template class DL_StackIter class for stack iterator on DL_List
template
<
class
Dtype
>
class
DL_StackIter
:
protected
DL_Iter
<
Dtype
>
{
public
:
//!Constructor of stack iterator for given list
DL_StackIter
(
DL_List
<
Dtype
>
*
);
//!Constructor of stack iterator no list attached
DL_StackIter
();
//!Destructor of stack iterator
~
DL_StackIter
();
//!Remove all items from the stack
void
remove_all
();
//!push given item on the stack
void
push
(
Dtype
n
);
//!get last inserted item from stack
Dtype
pop
();
//!is stack empty?
bool
empty
();
//!number of items on the stack
int
count
();
};
//!template class DL_SortIter
template
<
class
DType
>
class
DL_SortIter
:
public
DL_Iter
<
DType
>
{
public
:
//!Constructor of sort iterator for given list and sort function
DL_SortIter
(
DL_List
<
DType
>*
nw_list
,
int
(
*
new_func
)(
DType
,
DType
));
//!Constructor of sort iterator with sort function and no list attached
DL_SortIter
(
int
(
*
newfunc
)(
DType
,
DType
));
//!Destructor of sort iterator
~
DL_SortIter
();
//!insert item in sorted order
void
insert
(
DType
new_item
);
/*override following functions to give an error */
//!Not allowed
void
insend
(
bool
n
){
sortitererror
();};
//!Not allowed
void
insbegin
(
bool
n
){
sortitererror
();};
//!Not allowed
void
insbefore
(
bool
n
){
sortitererror
();};
//!Not allowed
void
insafter
(
bool
n
){
sortitererror
();};
//!Not allowed
void
takeover
(
DL_List
<
DType
>*
){
sortitererror
();};
//!Not allowed
void
takeover
(
DL_Iter
<
DType
>*
){
sortitererror
();};
//!Not allowed
void
takeover
(
DL_Iter
<
DType
>*
otheriter
,
int
maxcount
){
sortitererror
();};
//!Not allowed
void
next_wrap
()
{
sortitererror
();};
//!Not allowed
void
prev_wrap
()
{
sortitererror
();};
//!Not allowed
void
reset_tail
()
{
sortitererror
();};
//!Not allowed
void
reset_head
()
{
sortitererror
();};
private
:
//!Report off Iterator Errors
void
sortitererror
();
//!comparefunction used to insert items in sorted order
int
(
*
comparef
)(
DType
,
DType
);
};
#include "../include/_dl_itr.cpp"
#endif
polygon/kbool/include/_lnk_itr.cpp
deleted
100644 → 0
View file @
5d5698d6
/*! \file kbool/include/kbool/_lnk_itr.cpp
\author Probably Klaas Holwerda
Copyright: 2001-2004 (C) Probably Klaas Holwerda
Licence: wxWidgets Licence
RCS-ID: $Id: _lnk_itr.cpp,v 1.1 2005/05/24 19:13:36 titato Exp $
*/
#ifdef __GNUG__
#pragma implementation
#endif
#ifdef __UNIX__
#include "../include/_lnk_itr.h"
#endif
//=======================================================================
// implementation class LinkBaseIter
//=======================================================================
template
<
class
Type
>
TDLI
<
Type
>::
TDLI
(
DL_List
<
void
*>*
newlist
)
:
DL_Iter
<
void
*>
(
newlist
)
{
}
template
<
class
Type
>
TDLI
<
Type
>::
TDLI
(
DL_Iter
<
void
*>*
otheriter
)
:
DL_Iter
<
void
*>
(
otheriter
)
{
}
template
<
class
Type
>
TDLI
<
Type
>::
TDLI
()
:
DL_Iter
<
void
*>
()
{
}
// destructor TDLI
template
<
class
Type
>
TDLI
<
Type
>::~
TDLI
()
{
}
template
<
class
Type
>
void
TDLI
<
Type
>::
delete_all
()
{
DL_Node
<
void
*>*
node
;
Type
*
obj
;
for
(
int
i
=
0
;
i
<
NB
;
i
++
)
{
node
=
HD
;
HD
=
node
->
_next
;
obj
=
(
Type
*
)(
node
->
_item
);
delete
obj
;
delete
node
;
}
NB
=
0
;
//reset memory used (no lost pointers)
TL
=
RT
;
_current
=
RT
;
}
template
<
class
Type
>
void
TDLI
<
Type
>::
foreach_f
(
void
(
*
fp
)
(
Type
*
item
)
)
{
DL_Iter
<
void
*>::
foreach_f
(
(
void
(
*
)(
void
*
))
fp
);
//call fp for each item
}
template
<
class
Type
>
void
TDLI
<
Type
>::
foreach_mf
(
void
(
Type
::*
mfp
)
())
{
DL_Node
<
void
*>*
node
=
HD
;
//can be 0 if empty
Type
*
obj
;
for
(
int
i
=
0
;
i
<
NB
;
i
++
)
{
obj
=
(
Type
*
)(
node
->
_item
);
(
obj
->*
mfp
)();
node
=
node
->
_next
;
}
}
template
<
class
Type
>
void
TDLI
<
Type
>::
takeover
(
DL_List
<
void
*>*
otherlist
)
{
DL_Iter
<
void
*>::
takeover
(
(
DL_List
<
void
*>*
)
otherlist
);
}
template
<
class
Type
>
void
TDLI
<
Type
>::
takeover
(
TDLI
*
otheriter
)
{
DL_Iter
<
void
*>::
takeover
(
(
DL_Iter
<
void
*>*
)
otheriter
);
}
template
<
class
Type
>
void
TDLI
<
Type
>::
takeover
(
TDLI
*
otheriter
,
int
maxcount
)
{
DL_Iter
<
void
*>::
takeover
(
(
DL_Iter
<
void
*>*
)
otheriter
,
maxcount
);
}
// is item element of the list?
template
<
class
Type
>
bool
TDLI
<
Type
>::
has
(
Type
*
otheritem
)
{
return
DL_Iter
<
void
*>::
has
(
(
void
*
)
otheritem
);
}
// goto to item
template
<
class
Type
>
bool
TDLI
<
Type
>::
toitem
(
Type
*
item
)
{
return
DL_Iter
<
void
*>::
toitem
(
(
void
*
)
item
);
}
// get current item
template
<
class
Type
>
Type
*
TDLI
<
Type
>::
item
()
{
return
(
Type
*
)
DL_Iter
<
void
*>::
item
();
}
template
<
class
Type
>
void
TDLI
<
Type
>::
insend
(
Type
*
newitem
)
{
DL_Iter
<
void
*>::
insend
(
(
void
*
)
newitem
);
}
template
<
class
Type
>
void
TDLI
<
Type
>::
insbegin
(
Type
*
newitem
)
{
DL_Iter
<
void
*>::
insbegin
(
(
void
*
)
newitem
);
}
template
<
class
Type
>
void
TDLI
<
Type
>::
insbefore
(
Type
*
newitem
)
{
DL_Iter
<
void
*>::
insbefore
(
(
void
*
)
newitem
);
}
template
<
class
Type
>
void
TDLI
<
Type
>::
insafter
(
Type
*
newitem
)
{
DL_Iter
<
void
*>::
insafter
(
(
void
*
)
newitem
);
}
template
<
class
Type
>
void
TDLI
<
Type
>::
insend_unsave
(
Type
*
newitem
)
{
short
int
iterbackup
=
_list
->
_iterlevel
;
_list
->
_iterlevel
=
0
;
DL_Iter
<
void
*>::
insend
(
(
void
*
)
newitem
);
_list
->
_iterlevel
=
iterbackup
;
}
template
<
class
Type
>
void
TDLI
<
Type
>::
insbegin_unsave
(
Type
*
newitem
)
{
short
int
iterbackup
=
_list
->
_iterlevel
;
_list
->
_iterlevel
=
0
;
DL_Iter
<
void
*>::
insbegin
(
(
void
*
)
newitem
);
_list
->
_iterlevel
=
iterbackup
;
}
template
<
class
Type
>
void
TDLI
<
Type
>::
insbefore_unsave
(
Type
*
newitem
)
{
short
int
iterbackup
=
_list
->
_iterlevel
;
_list
->
_iterlevel
=
0
;
DL_Iter
<
void
*>::
insbefore
(
(
void
*
)
newitem
);
_list
->
_iterlevel
=
iterbackup
;
}
template
<
class
Type
>
void
TDLI
<
Type
>::
insafter_unsave
(
Type
*
newitem
)
{
short
int
iterbackup
=
_list
->
_iterlevel
;
_list
->
_iterlevel
=
0
;
DL_Iter
<
void
*>::
insafter
(
(
void
*
)
newitem
);
_list
->
_iterlevel
=
iterbackup
;
}
template
<
class
Type
>
void
TDLI
<
Type
>::
mergesort
(
int
(
*
f
)(
Type
*
a
,
Type
*
b
))
{
DL_Iter
<
void
*>::
mergesort
(
(
int
(
*
)(
void
*
,
void
*
))
f
);
}
template
<
class
Type
>
int
TDLI
<
Type
>::
cocktailsort
(
int
(
*
f
)(
Type
*
a
,
Type
*
b
),
bool
(
*
f2
)(
Type
*
c
,
Type
*
d
))
{
return
DL_Iter
<
void
*>::
cocktailsort
(
(
int
(
*
)(
void
*
,
void
*
))
f
,(
bool
(
*
)(
void
*
,
void
*
))
f2
);
}
template
<
class
Type
>
TDLISort
<
Type
>::
TDLISort
(
DL_List
<
void
*>*
lista
,
int
(
*
newfunc
)(
void
*
,
void
*
))
:
DL_SortIter
<
void
*>
(
lista
,
newfunc
)
{
}
template
<
class
Type
>
TDLISort
<
Type
>::~
TDLISort
()
{
}
template
<
class
Type
>
void
TDLISort
<
Type
>::
delete_all
()
{
DL_Node
<
void
*>*
node
;
Type
*
obj
;
for
(
int
i
=
0
;
i
<
NB
;
i
++
)
{
node
=
HD
;
HD
=
node
->
_next
;
obj
=
(
Type
*
)(
node
->
_item
);
delete
obj
;
delete
node
;
}
NB
=
0
;
//reset memory used (no lost pointers)
TL
=
RT
;
_current
=
RT
;
}
// is item element of the list?
template
<
class
Type
>
bool
TDLISort
<
Type
>::
has
(
Type
*
otheritem
)
{
return
DL_Iter
<
void
*>::
has
(
(
void
*
)
otheritem
);
}
// goto to item
template
<
class
Type
>
bool
TDLISort
<
Type
>::
toitem
(
Type
*
item
)
{
return
DL_Iter
<
void
*>::
toitem
(
(
void
*
)
item
);
}
// get current item
template
<
class
Type
>
Type
*
TDLISort
<
Type
>::
item
()
{
return
(
Type
*
)
DL_Iter
<
void
*>::
item
();
}
template
<
class
Type
>
TDLIStack
<
Type
>::
TDLIStack
(
DL_List
<
void
*>*
newlist
)
:
DL_StackIter
<
void
*>
(
newlist
)
{
}
// destructor TDLI
template
<
class
Type
>
TDLIStack
<
Type
>::~
TDLIStack
()
{
}
// plaats nieuw item op stack
template
<
class
Type
>
void
TDLIStack
<
Type
>::
push
(
Type
*
newitem
)
{
DL_StackIter
<
void
*>::
push
((
Type
*
)
newitem
);
}
// haal bovenste item van stack
template
<
class
Type
>
Type
*
TDLIStack
<
Type
>::
pop
()
{
return
(
Type
*
)
DL_StackIter
<
void
*>::
pop
();
}
polygon/kbool/include/_lnk_itr.h
deleted
100644 → 0
View file @
5d5698d6
/*! \file kbool/include/kbool/_lnk_itr.h
\author Probably Klaas Holwerda
Copyright: 2001-2004 (C) Probably Klaas Holwerda
Licence: wxWidgets Licence
RCS-ID: $Id: _lnk_itr.h,v 1.1 2005/05/24 19:13:36 titato Exp $
*/
//! author="Klaas Holwerda"
//! version="1.0"
/*
* Definitions of classes, for list implementation
* template list and iterator for any list node type
*/
#ifndef _LinkBaseIter_H
#define _LinkBaseIter_H
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
#pragma interface
#endif
//! headerfiles="_dl_itr.h stdlib.h misc.h gdsmes.h"
#include <stdlib.h>
#include "../include/booleng.h"
#define SWAP(x,y,t)((t)=(x),(x)=(y),(y)=(t))
#include "../include/_dl_itr.h"
//! codefiles="_dl_itr.cpp"
//! Template class TDLI
/*!
class for iterator on DL_List<void*> that is type casted version of DL_Iter
\sa DL_Iter for further documentation
*/
template
<
class
Type
>
class
TDLI
:
public
DL_Iter
<
void
*>
{
public
:
//!constructor
/*!
\param list to iterate on.
*/
TDLI
(
DL_List
<
void
*>*
list
);
//!constructor
TDLI
(
DL_Iter
<
void
*>*
otheriter
);
//! nolist constructor
TDLI
();
//! destructor
~
TDLI
();
//!call fp for each item
void
foreach_f
(
void
(
*
fp
)
(
Type
*
item
)
);
//!call fp for each item
void
foreach_mf
(
void
(
Type
::*
fp
)
()
);
/* list mutations */
//! delete all items
void
delete_all
();
//! insert at end
void
insend
(
Type
*
n
);
//! insert at begin
void
insbegin
(
Type
*
n
);
//! insert before current
void
insbefore
(
Type
*
n
);
//! insert after current
void
insafter
(
Type
*
n
);
//! insert at end unsave (works even if more then one iterator is on the list
//! the user must be sure not to delete/remove items where other iterators
//! are pointing to.
void
insend_unsave
(
Type
*
n
);
//! insert at begin unsave (works even if more then one iterator is on the list
//! the user must be sure not to delete/remove items where other iterators
//! are pointing to.
void
insbegin_unsave
(
Type
*
n
);
//! insert before iterator position unsave (works even if more then one iterator is on the list
//! the user must be sure not to delete/remove items where other iterators
//! are pointing to.
void
insbefore_unsave
(
Type
*
n
);
//! insert after iterator position unsave (works even if more then one iterator is on the list
//! the user must be sure not to delete/remove items where other iterators
//! are pointing to.
void
insafter_unsave
(
Type
*
n
);
//! \sa DL_Iter::takeover(DL_List< Dtype >* otherlist )
void
takeover
(
DL_List
<
void
*>*
otherlist
);
//! \sa DL_Iter::takeover(DL_Iter* otheriter)
void
takeover
(
TDLI
*
otheriter
);
//! \sa DL_Iter::takeover(DL_Iter* otheriter, int maxcount)
void
takeover
(
TDLI
*
otheriter
,
int
maxcount
);
//! \sa DL_Iter::has
bool
has
(
Type
*
);
//! \sa DL_Iter::toitem
bool
toitem
(
Type
*
);
//!get the item then iterator is pointing at
Type
*
item
();
//! \sa DL_Iter::mergesort
void
mergesort
(
int
(
*
f
)(
Type
*
a
,
Type
*
b
));
//! \sa DL_Iter::cocktailsort
int
cocktailsort
(
int
(
*
)
(
Type
*
a
,
Type
*
b
),
bool
(
*
)
(
Type
*
c
,
Type
*
d
)
=
NULL
);
};
//! Template class TDLIsort
/*!
// class for sort iterator on DL_List<void*> that is type casted version of DL_SortIter
// see also inhereted class DL_SortIter for further documentation
*/
template
<
class
Type
>
class
TDLISort
:
public
DL_SortIter
<
void
*>
{
public
:
//!constructor givin a list and a sort function
TDLISort
(
DL_List
<
void
*>*
list
,
int
(
*
newfunc
)(
void
*
,
void
*
));
~
TDLISort
();
//!delete all items from the list
void
delete_all
();
bool
has
(
Type
*
);
bool
toitem
(
Type
*
);
Type
*
item
();
};
//! Template class TDLIStack
/*!
class for iterator on DL_List<void*> that is type casted version of DL_StackIter
see also inhereted class DL_StackIter for further documentation
*/
template
<
class
Type
>
class
TDLIStack
:
public
DL_StackIter
<
void
*>
{
public
:
//constructor givin a list
TDLIStack
(
DL_List
<
void
*>*
list
);
~
TDLIStack
();
void
push
(
Type
*
);
Type
*
pop
();
};
#include"../include/_lnk_itr.cpp"
#endif
polygon/kbool/include/booleng.h
deleted
100644 → 0
View file @
5d5698d6
/*! \file kbool/include/kbool/booleng.h
\author Probably Klaas Holwerda
Copyright: 2001-2004 (C) Probably Klaas Holwerda
Licence: wxWidgets Licence
RCS-ID: $Id: booleng.h,v 1.3 2005/06/11 19:25:12 frm Exp $
*/
#ifndef BOOLENG_H
#define BOOLENG_H
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
#pragma interface
#endif
#include <stdio.h>
#include <limits.h>
#ifdef A2DKBOOLMAKINGDLL
#define A2DKBOOLDLLEXP WXEXPORT
#define A2DKBOOLDLLEXP_DATA(type) WXEXPORT type
#define A2DKBOOLDLLEXP_CTORFN
#if 0 // Kicad does dot use wxWidgets lib when building the kbool library
// but uses wxWidgets. So WXUSINGDLL has no meaning here, but could be defined in makefiles
// but must not be used when building kbool
#elif
defined
(
WXUSINGDLL
)
#define A2DKBOOLDLLEXP WXIMPORT
#define A2DKBOOLDLLEXP_DATA(type) WXIMPORT type
#define A2DKBOOLDLLEXP_CTORFN
#endif
#else // not making nor using DLL
#define A2DKBOOLDLLEXP
#define A2DKBOOLDLLEXP_DATA(type) type
#define A2DKBOOLDLLEXP_CTORFN
#endif
#define KBOOL_VERSION "1.8"
#define KBOOL_DEBUG 0
#define KBOOL_LOG 0
#define KBOOL_INT64 1
class
KBoolLink
;
#define LINELENGTH 200
#ifdef MAXDOUBLE
#undef MAXDOUBLE
#endif
#define MAXDOUBLE 1.7976931348623158e+308
#ifdef KBOOL_INT64
#if defined(__UNIX__) || defined(__GNUG__)
typedef
long
long
B_INT
;
// 8 bytes integer
//#define MAXB_INT LONG_LONG_MAX
//#define MINB_INT LONG_LONG_MIN // 8 bytes integer
#ifndef MAXB_INT
const
B_INT
MAXB_INT
=
(
0x7fffffffffffffffLL
);
// 8 bytes integer
#endif
#ifndef MINB_INT
const
B_INT
MINB_INT
=
(
0x8000000000000000LL
);
#endif
#else //defined(__UNIX__) || defined(__GNUG__)
typedef
__int64
B_INT
;
// 8 bytes integer
#undef MAXB_INT
#undef MINB_INT
const
B_INT
MAXB_INT
=
(
0x7fffffffffffffff
);
// 8 bytes integer
const
B_INT
MINB_INT
=
(
0x8000000000000000
);
#endif //defined(__UNIX__) || defined(__GNUG__)
#else //KBOOL_INT64
#if defined(__UNIX__) || defined(__GNUG__)
typedef
long
B_INT
;
// 4 bytes integer
const
B_INT
MAXB_INT
=
(
0x7fffffffL
);
// 4 bytes integer
const
B_INT
MINB_INT
=
(
0x80000000L
);
#else
typedef
long
B_INT
;
// 4 bytes integer
const
B_INT
MAXB_INT
=
(
0x7fffffff
);
// 4 bytes integer
const
B_INT
MINB_INT
=
(
0x80000000
);
#endif
#endif //KBOOL_INT64
B_INT
babs
(
B_INT
);
#ifdef M_PI
#undef M_PI
#endif
#define M_PI (3.1415926535897932384626433832795028841972)
#ifdef M_PI_2
#undef M_PI_2
#endif
#define M_PI_2 1.57079632679489661923
#ifdef M_PI_4
#undef M_PI_4
#endif
#define M_PI_4 0.785398163397448309616
#ifndef NULL
#define NULL 0
#endif
B_INT
bmin
(
B_INT
const
value1
,
B_INT
const
value2
);
B_INT
bmax
(
B_INT
const
value1
,
B_INT
const
value2
);
B_INT
bmin
(
B_INT
value1
,
B_INT
value2
);
B_INT
bmax
(
B_INT
value1
,
B_INT
value2
);
#include <string.h>
//! errors in the boolean algorithm will be thrown using this class
class
A2DKBOOLDLLEXP
Bool_Engine_Error
{
public
:
Bool_Engine_Error
(
const
char
*
message
,
const
char
*
header
=
0
,
int
degree
=
9
,
int
fatal
=
0
);
Bool_Engine_Error
(
const
Bool_Engine_Error
&
a
);
~
Bool_Engine_Error
();
char
*
GetErrorMessage
();
char
*
GetHeaderMessage
();
int
GetErrorDegree
();
int
GetFatal
();
protected
:
char
*
_message
;
char
*
_header
;
int
_degree
;
int
_fatal
;
};
#define KBOOL_LOGFILE "kbool.log"
enum
kbEdgeType
{
KB_OUTSIDE_EDGE
,
/*!< edge of the outside contour of a polygon */
KB_INSIDE_EDGE
,
/*!< edge of the inside hole a polygon */
KB_FALSE_EDGE
/*!< edge to connect holes into polygons */
}
;
enum
GroupType
{
GROUP_A
,
/*!< to set Group A for polygons */
GROUP_B
/*!< to set Group A for polygons */
};
enum
BOOL_OP
{
BOOL_NON
,
/*!< No operation */
BOOL_OR
,
/*!< boolean OR operation */
BOOL_AND
,
/*!< boolean AND operation */
BOOL_EXOR
,
/*!< boolean EX_OR operation */
BOOL_A_SUB_B
,
/*!< boolean Group A - Group B operation */
BOOL_B_SUB_A
,
/*!< boolean Group B - Group A operation */
BOOL_CORRECTION
,
/*!< polygon correction/offset operation */
BOOL_SMOOTHEN
,
/*!< smooth operation */
BOOL_MAKERING
/*!< create a ring on all polygons */
};
class
GraphList
;
class
Graph
;
class
KBoolLink
;
class
Node
;
template
<
class
Type
>
class
TDLI
;
//! boolean engine to perform operation on two sets of polygons.
/*
First the engine needs to be filled with polygons.
The first operand in the operation is called group A polygons, the second group B.
The boolean operation ( BOOL_OR, BOOL_AND, BOOL_EXOR, BOOL_A_SUB_B, BOOL_B_SUB_A )
are based on the two sets of polygons in group A and B.
The other operation on group A only.
At the end of the operation the resulting polygons can be extracted.
*/
class
A2DKBOOLDLLEXP
Bool_Engine
{
public
:
//! constructor
Bool_Engine
();
//! destructor
virtual
~
Bool_Engine
();
const
char
*
GetVersion
()
{
return
KBOOL_VERSION
;
}
//! reports progress of algorithm.
virtual
void
SetState
(
const
char
*
=
0
);
//! called at an internal error.
virtual
void
error
(
const
char
*
text
,
const
char
*
title
);
//! called at an internal generated possible error.
virtual
void
info
(
const
char
*
text
,
const
char
*
title
);
bool
Do_Operation
(
BOOL_OP
operation
);
//! distance within which points and lines will be snapped towards lines and other points
/*
The algorithm takes into account gaps and inaccuracies caused by rounding to integer coordinates
in the original data.
Imagine two rectangles one with a side ( 0,0 ) ( 2.0, 17.0 )
and the other has a side ( 0,0 ) ( 1.0, 8.5 )
If for some reason those coordinates where round to ( 0,0 ) ( 2, 17 ) ( 0,0 ) ( 1, 9 ),
there will be clearly a gap or overlap that was not intended.
Even without rounding this effect takes place since there is always a minimum significant bit
also when using doubles.
If the user used as minimum accuracy 0.001, you need to choose Marge > 0.001
The boolean engine scales up the input data with GetDGrid() * GetGrid() and rounds the result to
integer, So (assuming GRID = 100 DGRID = 1000) a vertex of 123.001 in the user data will
become 12300100 internal.
At the end of the algorithm the internal vertexes are scaled down again with GetDGrid() * GetGrid(),
so 12300103 becomes 123.00103 eventually.
So indeed the minimum accuracy might increase, you are free to round again if needed.
*/
void
SetMarge
(
double
marge
);
double
GetMarge
();
//! input points are scaled up with GetDGrid() * GetGrid()
/*
Grid makes sure that the integer data used within the algorithm has room for extra intersections
smaller than the smallest number within the input data.
The input data scaled up with DGrid is related to the accuracy the user has in his input data.
Another scaling with Grid is applied on top of it to create space in the integer number for
even smaller numbers.
*/
void
SetGrid
(
B_INT
grid
);
//! See SetGrid
B_INT
GetGrid
();
//! input points are scaled up with GetDGrid() * GetGrid()
/*
The input data scaled up with DGrid is related to the accuracy the user has in his input data.
User data with a minimum accuracy of 0.001, means set the DGrid to 1000.
The input data may contain data with a minimum accuracy much smaller, but by setting the DGrid
everything smaller than 1/DGrid is rounded.
DGRID is only meant to make fractional parts of input data which can be
doubles, part of the integers used in vertexes within the boolean algorithm.
And therefore DGRID bigger than 1 is not usefull, you would only loose accuracy.
Within the algorithm all input data is multiplied with DGRID, and the result
is rounded to an integer.
*/
void
SetDGrid
(
double
dgrid
);
//! See SetDGrid
double
GetDGrid
();
//! When doing a correction operation ( also known as process offset )
//! this defines the detail in the rounded corners.
/*
Depending on the round factor the corners of the polygon may be rounding within the correction
algorithm. The detail within this rounded corner is set here.
It defines the deviation the generated segments in arc like polygon may have towards the ideal
rounded corner using a perfect arc.
*/
void
SetCorrectionAber
(
double
aber
);
//! see SetCorrectionAber
double
GetCorrectionAber
();
//! When doing a correction operation ( also known as process offset )
//! this defines the amount of correction.
/*
The correction algorithm can apply positive and negative offset to polygons.
It takes into account closed in areas within a polygon, caused by overlapping/selfintersecting
polygons. So holes form that way are corrected proberly, but the overlapping parts itself
are left alone. An often used trick to present polygons with holes by linking to the outside
boundary, is therefore also handled properly.
The algoritm first does a boolean OR operation on the polygon, and seperates holes and
outside contours.
After this it creates a ring shapes on the above holes and outside contours.
This ring shape is added or subtracted from the holes and outside contours.
The result is the corrected polygon.
If the correction factor is > 0, the outside contours will become larger, while the hole contours
will become smaller.
*/
void
SetCorrectionFactor
(
double
aber
);
//! see SetCorrectionFactor
double
GetCorrectionFactor
();
//! used within the smooth algorithm to define how much the smoothed curve may deviate
//! from the original.
void
SetSmoothAber
(
double
aber
);
//! see SetSmoothAber
double
GetSmoothAber
();
//! segments of this size will be left alone in the smooth algorithm.
void
SetMaxlinemerge
(
double
maxline
);
//! see SetMaxlinemerge
double
GetMaxlinemerge
();
//! Polygon may be filled in different ways (alternate and winding rule).
//! This here defines which method will be assumed within the algorithm.
void
SetWindingRule
(
bool
rule
);
//! see SetWindingRule
bool
GetWindingRule
();
//! the smallest accuracy used within the algorithm for comparing two real numbers.
double
GetAccur
();
//! Used with in correction/offset algorithm.
/*
When the polygon contains sharp angles ( < 90 ), after a positive correction the
extended parrallel constructed offset lines may leed to extreme offsets on the angles.
The length of the crossing generated by the parrallel constructed offset lines
towards the original point in the polygon is compared to the offset which needs to be applied.
The Roundfactor then decides if this corner will be rounded.
A Roundfactor of 1 means that the resulting offset will not be bigger then the correction factor
set in the algorithm. Meaning even straight 90 degrees corners will be rounded.
A Roundfactor of > sqrt(2) is where 90 corners will be left alone, and smaller corners will be rounded.
*/
void
SetRoundfactor
(
double
roundfac
);
//! see SetRoundfactor
double
GetRoundfactor
();
// the following are only be used within the algorithm,
// since they are scaled with m_DGRID
//! only used internal.
void
SetInternalMarge
(
B_INT
marge
);
//! only used internal.
B_INT
GetInternalMarge
();
//! only used internal.
double
GetInternalCorrectionAber
();
//! only used internal.
double
GetInternalCorrectionFactor
();
//! only used internal.
double
GetInternalSmoothAber
();
//! only used internal.
B_INT
GetInternalMaxlinemerge
();
//! in this mode polygons add clockwise, or contours,
/*!
and polygons added counter clockwise or holes.
*/
void
SetOrientationEntryMode
(
bool
orientationEntryMode
)
{
m_orientationEntryMode
=
orientationEntryMode
;
}
//! see SetOrientationEntryMode()
bool
GetOrientationEntryMode
()
{
return
m_orientationEntryMode
;
}
//! if set true holes are linked into outer contours by double overlapping segments.
/*!
This mode is needed when the software using the boolean algorithm does
not understand hole polygons. In that case a contour and its holes form one
polygon. In cases where software understands the concept of holes, contours
are clockwise oriented, while holes are anticlockwise oriented.
The output of the boolean operations, is following those rules also.
But even if extracting the polygons from the engine, each segment is marked such
that holes and non holes and linksegments to holes can be recognized.
*/
void
SetLinkHoles
(
bool
doLinkHoles
)
{
m_doLinkHoles
=
doLinkHoles
;
}
//! see SetLinkHoles()
bool
GetLinkHoles
()
{
return
m_doLinkHoles
;
}
//!lof file will be created when set True
void
SetLog
(
bool
OnOff
);
//! used to write to log file
void
Write_Log
(
const
char
*
);
//! used to write to log file
void
Write_Log
(
const
char
*
,
const
char
*
);
//! used to write to log file
void
Write_Log
(
const
char
*
,
double
);
//! used to write to log file
void
Write_Log
(
const
char
*
,
B_INT
);
FILE
*
GetLogFile
()
{
return
m_logfile
;
}
// methods used to add polygons to the eng using points
//! Start adding a polygon to the engine
/*
The boolean operation work on two groups of polygons ( group A or B ),
other algorithms are only using group A.
You add polygons like this to the engine.
// foreach point in a polygon ...
if (booleng->StartPolygonAdd(GROUP_A))
{
booleng->AddPoint(100,100);
booleng->AddPoint(-100,100);
booleng->AddPoint(-100,-100);
booleng->AddPoint(100,-100);
}
booleng->EndPolygonAdd();
\param A_or_B defines if the new polygon will be of group A or B
Holes or added by adding an inside polygons with opposite orientation compared
to another polygon added.
So the contour polygon ClockWise, then add counterclockwise polygons for holes, and visa versa.
BUT only if m_orientationEntryMode is set true, else all polygons are redirected, and become
individual areas without holes.
Holes in such a case must be linked into the contour using two extra segments.
*/
bool
StartPolygonAdd
(
GroupType
A_or_B
);
//! see StartPolygonAdd
bool
AddPoint
(
double
x
,
double
y
);
//! see StartPolygonAdd
bool
EndPolygonAdd
();
// methods used to extract polygons from the eng by getting its points
//! Use after StartPolygonGet()
int
GetNumPointsInPolygon
()
{
return
m_numPtsInPolygon
;
}
//! get resulting polygons at end of an operation
/*!
// foreach resultant polygon in the booleng ...
while ( booleng->StartPolygonGet() )
{
// foreach point in the polygon
while ( booleng->PolygonHasMorePoints() )
{
fprintf(stdout,"x = %f\t", booleng->GetPolygonXPoint());
fprintf(stdout,"y = %f\n", booleng->GetPolygonYPoint());
}
booleng->EndPolygonGet();
}
*/
bool
StartPolygonGet
();
//! see StartPolygonGet
/*!
This iterates through the first graph in the graphlist.
Setting the current Node properly by following the links in the graph
through its nodes.
*/
bool
PolygonHasMorePoints
();
//! see StartPolygonGet
double
GetPolygonXPoint
();
//! see StartPolygonGet
double
GetPolygonYPoint
();
//! in the resulting polygons this tells if the current polygon segment is one
//! used to link holes into the outer contour of the surrounding polygon
bool
GetHoleConnectionSegment
();
//! in the resulting polygons this tells if the current polygon segment is part
//! of a hole within a polygon.
bool
GetHoleSegment
();
//! an other way to get the type of segment.
kbEdgeType
GetPolygonPointEdgeType
();
//! see StartPolygonGet()
/*!
Removes a graph from the graphlist.
Called after an extraction of an output polygon was done.
*/
void
EndPolygonGet
();
private
:
bool
m_doLog
;
//! contains polygons in graph form
GraphList
*
m_graphlist
;
double
m_MARGE
;
B_INT
m_GRID
;
double
m_DGRID
;
double
m_CORRECTIONABER
;
double
m_CORRECTIONFACTOR
;
double
m_SMOOTHABER
;
double
m_MAXLINEMERGE
;
bool
m_WINDINGRULE
;
double
m_ACCUR
;
double
m_ROUNDFACTOR
;
bool
m_orientationEntryMode
;
bool
m_doLinkHoles
;
//! used in the StartPolygonAdd, AddPt, EndPolygonAdd sequence
Graph
*
m_GraphToAdd
;
//! used in the StartPolygonAdd, AddPt, EndPolygonAdd sequence
Node
*
m_lastNodeToAdd
;
//! used in the StartPolygonAdd, AddPt, EndPolygonAdd sequence
Node
*
m_firstNodeToAdd
;
//! the current group type ( group A or B )
GroupType
m_groupType
;
//! used in extracting the points from the resultant polygons
Graph
*
m_getGraph
;
//! used in extracting the points from the resultant polygons
KBoolLink
*
m_getLink
;
//! used in extracting the points from the resultant polygons
Node
*
m_getNode
;
//! used in extracting the points from the resultant polygons
double
m_PolygonXPoint
;
//! used in extracting the points from the resultant polygons
double
m_PolygonYPoint
;
//! used in extracting the points from the resultant polygons
int
m_numPtsInPolygon
;
//! used in extracting the points from the resultant polygons
int
m_numNodesVisited
;
FILE
*
m_logfile
;
public
:
//! use in Node to iterate links.
TDLI
<
KBoolLink
>*
_linkiter
;
//! how many time run intersections fase.
unsigned
int
m_intersectionruns
;
};
#endif
polygon/kbool/include/graph.h
deleted
100644 → 0
View file @
5d5698d6
/*! \file ../include/../graph.h
\author Probably Klaas Holwerda
Copyright: 2001-2004 (C) Probably Klaas Holwerda
Licence: wxWidgets Licence
RCS-ID: $Id: graph.h,v 1.1 2005/05/24 19:13:37 titato Exp $
*/
/* @@(#) $Source: /cvsroot/wxart2d/wxArt2D/modules/../include/graph.h,v $ $Revision: 1.1 $ $Date: 2005/05/24 19:13:37 $ */
/*
Program GRAPH.H
Purpose Used to Intercect and other process functions
Last Update 03-04-1996
*/
#ifndef GRAPH_H
#define GRAPH_H
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
#pragma interface
#endif
#include "../include/booleng.h"
#include "../include/_lnk_itr.h"
#include "../include/link.h"
#include "../include/line.h"
#include "../include/scanbeam.h"
class
Node
;
class
GraphList
;
//! one graph containing links that cab be connected.
class
A2DKBOOLDLLEXP
Graph
{
protected
:
Bool_Engine
*
_GC
;
public
:
Graph
(
Bool_Engine
*
GC
);
Graph
(
KBoolLink
*
,
Bool_Engine
*
GC
);
Graph
(
Graph
*
other
);
~
Graph
();
bool
GetBin
()
{
return
_bin
;
};
void
SetBin
(
bool
b
)
{
_bin
=
b
;
};
void
Prepare
(
int
intersectionruns
);
void
RoundInt
(
B_INT
grid
);
void
Rotate
(
bool
plus90
);
//! adds a link to the linklist
void
AddLink
(
Node
*
begin
,
Node
*
end
);
//! adds a link to the linklist
void
AddLink
(
KBoolLink
*
a_link
);
bool
AreZeroLines
(
B_INT
Marge
);
//! Delete parallel lines
void
DeleteDoubles
();
//! delete zerolines
bool
DeleteZeroLines
(
B_INT
Marge
);
bool
RemoveNullLinks
();
//! Process found intersections
void
ProcessCrossings
();
//! set flags for operations based on group
void
Set_Operation_Flags
();
//! Left Right values
void
Remove_IN_Links
();
//! reset bin and mark flags in links.
void
ResetBinMark
();
// Remove unused links
void
ReverseAllLinks
();
//! Simplify the graph
bool
Simplify
(
B_INT
Marge
);
//! Takes over all links of the argument
bool
Smoothen
(
B_INT
Marge
);
void
TakeOver
(
Graph
*
);
//! function for maximum performance
//! Get the First link from the graph
KBoolLink
*
GetFirstLink
();
Node
*
GetTopNode
();
void
SetBeenHere
(
bool
);
void
Reset_flags
();
//! Set the group of a graph
void
SetGroup
(
GroupType
);
//! Set the number of the graph
void
SetNumber
(
int
);
void
Reset_Mark_and_Bin
();
bool
GetBeenHere
();
int
GetGraphNum
();
int
GetNumberOfLinks
();
void
Boolean
(
BOOL_OP
operation
,
GraphList
*
Result
);
void
Correction
(
GraphList
*
Result
,
double
factor
);
void
MakeRing
(
GraphList
*
Result
,
double
factor
);
void
CreateRing
(
GraphList
*
ring
,
double
factor
);
void
CreateRing_fast
(
GraphList
*
ring
,
double
factor
);
void
CreateArc
(
Node
*
center
,
KBoolLine
*
incoming
,
Node
*
end
,
double
radius
,
double
aber
);
void
CreateArc
(
Node
*
center
,
Node
*
begin
,
Node
*
end
,
double
radius
,
bool
clock
,
double
aber
);
void
MakeOneDirection
();
void
Make_Rounded_Shape
(
KBoolLink
*
a_link
,
double
factor
);
bool
MakeClockWise
();
bool
writegraph
(
bool
linked
);
bool
writeintersections
();
void
WriteKEY
(
Bool_Engine
*
GC
,
FILE
*
file
=
NULL
);
void
WriteGraphKEY
(
Bool_Engine
*
GC
);
protected
:
//! Extracts partical polygons from the graph
/*
Links are sorted in XY at beginpoint. Bin and mark flag are reset.
Next start to collect subparts from the graph, setting the links bin for all found parts.
The parts are searched starting at a topleft corner NON set bin flag link.
Found parts are numbered, to be easily split into to real sperate graphs by Split()
\param operation operation to collect for.
\param detecthole if you want holes detected, influences also way of extraction.
\param foundholes when holes are found this flag is set true, but only if detecthole is set true.
*/
void
Extract_Simples
(
BOOL_OP
operation
,
bool
detecthole
,
bool
&
foundholes
);
//! split graph into small graph, using the numbers in links.
void
Split
(
GraphList
*
partlist
);
//! Collect a graph by starting at argument link
/*
Called from Extract_Simples, and assumes sorted links with bin flag unset for non extarted piece
Collect graphs pieces from a total graph, by following links set to a given boolean operation.
\param current_node start node to collect
\param operation operation to collect for.
\param detecthole if you want holes detected, influences also way of extraction.
\param graphnumber number to be given to links in the extracted graph piece
\param foundholes when holes are found this flag is set true.
*/
void
CollectGraph
(
Node
*
current_node
,
BOOL_OP
operation
,
bool
detecthole
,
int
graphnumber
,
bool
&
foundholes
);
void
CollectGraphLast
(
Node
*
current_node
,
BOOL_OP
operation
,
bool
detecthole
,
int
graphnumber
,
bool
&
foundholes
);
//! find a link not bin in the top left corner ( links should be sorted already )
/*!
Last found position is used to find it quickly.
Used in ExtractSimples()
*/
Node
*
GetMostTopLeft
(
TDLI
<
KBoolLink
>*
_LI
);
//! calculates crossing for all links in a graph, and add those as part of the graph.
/*
It is not just crossings calculation, snapping close nodes is part of it.
This is not done at maximum stability in economic time.
There are faster ways, but hardly ever they solve the problems, and they do not snap.
Here it is on purpose split into separate steps, to get a better result in snapping, and
to reach a better stability.
\param Marge nodes and lines closer to eachother then this, are merged.
*/
bool
CalculateCrossings
(
B_INT
Marge
);
//! equal nodes in position are merged into one.
int
Merge_NodeToNode
(
B_INT
Marge
);
//! basic scan algorithm with a sweeping beam are line.
/*!
\param scantype a different face in the algorithm.
\param holes to detect hole when needed.
*/
int
ScanGraph2
(
SCANTYPE
scantype
,
bool
&
holes
);
//! links not used for a certain operation can be deleted, simplifying extraction
void
DeleteNonCond
(
BOOL_OP
operation
);
//! links not used for a certain operation can be set bin, simplifying extraction
void
HandleNonCond
(
BOOL_OP
operation
);
//! debug
bool
checksort
();
//! used in correction/offset algorithm
bool
Small
(
B_INT
howsmall
);
bool
_bin
;
DL_List
<
void
*>*
_linklist
;
};
#endif
polygon/kbool/include/graphlst.h
deleted
100644 → 0
View file @
5d5698d6
/*! \file ../include/../graphlst.h
\author Probably Klaas Holwerda
Copyright: 2001-2004 (C) Probably Klaas Holwerda
Licence: wxWidgets Licence
RCS-ID: $Id: graphlst.h,v 1.1 2005/05/24 19:13:37 titato Exp $
*/
/* @@(#) $Source: /cvsroot/wxart2d/wxArt2D/modules/../include/graphlst.h,v $ $Revision: 1.1 $ $Date: 2005/05/24 19:13:37 $ */
/*
Program GRAPHLST.H
Purpose Implements a list of graphs (header)
Last Update 11-03-1996
*/
#ifndef GRAPHLIST_H
#define GRAPHLIST_H
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
#pragma interface
#endif
#include "../include/booleng.h"
#include "../include/_lnk_itr.h"
#include "../include/graph.h"
class
Debug_driver
;
class
A2DKBOOLDLLEXP
GraphList
:
public
DL_List
<
void
*>
{
protected
:
Bool_Engine
*
_GC
;
public
:
GraphList
(
Bool_Engine
*
GC
);
GraphList
(
GraphList
*
other
);
~
GraphList
();
void
MakeOneGraph
(
Graph
*
total
);
void
Prepare
(
Graph
*
total
);
void
MakeRings
();
void
Correction
();
void
Simplify
(
double
marge
);
void
Smoothen
(
double
marge
);
void
Merge
();
void
Boolean
(
BOOL_OP
operation
,
int
intersectionRunsMax
);
void
WriteGraphs
();
void
WriteGraphsKEY
(
Bool_Engine
*
GC
);
protected
:
void
Renumber
();
void
UnMarkAll
();
};
#endif
polygon/kbool/include/_dl_itr.cpp
→
polygon/kbool/include/
kbool/
_dl_itr.cpp
View file @
521f428c
/*! \file kbool/
include/kbool/
_dl_itr.cpp
/*! \file kbool/_dl_itr.cpp
\brief Double Linked list with Iterators on list
\brief Double Linked list with Iterators on list
\author Probably Klaas Holwerda
\author Probably Klaas Holwerda
...
@@ -6,15 +6,11 @@
...
@@ -6,15 +6,11 @@
Licence: wxWidgets Licence
Licence: wxWidgets Licence
RCS-ID: $Id: _dl_itr.cpp,v 1.
1 2005/05/24 19:13:35
titato Exp $
RCS-ID: $Id: _dl_itr.cpp,v 1.
3 2006/12/13 21:43:33
titato Exp $
*/
*/
#ifdef __GNUG__
#pragma implementation
#endif
#ifdef __UNIX__
#ifdef __UNIX__
#include "
../include
/_dl_itr.h"
#include "
kbool
/_dl_itr.h"
#endif
#endif
//=======================================================================
//=======================================================================
...
@@ -34,8 +30,8 @@ Construct a node for a list object
...
@@ -34,8 +30,8 @@ Construct a node for a list object
\param it Item the node will contain
\param it Item the node will contain
*/
*/
template
<
class
Dtype
>
template
<
class
Dtype
>
DL_Node
<
Dtype
>::
DL_Node
(
Dtype
it
)
// + init nodeitem
DL_Node
<
Dtype
>::
DL_Node
(
Dtype
it
)
// + init nodeitem
:
_item
(
it
)
:
_item
(
it
)
{}
{}
/*!
/*!
...
@@ -44,7 +40,7 @@ DL_Node<Dtype>::DL_Node(Dtype it) // + init nodeitem
...
@@ -44,7 +40,7 @@ DL_Node<Dtype>::DL_Node(Dtype it) // + init nodeitem
*/
*/
template
<
class
Dtype
>
template
<
class
Dtype
>
DL_Node
<
Dtype
>::
DL_Node
()
DL_Node
<
Dtype
>::
DL_Node
()
:
_item
(
0
)
:
_item
(
0
)
{}
{}
/*!
/*!
...
@@ -52,8 +48,7 @@ Destruct a node object
...
@@ -52,8 +48,7 @@ Destruct a node object
*/
*/
template
<
class
Dtype
>
template
<
class
Dtype
>
DL_Node
<
Dtype
>::~
DL_Node
()
DL_Node
<
Dtype
>::~
DL_Node
()
{
{}
}
//=======================================================================
//=======================================================================
...
@@ -78,11 +73,11 @@ Construct a node object
...
@@ -78,11 +73,11 @@ Construct a node object
*/
*/
template
<
class
Dtype
>
template
<
class
Dtype
>
DL_List
<
Dtype
>::
DL_List
()
DL_List
<
Dtype
>::
DL_List
()
:
_nbitems
(
0
),
_iterlevel
(
0
)
:
_nbitems
(
0
),
_iterlevel
(
0
)
{
{
_root
=
new
DL_Node
<
Dtype
>
();
_root
=
new
DL_Node
<
Dtype
>
();
_root
->
_next
=
_root
;
_root
->
_next
=
_root
;
_root
->
_prev
=
_root
;
_root
->
_prev
=
_root
;
}
}
...
@@ -98,12 +93,12 @@ DL_List<Dtype>::DL_List()
...
@@ -98,12 +93,12 @@ DL_List<Dtype>::DL_List()
template
<
class
Dtype
>
template
<
class
Dtype
>
DL_List
<
Dtype
>::~
DL_List
()
DL_List
<
Dtype
>::~
DL_List
()
{
{
if
(
_iterlevel
!=
0
)
if
(
_iterlevel
!=
0
)
throw
Bool_Engine_Error
(
"DL_List::~DL_List()
\n
_iterlevel > 0 "
,
"list error"
,
0
,
1
);
throw
Bool_Engine_Error
(
"DL_List::~DL_List()
\n
_iterlevel > 0 "
,
"list error"
,
0
,
1
);
remove_all
(
false
);
remove_all
(
false
);
delete
_root
;
delete
_root
;
_root
=
0
;
_nbitems
=
0
;
//reset memory used (no lost pointers)
_root
=
0
;
_nbitems
=
0
;
//reset memory used (no lost pointers)
}
}
/*!
/*!
...
@@ -121,23 +116,23 @@ Error("remove_all",ITER_GT_O);
...
@@ -121,23 +116,23 @@ Error("remove_all",ITER_GT_O);
\param error code to generate a message for
\param error code to generate a message for
*/
*/
template
<
class
Dtype
>
template
<
class
Dtype
>
void
DL_List
<
Dtype
>::
Error
(
const
char
*
function
,
Lerror
a_error
)
void
DL_List
<
Dtype
>::
Error
(
const
char
*
function
,
Lerror
a_error
)
{
{
char
buf
[
100
];
char
buf
[
100
];
strcpy
(
buf
,
"DL_List<Dtype>::"
);
strcpy
(
buf
,
"DL_List<Dtype>::"
);
strcat
(
buf
,
function
);
strcat
(
buf
,
function
);
switch
(
a_error
)
switch
(
a_error
)
{
{
case
NO_MES
:
strcat
(
buf
,
""
);
break
;
case
NO_MES
:
strcat
(
buf
,
""
);
break
;
case
EMPTY
:
strcat
(
buf
,
"list is empty"
);
break
;
case
EMPTY
:
strcat
(
buf
,
"list is empty"
);
break
;
case
ITER_GT_0
:
strcat
(
buf
,
"more then zero iter"
);
break
;
case
ITER_GT_0
:
strcat
(
buf
,
"more then zero iter"
);
break
;
case
NO_LIST
:
strcat
(
buf
,
"no list attached"
);
break
;
case
NO_LIST
:
strcat
(
buf
,
"no list attached"
);
break
;
case
SAME_LIST
:
strcat
(
buf
,
"same list not allowed"
);
break
;
case
SAME_LIST
:
strcat
(
buf
,
"same list not allowed"
);
break
;
case
AC_ITER_LIST_OTHER
:
strcat
(
buf
,
"iter not allowed on other list"
);
break
;
case
AC_ITER_LIST_OTHER
:
strcat
(
buf
,
"iter not allowed on other list"
);
break
;
default
:
strcat
(
buf
,
"unhandled error"
);
break
;
default
:
strcat
(
buf
,
"unhandled error"
);
break
;
}
}
throw
Bool_Engine_Error
(
buf
,
"list error"
,
0
,
1
);
throw
Bool_Engine_Error
(
buf
,
"list error"
,
0
,
1
);
}
}
/*!
/*!
...
@@ -157,7 +152,7 @@ DL_List<int> _intlist; #create a list of integers
...
@@ -157,7 +152,7 @@ DL_List<int> _intlist; #create a list of integers
template
<
class
Dtype
>
template
<
class
Dtype
>
bool
DL_List
<
Dtype
>::
empty
()
bool
DL_List
<
Dtype
>::
empty
()
{
{
return
(
bool
)(
_nbitems
==
0
);
return
(
bool
)(
_nbitems
==
0
);
}
}
/*!
/*!
...
@@ -212,25 +207,25 @@ int DL_List<Dtype>::count()
...
@@ -212,25 +207,25 @@ int DL_List<Dtype>::count()
template
<
class
Dtype
>
template
<
class
Dtype
>
void
DL_List
<
Dtype
>::
remove_all
(
bool
deleteObject
)
void
DL_List
<
Dtype
>::
remove_all
(
bool
deleteObject
)
{
{
if
(
_iterlevel
>
0
)
if
(
_iterlevel
>
0
)
Error
(
"remove_all()"
,
ITER_GT_0
);
Error
(
"remove_all()"
,
ITER_GT_0
);
Dtype
*
obj
;
Dtype
*
obj
;
DL_Node
<
Dtype
>
*
node
;
DL_Node
<
Dtype
>
*
node
;
for
(
int
i
=
0
;
i
<
_nbitems
;
i
++
)
for
(
int
i
=
0
;
i
<
_nbitems
;
i
++
)
{
{
node
=
_root
->
_next
;
node
=
_root
->
_next
;
_root
->
_next
=
node
->
_next
;
_root
->
_next
=
node
->
_next
;
if
(
deleteObject
==
true
)
if
(
deleteObject
==
true
)
{
{
obj
=
(
Dtype
*
)(
node
->
_item
);
obj
=
(
Dtype
*
)(
node
->
_item
);
delete
obj
;
delete
obj
;
}
}
delete
node
;
delete
node
;
}
}
_nbitems
=
0
;
_iterlevel
=
0
;
//reset memory used (no lost pointers)
_nbitems
=
0
;
_iterlevel
=
0
;
//reset memory used (no lost pointers)
_root
->
_prev
=
_root
;
_root
->
_prev
=
_root
;
}
}
/*!
/*!
...
@@ -265,12 +260,12 @@ DL_List<int> _intlist; #create a list of integers
...
@@ -265,12 +260,12 @@ DL_List<int> _intlist; #create a list of integers
template
<
class
Dtype
>
template
<
class
Dtype
>
void
DL_List
<
Dtype
>::
removehead
()
void
DL_List
<
Dtype
>::
removehead
()
{
{
if
(
_iterlevel
>
0
)
if
(
_iterlevel
>
0
)
Error
(
"removehead()"
,
ITER_GT_0
);
Error
(
"removehead()"
,
ITER_GT_0
);
if
(
_nbitems
==
0
)
if
(
_nbitems
==
0
)
Error
(
"removehead()"
,
EMPTY
);
Error
(
"removehead()"
,
EMPTY
);
DL_Node
<
Dtype
>*
node
=
_root
->
_next
;
DL_Node
<
Dtype
>*
node
=
_root
->
_next
;
node
->
_prev
->
_next
=
node
->
_next
;
// update forward link
node
->
_prev
->
_next
=
node
->
_next
;
// update forward link
node
->
_next
->
_prev
=
node
->
_prev
;
// update backward link
node
->
_next
->
_prev
=
node
->
_prev
;
// update backward link
...
@@ -308,12 +303,12 @@ DL_List<int> _intlist; #create a list of integers
...
@@ -308,12 +303,12 @@ DL_List<int> _intlist; #create a list of integers
template
<
class
Dtype
>
template
<
class
Dtype
>
void
DL_List
<
Dtype
>::
removetail
()
void
DL_List
<
Dtype
>::
removetail
()
{
{
if
(
_iterlevel
>
0
)
if
(
_iterlevel
>
0
)
Error
(
"removetail()"
,
ITER_GT_0
);
Error
(
"removetail()"
,
ITER_GT_0
);
if
(
_nbitems
==
0
)
if
(
_nbitems
==
0
)
Error
(
"removehead()"
,
EMPTY
);
Error
(
"removehead()"
,
EMPTY
);
DL_Node
<
Dtype
>*
node
=
_root
->
_prev
;
DL_Node
<
Dtype
>*
node
=
_root
->
_prev
;
node
->
_prev
->
_next
=
node
->
_next
;
// update forward link
node
->
_prev
->
_next
=
node
->
_next
;
// update forward link
node
->
_next
->
_prev
=
node
->
_prev
;
// update backward link
node
->
_next
->
_prev
=
node
->
_prev
;
// update backward link
...
@@ -343,12 +338,12 @@ too insert integer a at end of list
...
@@ -343,12 +338,12 @@ too insert integer a at end of list
\param newitem an object for which the template list was generated
\param newitem an object for which the template list was generated
*/
*/
template
<
class
Dtype
>
template
<
class
Dtype
>
DL_Node
<
Dtype
>*
DL_List
<
Dtype
>::
insend
(
Dtype
newitem
)
DL_Node
<
Dtype
>*
DL_List
<
Dtype
>::
insend
(
Dtype
newitem
)
{
{
if
(
_iterlevel
>
0
)
if
(
_iterlevel
>
0
)
Error
(
"insend()"
,
ITER_GT_0
);
Error
(
"insend()"
,
ITER_GT_0
);
DL_Node
<
Dtype
>*
newnode
=
new
DL_Node
<
Dtype
>
(
newitem
);
DL_Node
<
Dtype
>*
newnode
=
new
DL_Node
<
Dtype
>
(
newitem
);
newnode
->
_next
=
_root
;
newnode
->
_next
=
_root
;
newnode
->
_prev
=
_root
->
_prev
;
newnode
->
_prev
=
_root
->
_prev
;
...
@@ -382,12 +377,12 @@ too insert integer a at begin of list
...
@@ -382,12 +377,12 @@ too insert integer a at begin of list
\param newitem an object for which the template list was generated
\param newitem an object for which the template list was generated
*/
*/
template
<
class
Dtype
>
template
<
class
Dtype
>
DL_Node
<
Dtype
>*
DL_List
<
Dtype
>::
insbegin
(
Dtype
newitem
)
DL_Node
<
Dtype
>*
DL_List
<
Dtype
>::
insbegin
(
Dtype
newitem
)
{
{
if
(
_iterlevel
>
0
)
if
(
_iterlevel
>
0
)
Error
(
"insbegin()"
,
ITER_GT_0
);
Error
(
"insbegin()"
,
ITER_GT_0
);
DL_Node
<
Dtype
>*
newnode
=
new
DL_Node
<
Dtype
>
(
newitem
);
DL_Node
<
Dtype
>*
newnode
=
new
DL_Node
<
Dtype
>
(
newitem
);
newnode
->
_prev
=
_root
;
newnode
->
_prev
=
_root
;
newnode
->
_next
=
_root
->
_next
;
newnode
->
_next
=
_root
->
_next
;
...
@@ -459,31 +454,31 @@ Dtype DL_List<Dtype>::tailitem()
...
@@ -459,31 +454,31 @@ Dtype DL_List<Dtype>::tailitem()
* \param otherlist the list to take the items from
* \param otherlist the list to take the items from
*/
*/
template
<
class
Dtype
>
template
<
class
Dtype
>
void
DL_List
<
Dtype
>::
takeover
(
DL_List
<
Dtype
>*
otherlist
)
void
DL_List
<
Dtype
>::
takeover
(
DL_List
<
Dtype
>*
otherlist
)
{
{
if
(
otherlist
==
0
)
if
(
otherlist
==
0
)
Error
(
"takeover(DL_List*)"
,
NO_LIST
);
Error
(
"takeover(DL_List*)"
,
NO_LIST
);
// no iterators allowed on otherlist
// no iterators allowed on otherlist
if
(
otherlist
->
_iterlevel
>
0
)
if
(
otherlist
->
_iterlevel
>
0
)
Error
(
"takeover(DL_List*)"
,
AC_ITER_LIST_OTHER
);
Error
(
"takeover(DL_List*)"
,
AC_ITER_LIST_OTHER
);
// otherlist not this list
// otherlist not this list
else
if
(
otherlist
==
this
)
else
if
(
otherlist
==
this
)
Error
(
"takeover(DL_List*)"
,
SAME_LIST
);
Error
(
"takeover(DL_List*)"
,
SAME_LIST
);
if
(
otherlist
->
_nbitems
==
0
)
if
(
otherlist
->
_nbitems
==
0
)
return
;
return
;
//link other list into this list at the end
//link other list into this list at the end
_root
->
_prev
->
_next
=
otherlist
->
_root
->
_next
;
_root
->
_prev
->
_next
=
otherlist
->
_root
->
_next
;
otherlist
->
_root
->
_next
->
_prev
=
_root
->
_prev
;
otherlist
->
_root
->
_next
->
_prev
=
_root
->
_prev
;
otherlist
->
_root
->
_prev
->
_next
=
_root
;
otherlist
->
_root
->
_prev
->
_next
=
_root
;
_root
->
_prev
=
otherlist
->
_root
->
_prev
;
_root
->
_prev
=
otherlist
->
_root
->
_prev
;
//empty other list
//empty other list
_nbitems
+=
otherlist
->
_nbitems
;
_nbitems
+=
otherlist
->
_nbitems
;
otherlist
->
_nbitems
=
0
;
otherlist
->
_nbitems
=
0
;
otherlist
->
_root
->
_next
=
otherlist
->
_root
;
otherlist
->
_root
->
_next
=
otherlist
->
_root
;
otherlist
->
_root
->
_prev
=
otherlist
->
_root
;
otherlist
->
_root
->
_prev
=
otherlist
->
_root
;
}
}
//=======================================================================
//=======================================================================
...
@@ -537,30 +532,30 @@ void DL_List<Dtype>::takeover(DL_List<Dtype>* otherlist)
...
@@ -537,30 +532,30 @@ void DL_List<Dtype>::takeover(DL_List<Dtype>* otherlist)
\param a_error: error code to generate a message for
\param a_error: error code to generate a message for
*/
*/
template
<
class
Dtype
>
template
<
class
Dtype
>
void
DL_Iter
<
Dtype
>::
Error
(
const
char
*
function
,
Lerror
a_error
)
void
DL_Iter
<
Dtype
>::
Error
(
const
char
*
function
,
Lerror
a_error
)
{
{
char
buf
[
100
];
char
buf
[
100
];
strcpy
(
buf
,
"DL_Iter<Dtype>::"
);
strcpy
(
buf
,
"DL_Iter<Dtype>::"
);
strcat
(
buf
,
function
);
strcat
(
buf
,
function
);
switch
(
a_error
)
switch
(
a_error
)
{
{
case
NO_MES
:
strcat
(
buf
,
""
);
break
;
case
NO_MES
:
strcat
(
buf
,
""
);
break
;
case
NO_LIST
:
strcat
(
buf
,
"no list attached"
);
break
;
case
NO_LIST
:
strcat
(
buf
,
"no list attached"
);
break
;
case
NO_LIST_OTHER
:
strcat
(
buf
,
"no list on other iter"
);
break
;
case
NO_LIST_OTHER
:
strcat
(
buf
,
"no list on other iter"
);
break
;
case
AC_ITER_LIST_OTHER
:
strcat
(
buf
,
"iter not allowed on other list"
);
break
;
case
AC_ITER_LIST_OTHER
:
strcat
(
buf
,
"iter not allowed on other list"
);
break
;
case
SAME_LIST
:
strcat
(
buf
,
"same list not allowed"
);
break
;
case
SAME_LIST
:
strcat
(
buf
,
"same list not allowed"
);
break
;
case
NOT_SAME_LIST
:
strcat
(
buf
,
"must be same list"
);
break
;
case
NOT_SAME_LIST
:
strcat
(
buf
,
"must be same list"
);
break
;
case
ITER_GT_1
:
strcat
(
buf
,
"more then one iter"
);
break
;
case
ITER_GT_1
:
strcat
(
buf
,
"more then one iter"
);
break
;
case
ITER_HITROOT
:
strcat
(
buf
,
"iter at root"
);
break
;
case
ITER_HITROOT
:
strcat
(
buf
,
"iter at root"
);
break
;
case
NO_ITEM
:
strcat
(
buf
,
"no item at current"
);
break
;
case
NO_ITEM
:
strcat
(
buf
,
"no item at current"
);
break
;
case
NO_NEXT
:
strcat
(
buf
,
"no next after current"
);
break
;
case
NO_NEXT
:
strcat
(
buf
,
"no next after current"
);
break
;
case
NO_PREV
:
strcat
(
buf
,
"no prev before current"
);
break
;
case
NO_PREV
:
strcat
(
buf
,
"no prev before current"
);
break
;
case
EMPTY
:
strcat
(
buf
,
"list is empty"
);
break
;
case
EMPTY
:
strcat
(
buf
,
"list is empty"
);
break
;
case
NOT_ALLOW
:
strcat
(
buf
,
"not allowed"
);
break
;
case
NOT_ALLOW
:
strcat
(
buf
,
"not allowed"
);
break
;
case
ITER_NEG
:
strcat
(
buf
,
"to much iters deleted"
);
break
;
case
ITER_NEG
:
strcat
(
buf
,
"to much iters deleted"
);
break
;
default
:
strcat
(
buf
,
"unhandled error"
);
break
;
default
:
strcat
(
buf
,
"unhandled error"
);
break
;
}
}
throw
Bool_Engine_Error
(
buf
,
"list error"
,
0
,
1
);
throw
Bool_Engine_Error
(
buf
,
"list error"
,
0
,
1
);
}
}
/*!
/*!
...
@@ -576,8 +571,8 @@ void DL_Iter<Dtype>::Error(const char* function,Lerror a_error)
...
@@ -576,8 +571,8 @@ void DL_Iter<Dtype>::Error(const char* function,Lerror a_error)
\param newlist: list for the iterator
\param newlist: list for the iterator
*/
*/
template
<
class
Dtype
>
template
<
class
Dtype
>
DL_Iter
<
Dtype
>::
DL_Iter
(
DL_List
<
Dtype
>*
newlist
)
DL_Iter
<
Dtype
>::
DL_Iter
(
DL_List
<
Dtype
>*
newlist
)
:
_list
(
newlist
),
_current
(
RT
)
:
_list
(
newlist
),
_current
(
RT
)
{
{
_list
->
_iterlevel
++
;
// add 1 to DL_Iters on list
_list
->
_iterlevel
++
;
// add 1 to DL_Iters on list
}
}
...
@@ -600,13 +595,13 @@ tcarg: class | Dtype | list item object
...
@@ -600,13 +595,13 @@ tcarg: class | Dtype | list item object
\param otheriter other iterator on same list
\param otheriter other iterator on same list
*/
*/
template
<
class
Dtype
>
template
<
class
Dtype
>
DL_Iter
<
Dtype
>::
DL_Iter
(
DL_Iter
*
otheriter
)
DL_Iter
<
Dtype
>::
DL_Iter
(
DL_Iter
*
otheriter
)
{
{
if
(
otheriter
->
_current
==
0
)
if
(
otheriter
->
_current
==
0
)
Error
(
"DL_Iter(otheriter)"
,
NO_LIST_OTHER
);
Error
(
"DL_Iter(otheriter)"
,
NO_LIST_OTHER
);
_list
=
otheriter
->
_list
;
_list
=
otheriter
->
_list
;
_list
->
_iterlevel
++
;
// add 1 to DL_Iters on List
_list
->
_iterlevel
++
;
// add 1 to DL_Iters on List
_current
=
otheriter
->
_current
;
_current
=
otheriter
->
_current
;
}
}
/*!
/*!
...
@@ -635,9 +630,8 @@ tcarg: class | Dtype | list item object
...
@@ -635,9 +630,8 @@ tcarg: class | Dtype | list item object
*/
*/
template
<
class
Dtype
>
template
<
class
Dtype
>
DL_Iter
<
Dtype
>::
DL_Iter
()
DL_Iter
<
Dtype
>::
DL_Iter
()
:
_list
(
0
),
_current
(
0
)
:
_list
(
0
),
_current
(
0
)
{
{}
}
/*!
/*!
destruct an iterator for a list of a given type.
destruct an iterator for a list of a given type.
...
@@ -645,11 +639,11 @@ destruct an iterator for a list of a given type.
...
@@ -645,11 +639,11 @@ destruct an iterator for a list of a given type.
template
<
class
Dtype
>
template
<
class
Dtype
>
DL_Iter
<
Dtype
>::~
DL_Iter
()
DL_Iter
<
Dtype
>::~
DL_Iter
()
{
{
if
(
_current
==
0
)
if
(
_current
==
0
)
return
;
return
;
_list
->
_iterlevel
--
;
// decrease iterators
_list
->
_iterlevel
--
;
// decrease iterators
if
(
_list
->
_iterlevel
<
0
)
if
(
_list
->
_iterlevel
<
0
)
Error
(
"~DL_Iter()"
,
ITER_NEG
);
Error
(
"~DL_Iter()"
,
ITER_NEG
);
}
}
/*!
/*!
...
@@ -675,12 +669,12 @@ a_iter.Detach();
...
@@ -675,12 +669,12 @@ a_iter.Detach();
\param newlist the list to attached the iterator to
\param newlist the list to attached the iterator to
*/
*/
template
<
class
Dtype
>
template
<
class
Dtype
>
void
DL_Iter
<
Dtype
>::
Attach
(
DL_List
<
Dtype
>*
newlist
)
void
DL_Iter
<
Dtype
>::
Attach
(
DL_List
<
Dtype
>*
newlist
)
{
{
if
(
_current
!=
0
)
if
(
_current
!=
0
)
Error
(
"Attach(list)"
,
NOT_ALLOW
);
Error
(
"Attach(list)"
,
NOT_ALLOW
);
_list
=
newlist
;
_list
=
newlist
;
_current
=
HD
;
_current
=
HD
;
_list
->
_iterlevel
++
;
// add 1 to DL_Iters on list
_list
->
_iterlevel
++
;
// add 1 to DL_Iters on list
}
}
...
@@ -709,11 +703,11 @@ a_iter.Detach();
...
@@ -709,11 +703,11 @@ a_iter.Detach();
template
<
class
Dtype
>
template
<
class
Dtype
>
void
DL_Iter
<
Dtype
>::
Detach
()
void
DL_Iter
<
Dtype
>::
Detach
()
{
{
if
(
_current
==
0
)
if
(
_current
==
0
)
Error
(
"Attach()"
,
NO_LIST
);
Error
(
"Attach()"
,
NO_LIST
);
_list
->
_iterlevel
--
;
// subtract 1 from DL_Iters on list
_list
->
_iterlevel
--
;
// subtract 1 from DL_Iters on list
_list
=
0
;
_list
=
0
;
_current
=
0
;
_current
=
0
;
}
}
/*
/*
...
@@ -745,13 +739,13 @@ void DL_Iter<Dtype>::foreach_mf(void (Dtype::*mfp)())
...
@@ -745,13 +739,13 @@ void DL_Iter<Dtype>::foreach_mf(void (Dtype::*mfp)())
/*! call given function for each item*/
/*! call given function for each item*/
template
<
class
Dtype
>
template
<
class
Dtype
>
void
DL_Iter
<
Dtype
>::
foreach_f
(
void
(
*
fp
)
(
Dtype
n
)
)
void
DL_Iter
<
Dtype
>::
foreach_f
(
void
(
*
fp
)
(
Dtype
n
)
)
{
{
DL_Node
<
Dtype
>*
node
=
HD
;
//can be 0 if empty
DL_Node
<
Dtype
>*
node
=
HD
;
//can be 0 if empty
for
(
int
i
=
0
;
i
<
NB
;
i
++
)
for
(
int
i
=
0
;
i
<
NB
;
i
++
)
{
{
fp
(
node
->
_item
);
fp
(
node
->
_item
);
node
=
node
->
_next
;
node
=
node
->
_next
;
}
}
}
}
...
@@ -782,31 +776,31 @@ a_listiter2->takeover(_intlist)
...
@@ -782,31 +776,31 @@ a_listiter2->takeover(_intlist)
\param otherlist the list to take the items from
\param otherlist the list to take the items from
*/
*/
template
<
class
Dtype
>
template
<
class
Dtype
>
void
DL_Iter
<
Dtype
>::
takeover
(
DL_List
<
Dtype
>*
otherlist
)
void
DL_Iter
<
Dtype
>::
takeover
(
DL_List
<
Dtype
>*
otherlist
)
{
{
if
(
_current
==
0
)
if
(
_current
==
0
)
Error
(
"takeover(DL_List*)"
,
NO_LIST
);
Error
(
"takeover(DL_List*)"
,
NO_LIST
);
// no iterators allowed on otherlist
// no iterators allowed on otherlist
if
(
otherlist
->
_iterlevel
>
0
)
if
(
otherlist
->
_iterlevel
>
0
)
Error
(
"takeover(DL_List*)"
,
AC_ITER_LIST_OTHER
);
Error
(
"takeover(DL_List*)"
,
AC_ITER_LIST_OTHER
);
// otherlist not this list
// otherlist not this list
else
if
(
otherlist
==
_list
)
else
if
(
otherlist
==
_list
)
Error
(
"takeover(DL_List*)"
,
SAME_LIST
);
Error
(
"takeover(DL_List*)"
,
SAME_LIST
);
if
(
otherlist
->
_nbitems
==
0
)
if
(
otherlist
->
_nbitems
==
0
)
return
;
return
;
//link other list into this list at the end
//link other list into this list at the end
TL
->
_next
=
otherlist
->
_root
->
_next
;
TL
->
_next
=
otherlist
->
_root
->
_next
;
otherlist
->
_root
->
_next
->
_prev
=
TL
;
otherlist
->
_root
->
_next
->
_prev
=
TL
;
otherlist
->
_root
->
_prev
->
_next
=
RT
;
otherlist
->
_root
->
_prev
->
_next
=
RT
;
TL
=
otherlist
->
_root
->
_prev
;
TL
=
otherlist
->
_root
->
_prev
;
//empty other list
//empty other list
NB
+=
otherlist
->
_nbitems
;
NB
+=
otherlist
->
_nbitems
;
otherlist
->
_nbitems
=
0
;
otherlist
->
_nbitems
=
0
;
otherlist
->
_root
->
_next
=
otherlist
->
_root
;
otherlist
->
_root
->
_next
=
otherlist
->
_root
;
otherlist
->
_root
->
_prev
=
otherlist
->
_root
;
otherlist
->
_root
->
_prev
=
otherlist
->
_root
;
}
}
...
@@ -842,35 +836,35 @@ a_listiter2->takeover(a_listiter1)
...
@@ -842,35 +836,35 @@ a_listiter2->takeover(a_listiter1)
\param otheriter: the iterator to take the items from
\param otheriter: the iterator to take the items from
*/
*/
template
<
class
Dtype
>
template
<
class
Dtype
>
void
DL_Iter
<
Dtype
>::
takeover
(
DL_Iter
*
otheriter
)
void
DL_Iter
<
Dtype
>::
takeover
(
DL_Iter
*
otheriter
)
{
{
if
(
otheriter
->
_current
==
0
)
if
(
otheriter
->
_current
==
0
)
Error
(
" DL_Iter"
,
NO_LIST_OTHER
);
Error
(
" DL_Iter"
,
NO_LIST_OTHER
);
if
(
_current
==
0
)
if
(
_current
==
0
)
Error
(
" DL_Iter"
,
NO_LIST
);
Error
(
" DL_Iter"
,
NO_LIST
);
// only one iterator allowed on other list?
// only one iterator allowed on other list?
if
(
otheriter
->
_list
->
_iterlevel
>
1
)
if
(
otheriter
->
_list
->
_iterlevel
>
1
)
Error
(
"takeover(DL_Iter*)"
,
AC_ITER_LIST_OTHER
);
Error
(
"takeover(DL_Iter*)"
,
AC_ITER_LIST_OTHER
);
// otherlist not this list?
// otherlist not this list?
else
if
(
otheriter
->
_list
==
_list
)
else
if
(
otheriter
->
_list
==
_list
)
Error
(
"takeover(DL_Iter*)"
,
SAME_LIST
);
Error
(
"takeover(DL_Iter*)"
,
SAME_LIST
);
if
(
otheriter
->
NB
==
0
)
if
(
otheriter
->
NB
==
0
)
return
;
return
;
//link other list into this list at the end
//link other list into this list at the end
TL
->
_next
=
otheriter
->
HD
;
TL
->
_next
=
otheriter
->
HD
;
otheriter
->
HD
->
_prev
=
TL
;
otheriter
->
HD
->
_prev
=
TL
;
otheriter
->
TL
->
_next
=
RT
;
otheriter
->
TL
->
_next
=
RT
;
TL
=
otheriter
->
TL
;
TL
=
otheriter
->
TL
;
//empty other iter & list
//empty other iter & list
NB
+=
otheriter
->
NB
;
NB
+=
otheriter
->
NB
;
otheriter
->
NB
=
0
;
otheriter
->
NB
=
0
;
otheriter
->
HD
=
otheriter
->
RT
;
otheriter
->
HD
=
otheriter
->
RT
;
otheriter
->
TL
=
otheriter
->
RT
;
otheriter
->
TL
=
otheriter
->
RT
;
otheriter
->
_current
=
otheriter
->
RT
;
otheriter
->
_current
=
otheriter
->
RT
;
}
}
/*!
/*!
...
@@ -906,84 +900,84 @@ a_listiter2->takeover(a_listiter1,1);
...
@@ -906,84 +900,84 @@ a_listiter2->takeover(a_listiter1,1);
\param maxcount maximum number of objects to take over
\param maxcount maximum number of objects to take over
*/
*/
template
<
class
Dtype
>
template
<
class
Dtype
>
void
DL_Iter
<
Dtype
>::
takeover
(
DL_Iter
*
otheriter
,
int
maxcount
)
void
DL_Iter
<
Dtype
>::
takeover
(
DL_Iter
*
otheriter
,
int
maxcount
)
{
{
if
(
otheriter
->
_current
==
0
)
if
(
otheriter
->
_current
==
0
)
Error
(
"takeover(DL_Iter*,int)"
,
NO_LIST_OTHER
);
Error
(
"takeover(DL_Iter*,int)"
,
NO_LIST_OTHER
);
if
(
_current
==
0
)
if
(
_current
==
0
)
Error
(
"takeover(DL_Iter*,int)"
,
NO_LIST
);
Error
(
"takeover(DL_Iter*,int)"
,
NO_LIST
);
if
(
otheriter
->
_list
->
_iterlevel
>
1
)
if
(
otheriter
->
_list
->
_iterlevel
>
1
)
Error
(
"takeover(DL_Iter*,int)"
,
AC_ITER_LIST_OTHER
);
Error
(
"takeover(DL_Iter*,int)"
,
AC_ITER_LIST_OTHER
);
else
if
(
otheriter
->
_list
==
_list
)
else
if
(
otheriter
->
_list
==
_list
)
Error
(
"takeover(DL_Iter*,int)"
,
SAME_LIST
);
Error
(
"takeover(DL_Iter*,int)"
,
SAME_LIST
);
if
(
maxcount
<
0
)
if
(
maxcount
<
0
)
Error
(
"takeover(DL_Iter*,int), maxcount < 0"
,
NO_MES
);
Error
(
"takeover(DL_Iter*,int), maxcount < 0"
,
NO_MES
);
if
(
otheriter
->
NB
==
0
)
if
(
otheriter
->
NB
==
0
)
return
;
return
;
if
(
otheriter
->
NB
<=
maxcount
)
if
(
otheriter
->
NB
<=
maxcount
)
{
//take it all
{
//take it all
//link other list into this list at the end
//link other list into this list at the end
TL
->
_next
=
otheriter
->
HD
;
TL
->
_next
=
otheriter
->
HD
;
otheriter
->
HD
->
_prev
=
TL
;
otheriter
->
HD
->
_prev
=
TL
;
otheriter
->
TL
->
_next
=
RT
;
otheriter
->
TL
->
_next
=
RT
;
TL
=
otheriter
->
TL
;
TL
=
otheriter
->
TL
;
//empty other iter & list
//empty other iter & list
NB
+=
otheriter
->
NB
;
NB
+=
otheriter
->
NB
;
otheriter
->
NB
=
0
;
otheriter
->
NB
=
0
;
otheriter
->
HD
=
otheriter
->
RT
;
otheriter
->
HD
=
otheriter
->
RT
;
otheriter
->
TL
=
otheriter
->
RT
;
otheriter
->
TL
=
otheriter
->
RT
;
otheriter
->
_current
=
otheriter
->
RT
;
otheriter
->
_current
=
otheriter
->
RT
;
}
}
else
else
{
//take maxcount elements from otheriter
{
//take maxcount elements from otheriter
//set cursor in otherlist to element maxcount
//set cursor in otherlist to element maxcount
DL_Node
<
Dtype
>*
node
;
DL_Node
<
Dtype
>*
node
;
if
(
NB
/
2
<
maxcount
)
if
(
NB
/
2
<
maxcount
)
{
// this is faster (1st half)
{
// this is faster (1st half)
node
=
otheriter
->
HD
;
node
=
otheriter
->
HD
;
for
(
int
i
=
1
;
i
<
maxcount
;
i
++
)
for
(
int
i
=
1
;
i
<
maxcount
;
i
++
)
node
=
node
->
_next
;
node
=
node
->
_next
;
}
}
else
else
{
// no, this is faster (2nd half)
{
// no, this is faster (2nd half)
node
=
otheriter
->
TL
;
node
=
otheriter
->
TL
;
for
(
int
i
=
NB
;
i
>
maxcount
+
1
;
i
--
)
for
(
int
i
=
NB
;
i
>
maxcount
+
1
;
i
--
)
node
=
node
->
_prev
;
node
=
node
->
_prev
;
}
}
// link this->tail to other->head
// link this->tail to other->head
if
(
NB
>
0
)
if
(
NB
>
0
)
{
{
TL
->
_next
=
otheriter
->
HD
;
TL
->
_next
=
otheriter
->
HD
;
otheriter
->
HD
->
_prev
=
TL
;
otheriter
->
HD
->
_prev
=
TL
;
}
}
else
// target is empty
else
// target is empty
{
{
HD
=
otheriter
->
HD
;
HD
=
otheriter
->
HD
;
otheriter
->
HD
->
_prev
=
RT
;
otheriter
->
HD
->
_prev
=
RT
;
}
}
// set other root to node-> next (after last to copy)
// set other root to node-> next (after last to copy)
otheriter
->
HD
=
node
->
_next
;
otheriter
->
HD
=
node
->
_next
;
otheriter
->
HD
->
_prev
=
otheriter
->
RT
;
otheriter
->
HD
->
_prev
=
otheriter
->
RT
;
// set this->tail to other->item()->prev (last element to be copied)
// set this->tail to other->item()->prev (last element to be copied)
TL
=
node
;
TL
=
node
;
node
->
_next
=
RT
;
node
->
_next
=
RT
;
// still need to update element counter
// still need to update element counter
NB
+=
maxcount
;
NB
+=
maxcount
;
// update other list
// update other list
otheriter
->
NB
-=
maxcount
;
otheriter
->
NB
-=
maxcount
;
otheriter
->
_current
=
otheriter
->
HD
;
// other->current is moved to this!
otheriter
->
_current
=
otheriter
->
HD
;
// other->current is moved to this!
}
}
}
}
...
@@ -1011,24 +1005,24 @@ a_listiter->tohead(); //the new head will be at object 3456
...
@@ -1011,24 +1005,24 @@ a_listiter->tohead(); //the new head will be at object 3456
template
<
class
Dtype
>
template
<
class
Dtype
>
void
DL_Iter
<
Dtype
>::
reset_head
()
void
DL_Iter
<
Dtype
>::
reset_head
()
{
{
if
(
_current
==
0
)
if
(
_current
==
0
)
Error
(
"reset_head()"
,
NO_LIST
);
Error
(
"reset_head()"
,
NO_LIST
);
if
(
_list
->
_iterlevel
>
1
)
if
(
_list
->
_iterlevel
>
1
)
Error
(
"reset_head()"
,
ITER_GT_1
);
Error
(
"reset_head()"
,
ITER_GT_1
);
if
(
_current
==
RT
)
if
(
_current
==
RT
)
Error
(
"reset head()"
,
ITER_HITROOT
);
Error
(
"reset head()"
,
ITER_HITROOT
);
//link out RT
//link out RT
HD
->
_prev
=
TL
;
HD
->
_prev
=
TL
;
TL
->
_next
=
HD
;
TL
->
_next
=
HD
;
//link in RT before current
//link in RT before current
HD
=
_current
;
HD
=
_current
;
TL
=
_current
->
_prev
;
TL
=
_current
->
_prev
;
TL
->
_next
=
RT
;
TL
->
_next
=
RT
;
HD
->
_prev
=
RT
;
HD
->
_prev
=
RT
;
}
}
/*!
/*!
...
@@ -1054,24 +1048,24 @@ a_listiter->totail(); //the new tail will be at object 1234
...
@@ -1054,24 +1048,24 @@ a_listiter->totail(); //the new tail will be at object 1234
template
<
class
Dtype
>
template
<
class
Dtype
>
void
DL_Iter
<
Dtype
>::
reset_tail
()
void
DL_Iter
<
Dtype
>::
reset_tail
()
{
{
if
(
_current
==
0
)
if
(
_current
==
0
)
Error
(
"reset_tail()"
,
NO_LIST
);
Error
(
"reset_tail()"
,
NO_LIST
);
if
(
_list
->
_iterlevel
>
1
)
if
(
_list
->
_iterlevel
>
1
)
Error
(
"reset_tail()"
,
ITER_GT_1
);
Error
(
"reset_tail()"
,
ITER_GT_1
);
if
(
_current
==
RT
)
if
(
_current
==
RT
)
Error
(
"reset head()"
,
ITER_HITROOT
);
Error
(
"reset head()"
,
ITER_HITROOT
);
//link out RT
//link out RT
HD
->
_prev
=
TL
;
HD
->
_prev
=
TL
;
TL
->
_next
=
HD
;
TL
->
_next
=
HD
;
//link in RT after current
//link in RT after current
TL
=
_current
;
TL
=
_current
;
HD
=
_current
->
_next
;
HD
=
_current
->
_next
;
HD
->
_prev
=
RT
;
HD
->
_prev
=
RT
;
TL
->
_next
=
RT
;
TL
->
_next
=
RT
;
}
}
/*!
/*!
...
@@ -1090,10 +1084,10 @@ if (a_listiter->Empty())
...
@@ -1090,10 +1084,10 @@ if (a_listiter->Empty())
template
<
class
Dtype
>
template
<
class
Dtype
>
bool
DL_Iter
<
Dtype
>::
empty
()
bool
DL_Iter
<
Dtype
>::
empty
()
{
{
if
(
_current
==
0
)
if
(
_current
==
0
)
Error
(
"empty()"
,
NO_LIST
);
Error
(
"empty()"
,
NO_LIST
);
return
(
bool
)(
NB
==
0
);
return
(
bool
)(
NB
==
0
);
}
}
/*!
/*!
...
@@ -1127,10 +1121,10 @@ while ( ! a_listiter->hitroot())
...
@@ -1127,10 +1121,10 @@ while ( ! a_listiter->hitroot())
template
<
class
Dtype
>
template
<
class
Dtype
>
bool
DL_Iter
<
Dtype
>::
hitroot
()
bool
DL_Iter
<
Dtype
>::
hitroot
()
{
{
if
(
_current
==
0
)
if
(
_current
==
0
)
Error
(
"hitroot()"
,
NO_LIST
);
Error
(
"hitroot()"
,
NO_LIST
);
return
(
bool
)(
_current
==
RT
);
return
(
bool
)(
_current
==
RT
);
}
}
/*!
/*!
...
@@ -1150,10 +1144,10 @@ if (a_listiter->athead())
...
@@ -1150,10 +1144,10 @@ if (a_listiter->athead())
template
<
class
Dtype
>
template
<
class
Dtype
>
bool
DL_Iter
<
Dtype
>::
athead
()
bool
DL_Iter
<
Dtype
>::
athead
()
{
{
if
(
_current
==
0
)
if
(
_current
==
0
)
Error
(
"athead()"
,
NO_LIST
);
Error
(
"athead()"
,
NO_LIST
);
return
(
bool
)(
_current
==
HD
);
return
(
bool
)(
_current
==
HD
);
}
}
/*!
/*!
...
@@ -1174,10 +1168,10 @@ if (a_listiter->attail())
...
@@ -1174,10 +1168,10 @@ if (a_listiter->attail())
template
<
class
Dtype
>
template
<
class
Dtype
>
bool
DL_Iter
<
Dtype
>::
attail
()
bool
DL_Iter
<
Dtype
>::
attail
()
{
{
if
(
_current
==
0
)
if
(
_current
==
0
)
Error
(
"attail()"
,
NO_LIST
);
Error
(
"attail()"
,
NO_LIST
);
return
(
bool
)(
_current
==
TL
);
return
(
bool
)(
_current
==
TL
);
}
}
/*!
/*!
...
@@ -1196,16 +1190,17 @@ if (a_listiter->has(1234))
...
@@ -1196,16 +1190,17 @@ if (a_listiter->has(1234))
\param otheritem item to search for
\param otheritem item to search for
*/
*/
template
<
class
Dtype
>
template
<
class
Dtype
>
bool
DL_Iter
<
Dtype
>::
has
(
Dtype
otheritem
)
bool
DL_Iter
<
Dtype
>::
has
(
Dtype
otheritem
)
{
{
if
(
_current
==
0
)
if
(
_current
==
0
)
Error
(
"has()"
,
NO_LIST
);
Error
(
"has()"
,
NO_LIST
);
DL_Node
<
Dtype
>*
node
=
HD
;
//can be 0 if empty
DL_Node
<
Dtype
>*
node
=
HD
;
//can be 0 if empty
for
(
int
i
=
0
;
i
<
NB
;
i
++
)
for
(
int
i
=
0
;
i
<
NB
;
i
++
)
{
if
(
node
->
_item
==
otheritem
)
{
if
(
node
->
_item
==
otheritem
)
return
true
;
return
true
;
node
=
node
->
_next
;
node
=
node
->
_next
;
}
}
return
false
;
return
false
;
}
}
...
@@ -1225,8 +1220,8 @@ if (a_listiter->count() == 1)
...
@@ -1225,8 +1220,8 @@ if (a_listiter->count() == 1)
template
<
class
Dtype
>
template
<
class
Dtype
>
int
DL_Iter
<
Dtype
>::
count
()
int
DL_Iter
<
Dtype
>::
count
()
{
{
if
(
_current
==
0
)
if
(
_current
==
0
)
Error
(
"count()"
,
NO_LIST
);
Error
(
"count()"
,
NO_LIST
);
return
NB
;
return
NB
;
}
}
...
@@ -1246,10 +1241,10 @@ a_listiter->tohead();
...
@@ -1246,10 +1241,10 @@ a_listiter->tohead();
template
<
class
Dtype
>
template
<
class
Dtype
>
void
DL_Iter
<
Dtype
>::
tohead
()
void
DL_Iter
<
Dtype
>::
tohead
()
{
{
if
(
_current
==
0
)
if
(
_current
==
0
)
Error
(
"tohead()"
,
NO_LIST
);
Error
(
"tohead()"
,
NO_LIST
);
_current
=
HD
;
_current
=
HD
;
}
}
/*!
/*!
...
@@ -1267,10 +1262,10 @@ a_listiter->totail();
...
@@ -1267,10 +1262,10 @@ a_listiter->totail();
template
<
class
Dtype
>
template
<
class
Dtype
>
void
DL_Iter
<
Dtype
>::
totail
()
void
DL_Iter
<
Dtype
>::
totail
()
{
{
if
(
_current
==
0
)
if
(
_current
==
0
)
Error
(
"totail()"
,
NO_LIST
);
Error
(
"totail()"
,
NO_LIST
);
_current
=
TL
;
_current
=
TL
;
}
}
/*!
/*!
...
@@ -1290,10 +1285,10 @@ while (a_listiter->iterate())
...
@@ -1290,10 +1285,10 @@ while (a_listiter->iterate())
template
<
class
Dtype
>
template
<
class
Dtype
>
void
DL_Iter
<
Dtype
>::
toroot
()
void
DL_Iter
<
Dtype
>::
toroot
()
{
{
if
(
_current
==
0
)
if
(
_current
==
0
)
Error
(
"toroot()"
,
NO_LIST
);
Error
(
"toroot()"
,
NO_LIST
);
_current
=
RT
;
_current
=
RT
;
}
}
/*!
/*!
...
@@ -1314,12 +1309,12 @@ while (!a_listiter->hitroot())
...
@@ -1314,12 +1309,12 @@ while (!a_listiter->hitroot())
\endcode
\endcode
*/
*/
template
<
class
Dtype
>
template
<
class
Dtype
>
void
DL_Iter
<
Dtype
>::
operator
++
(
void
)
void
DL_Iter
<
Dtype
>::
operator
++
(
void
)
{
{
if
(
_current
==
0
)
if
(
_current
==
0
)
Error
(
"operator++()"
,
NO_LIST
);
Error
(
"operator++()"
,
NO_LIST
);
_current
=
_current
->
_next
;
_current
=
_current
->
_next
;
}
}
/*!
/*!
...
@@ -1340,12 +1335,12 @@ while (!a_listiter->hitroot())
...
@@ -1340,12 +1335,12 @@ while (!a_listiter->hitroot())
\endcode
\endcode
*/
*/
template
<
class
Dtype
>
template
<
class
Dtype
>
void
DL_Iter
<
Dtype
>::
operator
++
(
int
)
void
DL_Iter
<
Dtype
>::
operator
++
(
int
)
{
{
if
(
_current
==
0
)
if
(
_current
==
0
)
Error
(
"operator++(int)"
,
NO_LIST
);
Error
(
"operator++(int)"
,
NO_LIST
);
_current
=
_current
->
_next
;
_current
=
_current
->
_next
;
}
}
...
@@ -1367,12 +1362,12 @@ while (!a_listiter->hitroot())
...
@@ -1367,12 +1362,12 @@ while (!a_listiter->hitroot())
\endcode
\endcode
*/
*/
template
<
class
Dtype
>
template
<
class
Dtype
>
void
DL_Iter
<
Dtype
>::
operator
--
(
void
)
void
DL_Iter
<
Dtype
>::
operator
--
(
void
)
{
{
if
(
_current
==
0
)
if
(
_current
==
0
)
Error
(
"operator++()"
,
NO_LIST
);
Error
(
"operator++()"
,
NO_LIST
);
_current
=
_current
->
_prev
;
_current
=
_current
->
_prev
;
}
}
...
@@ -1394,12 +1389,12 @@ while (!a_listiter->hitroot())
...
@@ -1394,12 +1389,12 @@ while (!a_listiter->hitroot())
\endcode
\endcode
*/
*/
template
<
class
Dtype
>
template
<
class
Dtype
>
void
DL_Iter
<
Dtype
>::
operator
--
(
int
)
void
DL_Iter
<
Dtype
>::
operator
--
(
int
)
{
{
if
(
_current
==
0
)
if
(
_current
==
0
)
Error
(
"operator++(int)"
,
NO_LIST
);
Error
(
"operator++(int)"
,
NO_LIST
);
_current
=
_current
->
_prev
;
_current
=
_current
->
_prev
;
}
}
...
@@ -1417,13 +1412,13 @@ a_listiter>>2;//at root now
...
@@ -1417,13 +1412,13 @@ a_listiter>>2;//at root now
\param n go n places forward
\param n go n places forward
*/
*/
template
<
class
Dtype
>
template
<
class
Dtype
>
void
DL_Iter
<
Dtype
>::
operator
>>
(
int
n
)
void
DL_Iter
<
Dtype
>::
operator
>>
(
int
n
)
{
{
if
(
_current
==
0
)
if
(
_current
==
0
)
Error
(
"operator>>()"
,
NO_LIST
);
Error
(
"operator>>()"
,
NO_LIST
);
for
(
int
i
=
0
;
i
<
n
;
i
++
)
for
(
int
i
=
0
;
i
<
n
;
i
++
)
_current
=
_current
->
_next
;
_current
=
_current
->
_next
;
}
}
...
@@ -1441,13 +1436,13 @@ a_listiter<<2;//at root now
...
@@ -1441,13 +1436,13 @@ a_listiter<<2;//at root now
\param n go n places back
\param n go n places back
*/
*/
template
<
class
Dtype
>
template
<
class
Dtype
>
void
DL_Iter
<
Dtype
>::
operator
<<
(
int
n
)
void
DL_Iter
<
Dtype
>::
operator
<<
(
int
n
)
{
{
if
(
_current
==
0
)
if
(
_current
==
0
)
Error
(
"operator<<()"
,
NO_LIST
);
Error
(
"operator<<()"
,
NO_LIST
);
for
(
int
i
=
0
;
i
<
n
;
i
++
)
for
(
int
i
=
0
;
i
<
n
;
i
++
)
_current
=
_current
->
_prev
;
_current
=
_current
->
_prev
;
}
}
...
@@ -1468,18 +1463,19 @@ a_listiter->toitem(2345); template <class Dtype>
...
@@ -1468,18 +1463,19 @@ a_listiter->toitem(2345); template <class Dtype>
\endcode
\endcode
*/
*/
template
<
class
Dtype
>
template
<
class
Dtype
>
bool
DL_Iter
<
Dtype
>::
toitem
(
Dtype
item
)
bool
DL_Iter
<
Dtype
>::
toitem
(
Dtype
item
)
{
{
if
(
_current
==
0
)
if
(
_current
==
0
)
Error
(
"toitem(item)"
,
NO_LIST
);
Error
(
"toitem(item)"
,
NO_LIST
);
DL_Node
<
Dtype
>*
node
=
HD
;
//can be 0 if empty
DL_Node
<
Dtype
>*
node
=
HD
;
//can be 0 if empty
for
(
int
i
=
0
;
i
<
NB
;
i
++
)
for
(
int
i
=
0
;
i
<
NB
;
i
++
)
{
if
(
node
->
_item
==
item
)
{
if
(
node
->
_item
==
item
)
{
{
_current
=
node
;
_current
=
node
;
return
true
;
return
true
;
}
}
node
=
node
->
_next
;
node
=
node
->
_next
;
}
}
return
false
;
return
false
;
}
}
...
@@ -1502,13 +1498,13 @@ a_listiter2->toiter(a_listiter2);
...
@@ -1502,13 +1498,13 @@ a_listiter2->toiter(a_listiter2);
\param otheriter other iterator to let this iterator point to.
\param otheriter other iterator to let this iterator point to.
*/
*/
template
<
class
Dtype
>
template
<
class
Dtype
>
void
DL_Iter
<
Dtype
>::
toiter
(
DL_Iter
*
otheriter
)
void
DL_Iter
<
Dtype
>::
toiter
(
DL_Iter
*
otheriter
)
{
{
if
(
otheriter
->
_current
==
0
)
if
(
otheriter
->
_current
==
0
)
Error
(
"toiter(otheriter)"
,
NO_LIST
);
Error
(
"toiter(otheriter)"
,
NO_LIST
);
// both iters must have the same list
// both iters must have the same list
if
(
_list
!=
otheriter
->
_list
)
if
(
_list
!=
otheriter
->
_list
)
Error
(
"toiter(otheriter)"
,
NOT_SAME_LIST
);
Error
(
"toiter(otheriter)"
,
NOT_SAME_LIST
);
_current
=
otheriter
->
_current
;
_current
=
otheriter
->
_current
;
}
}
...
@@ -1521,16 +1517,17 @@ put the iterator at the position of the given object in the list.
...
@@ -1521,16 +1517,17 @@ put the iterator at the position of the given object in the list.
\param othernode a node to let this iterator point to.
\param othernode a node to let this iterator point to.
*/
*/
template
<
class
Dtype
>
template
<
class
Dtype
>
bool
DL_Iter
<
Dtype
>::
tonode
(
DL_Node
<
Dtype
>
*
othernode
)
bool
DL_Iter
<
Dtype
>::
tonode
(
DL_Node
<
Dtype
>
*
othernode
)
{
{
DL_Node
<
Dtype
>*
node
=
HD
;
//can be 0 if empty //node is a temporary cursor
DL_Node
<
Dtype
>*
node
=
HD
;
//can be 0 if empty //node is a temporary cursor
for
(
int
i
=
0
;
i
<
NB
;
i
++
)
for
(
int
i
=
0
;
i
<
NB
;
i
++
)
{
if
(
node
==
othernode
)
{
if
(
node
==
othernode
)
{
{
_current
=
othernode
;
_current
=
othernode
;
return
true
;
return
true
;
}
}
node
=
node
->
_next
;
node
=
node
->
_next
;
}
}
return
false
;
return
false
;
}
}
...
@@ -1564,13 +1561,13 @@ while (a_listiter->iterate())
...
@@ -1564,13 +1561,13 @@ while (a_listiter->iterate())
\endcode
\endcode
*/
*/
template
<
class
Dtype
>
template
<
class
Dtype
>
bool
DL_Iter
<
Dtype
>::
iterate
(
void
)
bool
DL_Iter
<
Dtype
>::
iterate
(
void
)
{
{
if
(
_current
==
0
)
if
(
_current
==
0
)
Error
(
"iterate()"
,
NO_LIST
);
Error
(
"iterate()"
,
NO_LIST
);
_current
=
_current
->
_next
;
_current
=
_current
->
_next
;
if
(
_current
==
RT
)
if
(
_current
==
RT
)
return
false
;
return
false
;
return
true
;
return
true
;
}
}
...
@@ -1595,10 +1592,10 @@ int theitem=a_listiter->item();
...
@@ -1595,10 +1592,10 @@ int theitem=a_listiter->item();
template
<
class
Dtype
>
template
<
class
Dtype
>
Dtype
DL_Iter
<
Dtype
>::
item
()
Dtype
DL_Iter
<
Dtype
>::
item
()
{
{
if
(
_current
==
0
)
if
(
_current
==
0
)
Error
(
"item()"
,
NO_LIST
);
Error
(
"item()"
,
NO_LIST
);
if
(
_current
==
RT
)
if
(
_current
==
RT
)
Error
(
"item()"
,
NO_ITEM
);
Error
(
"item()"
,
NO_ITEM
);
return
_current
->
_item
;
return
_current
->
_item
;
}
}
...
@@ -1607,10 +1604,10 @@ Dtype DL_Iter<Dtype>::item()
...
@@ -1607,10 +1604,10 @@ Dtype DL_Iter<Dtype>::item()
template
<
class
Dtype
>
template
<
class
Dtype
>
DL_Node
<
Dtype
>*
DL_Iter
<
Dtype
>::
node
()
DL_Node
<
Dtype
>*
DL_Iter
<
Dtype
>::
node
()
{
{
if
(
_current
==
0
)
if
(
_current
==
0
)
Error
(
"item()"
,
NO_LIST
);
Error
(
"item()"
,
NO_LIST
);
if
(
_current
==
RT
)
if
(
_current
==
RT
)
Error
(
"item()"
,
NO_ITEM
);
Error
(
"item()"
,
NO_ITEM
);
return
_current
;
return
_current
;
}
}
...
@@ -1622,10 +1619,10 @@ set the iterator position to next object in the list ( can be the root also).
...
@@ -1622,10 +1619,10 @@ set the iterator position to next object in the list ( can be the root also).
template
<
class
Dtype
>
template
<
class
Dtype
>
void
DL_Iter
<
Dtype
>::
next
()
void
DL_Iter
<
Dtype
>::
next
()
{
{
if
(
_current
==
0
)
if
(
_current
==
0
)
Error
(
"item()"
,
NO_LIST
);
Error
(
"item()"
,
NO_LIST
);
_current
=
_current
->
_next
;
_current
=
_current
->
_next
;
}
}
...
@@ -1654,12 +1651,12 @@ while (count)
...
@@ -1654,12 +1651,12 @@ while (count)
template
<
class
Dtype
>
template
<
class
Dtype
>
void
DL_Iter
<
Dtype
>::
next_wrap
()
void
DL_Iter
<
Dtype
>::
next_wrap
()
{
{
if
(
_current
==
0
)
if
(
_current
==
0
)
Error
(
"item()"
,
NO_LIST
);
Error
(
"item()"
,
NO_LIST
);
_current
=
_current
->
_next
;
_current
=
_current
->
_next
;
if
(
_current
==
RT
)
if
(
_current
==
RT
)
_current
=
_current
->
_next
;
_current
=
_current
->
_next
;
}
}
...
@@ -1670,10 +1667,10 @@ set the iterator position to previous object in the list ( can be the root also)
...
@@ -1670,10 +1667,10 @@ set the iterator position to previous object in the list ( can be the root also)
template
<
class
Dtype
>
template
<
class
Dtype
>
void
DL_Iter
<
Dtype
>::
prev
()
void
DL_Iter
<
Dtype
>::
prev
()
{
{
if
(
_current
==
0
)
if
(
_current
==
0
)
Error
(
"item()"
,
NO_LIST
);
Error
(
"item()"
,
NO_LIST
);
_current
=
_current
->
_prev
;
_current
=
_current
->
_prev
;
}
}
/*!
/*!
...
@@ -1701,26 +1698,26 @@ while (count)
...
@@ -1701,26 +1698,26 @@ while (count)
template
<
class
Dtype
>
template
<
class
Dtype
>
void
DL_Iter
<
Dtype
>::
prev_wrap
()
void
DL_Iter
<
Dtype
>::
prev_wrap
()
{
{
if
(
_current
==
0
)
if
(
_current
==
0
)
Error
(
"item()"
,
NO_LIST
);
Error
(
"item()"
,
NO_LIST
);
_current
=
_current
->
_prev
;
_current
=
_current
->
_prev
;
if
(
_current
==
RT
)
if
(
_current
==
RT
)
_current
=
_current
->
_prev
;
_current
=
_current
->
_prev
;
}
}
template
<
class
Dtype
>
template
<
class
Dtype
>
void
DL_Iter
<
Dtype
>::
remove_all
()
void
DL_Iter
<
Dtype
>::
remove_all
()
{
{
if
(
_current
==
0
)
if
(
_current
==
0
)
Error
(
"remove_all()"
,
NO_LIST
);
Error
(
"remove_all()"
,
NO_LIST
);
if
(
_list
->
_iterlevel
>
1
)
if
(
_list
->
_iterlevel
>
1
)
Error
(
"remove_all()"
,
ITER_GT_1
);
Error
(
"remove_all()"
,
ITER_GT_1
);
_list
->
_iterlevel
--
;
_list
->
_iterlevel
--
;
_list
->
remove_all
();
_list
->
remove_all
();
_list
->
_iterlevel
++
;
_list
->
_iterlevel
++
;
_current
=
RT
;
_current
=
RT
;
}
}
/*!
/*!
...
@@ -1749,16 +1746,16 @@ a_listiter->remove();
...
@@ -1749,16 +1746,16 @@ a_listiter->remove();
template
<
class
Dtype
>
template
<
class
Dtype
>
void
DL_Iter
<
Dtype
>::
remove
()
void
DL_Iter
<
Dtype
>::
remove
()
{
{
if
(
_current
==
0
)
if
(
_current
==
0
)
Error
(
"remove()"
,
NO_LIST
);
Error
(
"remove()"
,
NO_LIST
);
if
(
_list
->
_iterlevel
>
1
)
if
(
_list
->
_iterlevel
>
1
)
Error
(
"remove()"
,
ITER_GT_1
);
Error
(
"remove()"
,
ITER_GT_1
);
if
(
_current
==
RT
)
if
(
_current
==
RT
)
Error
(
"remove()"
,
ITER_HITROOT
);
Error
(
"remove()"
,
ITER_HITROOT
);
DL_Node
<
Dtype
>*
node
=
_current
;
DL_Node
<
Dtype
>*
node
=
_current
;
_current
=
_current
->
_next
;
_current
=
_current
->
_next
;
node
->
_prev
->
_next
=
node
->
_next
;
// update forward link
node
->
_prev
->
_next
=
node
->
_next
;
// update forward link
node
->
_next
->
_prev
=
node
->
_prev
;
// update backward link
node
->
_next
->
_prev
=
node
->
_prev
;
// update backward link
...
@@ -1792,15 +1789,15 @@ a_listiter->removehead();
...
@@ -1792,15 +1789,15 @@ a_listiter->removehead();
template
<
class
Dtype
>
template
<
class
Dtype
>
void
DL_Iter
<
Dtype
>::
removehead
()
void
DL_Iter
<
Dtype
>::
removehead
()
{
{
if
(
_current
==
0
)
if
(
_current
==
0
)
Error
(
"removehead()"
,
NO_LIST
);
Error
(
"removehead()"
,
NO_LIST
);
if
(
_list
->
_iterlevel
>
1
)
if
(
_list
->
_iterlevel
>
1
)
Error
(
"removehead()"
,
ITER_GT_1
);
Error
(
"removehead()"
,
ITER_GT_1
);
if
(
NB
==
0
)
if
(
NB
==
0
)
Error
(
"removehead()"
,
EMPTY
);
Error
(
"removehead()"
,
EMPTY
);
if
(
_current
==
HD
)
if
(
_current
==
HD
)
_current
=
_current
->
_next
;
_current
=
_current
->
_next
;
_list
->
_iterlevel
--
;
_list
->
_iterlevel
--
;
_list
->
removehead
();
_list
->
removehead
();
...
@@ -1833,15 +1830,15 @@ a_listiter->removetail();
...
@@ -1833,15 +1830,15 @@ a_listiter->removetail();
template
<
class
Dtype
>
template
<
class
Dtype
>
void
DL_Iter
<
Dtype
>::
removetail
()
void
DL_Iter
<
Dtype
>::
removetail
()
{
{
if
(
_current
==
0
)
if
(
_current
==
0
)
Error
(
"removetail()"
,
NO_LIST
);
Error
(
"removetail()"
,
NO_LIST
);
if
(
_list
->
_iterlevel
>
1
)
if
(
_list
->
_iterlevel
>
1
)
Error
(
"removetail()"
,
ITER_GT_1
);
Error
(
"removetail()"
,
ITER_GT_1
);
if
(
NB
==
0
)
if
(
NB
==
0
)
Error
(
"removehead()"
,
EMPTY
);
Error
(
"removehead()"
,
EMPTY
);
if
(
_current
==
TL
)
if
(
_current
==
TL
)
_current
=
_current
->
_prev
;
_current
=
_current
->
_prev
;
_list
->
_iterlevel
--
;
_list
->
_iterlevel
--
;
_list
->
removetail
();
_list
->
removetail
();
...
@@ -1868,15 +1865,15 @@ a_listiter->insend(a);
...
@@ -1868,15 +1865,15 @@ a_listiter->insend(a);
\endcode
\endcode
*/
*/
template
<
class
Dtype
>
template
<
class
Dtype
>
DL_Node
<
Dtype
>*
DL_Iter
<
Dtype
>::
insend
(
Dtype
newitem
)
DL_Node
<
Dtype
>*
DL_Iter
<
Dtype
>::
insend
(
Dtype
newitem
)
{
{
if
(
_current
==
0
)
if
(
_current
==
0
)
Error
(
"insend()"
,
NO_LIST
);
Error
(
"insend()"
,
NO_LIST
);
if
(
_list
->
_iterlevel
>
1
)
if
(
_list
->
_iterlevel
>
1
)
Error
(
"insend()"
,
ITER_GT_1
);
Error
(
"insend()"
,
ITER_GT_1
);
_list
->
_iterlevel
--
;
_list
->
_iterlevel
--
;
DL_Node
<
Dtype
>*
ret
=
_list
->
insend
(
newitem
);
DL_Node
<
Dtype
>*
ret
=
_list
->
insend
(
newitem
);
_list
->
_iterlevel
++
;
_list
->
_iterlevel
++
;
return
ret
;
return
ret
;
}
}
...
@@ -1902,15 +1899,15 @@ a_listiter->insbegin(a);
...
@@ -1902,15 +1899,15 @@ a_listiter->insbegin(a);
\param newitem an object for which the template list/iterator was generated
\param newitem an object for which the template list/iterator was generated
*/
*/
template
<
class
Dtype
>
template
<
class
Dtype
>
DL_Node
<
Dtype
>*
DL_Iter
<
Dtype
>::
insbegin
(
Dtype
newitem
)
DL_Node
<
Dtype
>*
DL_Iter
<
Dtype
>::
insbegin
(
Dtype
newitem
)
{
{
if
(
_current
==
0
)
if
(
_current
==
0
)
Error
(
"insbegin()"
,
NO_LIST
);
Error
(
"insbegin()"
,
NO_LIST
);
if
(
_list
->
_iterlevel
>
1
)
if
(
_list
->
_iterlevel
>
1
)
Error
(
"insbegin()"
,
ITER_GT_1
);
Error
(
"insbegin()"
,
ITER_GT_1
);
_list
->
_iterlevel
--
;
_list
->
_iterlevel
--
;
DL_Node
<
Dtype
>*
ret
=
_list
->
insbegin
(
newitem
);
DL_Node
<
Dtype
>*
ret
=
_list
->
insbegin
(
newitem
);
_list
->
_iterlevel
++
;
_list
->
_iterlevel
++
;
return
ret
;
return
ret
;
}
}
...
@@ -1932,14 +1929,14 @@ a_listiter->insbefore(a); // insert before tail
...
@@ -1932,14 +1929,14 @@ a_listiter->insbefore(a); // insert before tail
\param newitem an object for which the template list/iterator was generated
\param newitem an object for which the template list/iterator was generated
*/
*/
template
<
class
Dtype
>
template
<
class
Dtype
>
DL_Node
<
Dtype
>*
DL_Iter
<
Dtype
>::
insbefore
(
Dtype
newitem
)
DL_Node
<
Dtype
>*
DL_Iter
<
Dtype
>::
insbefore
(
Dtype
newitem
)
{
{
if
(
_current
==
0
)
if
(
_current
==
0
)
Error
(
"insbefore()"
,
NO_LIST
);
Error
(
"insbefore()"
,
NO_LIST
);
if
(
_list
->
_iterlevel
>
1
)
if
(
_list
->
_iterlevel
>
1
)
Error
(
"insbefore()"
,
ITER_GT_1
);
Error
(
"insbefore()"
,
ITER_GT_1
);
DL_Node
<
Dtype
>*
newnode
=
new
DL_Node
<
Dtype
>
(
newitem
);
DL_Node
<
Dtype
>*
newnode
=
new
DL_Node
<
Dtype
>
(
newitem
);
newnode
->
_next
=
_current
;
newnode
->
_next
=
_current
;
_current
->
_prev
->
_next
=
newnode
;
_current
->
_prev
->
_next
=
newnode
;
...
@@ -1967,14 +1964,14 @@ a_listiter->insafter(a); // insert after head
...
@@ -1967,14 +1964,14 @@ a_listiter->insafter(a); // insert after head
\param newitem an object for which the template list/iterator was generated
\param newitem an object for which the template list/iterator was generated
*/
*/
template
<
class
Dtype
>
template
<
class
Dtype
>
DL_Node
<
Dtype
>*
DL_Iter
<
Dtype
>::
insafter
(
Dtype
newitem
)
DL_Node
<
Dtype
>*
DL_Iter
<
Dtype
>::
insafter
(
Dtype
newitem
)
{
{
if
(
_current
==
0
)
if
(
_current
==
0
)
Error
(
"insafter()"
,
NO_LIST
);
Error
(
"insafter()"
,
NO_LIST
);
if
(
_list
->
_iterlevel
>
1
)
if
(
_list
->
_iterlevel
>
1
)
Error
(
"insafter()"
,
ITER_GT_1
);
Error
(
"insafter()"
,
ITER_GT_1
);
DL_Node
<
Dtype
>*
newnode
=
new
DL_Node
<
Dtype
>
(
newitem
);
DL_Node
<
Dtype
>*
newnode
=
new
DL_Node
<
Dtype
>
(
newitem
);
newnode
->
_next
=
_current
->
_next
;
newnode
->
_next
=
_current
->
_next
;
newnode
->
_prev
=
_current
;
newnode
->
_prev
=
_current
;
...
@@ -2038,11 +2035,11 @@ a_listiter->cocktailsort(numbersorter,NULL);
...
@@ -2038,11 +2035,11 @@ a_listiter->cocktailsort(numbersorter,NULL);
\param fswap swapfunction
\param fswap swapfunction
*/
*/
template
<
class
Dtype
>
template
<
class
Dtype
>
int
DL_Iter
<
Dtype
>::
cocktailsort
(
int
(
*
fcmp
)
(
Dtype
,
Dtype
),
bool
(
*
fswap
)(
Dtype
,
Dtype
)
)
int
DL_Iter
<
Dtype
>::
cocktailsort
(
int
(
*
fcmp
)
(
Dtype
,
Dtype
),
bool
(
*
fswap
)(
Dtype
,
Dtype
)
)
{
{
if
(
_current
==
0
)
if
(
_current
==
0
)
Error
(
"cocktailsort()"
,
NO_LIST
);
Error
(
"cocktailsort()"
,
NO_LIST
);
if
(
NB
<=
1
)
if
(
NB
<=
1
)
return
0
;
return
0
;
DL_Node
<
Dtype
>*
cursor
;
DL_Node
<
Dtype
>*
cursor
;
...
@@ -2057,20 +2054,20 @@ int DL_Iter<Dtype>::cocktailsort(int (*fcmp) (Dtype, Dtype), bool (*fswap)(Dtype
...
@@ -2057,20 +2054,20 @@ int DL_Iter<Dtype>::cocktailsort(int (*fcmp) (Dtype, Dtype), bool (*fswap)(Dtype
bool
swapped
=
true
;
bool
swapped
=
true
;
// while swaping is done & lowerborder upperborder don't touch
// while swaping is done & lowerborder upperborder don't touch
while
(
swapped
&&
(
og
!=
bg
)
)
while
(
swapped
&&
(
og
!=
bg
)
)
{
{
swapped
=
false
;
swapped
=
false
;
// BUBBELSLAG lowerborder--->> upperborder
// BUBBELSLAG lowerborder--->> upperborder
cursor
=
og
;
cursor
=
og
;
while
(
!
(
cursor
==
bgold
)
)
while
(
!
(
cursor
==
bgold
)
)
{
{
// (current.next < current)?
// (current.next < current)?
if
(
fcmp
(
cursor
->
_next
->
_item
,
cursor
->
_item
)
==
1
)
if
(
fcmp
(
cursor
->
_next
->
_item
,
cursor
->
_item
)
==
1
)
{
{
// user function
// user function
if
(
fswap
!=
NULL
)
if
(
fswap
!=
NULL
)
if
(
fswap
(
cursor
->
_item
,
cursor
->
_next
->
_item
)
)
if
(
fswap
(
cursor
->
_item
,
cursor
->
_next
->
_item
)
)
swapResult
++
;
swapResult
++
;
// update swap-flag en upperborder
// update swap-flag en upperborder
swapped
=
true
;
swapped
=
true
;
...
@@ -2080,20 +2077,20 @@ int DL_Iter<Dtype>::cocktailsort(int (*fcmp) (Dtype, Dtype), bool (*fswap)(Dtype
...
@@ -2080,20 +2077,20 @@ int DL_Iter<Dtype>::cocktailsort(int (*fcmp) (Dtype, Dtype), bool (*fswap)(Dtype
cursor
->
_item
=
cursor
->
_next
->
_item
;
cursor
->
_item
=
cursor
->
_next
->
_item
;
cursor
->
_next
->
_item
=
swap
;
cursor
->
_next
->
_item
=
swap
;
}
}
cursor
=
cursor
->
_next
;
cursor
=
cursor
->
_next
;
}
// end bubbelslag
}
// end bubbelslag
bgold
=
bg
;
bgold
=
bg
;
// BRICKSLAG lowerborder <<---upperborder
// BRICKSLAG lowerborder <<---upperborder
cursor
=
bg
;
cursor
=
bg
;
while
(
!
(
cursor
==
ogold
)
)
while
(
!
(
cursor
==
ogold
)
)
{
{
// (current < current.next)?
// (current < current.next)?
if
(
fcmp
(
cursor
->
_item
,
cursor
->
_prev
->
_item
)
==
1
)
if
(
fcmp
(
cursor
->
_item
,
cursor
->
_prev
->
_item
)
==
1
)
{
{
// user function
// user function
if
(
fswap
!=
NULL
)
if
(
fswap
!=
NULL
)
if
(
fswap
(
cursor
->
_item
,
cursor
->
_prev
->
_item
)
)
if
(
fswap
(
cursor
->
_item
,
cursor
->
_prev
->
_item
)
)
swapResult
++
;
swapResult
++
;
// update swap-flag and lowerborder
// update swap-flag and lowerborder
swapped
=
true
;
swapped
=
true
;
...
@@ -2103,7 +2100,7 @@ int DL_Iter<Dtype>::cocktailsort(int (*fcmp) (Dtype, Dtype), bool (*fswap)(Dtype
...
@@ -2103,7 +2100,7 @@ int DL_Iter<Dtype>::cocktailsort(int (*fcmp) (Dtype, Dtype), bool (*fswap)(Dtype
cursor
->
_item
=
cursor
->
_prev
->
_item
;
cursor
->
_item
=
cursor
->
_prev
->
_item
;
cursor
->
_prev
->
_item
=
swap
;
cursor
->
_prev
->
_item
=
swap
;
}
}
cursor
=
cursor
->
_prev
;
cursor
=
cursor
->
_prev
;
}
// end brickslag
}
// end brickslag
ogold
=
og
;
ogold
=
og
;
}
// end while(ongesorteerd)
}
// end while(ongesorteerd)
...
@@ -2163,66 +2160,68 @@ a_listiter->mergesort(numbersorter);
...
@@ -2163,66 +2160,68 @@ a_listiter->mergesort(numbersorter);
\endcode
\endcode
*/
*/
template
<
class
Dtype
>
template
<
class
Dtype
>
void
DL_Iter
<
Dtype
>::
mergesort
(
int
(
*
fcmp
)
(
Dtype
,
Dtype
)
)
void
DL_Iter
<
Dtype
>::
mergesort
(
int
(
*
fcmp
)
(
Dtype
,
Dtype
)
)
{
{
if
(
_current
==
0
)
if
(
_current
==
0
)
Error
(
"mergesort()"
,
NO_LIST
);
Error
(
"mergesort()"
,
NO_LIST
);
mergesort_rec
(
fcmp
,
RT
,
NB
);
mergesort_rec
(
fcmp
,
RT
,
NB
);
}
}
template
<
class
Dtype
>
template
<
class
Dtype
>
void
DL_Iter
<
Dtype
>::
mergesort_rec
(
int
(
*
fcmp
)(
Dtype
,
Dtype
),
DL_Node
<
Dtype
>
*
RT1
,
int
n1
)
void
DL_Iter
<
Dtype
>::
mergesort_rec
(
int
(
*
fcmp
)(
Dtype
,
Dtype
),
DL_Node
<
Dtype
>
*
RT1
,
int
n1
)
{
{
if
(
n1
>
1
)
//one element left then stop
if
(
n1
>
1
)
//one element left then stop
{
{
DL_Node
<
Dtype
>
RT2
;
DL_Node
<
Dtype
>
RT2
;
int
n2
;
int
n2
;
RT2
.
_prev
=
RT1
->
_prev
;
RT2
.
_prev
=
RT1
->
_prev
;
RT2
.
_next
=
RT1
->
_next
;
RT2
.
_next
=
RT1
->
_next
;
// goto middle
// goto middle
n2
=
n1
;
n1
>>=
1
;
n2
-=
n1
;
n2
=
n1
;
n1
>>=
1
;
n2
-=
n1
;
for
(
int
i
=
0
;
i
<
n1
;
i
++
)
for
(
int
i
=
0
;
i
<
n1
;
i
++
)
RT2
.
_next
=
RT2
.
_next
->
_next
;
RT2
.
_next
=
RT2
.
_next
->
_next
;
//RT2 is at half
//RT2 is at half
RT1
->
_prev
->
_next
=
&
RT2
;
RT1
->
_prev
->
_next
=
&
RT2
;
RT2
.
_prev
=
RT1
->
_prev
;
RT2
.
_prev
=
RT1
->
_prev
;
RT1
->
_prev
=
RT2
.
_next
->
_prev
;
RT1
->
_prev
=
RT2
.
_next
->
_prev
;
RT2
.
_next
->
_prev
->
_next
=
RT1
;
RT2
.
_next
->
_prev
->
_next
=
RT1
;
mergesort_rec
(
fcmp
,
RT1
,
n1
);
mergesort_rec
(
fcmp
,
RT1
,
n1
);
mergesort_rec
(
fcmp
,
&
RT2
,
n2
);
mergesort_rec
(
fcmp
,
&
RT2
,
n2
);
mergetwo
(
fcmp
,
RT1
,
&
RT2
);
mergetwo
(
fcmp
,
RT1
,
&
RT2
);
}
}
}
}
template
<
class
Dtype
>
template
<
class
Dtype
>
void
DL_Iter
<
Dtype
>::
mergetwo
(
int
(
*
fcmp
)(
Dtype
,
Dtype
),
DL_Node
<
Dtype
>
*
RT1
,
DL_Node
<
Dtype
>
*
RT2
)
void
DL_Iter
<
Dtype
>::
mergetwo
(
int
(
*
fcmp
)(
Dtype
,
Dtype
),
DL_Node
<
Dtype
>
*
RT1
,
DL_Node
<
Dtype
>
*
RT2
)
{
{
DL_Node
<
Dtype
>
*
c
,
*
a
,
*
b
;
DL_Node
<
Dtype
>
*
c
,
*
a
,
*
b
;
a
=
RT1
->
_next
;
b
=
RT2
->
_next
;
a
=
RT1
->
_next
;
b
=
RT2
->
_next
;
c
=
RT1
;
c
=
RT1
;
do
do
{
{
if
(
fcmp
(
a
->
_item
,
b
->
_item
)
>
-
1
)
if
(
fcmp
(
a
->
_item
,
b
->
_item
)
>
-
1
)
{
c
->
_next
=
a
;
a
->
_prev
=
c
;
c
=
a
;
a
=
a
->
_next
;}
{
c
->
_next
=
a
;
a
->
_prev
=
c
;
c
=
a
;
a
=
a
->
_next
;}
else
else
{
c
->
_next
=
b
;
b
->
_prev
=
c
;
c
=
b
;
b
=
b
->
_next
;}
{
c
->
_next
=
b
;
b
->
_prev
=
c
;
c
=
b
;
b
=
b
->
_next
;}
if
(
a
==
RT1
)
if
(
a
==
RT1
)
{
c
->
_next
=
{
b
;
b
->
_prev
=
c
;
//connect list b to the list made sofar
c
->
_next
=
RT1
->
_prev
=
RT2
->
_prev
;
b
;
b
->
_prev
=
c
;
//connect list b to the list made sofar
RT1
->
_prev
->
_next
=
RT1
;
RT1
->
_prev
=
RT2
->
_prev
;
RT1
->
_prev
->
_next
=
RT1
;
break
;
break
;
}
}
if
(
b
==
RT2
)
if
(
b
==
RT2
)
{
c
->
_next
=
a
;
a
->
_prev
=
c
;
//connect list a to the list made sofar
{
c
->
_next
=
a
;
a
->
_prev
=
c
;
//connect list a to the list made sofar
break
;
break
;
}
}
}
}
while
(
true
);
while
(
true
);
}
}
...
@@ -2266,22 +2265,21 @@ void DL_Iter<Dtype>::mergetwo(int (*fcmp)(Dtype,Dtype), DL_Node<Dtype> *RT1,DL_N
...
@@ -2266,22 +2265,21 @@ void DL_Iter<Dtype>::mergetwo(int (*fcmp)(Dtype,Dtype), DL_Node<Dtype> *RT1,DL_N
// constructor
// constructor
template
<
class
Dtype
>
template
<
class
Dtype
>
DL_StackIter
<
Dtype
>::
DL_StackIter
(
DL_List
<
Dtype
>
*
newlist
)
DL_StackIter
<
Dtype
>::
DL_StackIter
(
DL_List
<
Dtype
>
*
newlist
)
:
DL_Iter
<
Dtype
>
(
newlist
)
// initialiseer BaseIter
:
DL_Iter
<
Dtype
>
(
newlist
)
// initialiseer BaseIter
{}
{}
// destructor
// destructor
template
<
class
Dtype
>
template
<
class
Dtype
>
DL_StackIter
<
Dtype
>::~
DL_StackIter
()
DL_StackIter
<
Dtype
>::~
DL_StackIter
()
{
{}
}
// plaats nieuw item op stack
// plaats nieuw item op stack
template
<
class
Dtype
>
template
<
class
Dtype
>
void
DL_StackIter
<
Dtype
>::
push
(
Dtype
newitem
)
void
DL_StackIter
<
Dtype
>::
push
(
Dtype
newitem
)
{
{
DL_Iter
<
Dtype
>::
insbegin
(
newitem
);
DL_Iter
<
Dtype
>::
insbegin
(
newitem
);
}
}
// remove current item
// remove current item
template
<
class
Dtype
>
template
<
class
Dtype
>
...
@@ -2308,8 +2306,8 @@ int DL_StackIter<Dtype>::count()
...
@@ -2308,8 +2306,8 @@ int DL_StackIter<Dtype>::count()
template
<
class
Dtype
>
template
<
class
Dtype
>
Dtype
DL_StackIter
<
Dtype
>::
pop
()
Dtype
DL_StackIter
<
Dtype
>::
pop
()
{
{
if
(
DL_Iter
<
Dtype
>::
empty
()
)
if
(
DL_Iter
<
Dtype
>::
empty
()
)
this
->
Error
(
"pop()"
,
EMPTY
);
this
->
Error
(
"pop()"
,
EMPTY
);
DL_Iter
<
Dtype
>::
tohead
();
DL_Iter
<
Dtype
>::
tohead
();
Dtype
temp
=
DL_Iter
<
Dtype
>::
item
();
Dtype
temp
=
DL_Iter
<
Dtype
>::
item
();
...
@@ -2331,8 +2329,8 @@ Dtype DL_StackIter<Dtype>::pop()
...
@@ -2331,8 +2329,8 @@ Dtype DL_StackIter<Dtype>::pop()
// constructor
// constructor
template
<
class
DType
>
template
<
class
DType
>
DL_SortIter
<
DType
>::
DL_SortIter
(
DL_List
<
DType
>*
nw_list
,
int
(
*
new_func
)(
DType
,
DType
)
)
DL_SortIter
<
DType
>::
DL_SortIter
(
DL_List
<
DType
>*
nw_list
,
int
(
*
new_func
)(
DType
,
DType
)
)
:
DL_Iter
<
DType
>
(
nw_list
),
comparef
(
new_func
)
:
DL_Iter
<
DType
>
(
nw_list
),
comparef
(
new_func
)
{}
{}
// destructor
// destructor
...
@@ -2342,37 +2340,37 @@ DL_SortIter<DType>::~DL_SortIter()
...
@@ -2342,37 +2340,37 @@ DL_SortIter<DType>::~DL_SortIter()
// general function to insert item
// general function to insert item
template
<
class
DType
>
template
<
class
DType
>
void
DL_SortIter
<
DType
>::
insert
(
DType
new_item
)
void
DL_SortIter
<
DType
>::
insert
(
DType
new_item
)
{
{
DL_Node
<
DType
>*
cursor
=
this
->
_current
;
//can be 0 if empty //node is a temporary cursor
DL_Node
<
DType
>*
cursor
=
this
->
_current
;
//can be 0 if empty //node is a temporary cursor
// if list is empty directly insert
// if list is empty directly insert
if
(
DL_Iter
<
DType
>::
empty
()
)
if
(
DL_Iter
<
DType
>::
empty
()
)
{
{
DL_Iter
<
DType
>::
insend
(
new_item
);
DL_Iter
<
DType
>::
insend
(
new_item
);
}
}
else
else
{
{
// put new item left of item
// put new item left of item
DL_Iter
<
DType
>::
tohead
();
DL_Iter
<
DType
>::
tohead
();
while
(
!
DL_Iter
<
DType
>::
hitroot
()
)
while
(
!
DL_Iter
<
DType
>::
hitroot
()
)
{
{
if
(
!
(
*
comparef
)(
DL_Iter
<
DType
>::
item
(),
new_item
)
)
if
(
!
(
*
comparef
)(
DL_Iter
<
DType
>::
item
(),
new_item
)
)
break
;
break
;
DL_Iter
<
DType
>::
next
();
DL_Iter
<
DType
>::
next
();
}
}
//if at root
//if at root
DL_Iter
<
DType
>::
insbefore
(
new_item
);
DL_Iter
<
DType
>::
insbefore
(
new_item
);
}
}
this
->
_current
=
cursor
;
//set to old cursor position
this
->
_current
=
cursor
;
//set to old cursor position
}
}
template
<
class
DType
>
template
<
class
DType
>
void
DL_SortIter
<
DType
>::
sortitererror
()
void
DL_SortIter
<
DType
>::
sortitererror
()
{
{
this
->
Error
(
"sortiter()"
,
NOT_ALLOW
);
this
->
Error
(
"sortiter()"
,
NOT_ALLOW
);
}
}
polygon/kbool/include/kbool/_dl_itr.h
0 → 100644
View file @
521f428c
/*! \file kbool/include/kbool/_dl_itr.h
\author Probably Klaas Holwerda
Copyright: 2001-2004 (C) Probably Klaas Holwerda
Licence: wxWidgets Licence
RCS-ID: $Id: _dl_itr.h,v 1.3 2008/06/04 21:23:21 titato Exp $
*/
//! author="Klaas Holwerda"
/*
* Definitions of classes, for list implementation
* template list and iterator for any list node type
*/
#ifndef _DL_Iter_H
#define _DL_Iter_H
#define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES 1
#define _CRT_SECURE_NO_DEPRECATE 1
#include "kbool/booleng.h"
#include <stdlib.h>
#ifndef _STATUS_ENUM
#define _STATUS_ENUM
//!<enum Error codes for List and iterator class
enum
Lerror
{
NO_MES
,
/*!<No Message will be generated */
NO_LIST
,
/*!<List is not attached to the iterator*/
NO_LIST_OTHER
,
/*!<no attached list on other iter*/
AC_ITER_LIST_OTHER
,
/*!<iter not allowed on other list */
SAME_LIST
,
/*!<same list not allowed*/
NOT_SAME_LIST
,
/*!<must be same list*/
ITER_GT_1
,
/*!<more then one iteriter at root*/
ITER_GT_0
,
/*!<iter not allowed*/
ITER_HITROOT
,
/*!<iter at root*/
NO_ITEM
,
/*!<no item at current*/
NO_NEXT
,
/*!<no next after current*/
NO_PREV
,
/*!<no prev before current */
EMPTY
,
/*!<list is empty*/
NOT_ALLOW
,
/*!<not allowed*/
ITER_NEG
/*!<to much iters deleted*/
};
#endif
#define SWAP(x,y,t)((t)=(x),(x)=(y),(y)=(t))
#define RT _list->_root
#define HD _list->_root->_next
#define TL _list->_root->_prev
#define NB _list->_nbitems
template
<
class
Dtype
>
class
DL_List
;
template
<
class
Dtype
>
class
DL_Iter
;
template
<
class
Dtype
>
class
DL_SortIter
;
//! Template class DL_Node
template
<
class
Dtype
>
class
DL_Node
{
friend
class
DL_List
<
Dtype
>
;
friend
class
DL_Iter
<
Dtype
>
;
friend
class
DL_SortIter
<
Dtype
>
;
//!Public members
public
:
//!Template constructor no contents
//!Construct a node for a list object
DL_Node
();
//!constructor with init of Dtype
DL_Node
(
Dtype
n
);
//!Destructor
~
DL_Node
();
//!Public members
public
:
//!data in node
Dtype
_item
;
//!pointer to next node
DL_Node
*
_next
;
//!pointer to previous node
DL_Node
*
_prev
;
};
//!Template class DL_List
template
<
class
Dtype
>
class
DL_List
{
friend
class
DL_Iter
<
Dtype
>
;
friend
class
DL_SortIter
<
Dtype
>
;
public
:
//!Constructor
//!Construct a list object
//!!tcarg class | Dtype | list object
DL_List
();
//!destructor
~
DL_List
();
//!Report off List Errors
void
Error
(
const
char
*
function
,
Lerror
a_error
);
//!Number of items in the list
int
count
();
//!Empty List?
bool
empty
();
//!insert the object given at the end of the list, after tail
DL_Node
<
Dtype
>*
insend
(
Dtype
n
);
//!insert the object given at the begin of the list, before head
DL_Node
<
Dtype
>*
insbegin
(
Dtype
n
);
//!remove the object at the begin of the list (head)
void
removehead
();
//! remove the object at the end of the list (tail)
void
removetail
();
//!remove all objects from the list
void
remove_all
(
bool
deleteObject
=
false
);
//!Get the item at the head of the list
Dtype
headitem
();
//!Get the item at the tail of the list
Dtype
tailitem
();
//! to move all objects in a list to this list.
void
takeover
(
DL_List
<
Dtype
>*
otherlist
);
public
:
//!the root node pointer of the list, the first and last node
//! in the list are connected to the root node. The root node is used
//! to detect the end / beginning of the list while traversing it.
DL_Node
<
Dtype
>*
_root
;
//!the number of items in the list, if empty list it is 0
int
_nbitems
;
//!number of iterators on the list, Attaching or instantiating an iterator to list,
//! will increment this member, detaching and
//! destruction of iterator for a list will decrement this number
short
int
_iterlevel
;
};
//! Template class DL_Iter for iterator on DL_List
template
<
class
Dtype
>
class
DL_Iter
{
public
:
//!Construct an iterator object for a given list of type Dtype
DL_Iter
(
DL_List
<
Dtype
>*
newlist
);
//!Constructor of iterator for the same list as another iterator
DL_Iter
(
DL_Iter
*
otheriter
);
//!Constructor without an attached list
DL_Iter
();
//!destructor
~
DL_Iter
();
//!Report off Iterator Errors
void
Error
(
const
char
*
function
,
Lerror
a_error
);
//!This attaches an iterator to a list of a given type.
void
Attach
(
DL_List
<
Dtype
>*
newlist
);
//!This detaches an iterator from a list
void
Detach
();
//!execute given function for each item in the list/iterator
void
foreach_f
(
void
(
*
fp
)
(
Dtype
n
)
);
//! list mutations
//!insert after tail item
DL_Node
<
Dtype
>*
insend
(
Dtype
n
);
//!insert before head item
DL_Node
<
Dtype
>*
insbegin
(
Dtype
n
);
//!insert before current iterator position
DL_Node
<
Dtype
>*
insbefore
(
Dtype
n
);
//!insert after current iterator position
DL_Node
<
Dtype
>*
insafter
(
Dtype
n
);
//!to move all objects in a list to the list of the iterator.
void
takeover
(
DL_List
<
Dtype
>*
otherlist
);
//!to move all objects in a list (using iterator of that list) to the list of the iterator
void
takeover
(
DL_Iter
*
otheriter
);
//! to move maxcount objects in a list (using iterator of that list) to the list of the iterator
void
takeover
(
DL_Iter
*
otheriter
,
int
maxcount
);
//!remove object at current iterator position from the list.
void
remove
();
//!Remove head item
void
removehead
();
//!Remove tail item
void
removetail
();
//!Remove all items
void
remove_all
();
/* void foreach_mf(void (Dtype::*mfp)() ); //call Dtype::mfp for each item */
//!is list empty (contains items or not)?
bool
empty
();
//!is iterator at root node (begin or end)?
bool
hitroot
();
//!is iterator at head/first node?
bool
athead
();
//!is iterator at tail/last node?
bool
attail
();
//!is given item member of the list
bool
has
(
Dtype
otheritem
);
//!Number of items in the list
int
count
();
/* cursor movements */
//!go to last item, if list is empty goto hite
void
totail
();
//!go to first item, if list is empty goto hite
void
tohead
();
//!set the iterator position to the root (empty dummy) object in the list.
void
toroot
();
//! set the iterator position to next object in the list ( can be the root also).
void
operator
++
(
void
);
//!set iterator to next item (pre fix)
void
operator
++
(
int
);
//!set the iterator position to previous object in the list ( can be the root also)(postfix).
void
operator
--
(
void
);
//!set the iterator position to previous object in the list ( can be the root also)(pre fix).
void
operator
--
(
int
);
//!set the iterator position n objects in the next direction ( can be the root also).
void
operator
>>
(
int
);
//!set the iterator position n objects in the previous direction ( can be the root also).
void
operator
<<
(
int
);
//!set the iterator position to next object in the list, if this would be the root object,
//!then set the iterator at the head object
void
next_wrap
();
//!set the iterator position to previous object in the list, if this would be the root object,
//!then set the iterator at the tail object
void
prev_wrap
();
//!move root in order to make the current node the tail
void
reset_tail
();
//!move root in order to make the current node the head
void
reset_head
();
//!put the iterator at the position of the given object in the list.
bool
toitem
(
Dtype
);
//!put the iterator at the same position as the given iterator in the list.
void
toiter
(
DL_Iter
*
otheriter
);
//!put the iterator at the position of the given node in the list.
bool
tonode
(
DL_Node
<
Dtype
>*
);
//!iterate through all items of the list
bool
iterate
(
void
);
//!To get the item at the current iterator position
Dtype
item
();
//! get node at iterator
DL_Node
<
Dtype
>*
node
();
//!sort list with mergesort
void
mergesort
(
int
(
*
fcmp
)
(
Dtype
,
Dtype
)
);
//!sort list with cocktailsort
/*!
\return number of swaps done.
*/
int
cocktailsort
(
int
(
*
)(
Dtype
,
Dtype
),
bool
(
*
)(
Dtype
,
Dtype
)
=
NULL
);
protected
:
//!sort list with mergesort
void
mergesort_rec
(
int
(
*
fcmp
)(
Dtype
,
Dtype
),
DL_Node
<
Dtype
>
*
RT1
,
int
n
);
//!sort list with mergesort
void
mergetwo
(
int
(
*
fcmp
)(
Dtype
,
Dtype
),
DL_Node
<
Dtype
>
*
RT1
,
DL_Node
<
Dtype
>
*
RT2
);
//!set the iterator position to next object in the list ( can be the root also).
void
next
();
//!set the iterator position to previous object in the list ( can be the root also).
void
prev
();
//!the list for this iterator
DL_List
<
Dtype
>
*
_list
;
//!the current position of the iterator
DL_Node
<
Dtype
>
*
_current
;
};
//! template class DL_StackIter class for stack iterator on DL_List
template
<
class
Dtype
>
class
DL_StackIter
:
protected
DL_Iter
<
Dtype
>
{
public
:
//!Constructor of stack iterator for given list
DL_StackIter
(
DL_List
<
Dtype
>
*
);
//!Constructor of stack iterator no list attached
DL_StackIter
();
//!Destructor of stack iterator
~
DL_StackIter
();
//!Remove all items from the stack
void
remove_all
();
//!push given item on the stack
void
push
(
Dtype
n
);
//!get last inserted item from stack
Dtype
pop
();
//!is stack empty?
bool
empty
();
//!number of items on the stack
int
count
();
};
//!template class DL_SortIter
template
<
class
DType
>
class
DL_SortIter
:
public
DL_Iter
<
DType
>
{
public
:
//!Constructor of sort iterator for given list and sort function
DL_SortIter
(
DL_List
<
DType
>*
nw_list
,
int
(
*
new_func
)(
DType
,
DType
)
);
//!Constructor of sort iterator with sort function and no list attached
DL_SortIter
(
int
(
*
newfunc
)(
DType
,
DType
)
);
//!Destructor of sort iterator
~
DL_SortIter
();
//!insert item in sorted order
void
insert
(
DType
new_item
);
/*override following functions to give an error */
//!Not allowed
void
insend
(
bool
n
){
sortitererror
();};
//!Not allowed
void
insbegin
(
bool
n
){
sortitererror
();};
//!Not allowed
void
insbefore
(
bool
n
){
sortitererror
();};
//!Not allowed
void
insafter
(
bool
n
){
sortitererror
();};
//!Not allowed
void
takeover
(
DL_List
<
DType
>*
){
sortitererror
();};
//!Not allowed
void
takeover
(
DL_Iter
<
DType
>*
){
sortitererror
();};
//!Not allowed
void
takeover
(
DL_Iter
<
DType
>*
otheriter
,
int
maxcount
){
sortitererror
();};
//!Not allowed
void
next_wrap
()
{
sortitererror
();};
//!Not allowed
void
prev_wrap
()
{
sortitererror
();};
//!Not allowed
void
reset_tail
()
{
sortitererror
();};
//!Not allowed
void
reset_head
()
{
sortitererror
();};
private
:
//!Report off Iterator Errors
void
sortitererror
();
//!comparefunction used to insert items in sorted order
int
(
*
comparef
)(
DType
,
DType
);
};
#include "kbool/_dl_itr.cpp"
#endif
polygon/kbool/include/kbool/_lnk_itr.cpp
0 → 100644
View file @
521f428c
/*! \file kbool/_lnk_itr.cpp
\author Probably Klaas Holwerda
Copyright: 2001-2004 (C) Probably Klaas Holwerda
Licence: wxWidgets Licence
RCS-ID: $Id: _lnk_itr.cpp,v 1.3 2006/12/13 21:43:33 titato Exp $
*/
#ifdef __UNIX__
#include "kbool/_lnk_itr.h"
#endif
//=======================================================================
// implementation class LinkBaseIter
//=======================================================================
template
<
class
Type
>
TDLI
<
Type
>::
TDLI
(
DL_List
<
void
*>*
newlist
)
:
DL_Iter
<
void
*>
(
newlist
)
{}
template
<
class
Type
>
TDLI
<
Type
>::
TDLI
(
DL_Iter
<
void
*>*
otheriter
)
:
DL_Iter
<
void
*>
(
otheriter
)
{}
template
<
class
Type
>
TDLI
<
Type
>::
TDLI
()
:
DL_Iter
<
void
*>
()
{}
// destructor TDLI
template
<
class
Type
>
TDLI
<
Type
>::~
TDLI
()
{}
template
<
class
Type
>
void
TDLI
<
Type
>::
delete_all
()
{
DL_Node
<
void
*>*
node
;
Type
*
obj
;
for
(
int
i
=
0
;
i
<
NB
;
i
++
)
{
node
=
HD
;
HD
=
node
->
_next
;
obj
=
(
Type
*
)(
node
->
_item
);
delete
obj
;
delete
node
;
}
NB
=
0
;
//reset memory used (no lost pointers)
TL
=
RT
;
_current
=
RT
;
}
template
<
class
Type
>
void
TDLI
<
Type
>::
foreach_f
(
void
(
*
fp
)
(
Type
*
item
)
)
{
DL_Iter
<
void
*>::
foreach_f
(
(
void
(
*
)(
void
*
)
)
fp
);
//call fp for each item
}
template
<
class
Type
>
void
TDLI
<
Type
>::
foreach_mf
(
void
(
Type
::*
mfp
)
()
)
{
DL_Node
<
void
*>*
node
=
HD
;
//can be 0 if empty
Type
*
obj
;
for
(
int
i
=
0
;
i
<
NB
;
i
++
)
{
obj
=
(
Type
*
)(
node
->
_item
);
(
obj
->*
mfp
)();
node
=
node
->
_next
;
}
}
template
<
class
Type
>
void
TDLI
<
Type
>::
takeover
(
DL_List
<
void
*>*
otherlist
)
{
DL_Iter
<
void
*>::
takeover
(
(
DL_List
<
void
*>*
)
otherlist
);
}
template
<
class
Type
>
void
TDLI
<
Type
>::
takeover
(
TDLI
*
otheriter
)
{
DL_Iter
<
void
*>::
takeover
(
(
DL_Iter
<
void
*>*
)
otheriter
);
}
template
<
class
Type
>
void
TDLI
<
Type
>::
takeover
(
TDLI
*
otheriter
,
int
maxcount
)
{
DL_Iter
<
void
*>::
takeover
(
(
DL_Iter
<
void
*>*
)
otheriter
,
maxcount
);
}
// is item element of the list?
template
<
class
Type
>
bool
TDLI
<
Type
>::
has
(
Type
*
otheritem
)
{
return
DL_Iter
<
void
*>::
has
(
(
void
*
)
otheritem
);
}
// goto to item
template
<
class
Type
>
bool
TDLI
<
Type
>::
toitem
(
Type
*
item
)
{
return
DL_Iter
<
void
*>::
toitem
(
(
void
*
)
item
);
}
// get current item
template
<
class
Type
>
Type
*
TDLI
<
Type
>::
item
()
{
return
(
Type
*
)
DL_Iter
<
void
*>::
item
();
}
template
<
class
Type
>
void
TDLI
<
Type
>::
insend
(
Type
*
newitem
)
{
DL_Iter
<
void
*>::
insend
(
(
void
*
)
newitem
);
}
template
<
class
Type
>
void
TDLI
<
Type
>::
insbegin
(
Type
*
newitem
)
{
DL_Iter
<
void
*>::
insbegin
(
(
void
*
)
newitem
);
}
template
<
class
Type
>
void
TDLI
<
Type
>::
insbefore
(
Type
*
newitem
)
{
DL_Iter
<
void
*>::
insbefore
(
(
void
*
)
newitem
);
}
template
<
class
Type
>
void
TDLI
<
Type
>::
insafter
(
Type
*
newitem
)
{
DL_Iter
<
void
*>::
insafter
(
(
void
*
)
newitem
);
}
template
<
class
Type
>
void
TDLI
<
Type
>::
insend_unsave
(
Type
*
newitem
)
{
short
int
iterbackup
=
_list
->
_iterlevel
;
_list
->
_iterlevel
=
0
;
DL_Iter
<
void
*>::
insend
(
(
void
*
)
newitem
);
_list
->
_iterlevel
=
iterbackup
;
}
template
<
class
Type
>
void
TDLI
<
Type
>::
insbegin_unsave
(
Type
*
newitem
)
{
short
int
iterbackup
=
_list
->
_iterlevel
;
_list
->
_iterlevel
=
0
;
DL_Iter
<
void
*>::
insbegin
(
(
void
*
)
newitem
);
_list
->
_iterlevel
=
iterbackup
;
}
template
<
class
Type
>
void
TDLI
<
Type
>::
insbefore_unsave
(
Type
*
newitem
)
{
short
int
iterbackup
=
_list
->
_iterlevel
;
_list
->
_iterlevel
=
0
;
DL_Iter
<
void
*>::
insbefore
(
(
void
*
)
newitem
);
_list
->
_iterlevel
=
iterbackup
;
}
template
<
class
Type
>
void
TDLI
<
Type
>::
insafter_unsave
(
Type
*
newitem
)
{
short
int
iterbackup
=
_list
->
_iterlevel
;
_list
->
_iterlevel
=
0
;
DL_Iter
<
void
*>::
insafter
(
(
void
*
)
newitem
);
_list
->
_iterlevel
=
iterbackup
;
}
template
<
class
Type
>
void
TDLI
<
Type
>::
mergesort
(
int
(
*
f
)(
Type
*
a
,
Type
*
b
)
)
{
DL_Iter
<
void
*>::
mergesort
(
(
int
(
*
)(
void
*
,
void
*
)
)
f
);
}
template
<
class
Type
>
int
TDLI
<
Type
>::
cocktailsort
(
int
(
*
f
)(
Type
*
a
,
Type
*
b
),
bool
(
*
f2
)(
Type
*
c
,
Type
*
d
)
)
{
return
DL_Iter
<
void
*>::
cocktailsort
(
(
int
(
*
)(
void
*
,
void
*
)
)
f
,
(
bool
(
*
)(
void
*
,
void
*
)
)
f2
);
}
template
<
class
Type
>
TDLISort
<
Type
>::
TDLISort
(
DL_List
<
void
*>*
lista
,
int
(
*
newfunc
)(
void
*
,
void
*
)
)
:
DL_SortIter
<
void
*>
(
lista
,
newfunc
)
{}
template
<
class
Type
>
TDLISort
<
Type
>::~
TDLISort
()
{}
template
<
class
Type
>
void
TDLISort
<
Type
>::
delete_all
()
{
DL_Node
<
void
*>*
node
;
Type
*
obj
;
for
(
int
i
=
0
;
i
<
NB
;
i
++
)
{
node
=
HD
;
HD
=
node
->
_next
;
obj
=
(
Type
*
)(
node
->
_item
);
delete
obj
;
delete
node
;
}
NB
=
0
;
//reset memory used (no lost pointers)
TL
=
RT
;
_current
=
RT
;
}
// is item element of the list?
template
<
class
Type
>
bool
TDLISort
<
Type
>::
has
(
Type
*
otheritem
)
{
return
DL_Iter
<
void
*>::
has
(
(
void
*
)
otheritem
);
}
// goto to item
template
<
class
Type
>
bool
TDLISort
<
Type
>::
toitem
(
Type
*
item
)
{
return
DL_Iter
<
void
*>::
toitem
(
(
void
*
)
item
);
}
// get current item
template
<
class
Type
>
Type
*
TDLISort
<
Type
>::
item
()
{
return
(
Type
*
)
DL_Iter
<
void
*>::
item
();
}
template
<
class
Type
>
TDLIStack
<
Type
>::
TDLIStack
(
DL_List
<
void
*>*
newlist
)
:
DL_StackIter
<
void
*>
(
newlist
)
{}
// destructor TDLI
template
<
class
Type
>
TDLIStack
<
Type
>::~
TDLIStack
()
{}
// plaats nieuw item op stack
template
<
class
Type
>
void
TDLIStack
<
Type
>::
push
(
Type
*
newitem
)
{
DL_StackIter
<
void
*>::
push
(
(
Type
*
)
newitem
);
}
// haal bovenste item van stack
template
<
class
Type
>
Type
*
TDLIStack
<
Type
>::
pop
()
{
return
(
Type
*
)
DL_StackIter
<
void
*>::
pop
();
}
polygon/kbool/include/kbool/_lnk_itr.h
0 → 100644
View file @
521f428c
/*! \file kbool/include/kbool/_lnk_itr.h
\author Probably Klaas Holwerda
Copyright: 2001-2004 (C) Probably Klaas Holwerda
Licence: wxWidgets Licence
RCS-ID: $Id: _lnk_itr.h,v 1.2 2006/12/15 21:00:05 titato Exp $
*/
//! author="Klaas Holwerda"
//! version="1.0"
/*
* Definitions of classes, for list implementation
* template list and iterator for any list node type
*/
#ifndef _LinkBaseIter_H
#define _LinkBaseIter_H
//! headerfiles="_dl_itr.h stdlib.h misc.h gdsmes.h"
#include <stdlib.h>
#include "kbool/booleng.h"
#define SWAP(x,y,t)((t)=(x),(x)=(y),(y)=(t))
#include "kbool/_dl_itr.h"
//! codefiles="_dl_itr.cpp"
//! Template class TDLI
/*!
class for iterator on DL_List<void*> that is type casted version of DL_Iter
\sa DL_Iter for further documentation
*/
template
<
class
Type
>
class
TDLI
:
public
DL_Iter
<
void
*>
{
public
:
//!constructor
/*!
\param list to iterate on.
*/
TDLI
(
DL_List
<
void
*>*
list
);
//!constructor
TDLI
(
DL_Iter
<
void
*>*
otheriter
);
//! nolist constructor
TDLI
();
//! destructor
~
TDLI
();
//!call fp for each item
void
foreach_f
(
void
(
*
fp
)
(
Type
*
item
)
);
//!call fp for each item
void
foreach_mf
(
void
(
Type
::*
fp
)
()
);
/* list mutations */
//! delete all items
void
delete_all
();
//! insert at end
void
insend
(
Type
*
n
);
//! insert at begin
void
insbegin
(
Type
*
n
);
//! insert before current
void
insbefore
(
Type
*
n
);
//! insert after current
void
insafter
(
Type
*
n
);
//! insert at end unsave (works even if more then one iterator is on the list
//! the user must be sure not to delete/remove items where other iterators
//! are pointing to.
void
insend_unsave
(
Type
*
n
);
//! insert at begin unsave (works even if more then one iterator is on the list
//! the user must be sure not to delete/remove items where other iterators
//! are pointing to.
void
insbegin_unsave
(
Type
*
n
);
//! insert before iterator position unsave (works even if more then one iterator is on the list
//! the user must be sure not to delete/remove items where other iterators
//! are pointing to.
void
insbefore_unsave
(
Type
*
n
);
//! insert after iterator position unsave (works even if more then one iterator is on the list
//! the user must be sure not to delete/remove items where other iterators
//! are pointing to.
void
insafter_unsave
(
Type
*
n
);
//! \sa DL_Iter::takeover(DL_List< Dtype >* otherlist )
void
takeover
(
DL_List
<
void
*>*
otherlist
);
//! \sa DL_Iter::takeover(DL_Iter* otheriter)
void
takeover
(
TDLI
*
otheriter
);
//! \sa DL_Iter::takeover(DL_Iter* otheriter, int maxcount)
void
takeover
(
TDLI
*
otheriter
,
int
maxcount
);
//! \sa DL_Iter::has
bool
has
(
Type
*
);
//! \sa DL_Iter::toitem
bool
toitem
(
Type
*
);
//!get the item then iterator is pointing at
Type
*
item
();
//! \sa DL_Iter::mergesort
void
mergesort
(
int
(
*
f
)(
Type
*
a
,
Type
*
b
)
);
//! \sa DL_Iter::cocktailsort
int
cocktailsort
(
int
(
*
)
(
Type
*
a
,
Type
*
b
),
bool
(
*
)
(
Type
*
c
,
Type
*
d
)
=
NULL
);
};
//! Template class TDLIsort
/*!
// class for sort iterator on DL_List<void*> that is type casted version of DL_SortIter
// see also inhereted class DL_SortIter for further documentation
*/
template
<
class
Type
>
class
TDLISort
:
public
DL_SortIter
<
void
*>
{
public
:
//!constructor givin a list and a sort function
TDLISort
(
DL_List
<
void
*>*
list
,
int
(
*
newfunc
)(
void
*
,
void
*
)
);
~
TDLISort
();
//!delete all items from the list
void
delete_all
();
bool
has
(
Type
*
);
bool
toitem
(
Type
*
);
Type
*
item
();
};
//! Template class TDLIStack
/*!
class for iterator on DL_List<void*> that is type casted version of DL_StackIter
see also inhereted class DL_StackIter for further documentation
*/
template
<
class
Type
>
class
TDLIStack
:
public
DL_StackIter
<
void
*>
{
public
:
//constructor givin a list
TDLIStack
(
DL_List
<
void
*>*
list
);
~
TDLIStack
();
void
push
(
Type
*
);
Type
*
pop
();
};
#include"kbool/_lnk_itr.cpp"
#endif
polygon/kbool/include/kbool/booleng.h
0 → 100644
View file @
521f428c
/*! \file include/booleng.h
\author Klaas Holwerda
Copyright: 2001-2004 (C) Klaas Holwerda
Licence: see kboollicense.txt
RCS-ID: $Id: booleng.h,v 1.4 2008/09/05 19:01:14 titato Exp $
*/
#ifndef BOOLENG_H
#define BOOLENG_H
#undef _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES
#define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES 1
#define _CRT_SECURE_NO_DEPRECATE 1
#include <stdio.h>
#include <limits.h>
#include <assert.h>
#include <math.h>
#if 0 // Kicad does not use kbool in dll version
#if defined(__WXMSW__)
/*
__declspec works in BC++ 5 and later, Watcom C++ 11.0 and later as well
as VC++ and gcc
*/
# if defined(__VISUALC__) || defined(__BORLANDC__) || defined(__GNUC__) || defined(__WATCOMC__)
# define WXEXPORT __declspec(dllexport)
# define WXIMPORT __declspec(dllimport)
# else /* compiler doesn't support __declspec() */
# define WXEXPORT
# define WXIMPORT
# endif
#elif defined(__WXPM__)
# if defined (__WATCOMC__)
# define WXEXPORT __declspec(dllexport)
/*
__declspec(dllimport) prepends __imp to imported symbols. We do NOT
want that!
*/
# define WXIMPORT
# elif defined(__EMX__)
# define WXEXPORT
# define WXIMPORT
# elif (!(defined(__VISAGECPP__) && (__IBMCPP__ < 400 || __IBMC__ < 400 )))
# define WXEXPORT _Export
# define WXIMPORT _Export
# endif
#elif defined(__WXMAC__) || defined(__WXCOCOA__)
# ifdef __MWERKS__
# define WXEXPORT __declspec(export)
# define WXIMPORT __declspec(import)
# endif
#elif defined(__CYGWIN__)
# define WXEXPORT __declspec(dllexport)
# define WXIMPORT __declspec(dllimport)
#endif
#endif // if 0 for kicad
/* for other platforms/compilers we don't anything */
#ifndef WXEXPORT
# define WXEXPORT
# define WXIMPORT
#endif
#ifdef A2DKBOOLMAKINGDLL
#define A2DKBOOLDLLEXP WXEXPORT
#define A2DKBOOLDLLEXP_DATA(type) WXEXPORT type
#define A2DKBOOLDLLEXP_CTORFN
#elif defined(WXART2D_USINGDLL)
#define A2DKBOOLDLLEXP WXIMPORT
#define A2DKBOOLDLLEXP_DATA(type) WXIMPORT type
#define A2DKBOOLDLLEXP_CTORFN
#else // not making nor using DLL
#define A2DKBOOLDLLEXP
#define A2DKBOOLDLLEXP_DATA(type) type
#define A2DKBOOLDLLEXP_CTORFN
#endif
#define KBOOL_VERSION "1.9"
#define KBOOL_DEBUG 0
#define KBOOL_LOG 0
#define KBOOL_INT64 1
class
KBoolLink
;
#define LINELENGTH 200
#ifdef MAXDOUBLE
#undef MAXDOUBLE
#endif
#define MAXDOUBLE 1.7976931348623158e+308
#ifdef KBOOL_INT64
#if defined(__UNIX__) || defined(__GNUG__)
typedef
long
long
B_INT
;
// 8 bytes integer
//#define MAXB_INT LONG_LONG_MAX
//#define MINB_INT LONG_LONG_MIN // 8 bytes integer
const
B_INT
MAXB_INT
=
(
0x7fffffffffffffffLL
);
// 8 bytes integer
const
B_INT
MINB_INT
=
(
0x8000000000000000LL
);
#else //defined(__UNIX__) || defined(__GNUG__)
typedef
__int64
B_INT
;
// 8 bytes integer
#undef MAXB_INT
#undef MINB_INT
const
B_INT
MAXB_INT
=
(
0x7fffffffffffffff
);
// 8 bytes integer
const
B_INT
MINB_INT
=
(
0x8000000000000000
);
#endif //defined(__UNIX__) || defined(__GNUG__)
#else //KBOOL_INT64
#if defined(__UNIX__) || defined(__GNUG__)
typedef
long
B_INT
;
// 8 bytes integer
const
B_INT
MAXB_INT
=
(
0x7fffffffL
);
// 8 bytes integer
const
B_INT
MINB_INT
=
(
0x80000000L
);
#else
typedef
long
B_INT
;
// 8 bytes integer
const
B_INT
MAXB_INT
=
(
0x7fffffff
);
// 8 bytes integer
const
B_INT
MINB_INT
=
(
0x80000000
);
#endif
#endif //KBOOL_INT64
B_INT
babs
(
B_INT
);
#ifdef M_PI
#undef M_PI
#endif
#define M_PI (3.1415926535897932384626433832795028841972)
#ifdef M_PI_2
#undef M_PI_2
#endif
#define M_PI_2 1.57079632679489661923
#ifdef M_PI_4
#undef M_PI_4
#endif
#define M_PI_4 0.785398163397448309616
#ifndef NULL
#define NULL 0
#endif
B_INT
bmin
(
B_INT
const
value1
,
B_INT
const
value2
);
B_INT
bmax
(
B_INT
const
value1
,
B_INT
const
value2
);
B_INT
bmin
(
B_INT
value1
,
B_INT
value2
);
B_INT
bmax
(
B_INT
value1
,
B_INT
value2
);
#include <string.h>
//! errors in the boolean algorithm will be thrown using this class
class
A2DKBOOLDLLEXP
Bool_Engine_Error
{
public
:
Bool_Engine_Error
(
const
char
*
message
,
const
char
*
header
=
0
,
int
degree
=
9
,
int
fatal
=
0
);
Bool_Engine_Error
(
const
Bool_Engine_Error
&
a
);
~
Bool_Engine_Error
();
char
*
GetErrorMessage
();
char
*
GetHeaderMessage
();
int
GetErrorDegree
();
int
GetFatal
();
protected
:
char
*
_message
;
char
*
_header
;
int
_degree
;
int
_fatal
;
};
#define KBOOL_LOGFILE "kbool.log"
enum
kbEdgeType
{
KB_OUTSIDE_EDGE
,
/*!< edge of the outside contour of a polygon */
KB_INSIDE_EDGE
,
/*!< edge of the inside hole a polygon */
KB_FALSE_EDGE
/*!< edge to connect holes into polygons */
}
;
enum
GroupType
{
GROUP_A
,
/*!< to set Group A for polygons */
GROUP_B
/*!< to set Group A for polygons */
};
enum
BOOL_OP
{
BOOL_NON
,
/*!< No operation */
BOOL_OR
,
/*!< boolean OR operation */
BOOL_AND
,
/*!< boolean AND operation */
BOOL_EXOR
,
/*!< boolean EX_OR operation */
BOOL_A_SUB_B
,
/*!< boolean Group A - Group B operation */
BOOL_B_SUB_A
,
/*!< boolean Group B - Group A operation */
BOOL_CORRECTION
,
/*!< polygon correction/offset operation */
BOOL_SMOOTHEN
,
/*!< smooth operation */
BOOL_MAKERING
/*!< create a ring on all polygons */
};
class
GraphList
;
class
Graph
;
class
KBoolLink
;
class
Node
;
template
<
class
Type
>
class
TDLI
;
//! boolean engine to perform operation on two sets of polygons.
/*
First the engine needs to be filled with polygons.
The first operand in the operation is called group A polygons, the second group B.
The boolean operation ( BOOL_OR, BOOL_AND, BOOL_EXOR, BOOL_A_SUB_B, BOOL_B_SUB_A )
are based on the two sets of polygons in group A and B.
The other operation on group A only.
At the end of the operation the resulting polygons can be extracted.
*/
class
A2DKBOOLDLLEXP
Bool_Engine
{
public
:
//! constructor
Bool_Engine
();
//! destructor
virtual
~
Bool_Engine
();
const
char
*
GetVersion
()
{
return
KBOOL_VERSION
;
}
//! reports progress of algorithm.
virtual
void
SetState
(
const
char
*
=
0
);
//! called at an internal error.
virtual
void
error
(
const
char
*
text
,
const
char
*
title
);
//! called at an internal generated possible error.
virtual
void
info
(
const
char
*
text
,
const
char
*
title
);
bool
Do_Operation
(
BOOL_OP
operation
);
//! distance within which points and lines will be snapped towards lines and other points
/*
The algorithm takes into account gaps and inaccuracies caused by rounding to integer coordinates
in the original data.
Imagine two rectangles one with a side ( 0,0 ) ( 2.0, 17.0 )
and the other has a side ( 0,0 ) ( 1.0, 8.5 )
If for some reason those coordinates where round to ( 0,0 ) ( 2, 17 ) ( 0,0 ) ( 1, 9 ),
there will be clearly a gap or overlap that was not intended.
Even without rounding this effect takes place since there is always a minimum significant bit
also when using doubles.
If the user used as minimum accuracy 0.001, you need to choose Marge > 0.001
The boolean engine scales up the input data with GetDGrid() * GetGrid() and rounds the result to
integer, So (assuming GRID = 100 DGRID = 1000) a vertex of 123.001 in the user data will
become 12300100 internal.
At the end of the algorithm the internal vertexes are scaled down again with GetDGrid() * GetGrid(),
so 12300103 becomes 123.00103 eventually.
So indeed the minimum accuracy might increase, you are free to round again if needed.
*/
void
SetMarge
(
double
marge
);
double
GetMarge
();
//! input points are scaled up with GetDGrid() * GetGrid()
/*
Grid makes sure that the integer data used within the algorithm has room for extra intersections
smaller than the smallest number within the input data.
The input data scaled up with DGrid is related to the accuracy the user has in his input data.
Another scaling with Grid is applied on top of it to create space in the integer number for
even smaller numbers.
*/
void
SetGrid
(
B_INT
grid
);
//! See SetGrid
B_INT
GetGrid
();
//! input points are scaled up with GetDGrid() * GetGrid()
/*
The input data scaled up with DGrid is related to the accuracy the user has in his input data.
User data with a minimum accuracy of 0.001, means set the DGrid to 1000.
The input data may contain data with a minimum accuracy much smaller, but by setting the DGrid
everything smaller than 1/DGrid is rounded.
DGRID is only meant to make fractional parts of input data which can be
doubles, part of the integers used in vertexes within the boolean algorithm.
And therefore DGRID bigger than 1 is not usefull, you would only loose accuracy.
Within the algorithm all input data is multiplied with DGRID, and the result
is rounded to an integer.
*/
void
SetDGrid
(
double
dgrid
);
//! See SetDGrid
double
GetDGrid
();
//! When doing a correction operation ( also known as process offset )
//! this defines the detail in the rounded corners.
/*
Depending on the round factor the corners of the polygon may be rounding within the correction
algorithm. The detail within this rounded corner is set here.
It defines the deviation the generated segments in arc like polygon may have towards the ideal
rounded corner using a perfect arc.
*/
void
SetCorrectionAber
(
double
aber
);
//! see SetCorrectionAber
double
GetCorrectionAber
();
//! When doing a correction operation ( also known as process offset )
//! this defines the amount of correction.
/*
The correction algorithm can apply positive and negative offset to polygons.
It takes into account closed in areas within a polygon, caused by overlapping/selfintersecting
polygons. So holes form that way are corrected proberly, but the overlapping parts itself
are left alone. An often used trick to present polygons with holes by linking to the outside
boundary, is therefore also handled properly.
The algoritm first does a boolean OR operation on the polygon, and seperates holes and
outside contours.
After this it creates a ring shapes on the above holes and outside contours.
This ring shape is added or subtracted from the holes and outside contours.
The result is the corrected polygon.
If the correction factor is > 0, the outside contours will become larger, while the hole contours
will become smaller.
*/
void
SetCorrectionFactor
(
double
aber
);
//! see SetCorrectionFactor
double
GetCorrectionFactor
();
//! used within the smooth algorithm to define how much the smoothed curve may deviate
//! from the original.
void
SetSmoothAber
(
double
aber
);
//! see SetSmoothAber
double
GetSmoothAber
();
//! segments of this size will be left alone in the smooth algorithm.
void
SetMaxlinemerge
(
double
maxline
);
//! see SetMaxlinemerge
double
GetMaxlinemerge
();
//! Polygon may be filled in different ways (alternate and winding rule).
//! This here defines which method will be assumed within the algorithm.
void
SetWindingRule
(
bool
rule
);
//! see SetWindingRule
bool
GetWindingRule
();
//! the smallest accuracy used within the algorithm for comparing two real numbers.
double
GetAccur
();
//! Used with in correction/offset algorithm.
/*
When the polygon contains sharp angles ( < 90 ), after a positive correction the
extended parrallel constructed offset lines may leed to extreme offsets on the angles.
The length of the crossing generated by the parrallel constructed offset lines
towards the original point in the polygon is compared to the offset which needs to be applied.
The Roundfactor then decides if this corner will be rounded.
A Roundfactor of 1 means that the resulting offset will not be bigger then the correction factor
set in the algorithm. Meaning even straight 90 degrees corners will be rounded.
A Roundfactor of > sqrt(2) is where 90 corners will be left alone, and smaller corners will be rounded.
*/
void
SetRoundfactor
(
double
roundfac
);
//! see SetRoundfactor
double
GetRoundfactor
();
// the following are only be used within the algorithm,
// since they are scaled with m_DGRID
//! only used internal.
void
SetInternalMarge
(
B_INT
marge
);
//! only used internal.
B_INT
GetInternalMarge
();
//! only used internal.
double
GetInternalCorrectionAber
();
//! only used internal.
double
GetInternalCorrectionFactor
();
//! only used internal.
double
GetInternalSmoothAber
();
//! only used internal.
B_INT
GetInternalMaxlinemerge
();
//! in this mode polygons add clockwise, or contours,
/*!
and polygons added counter clockwise or holes.
*/
void
SetOrientationEntryMode
(
bool
orientationEntryMode
)
{
m_orientationEntryMode
=
orientationEntryMode
;
}
//! see SetOrientationEntryMode()
bool
GetOrientationEntryMode
()
{
return
m_orientationEntryMode
;
}
//! if set true holes are linked into outer contours by double overlapping segments.
/*!
This mode is needed when the software using the boolean algorithm does
not understand hole polygons. In that case a contour and its holes form one
polygon. In cases where software understands the concept of holes, contours
are clockwise oriented, while holes are anticlockwise oriented.
The output of the boolean operations, is following those rules also.
But even if extracting the polygons from the engine, each segment is marked such
that holes and non holes and linksegments to holes can be recognized.
*/
void
SetLinkHoles
(
bool
doLinkHoles
)
{
m_doLinkHoles
=
doLinkHoles
;
}
//! see SetLinkHoles()
bool
GetLinkHoles
()
{
return
m_doLinkHoles
;
}
//!lof file will be created when set True
void
SetLog
(
bool
OnOff
);
//! used to write to log file
void
Write_Log
(
const
char
*
);
//! used to write to log file
void
Write_Log
(
const
char
*
,
const
char
*
);
//! used to write to log file
void
Write_Log
(
const
char
*
,
double
);
//! used to write to log file
void
Write_Log
(
const
char
*
,
B_INT
);
FILE
*
GetLogFile
()
{
return
m_logfile
;
}
// methods used to add polygons to the eng using points
//! Start adding a polygon to the engine
/*
The boolean operation work on two groups of polygons ( group A or B ),
other algorithms are only using group A.
You add polygons like this to the engine.
// foreach point in a polygon ...
if (booleng->StartPolygonAdd(GROUP_A))
{
booleng->AddPoint(100,100);
booleng->AddPoint(-100,100);
booleng->AddPoint(-100,-100);
booleng->AddPoint(100,-100);
}
booleng->EndPolygonAdd();
\param A_or_B defines if the new polygon will be of group A or B
Holes or added by adding an inside polygons with opposite orientation compared
to another polygon added.
So the contour polygon ClockWise, then add counterclockwise polygons for holes, and visa versa.
BUT only if m_orientationEntryMode is set true, else all polygons are redirected, and become
individual areas without holes.
Holes in such a case must be linked into the contour using two extra segments.
*/
bool
StartPolygonAdd
(
GroupType
A_or_B
);
//! see StartPolygonAdd
bool
AddPoint
(
double
x
,
double
y
);
//! see StartPolygonAdd
bool
EndPolygonAdd
();
// methods used to extract polygons from the eng by getting its points
//! Use after StartPolygonGet()
int
GetNumPointsInPolygon
()
{
return
m_numPtsInPolygon
;
}
//! get resulting polygons at end of an operation
/*!
// foreach resultant polygon in the booleng ...
while ( booleng->StartPolygonGet() )
{
// foreach point in the polygon
while ( booleng->PolygonHasMorePoints() )
{
fprintf(stdout,"x = %f\t", booleng->GetPolygonXPoint());
fprintf(stdout,"y = %f\n", booleng->GetPolygonYPoint());
}
booleng->EndPolygonGet();
}
*/
bool
StartPolygonGet
();
//! see StartPolygonGet
/*!
This iterates through the first graph in the graphlist.
Setting the current Node properly by following the links in the graph
through its nodes.
*/
bool
PolygonHasMorePoints
();
//! see StartPolygonGet
double
GetPolygonXPoint
();
//! see StartPolygonGet
double
GetPolygonYPoint
();
//! in the resulting polygons this tells if the current polygon segment is one
//! used to link holes into the outer contour of the surrounding polygon
bool
GetHoleConnectionSegment
();
//! in the resulting polygons this tells if the current polygon segment is part
//! of a hole within a polygon.
bool
GetHoleSegment
();
//! an other way to get the type of segment.
kbEdgeType
GetPolygonPointEdgeType
();
//! see StartPolygonGet()
/*!
Removes a graph from the graphlist.
Called after an extraction of an output polygon was done.
*/
void
EndPolygonGet
();
private
:
bool
m_doLog
;
//! contains polygons in graph form
GraphList
*
m_graphlist
;
double
m_MARGE
;
B_INT
m_GRID
;
double
m_DGRID
;
double
m_CORRECTIONABER
;
double
m_CORRECTIONFACTOR
;
double
m_SMOOTHABER
;
double
m_MAXLINEMERGE
;
bool
m_WINDINGRULE
;
double
m_ACCUR
;
double
m_ROUNDFACTOR
;
bool
m_orientationEntryMode
;
bool
m_doLinkHoles
;
//! used in the StartPolygonAdd, AddPt, EndPolygonAdd sequence
Graph
*
m_GraphToAdd
;
//! used in the StartPolygonAdd, AddPt, EndPolygonAdd sequence
Node
*
m_lastNodeToAdd
;
//! used in the StartPolygonAdd, AddPt, EndPolygonAdd sequence
Node
*
m_firstNodeToAdd
;
//! the current group type ( group A or B )
GroupType
m_groupType
;
//! used in extracting the points from the resultant polygons
Graph
*
m_getGraph
;
//! used in extracting the points from the resultant polygons
KBoolLink
*
m_getLink
;
//! used in extracting the points from the resultant polygons
Node
*
m_getNode
;
//! used in extracting the points from the resultant polygons
double
m_PolygonXPoint
;
//! used in extracting the points from the resultant polygons
double
m_PolygonYPoint
;
//! used in extracting the points from the resultant polygons
int
m_numPtsInPolygon
;
//! used in extracting the points from the resultant polygons
int
m_numNodesVisited
;
FILE
*
m_logfile
;
public
:
//! use in Node to iterate links.
TDLI
<
KBoolLink
>*
_linkiter
;
//! how many time run intersections fase.
unsigned
int
m_intersectionruns
;
};
#endif
polygon/kbool/include/kbool/graph.h
0 → 100644
View file @
521f428c
/*! \file include/graph.h
\author Klaas Holwerda
Copyright: 2001-2004 (C) Klaas Holwerda
Licence: see kboollicense.txt
RCS-ID: $Id: graph.h,v 1.3 2008/06/04 21:23:21 titato Exp $
*/
/* @@(#) $Source: /cvsroot/wxart2d/wxArt2D/thirdparty/kbool/include/kbool/graph.h,v $ $Revision: 1.3 $ $Date: 2008/06/04 21:23:21 $ */
/*
Program GRAPH.H
Purpose Used to Intercect and other process functions
Last Update 03-04-1996
*/
#ifndef GRAPH_H
#define GRAPH_H
#include "kbool/booleng.h"
#include "kbool/_lnk_itr.h"
#include "kbool/link.h"
#include "kbool/line.h"
#include "kbool/scanbeam.h"
class
Node
;
class
GraphList
;
//! one graph containing links that cab be connected.
class
A2DKBOOLDLLEXP
Graph
{
protected
:
Bool_Engine
*
_GC
;
public
:
Graph
(
Bool_Engine
*
GC
);
Graph
(
KBoolLink
*
,
Bool_Engine
*
GC
);
Graph
(
Graph
*
other
);
~
Graph
();
bool
GetBin
()
{
return
_bin
;
};
void
SetBin
(
bool
b
)
{
_bin
=
b
;
};
void
Prepare
(
int
intersectionruns
);
void
RoundInt
(
B_INT
grid
);
void
Rotate
(
bool
plus90
);
//! adds a link to the linklist
void
AddLink
(
Node
*
begin
,
Node
*
end
);
//! adds a link to the linklist
void
AddLink
(
KBoolLink
*
a_link
);
bool
AreZeroLines
(
B_INT
Marge
);
//! Delete parallel lines
void
DeleteDoubles
();
//! delete zerolines
bool
DeleteZeroLines
(
B_INT
Marge
);
bool
RemoveNullLinks
();
//! Process found intersections
void
ProcessCrossings
();
//! set flags for operations based on group
void
Set_Operation_Flags
();
//! Left Right values
void
Remove_IN_Links
();
//! reset bin and mark flags in links.
void
ResetBinMark
();
// Remove unused links
void
ReverseAllLinks
();
//! Simplify the graph
bool
Simplify
(
B_INT
Marge
);
//! Takes over all links of the argument
bool
Smoothen
(
B_INT
Marge
);
void
TakeOver
(
Graph
*
);
//! function for maximum performance
//! Get the First link from the graph
KBoolLink
*
GetFirstLink
();
Node
*
GetTopNode
();
void
SetBeenHere
(
bool
);
void
Reset_flags
();
//! Set the group of a graph
void
SetGroup
(
GroupType
);
//! Set the number of the graph
void
SetNumber
(
int
);
void
Reset_Mark_and_Bin
();
bool
GetBeenHere
();
int
GetGraphNum
();
int
GetNumberOfLinks
();
void
Boolean
(
BOOL_OP
operation
,
GraphList
*
Result
);
void
Correction
(
GraphList
*
Result
,
double
factor
);
void
MakeRing
(
GraphList
*
Result
,
double
factor
);
void
CreateRing
(
GraphList
*
ring
,
double
factor
);
void
CreateRing_fast
(
GraphList
*
ring
,
double
factor
);
void
CreateArc
(
Node
*
center
,
KBoolLine
*
incoming
,
Node
*
end
,
double
radius
,
double
aber
);
void
CreateArc
(
Node
*
center
,
Node
*
begin
,
Node
*
end
,
double
radius
,
bool
clock
,
double
aber
);
void
MakeOneDirection
();
void
Make_Rounded_Shape
(
KBoolLink
*
a_link
,
double
factor
);
bool
MakeClockWise
();
bool
writegraph
(
bool
linked
);
bool
writeintersections
();
void
WriteKEY
(
Bool_Engine
*
GC
,
FILE
*
file
=
NULL
);
void
WriteGraphKEY
(
Bool_Engine
*
GC
);
protected
:
//! Extracts partical polygons from the graph
/*
Links are sorted in XY at beginpoint. Bin and mark flag are reset.
Next start to collect subparts from the graph, setting the links bin for all found parts.
The parts are searched starting at a topleft corner NON set bin flag link.
Found parts are numbered, to be easily split into to real sperate graphs by Split()
\param operation operation to collect for.
\param detecthole if you want holes detected, influences also way of extraction.
\param foundholes when holes are found this flag is set true, but only if detecthole is set true.
*/
void
Extract_Simples
(
BOOL_OP
operation
,
bool
detecthole
,
bool
&
foundholes
);
//! split graph into small graph, using the numbers in links.
void
Split
(
GraphList
*
partlist
);
//! Collect a graph by starting at argument link
/*
Called from Extract_Simples, and assumes sorted links with bin flag unset for non extarted piece
Collect graphs pieces from a total graph, by following links set to a given boolean operation.
\param current_node start node to collect
\param operation operation to collect for.
\param detecthole if you want holes detected, influences also way of extraction.
\param graphnumber number to be given to links in the extracted graph piece
\param foundholes when holes are found this flag is set true.
*/
void
CollectGraph
(
Node
*
current_node
,
BOOL_OP
operation
,
bool
detecthole
,
int
graphnumber
,
bool
&
foundholes
);
void
CollectGraphLast
(
Node
*
current_node
,
BOOL_OP
operation
,
bool
detecthole
,
int
graphnumber
,
bool
&
foundholes
);
//! find a link not bin in the top left corner ( links should be sorted already )
/*!
Last found position is used to find it quickly.
Used in ExtractSimples()
*/
Node
*
GetMostTopLeft
(
TDLI
<
KBoolLink
>*
_LI
);
//! calculates crossing for all links in a graph, and add those as part of the graph.
/*
It is not just crossings calculation, snapping close nodes is part of it.
This is not done at maximum stability in economic time.
There are faster ways, but hardly ever they solve the problems, and they do not snap.
Here it is on purpose split into separate steps, to get a better result in snapping, and
to reach a better stability.
\param Marge nodes and lines closer to eachother then this, are merged.
*/
bool
CalculateCrossings
(
B_INT
Marge
);
//! equal nodes in position are merged into one.
int
Merge_NodeToNode
(
B_INT
Marge
);
//! basic scan algorithm with a sweeping beam are line.
/*!
\param scantype a different face in the algorithm.
\param holes to detect hole when needed.
*/
int
ScanGraph2
(
SCANTYPE
scantype
,
bool
&
holes
);
//! links not used for a certain operation can be deleted, simplifying extraction
void
DeleteNonCond
(
BOOL_OP
operation
);
//! links not used for a certain operation can be set bin, simplifying extraction
void
HandleNonCond
(
BOOL_OP
operation
);
//! debug
bool
checksort
();
//! used in correction/offset algorithm
bool
Small
(
B_INT
howsmall
);
bool
_bin
;
DL_List
<
void
*>*
_linklist
;
};
#endif
polygon/kbool/include/kbool/graphlst.h
0 → 100644
View file @
521f428c
/*! \file include/graphlst.h
\author Klaas Holwerda
Copyright: 2001-2004 (C) Klaas Holwerda
Licence: see kboollicense.txt
RCS-ID: $Id: graphlst.h,v 1.3 2008/06/04 21:23:21 titato Exp $
*/
/* @@(#) $Source: /cvsroot/wxart2d/wxArt2D/thirdparty/kbool/include/kbool/graphlst.h,v $ $Revision: 1.3 $ $Date: 2008/06/04 21:23:21 $ */
/*
Program GRAPHLST.H
Purpose Implements a list of graphs (header)
Last Update 11-03-1996
*/
#ifndef GRAPHLIST_H
#define GRAPHLIST_H
#include "kbool/booleng.h"
#include "kbool/_lnk_itr.h"
#include "kbool/graph.h"
class
Debug_driver
;
class
A2DKBOOLDLLEXP
GraphList
:
public
DL_List
<
void
*>
{
protected
:
Bool_Engine
*
_GC
;
public
:
GraphList
(
Bool_Engine
*
GC
);
GraphList
(
GraphList
*
other
);
~
GraphList
();
void
MakeOneGraph
(
Graph
*
total
);
void
Prepare
(
Graph
*
total
);
void
MakeRings
();
void
Correction
();
void
Simplify
(
double
marge
);
void
Smoothen
(
double
marge
);
void
Merge
();
void
Boolean
(
BOOL_OP
operation
,
int
intersectionRunsMax
);
void
WriteGraphs
();
void
WriteGraphsKEY
(
Bool_Engine
*
GC
);
protected
:
void
Renumber
();
void
UnMarkAll
();
};
#endif
polygon/kbool/include/kbool/kboolmod.h
0 → 100644
View file @
521f428c
#ifndef __A2D_KBOOLMOD_H__
#define __A2D_KBOOLMOD_H__
#include "kbool/booleng.h"
#include "kbool/graph.h"
#include "kbool/graphlst.h"
#include "kbool/line.h"
#include "kbool/link.h"
#include "kbool/lpoint.h"
#include "kbool/node.h"
#include "kbool/record.h"
#include "kbool/scanbeam.h"
#endif
polygon/kbool/include/kbool/line.h
0 → 100644
View file @
521f428c
/*! \file include/line.h
\brief Mainy used for calculating crossings
\author Klaas Holwerda
Copyright: 2001-2004 (C) Klaas Holwerda
Licence: see kboollicense.txt
RCS-ID: $Id: line.h,v 1.3 2008/06/04 21:23:21 titato Exp $
*/
#ifndef LINE_H
#define LINE_H
#include "kbool/booleng.h"
#include "kbool/link.h"
class
A2DKBOOLDLLEXP
Bool_Engine
;
// Status of a point to a line
enum
PointStatus
{
LEFT_SIDE
,
RIGHT_SIDE
,
ON_AREA
,
IN_AREA
};
class
A2DKBOOLDLLEXP
Graph
;
class
A2DKBOOLDLLEXP
KBoolLine
{
protected
:
Bool_Engine
*
m_GC
;
public
:
// constructors and destructor
KBoolLine
(
Bool_Engine
*
GC
);
KBoolLine
(
KBoolLink
*
,
Bool_Engine
*
GC
);
~
KBoolLine
();
void
Set
(
KBoolLink
*
);
KBoolLink
*
GetLink
();
//! Get the beginnode from a line
Node
*
GetBeginNode
();
//! Get the endnode from a line
Node
*
GetEndNode
();
//! Check if two lines intersects
int
CheckIntersect
(
KBoolLine
*
,
double
Marge
);
//! Intersects two lines
int
Intersect
(
KBoolLine
*
,
double
Marge
);
int
Intersect_simple
(
KBoolLine
*
lijn
);
bool
Intersect2
(
Node
*
crossing
,
KBoolLine
*
lijn
);
//!For an infinite line
PointStatus
PointOnLine
(
Node
*
a_node
,
double
&
Distance
,
double
Marge
);
//!For a non-infinite line
PointStatus
PointInLine
(
Node
*
a_node
,
double
&
Distance
,
double
Marge
);
//! Caclulate Y if X is known
B_INT
Calculate_Y
(
B_INT
X
);
B_INT
Calculate_Y_from_X
(
B_INT
X
);
void
Virtual_Point
(
LPoint
*
a_point
,
double
distance
);
//! assignment operator
KBoolLine
&
operator
=
(
const
KBoolLine
&
);
Node
*
OffsetContour
(
KBoolLine
*
const
nextline
,
Node
*
last_ins
,
double
factor
,
Graph
*
shape
);
Node
*
OffsetContour_rounded
(
KBoolLine
*
const
nextline
,
Node
*
_last_ins
,
double
factor
,
Graph
*
shape
);
bool
OkeForContour
(
KBoolLine
*
const
nextline
,
double
factor
,
Node
*
LastLeft
,
Node
*
LastRight
,
LinkStatus
&
_outproduct
);
bool
Create_Ring_Shape
(
KBoolLine
*
nextline
,
Node
**
_last_ins_left
,
Node
**
_last_ins_right
,
double
factor
,
Graph
*
shape
);
void
Create_Begin_Shape
(
KBoolLine
*
nextline
,
Node
**
_last_ins_left
,
Node
**
_last_ins_right
,
double
factor
,
Graph
*
shape
);
void
Create_End_Shape
(
KBoolLine
*
nextline
,
Node
*
_last_ins_left
,
Node
*
_last_ins_right
,
double
factor
,
Graph
*
shape
);
//! Calculate the parameters if nessecary
void
CalculateLineParameters
();
//! Adds a crossing between the intersecting lines
void
AddLineCrossing
(
B_INT
,
B_INT
,
KBoolLine
*
);
void
AddCrossing
(
Node
*
a_node
);
Node
*
AddCrossing
(
B_INT
X
,
B_INT
Y
);
bool
ProcessCrossings
(
TDLI
<
KBoolLink
>*
_LI
);
// Linecrosslist
void
SortLineCrossings
();
bool
CrossListEmpty
();
DL_List
<
void
*>*
GetCrossList
();
// bool HasInCrossList(Node*);
private
:
//! Function needed for Intersect
int
ActionOnTable1
(
PointStatus
,
PointStatus
);
//! Function needed for Intersect
int
ActionOnTable2
(
PointStatus
,
PointStatus
);
double
m_AA
;
double
m_BB
;
double
m_CC
;
KBoolLink
*
m_link
;
bool
m_valid_parameters
;
//! List with crossings through this link
DL_List
<
void
*>
*
linecrosslist
;
};
#endif
polygon/kbool/include/kbool/link.h
0 → 100644
View file @
521f428c
/*! \file include/link.h
\brief Part of a graph, connection between nodes (Header)
\author Klaas Holwerda or Julian Smart
Copyright: 2001-2004 (C) Klaas Holwerda
Licence: see kboollicense.txt
RCS-ID: $Id: link.h,v 1.3 2008/06/04 21:23:22 titato Exp $
*/
#ifndef LINK_H
#define LINK_H
#include "kbool/booleng.h"
#include "kbool/_lnk_itr.h"
enum
LinkStatus
{
IS_LEFT
,
IS_ON
,
IS_RIGHT
};
class
LPoint
;
class
Node
;
class
Record
;
//! segment within a graph
/*
A Graph contains a list of KBoolLink, the KBoolLink or connected by Node's.
Several KBoolLink can be connected to one Node.
A KBoolLink has a direction defined by its begin and end node.
Node do have a list of connected KBoolLink's.
So one can walk trough a graph in two ways:
1- via its KBoolLink list
2- via the node connected to the KBoolLink's
*/
class
A2DKBOOLDLLEXP
KBoolLink
{
protected
:
Bool_Engine
*
_GC
;
public
:
//! contructors
KBoolLink
(
Bool_Engine
*
GC
);
//! contructors
KBoolLink
(
int
graphnr
,
Node
*
begin
,
Node
*
end
,
Bool_Engine
*
GC
);
//! contructors
KBoolLink
(
Node
*
begin
,
Node
*
end
,
Bool_Engine
*
GC
);
//! destructors
~
KBoolLink
();
//! Merges the other node with argument
void
MergeNodes
(
Node
*
const
);
//! outproduct of two links
LinkStatus
OutProduct
(
KBoolLink
*
const
two
,
double
accur
);
//! link three compared to this and two
LinkStatus
PointOnCorner
(
KBoolLink
*
const
,
KBoolLink
*
const
);
//! Removes argument from the link
void
Remove
(
Node
*
);
//! replaces olddone in the link by newnode
void
Replace
(
Node
*
oldnode
,
Node
*
newnode
);
//!top hole marking
void
SetTopHole
(
bool
value
);
//!top hole marking
bool
IsTopHole
();
//! Marking functions
void
UnMark
();
//! Marking functions
void
Mark
();
//! Marking functions
void
SetMark
(
bool
);
//! Marking functions
bool
IsMarked
();
//! holelink Marking functions
void
SetHoleLink
(
bool
val
){
m_holelink
=
val
;};
//! holelink Marking functions
bool
GetHoleLink
(){
return
m_holelink
;};
//! Bin functions
void
SetNotBeenHere
();
//! Bin functions
void
SetBeenHere
();
//! Have you been here ??
bool
BeenHere
();
//! Removes all the references to this
void
UnLink
();
//! functions for maximum performance
Node
*
GetBeginNode
();
//! Datamember access functions
Node
*
GetEndNode
();
Node
*
GetLowNode
();
Node
*
GetHighNode
();
//! Returns a next link beginning with argument
KBoolLink
*
Forth
(
Node
*
);
int
GetGraphNum
();
bool
GetInc
();
bool
GetLeftA
();
bool
GetLeftB
();
bool
GetRightA
();
bool
GetRightB
();
void
GetLRO
(
LPoint
*
,
int
&
,
int
&
,
double
);
//! Return a node not equal to arg.
Node
*
GetOther
(
const
Node
*
const
);
//! Is this link unused ?
bool
IsUnused
();
//! Used for given operation ?
bool
IsMarked
(
BOOL_OP
operation
);
//! return true if Left side is marked true for operation
bool
IsMarkedLeft
(
BOOL_OP
operation
);
//! return true if Right side is marked true for operation
bool
IsMarkedRight
(
BOOL_OP
operation
);
//! is this a hole link for given operation
bool
IsHole
(
BOOL_OP
operation
);
//! set the hole mark
void
SetHole
(
bool
);
//! is the hole mark set?
bool
GetHole
();
//! Are the nodes on about the same coordinates ?
bool
IsZero
(
B_INT
marge
);
bool
ShorterThan
(
B_INT
marge
);
//! Resets the link
void
Reset
(
Node
*
begin
,
Node
*
end
,
int
graphnr
=
0
);
void
Set
(
Node
*
begin
,
Node
*
end
);
void
SetBeginNode
(
Node
*
);
void
SetEndNode
(
Node
*
);
void
SetGraphNum
(
int
);
void
SetInc
(
bool
);
void
SetLeftA
(
bool
);
void
SetLeftB
(
bool
);
void
SetRightA
(
bool
);
void
SetRightB
(
bool
);
void
SetGroup
(
GroupType
);
GroupType
Group
();
//! Flag calculation (internal only)
void
SetLineTypes
();
void
Reset
();
void
Reset_flags
();
//!put in this direction
void
Redirect
(
Node
*
a_node
);
void
TakeOverOperationFlags
(
KBoolLink
*
link
);
void
SetRecordNode
(
DL_Node
<
Record
*>*
recordNode
)
{
m_record
=
recordNode
;
}
DL_Node
<
Record
*>*
GetRecordNode
()
{
return
m_record
;
}
protected
:
//! The mainitems of a link
Node
*
m_beginnode
,
*
m_endnode
;
//! Marker for walking over the graph
bool
m_bin
:
1
;
//! Is this a part of hole ?
bool
m_hole
:
1
;
//! link that is toplink of hole?
bool
m_hole_top
:
1
;
//! going in one more time in this graph if true else going out one time
bool
m_Inc
:
1
;
//! Is left in polygongroup A
bool
m_LeftA
:
1
;
//! Is right in polygon group A
bool
m_RightA
:
1
;
//! Is left in polygon group B
bool
m_LeftB
:
1
;
//! Is right in polygongroup B
bool
m_RightB
:
1
;
//! General purose marker, internally unused
bool
m_mark
:
1
;
//! link for linking holes
bool
m_holelink
:
1
;
//! Marker for Merge Left
bool
m_merge_L
:
1
;
//! Marker for substract a-b Left
bool
m_a_substract_b_L
:
1
;
//! Marker for substract b-a Left
bool
m_b_substract_a_L
:
1
;
//! Marker for intersect Left
bool
m_intersect_L
:
1
;
//! Marker for X-OR Left
bool
m_exor_L
:
1
;
//! Marker for Merge Right
bool
m_merge_R
:
1
;
//! Marker for substract a-b Right
bool
m_a_substract_b_R
:
1
;
//! Marker for substract b-a Right
bool
m_b_substract_a_R
:
1
;
//! Marker for intersect Right
bool
m_intersect_R
:
1
;
//! Marker for X-OR Right
bool
m_exor_R
:
1
;
//! belongs to group A or B
GroupType
m_group
:
1
;
//! belongs to this polygon part in the graph.
int
m_graphnum
;
DL_Node
<
Record
*>*
m_record
;
};
#endif
polygon/kbool/include/kbool/lpoint.h
0 → 100644
View file @
521f428c
/*! \file include/lpoint.h
\author Klaas Holwerda
Copyright: 2001-2004 (C) Klaas Holwerda
Licence: see kboollicense.txt
RCS-ID: $Id: lpoint.h,v 1.3 2008/06/04 21:23:22 titato Exp $
*/
/* @@(#) $Source: /cvsroot/wxart2d/wxArt2D/thirdparty/kbool/include/kbool/lpoint.h,v $ $Revision: 1.3 $ $Date: 2008/06/04 21:23:22 $ */
/*
Program LPOINT.H
Purpose Definition of GDSII pointtype structure
Last Update 12-12-1995
*/
#ifndef LPOINT_H
#define LPOINT_H
#include "kbool/booleng.h"
class
A2DKBOOLDLLEXP
LPoint
{
public
:
LPoint
();
LPoint
(
B_INT
const
,
B_INT
const
);
LPoint
(
LPoint
*
const
);
void
Set
(
const
B_INT
,
const
B_INT
);
void
Set
(
const
LPoint
&
);
LPoint
GetPoint
();
B_INT
GetX
();
B_INT
GetY
();
void
SetX
(
B_INT
);
void
SetY
(
B_INT
);
bool
Equal
(
const
LPoint
a_point
,
B_INT
Marge
);
bool
Equal
(
const
B_INT
,
const
B_INT
,
B_INT
Marge
);
bool
ShorterThan
(
const
LPoint
a_point
,
B_INT
marge
);
bool
ShorterThan
(
const
B_INT
X
,
const
B_INT
Y
,
B_INT
);
LPoint
&
operator
=
(
const
LPoint
&
);
LPoint
&
operator
+
(
const
LPoint
&
);
LPoint
&
operator
-
(
const
LPoint
&
);
LPoint
&
operator
*
(
int
);
LPoint
&
operator
/
(
int
);
int
operator
==
(
const
LPoint
&
)
const
;
int
operator
!=
(
const
LPoint
&
)
const
;
protected
:
B_INT
_x
;
B_INT
_y
;
};
#endif
polygon/kbool/include/kbool/node.h
0 → 100644
View file @
521f428c
/*! \file include/node.h
\brief Holds a GDSII node structure (Header)
\author Klaas Holwerda
Copyright: 2001-2004 (C) Klaas Holwerda
Licence: see kboollicense.txt
RCS-ID: $Id: node.h,v 1.3 2008/06/04 21:23:22 titato Exp $
*/
#ifndef NODE_H
#define NODE_H
#include "kbool/booleng.h"
#include "kbool/lpoint.h"
#include "kbool/link.h"
#include "kbool/_lnk_itr.h" // LinkBaseIter
#include <math.h>
enum
NodePosition
{
N_LEFT
,
N_ON
,
N_RIGHT
};
class
A2DKBOOLDLLEXP
Node
:
public
LPoint
{
protected
:
Bool_Engine
*
_GC
;
public
:
// friend must be deleted in the final version!
friend
class
Debug_driver
;
// constructors and destructors
Node
(
Bool_Engine
*
GC
);
Node
(
const
B_INT
,
const
B_INT
,
Bool_Engine
*
GC
);
Node
(
LPoint
*
const
a_point
,
Bool_Engine
*
GC
);
Node
(
Node
*
const
,
Bool_Engine
*
GC
);
Node
&
operator
=
(
const
Node
&
other_node
);
~
Node
();
//public member functions
void
AddLink
(
KBoolLink
*
);
DL_List
<
void
*>*
GetLinklist
();
//! check two link for its operation flags to be the same when coming from the prev link.
bool
SameSides
(
KBoolLink
*
const
prev
,
KBoolLink
*
const
link
,
BOOL_OP
operation
);
//! get the link most right or left to the current link, but with the specific operation
/*! flags the same on the sides of the new link.
*/
KBoolLink
*
GetMost
(
KBoolLink
*
const
prev
,
LinkStatus
whatside
,
BOOL_OP
operation
);
//! get link that is leading to a hole ( hole segment or linking segment )
KBoolLink
*
GetMostHole
(
KBoolLink
*
const
prev
,
LinkStatus
whatside
,
BOOL_OP
operation
);
//! get link that is not vertical.
KBoolLink
*
GetNotFlat
();
//! get a link to a hole or from a hole.
KBoolLink
*
GetHoleLink
(
KBoolLink
*
const
prev
,
bool
checkbin
,
BOOL_OP
operation
);
int
Merge
(
Node
*
);
void
RemoveLink
(
KBoolLink
*
);
bool
Simplify
(
Node
*
First
,
Node
*
Second
,
B_INT
Marge
);
// memberfunctions for maximum performance
void
RoundInt
(
B_INT
grid
);
KBoolLink
*
GetIncomingLink
();
int
GetNumberOfLinks
();
KBoolLink
*
GetNextLink
();
KBoolLink
*
GetOtherLink
(
KBoolLink
*
);
KBoolLink
*
GetOutgoingLink
();
KBoolLink
*
GetPrevLink
();
KBoolLink
*
Follow
(
KBoolLink
*
const
prev
);
KBoolLink
*
GetBinHighest
(
bool
binset
);
protected
:
DL_List
<
void
*>*
_linklist
;
};
#endif
polygon/kbool/include/kbool/record.h
0 → 100644
View file @
521f428c
/*! \file include/record.h
\author Klaas Holwerda
Copyright: 2001-2004 (C) Klaas Holwerda
Licence: see kboollicense.txt
RCS-ID: $Id: record.h,v 1.3 2008/06/04 21:23:22 titato Exp $
*/
#ifndef RECORD_H
#define RECORD_H
class
Node
;
#include "kbool/booleng.h"
#include "kbool/link.h"
#include "kbool/line.h"
enum
BEAM_TYPE
{
NORMAL
,
FLAT
};
enum
DIRECTION
{
GO_LEFT
,
GO_RIGHT
};
//extern void DeleteRecordPool();
class
A2DKBOOLDLLEXP
Bool_Engine
;
class
A2DKBOOLDLLEXP
Record
{
protected
:
Bool_Engine
*
_GC
;
public
:
// void deletepool();
Record
(
KBoolLink
*
link
,
Bool_Engine
*
GC
);
~
Record
();
// void* operator new(size_t size);
// void operator delete(void* recordptr);
void
SetNewLink
(
KBoolLink
*
link
);
void
Set_Flags
();
void
Calc_Ysp
(
Node
*
low
);
KBoolLink
*
GetLink
();
KBoolLine
*
GetLine
();
B_INT
Ysp
();
void
SetYsp
(
B_INT
ysp
);
DIRECTION
Direction
();
bool
Calc_Left_Right
(
Record
*
record_above_me
);
bool
Equal
(
Record
*
);
private
:
KBoolLine
_line
;
B_INT
_ysp
;
//! going left are right in beam
DIRECTION
_dir
;
//! how far in group_a
int
_a
;
//! how far in group_b
int
_b
;
};
#endif
polygon/kbool/include/kbool/scanbeam.h
0 → 100644
View file @
521f428c
/*! \file include/scanbeam.h
\author Klaas Holwerda
Copyright: 2001-2004 (C) Klaas Holwerda
Licence: see kboollicense.txt
RCS-ID: $Id: scanbeam.h,v 1.4 2008/09/05 19:01:14 titato Exp $
*/
#ifndef SCANBEAM_H
#define SCANBEAM_H
#include "kbool/booleng.h"
#include "kbool/_lnk_itr.h"
#include "kbool/record.h"
#include "kbool/link.h"
enum
SCANTYPE
{
NODELINK
,
LINKLINK
,
GENLR
,
LINKHOLES
,
INOUT
};
#if defined(WXART2D_USINGDLL)
template
class
A2DKBOOLDLLEXP
DL_Iter
<
Record
*>
;
#endif
class
A2DKBOOLDLLEXP
ScanBeam
:
public
DL_List
<
Record
*>
{
protected
:
Bool_Engine
*
_GC
;
public
:
ScanBeam
(
Bool_Engine
*
GC
);
~
ScanBeam
();
void
SetType
(
Node
*
low
,
Node
*
high
);
bool
FindNew
(
SCANTYPE
scantype
,
TDLI
<
KBoolLink
>*
_I
,
bool
&
holes
);
bool
RemoveOld
(
SCANTYPE
scantype
,
TDLI
<
KBoolLink
>*
_I
,
bool
&
holes
);
private
:
bool
ProcessHoles
(
bool
atinsert
,
TDLI
<
KBoolLink
>*
_LI
);
int
Process_LinkToLink_Crossings
();
// find crossings
int
Process_PointToLink_Crossings
();
int
Process_LinkToLink_Flat
(
KBoolLine
*
flatline
);
void
SortTheBeam
(
bool
backangle
);
bool
checksort
();
bool
writebeam
();
void
Calc_Ysp
();
//int FindCloseLinksAndCross(TDLI<KBoolLink>* _I,Node* _lowf);
void
Generate_INOUT
(
int
graphnumber
);
Node
*
_low
;
DL_Iter
<
Record
*>
_BI
;
int
lastinserted
;
BEAM_TYPE
_type
;
};
#endif
polygon/kbool/include/kbool/statusb.h
0 → 100644
View file @
521f428c
/*! \file kbool/include/kbool/statusb.h
\author Probably Klaas Holwerda
Copyright: 2001-2004 (C) Probably Klaas Holwerda
Licence: wxWidgets Licence
RCS-ID: $Id: statusb.h,v 1.2 2006/12/15 21:00:06 titato Exp $
*/
/* @@(#) $Source: /cvsroot/wxart2d/wxArt2D/thirdparty/kbool/include/kbool/statusb.h,v $ $Revision: 1.2 $ $Date: 2006/12/15 21:00:06 $ */
/*
Program STATUSB.H
Purpose Controls the statusbar of the application (header)
This statusbar is a typical Windows statusbar
For porting to another platform there must be a StatusBar class
derived from this.
User interface element (See documentation for more details
about the functions needed in this class)
*/
#ifndef STATUSB_H
#define STATUSB_H
#include <time.h>
// abstract base class for own statusbar inherite from it
class
A2DKBOOLDLLEXP
StatusBar
{
public
:
// constructor & destructor
StatusBar
(){};
~
StatusBar
(){};
virtual
void
SetXY
(
double
=
0
.
0
,
double
=
0
.
0
)
=
0
;
virtual
void
ResetCoord
()
=
0
;
virtual
void
SetFile
(
char
*
=
0
)
=
0
;
virtual
void
SetProcess
(
char
*
=
0
)
=
0
;
virtual
void
SetTime
(
time_t
seconds
=
0
)
=
0
;
virtual
void
SetRecording
(
int
status
=
0
)
=
0
;
virtual
void
SetZoom
(
float
factor
=
1
)
=
0
;
virtual
void
Reset
()
=
0
;
void
StartDTimer
();
void
EndDTimer
();
int
GetDTimerOn
();
time_t
GetDTimer
();
protected
:
int
timer
;
time_t
oldtime
;
time_t
curtime
;
};
#endif
polygon/kbool/include/valuesvc.h
→
polygon/kbool/include/
kbool/
valuesvc.h
View file @
521f428c
...
@@ -5,5 +5,5 @@
...
@@ -5,5 +5,5 @@
Licence: wxWidgets Licence
Licence: wxWidgets Licence
RCS-ID: $Id: valuesvc.h,v 1.1 200
5/05/24 19:13:37
titato Exp $
RCS-ID: $Id: valuesvc.h,v 1.1 200
6/11/04 21:49:01
titato Exp $
*/
*/
polygon/kbool/include/kboolmod.h
deleted
100644 → 0
View file @
5d5698d6
#ifndef __A2D_KBOOLMOD_H__
#define __A2D_KBOOLMOD_H__
#include "../include/booleng.h"
#include "../include/graph.h"
#include "../include/graphlst.h"
#include "../include/line.h"
#include "../include/link.h"
#include "../include/lpoint.h"
#include "../include/node.h"
#include "../include/record.h"
#include "../include/scanbeam.h"
#endif
\ No newline at end of file
polygon/kbool/include/line.h
deleted
100644 → 0
View file @
5d5698d6
/*! \file ../include/../line.h
\brief Mainy used for calculating crossings
\author Probably Klaas Holwerda
Copyright: 2001-2004 (C) Probably Klaas Holwerda
Licence: wxWidgets Licence
RCS-ID: $Id: line.h,v 1.2 2005/06/12 00:03:11 kbluck Exp $
*/
#ifndef LINE_H
#define LINE_H
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
#pragma interface
#endif
#include "../include/booleng.h"
#include "../include/link.h"
class
A2DKBOOLDLLEXP
Bool_Engine
;
// Status of a point to a line
enum
PointStatus
{
LEFT_SIDE
,
RIGHT_SIDE
,
ON_AREA
,
IN_AREA
};
class
A2DKBOOLDLLEXP
Graph
;
class
A2DKBOOLDLLEXP
KBoolLine
{
protected
:
Bool_Engine
*
m_GC
;
public
:
// constructors and destructor
KBoolLine
(
Bool_Engine
*
GC
);
KBoolLine
(
KBoolLink
*
,
Bool_Engine
*
GC
);
~
KBoolLine
();
void
Set
(
KBoolLink
*
);
KBoolLink
*
GetLink
();
//! Get the beginnode from a line
Node
*
GetBeginNode
();
//! Get the endnode from a line
Node
*
GetEndNode
();
//! Check if two lines intersects
int
CheckIntersect
(
KBoolLine
*
,
double
Marge
);
//! Intersects two lines
int
Intersect
(
KBoolLine
*
,
double
Marge
);
int
Intersect_simple
(
KBoolLine
*
lijn
);
bool
Intersect2
(
Node
*
crossing
,
KBoolLine
*
lijn
);
//!For an infinite line
PointStatus
PointOnLine
(
Node
*
a_node
,
double
&
Distance
,
double
Marge
);
//!For a non-infinite line
PointStatus
PointInLine
(
Node
*
a_node
,
double
&
Distance
,
double
Marge
);
//! Caclulate Y if X is known
B_INT
Calculate_Y
(
B_INT
X
);
B_INT
Calculate_Y_from_X
(
B_INT
X
);
void
Virtual_Point
(
LPoint
*
a_point
,
double
distance
);
//! assignment operator
KBoolLine
&
operator
=
(
const
KBoolLine
&
);
Node
*
OffsetContour
(
KBoolLine
*
const
nextline
,
Node
*
last_ins
,
double
factor
,
Graph
*
shape
);
Node
*
OffsetContour_rounded
(
KBoolLine
*
const
nextline
,
Node
*
_last_ins
,
double
factor
,
Graph
*
shape
);
bool
OkeForContour
(
KBoolLine
*
const
nextline
,
double
factor
,
Node
*
LastLeft
,
Node
*
LastRight
,
LinkStatus
&
_outproduct
);
bool
Create_Ring_Shape
(
KBoolLine
*
nextline
,
Node
**
_last_ins_left
,
Node
**
_last_ins_right
,
double
factor
,
Graph
*
shape
);
void
Create_Begin_Shape
(
KBoolLine
*
nextline
,
Node
**
_last_ins_left
,
Node
**
_last_ins_right
,
double
factor
,
Graph
*
shape
);
void
Create_End_Shape
(
KBoolLine
*
nextline
,
Node
*
_last_ins_left
,
Node
*
_last_ins_right
,
double
factor
,
Graph
*
shape
);
//! Calculate the parameters if nessecary
void
CalculateLineParameters
();
//! Adds a crossing between the intersecting lines
void
AddLineCrossing
(
B_INT
,
B_INT
,
KBoolLine
*
);
void
AddCrossing
(
Node
*
a_node
);
Node
*
AddCrossing
(
B_INT
X
,
B_INT
Y
);
bool
ProcessCrossings
(
TDLI
<
KBoolLink
>*
_LI
);
// Linecrosslist
void
SortLineCrossings
();
bool
CrossListEmpty
();
DL_List
<
void
*>*
GetCrossList
();
// bool HasInCrossList(Node*);
private
:
//! Function needed for Intersect
int
ActionOnTable1
(
PointStatus
,
PointStatus
);
//! Function needed for Intersect
int
ActionOnTable2
(
PointStatus
,
PointStatus
);
double
m_AA
;
double
m_BB
;
double
m_CC
;
KBoolLink
*
m_link
;
bool
m_valid_parameters
;
//! List with crossings through this link
DL_List
<
void
*>
*
linecrosslist
;
};
#endif
polygon/kbool/include/link.h
deleted
100644 → 0
View file @
5d5698d6
/*! \file kbool/include/kbool/link.h
\brief Part of a graph, connection between nodes (Header)
\author Probably Klaas Holwerda or Julian Smart
Copyright: 2001-2004 (C) Probably Klaas Holwerda
Licence: wxWidgets Licence
RCS-ID: $Id: link.h,v 1.1 2005/05/24 19:13:37 titato Exp $
*/
#ifndef LINK_H
#define LINK_H
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
#pragma interface
#endif
#include "../include/booleng.h"
#include "../include/_lnk_itr.h"
enum
LinkStatus
{
IS_LEFT
,
IS_ON
,
IS_RIGHT
};
class
LPoint
;
class
Node
;
class
Record
;
//! segment within a graph
/*
A Graph contains a list of KBoolLink, the KBoolLink or connected by Node's.
Several KBoolLink can be connected to one Node.
A KBoolLink has a direction defined by its begin and end node.
Node do have a list of connected KBoolLink's.
So one can walk trough a graph in two ways:
1- via its KBoolLink list
2- via the node connected to the KBoolLink's
*/
class
A2DKBOOLDLLEXP
KBoolLink
{
protected
:
Bool_Engine
*
_GC
;
public
:
//! contructors
KBoolLink
(
Bool_Engine
*
GC
);
//! contructors
KBoolLink
(
int
graphnr
,
Node
*
begin
,
Node
*
end
,
Bool_Engine
*
GC
);
//! contructors
KBoolLink
(
Node
*
begin
,
Node
*
end
,
Bool_Engine
*
GC
);
//! destructors
~
KBoolLink
();
//! Merges the other node with argument
void
MergeNodes
(
Node
*
const
);
//! outproduct of two links
LinkStatus
OutProduct
(
KBoolLink
*
const
two
,
double
accur
);
//! link three compared to this and two
LinkStatus
PointOnCorner
(
KBoolLink
*
const
,
KBoolLink
*
const
);
//! Removes argument from the link
void
Remove
(
Node
*
);
//! replaces olddone in the link by newnode
void
Replace
(
Node
*
oldnode
,
Node
*
newnode
);
//!top hole marking
void
SetTopHole
(
bool
value
);
//!top hole marking
bool
IsTopHole
();
//! Marking functions
void
UnMark
();
//! Marking functions
void
Mark
();
//! Marking functions
void
SetMark
(
bool
);
//! Marking functions
bool
IsMarked
();
//! holelink Marking functions
void
SetHoleLink
(
bool
val
){
m_holelink
=
val
;};
//! holelink Marking functions
bool
GetHoleLink
(){
return
m_holelink
;};
//! Bin functions
void
SetNotBeenHere
();
//! Bin functions
void
SetBeenHere
();
//! Have you been here ??
bool
BeenHere
();
//! Removes all the references to this
void
UnLink
();
//! functions for maximum performance
Node
*
GetBeginNode
();
//! Datamember access functions
Node
*
GetEndNode
();
Node
*
GetLowNode
();
Node
*
GetHighNode
();
//! Returns a next link beginning with argument
KBoolLink
*
Forth
(
Node
*
);
int
GetGraphNum
();
bool
GetInc
();
bool
GetLeftA
();
bool
GetLeftB
();
bool
GetRightA
();
bool
GetRightB
();
void
GetLRO
(
LPoint
*
,
int
&
,
int
&
,
double
);
//! Return a node not equal to arg.
Node
*
GetOther
(
const
Node
*
const
);
//! Is this link unused ?
bool
IsUnused
();
//! Used for given operation ?
bool
IsMarked
(
BOOL_OP
operation
);
//! return true if Left side is marked true for operation
bool
IsMarkedLeft
(
BOOL_OP
operation
);
//! return true if Right side is marked true for operation
bool
IsMarkedRight
(
BOOL_OP
operation
);
//! is this a hole link for given operation
bool
IsHole
(
BOOL_OP
operation
);
//! set the hole mark
void
SetHole
(
bool
);
//! is the hole mark set?
bool
GetHole
();
//! Are the nodes on about the same coordinates ?
bool
IsZero
(
B_INT
marge
);
bool
ShorterThan
(
B_INT
marge
);
//! Resets the link
void
Reset
(
Node
*
begin
,
Node
*
end
,
int
graphnr
=
0
);
void
Set
(
Node
*
begin
,
Node
*
end
);
void
SetBeginNode
(
Node
*
);
void
SetEndNode
(
Node
*
);
void
SetGraphNum
(
int
);
void
SetInc
(
bool
);
void
SetLeftA
(
bool
);
void
SetLeftB
(
bool
);
void
SetRightA
(
bool
);
void
SetRightB
(
bool
);
void
SetGroup
(
GroupType
);
GroupType
Group
();
//! Flag calculation (internal only)
void
SetLineTypes
();
void
Reset
();
void
Reset_flags
();
//!put in this direction
void
Redirect
(
Node
*
a_node
);
void
TakeOverOperationFlags
(
KBoolLink
*
link
);
void
SetRecordNode
(
DL_Node
<
Record
*>*
recordNode
)
{
m_record
=
recordNode
;
}
DL_Node
<
Record
*>*
GetRecordNode
()
{
return
m_record
;
}
protected
:
//! The mainitems of a link
Node
*
m_beginnode
,
*
m_endnode
;
//! Marker for walking over the graph
bool
m_bin
:
1
;
//! Is this a part of hole ?
bool
m_hole
:
1
;
//! link that is toplink of hole?
bool
m_hole_top
:
1
;
//! going in one more time in this graph if true else going out one time
bool
m_Inc
:
1
;
//! Is left in polygongroup A
bool
m_LeftA
:
1
;
//! Is right in polygon group A
bool
m_RightA
:
1
;
//! Is left in polygon group B
bool
m_LeftB
:
1
;
//! Is right in polygongroup B
bool
m_RightB
:
1
;
//! General purose marker, internally unused
bool
m_mark
:
1
;
//! link for linking holes
bool
m_holelink
:
1
;
//! Marker for Merge Left
bool
m_merge_L
:
1
;
//! Marker for substract a-b Left
bool
m_a_substract_b_L
:
1
;
//! Marker for substract b-a Left
bool
m_b_substract_a_L
:
1
;
//! Marker for intersect Left
bool
m_intersect_L
:
1
;
//! Marker for X-OR Left
bool
m_exor_L
:
1
;
//! Marker for Merge Right
bool
m_merge_R
:
1
;
//! Marker for substract a-b Right
bool
m_a_substract_b_R
:
1
;
//! Marker for substract b-a Right
bool
m_b_substract_a_R
:
1
;
//! Marker for intersect Right
bool
m_intersect_R
:
1
;
//! Marker for X-OR Right
bool
m_exor_R
:
1
;
//! belongs to group A or B
GroupType
m_group
:
1
;
//! belongs to this polygon part in the graph.
int
m_graphnum
;
DL_Node
<
Record
*>*
m_record
;
};
#endif
polygon/kbool/include/lpoint.h
deleted
100644 → 0
View file @
5d5698d6
/*! \file ../include/../lpoint.h
\author Probably Klaas Holwerda
Copyright: 2001-2004 (C) Probably Klaas Holwerda
Licence: wxWidgets Licence
RCS-ID: $Id: lpoint.h,v 1.1 2005/05/24 19:13:37 titato Exp $
*/
/* @@(#) $Source: /cvsroot/wxart2d/wxArt2D/modules/../include/lpoint.h,v $ $Revision: 1.1 $ $Date: 2005/05/24 19:13:37 $ */
/*
Program LPOINT.H
Purpose Definition of GDSII pointtype structure
Last Update 12-12-1995
*/
#ifndef LPOINT_H
#define LPOINT_H
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
#pragma interface
#endif
#include "../include/booleng.h"
class
A2DKBOOLDLLEXP
LPoint
{
public
:
LPoint
();
LPoint
(
B_INT
const
,
B_INT
const
);
LPoint
(
LPoint
*
const
);
void
Set
(
const
B_INT
,
const
B_INT
);
void
Set
(
const
LPoint
&
);
LPoint
GetPoint
();
B_INT
GetX
();
B_INT
GetY
();
void
SetX
(
B_INT
);
void
SetY
(
B_INT
);
bool
Equal
(
const
LPoint
a_point
,
B_INT
Marge
);
bool
Equal
(
const
B_INT
,
const
B_INT
,
B_INT
Marge
);
bool
ShorterThan
(
const
LPoint
a_point
,
B_INT
marge
);
bool
ShorterThan
(
const
B_INT
X
,
const
B_INT
Y
,
B_INT
);
LPoint
&
operator
=
(
const
LPoint
&
);
LPoint
&
operator
+
(
const
LPoint
&
);
LPoint
&
operator
-
(
const
LPoint
&
);
LPoint
&
operator
*
(
int
);
LPoint
&
operator
/
(
int
);
int
operator
==
(
const
LPoint
&
)
const
;
int
operator
!=
(
const
LPoint
&
)
const
;
protected
:
B_INT
_x
;
B_INT
_y
;
};
#endif
polygon/kbool/include/node.h
deleted
100644 → 0
View file @
5d5698d6
/*! \file ../include/../node.h
\brief Holds a GDSII node structure (Header)
\author Probably Klaas Holwerda
Copyright: 2001-2004 (C) Probably Klaas Holwerda
Licence: wxWidgets Licence
RCS-ID: $Id: node.h,v 1.1 2005/05/24 19:13:37 titato Exp $
*/
#ifndef NODE_H
#define NODE_H
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
#pragma interface
#endif
#include <math.h>
#include "../include/booleng.h"
#include "../include/lpoint.h"
#include "../include/link.h"
#include "../include/_lnk_itr.h" // LinkBaseIter
enum
NodePosition
{
N_LEFT
,
N_ON
,
N_RIGHT
};
class
A2DKBOOLDLLEXP
Node
:
public
LPoint
{
protected
:
Bool_Engine
*
_GC
;
public
:
// friend must be deleted in the final version!
friend
class
Debug_driver
;
// constructors and destructors
Node
(
Bool_Engine
*
GC
);
Node
(
const
B_INT
,
const
B_INT
,
Bool_Engine
*
GC
);
Node
(
LPoint
*
const
a_point
,
Bool_Engine
*
GC
);
Node
(
Node
*
const
,
Bool_Engine
*
GC
);
Node
&
operator
=
(
const
Node
&
other_node
);
~
Node
();
//public member functions
void
AddLink
(
KBoolLink
*
);
DL_List
<
void
*>*
GetLinklist
();
//! check two link for its operation flags to be the same when coming from the prev link.
bool
SameSides
(
KBoolLink
*
const
prev
,
KBoolLink
*
const
link
,
BOOL_OP
operation
);
//! get the link most right or left to the current link, but with the specific operation
/*! flags the same on the sides of the new link.
*/
KBoolLink
*
GetMost
(
KBoolLink
*
const
prev
,
LinkStatus
whatside
,
BOOL_OP
operation
);
//! get link that is leading to a hole ( hole segment or linking segment )
KBoolLink
*
GetMostHole
(
KBoolLink
*
const
prev
,
LinkStatus
whatside
,
BOOL_OP
operation
);
//! get link that is not vertical.
KBoolLink
*
GetNotFlat
();
//! get a link to a hole or from a hole.
KBoolLink
*
GetHoleLink
(
KBoolLink
*
const
prev
,
bool
checkbin
,
BOOL_OP
operation
);
int
Merge
(
Node
*
);
void
RemoveLink
(
KBoolLink
*
);
bool
Simplify
(
Node
*
First
,
Node
*
Second
,
B_INT
Marge
);
// memberfunctions for maximum performance
void
RoundInt
(
B_INT
grid
);
KBoolLink
*
GetIncomingLink
();
int
GetNumberOfLinks
();
KBoolLink
*
GetNextLink
();
KBoolLink
*
GetOtherLink
(
KBoolLink
*
);
KBoolLink
*
GetOutgoingLink
();
KBoolLink
*
GetPrevLink
();
KBoolLink
*
Follow
(
KBoolLink
*
const
prev
);
KBoolLink
*
GetBinHighest
(
bool
binset
);
protected
:
DL_List
<
void
*>*
_linklist
;
};
#endif
polygon/kbool/include/record.h
deleted
100644 → 0
View file @
5d5698d6
/*! \file ../include/../record.h
\author Probably Klaas Holwerda
Copyright: 2001-2004 (C) Probably Klaas Holwerda
Licence: wxWidgets Licence
RCS-ID: $Id: record.h,v 1.1 2005/05/24 19:13:37 titato Exp $
*/
#ifndef RECORD_H
#define RECORD_H
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
#pragma interface
#endif
class
Node
;
#include "../include/booleng.h"
#include "../include/link.h"
#include "../include/line.h"
enum
BEAM_TYPE
{
NORMAL
,
FLAT
};
enum
DIRECTION
{
GO_LEFT
,
GO_RIGHT
};
//extern void DeleteRecordPool();
class
A2DKBOOLDLLEXP
Bool_Engine
;
class
A2DKBOOLDLLEXP
Record
{
protected
:
Bool_Engine
*
_GC
;
public
:
// void deletepool();
Record
(
KBoolLink
*
link
,
Bool_Engine
*
GC
);
~
Record
();
// void* operator new(size_t size);
// void operator delete(void* recordptr);
void
SetNewLink
(
KBoolLink
*
link
);
void
Set_Flags
();
void
Calc_Ysp
(
Node
*
low
);
KBoolLink
*
GetLink
();
KBoolLine
*
GetLine
();
B_INT
Ysp
();
void
SetYsp
(
B_INT
ysp
);
DIRECTION
Direction
();
bool
Calc_Left_Right
(
Record
*
record_above_me
);
bool
Equal
(
Record
*
);
private
:
KBoolLine
_line
;
B_INT
_ysp
;
//! going left are right in beam
DIRECTION
_dir
;
//! how far in group_a
int
_a
;
//! how far in group_b
int
_b
;
};
#endif
polygon/kbool/include/scanbeam.h
deleted
100644 → 0
View file @
5d5698d6
/*! \file ../include/../scanbeam.h
\author Probably Klaas Holwerda
Copyright: 2001-2004 (C) Probably Klaas Holwerda
Licence: wxWidgets Licence
RCS-ID: $Id: scanbeam.h,v 1.2 2005/06/11 19:25:12 frm Exp $
*/
#ifndef SCANBEAM_H
#define SCANBEAM_H
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
#pragma interface
#endif
#include "../include/booleng.h"
#include "../include/_lnk_itr.h"
#include "../include/record.h"
#include "../include/link.h"
enum
SCANTYPE
{
NODELINK
,
LINKLINK
,
GENLR
,
LINKHOLES
,
INOUT
};
#if 0 // Kicad does dot use wxWidgets lib when building the kbool library
// but uses wxWidgets. So WXUSINGDLL could be defined in makefiles
// but must not be used when building kbool
#if defined(WXUSINGDLL)
template class A2DKBOOLDLLEXP DL_Iter<Record*>;
#endif
#endif
class
A2DKBOOLDLLEXP
ScanBeam
:
public
DL_List
<
Record
*>
{
protected
:
Bool_Engine
*
_GC
;
public
:
ScanBeam
(
Bool_Engine
*
GC
);
~
ScanBeam
();
void
SetType
(
Node
*
low
,
Node
*
high
);
bool
FindNew
(
SCANTYPE
scantype
,
TDLI
<
KBoolLink
>*
_I
,
bool
&
holes
);
bool
RemoveOld
(
SCANTYPE
scantype
,
TDLI
<
KBoolLink
>*
_I
,
bool
&
holes
);
private
:
bool
ProcessHoles
(
bool
atinsert
,
TDLI
<
KBoolLink
>*
_LI
);
int
Process_LinkToLink_Crossings
();
// find crossings
int
Process_PointToLink_Crossings
();
int
Process_LinkToLink_Flat
(
KBoolLine
*
flatline
);
void
SortTheBeam
(
bool
backangle
);
bool
checksort
();
bool
writebeam
();
void
Calc_Ysp
();
//int FindCloseLinksAndCross(TDLI<KBoolLink>* _I,Node* _lowf);
void
Generate_INOUT
(
int
graphnumber
);
Node
*
_low
;
DL_Iter
<
Record
*>
_BI
;
int
lastinserted
;
BEAM_TYPE
_type
;
};
#endif
polygon/kbool/infos_
and_license
.txt
→
polygon/kbool/infos_
kbool
.txt
View file @
521f428c
...
@@ -2,9 +2,6 @@ Boolean: GDSII viewer/editor + (boolean) operations on sets of 2d polygons.
...
@@ -2,9 +2,6 @@ Boolean: GDSII viewer/editor + (boolean) operations on sets of 2d polygons.
Boolean Web Site:
Boolean Web Site:
http://boolean.klaasholwerda.nl/bool.html
http://boolean.klaasholwerda.nl/bool.html
Copyright section form the site:
kbool is also used in wxArt2D
The code is written by Klaas Holwerda, it is free to use for non commercial open source projects licensed as GPL.
see www.wxart2d.org
the last version of kbool can be found on this site.
Note:
License info in kbool files:
files are under wxWidget license
polygon/kbool/kboollicense.txt
0 → 100644
View file @
521f428c
The kbool library is dual licensed.
The GPL applies for open source, but for commercial use it is proprietary.
Contact copyright holder for more information on other licensing schemes.
Software library is provided "AS IS" without warranty of any kind, conform point 16 and 17 down here.
Next a copy of the GPL license text.
==========================================================================
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
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 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<http://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
\ No newline at end of file
polygon/kbool/src/CMakeLists.txt
View file @
521f428c
if
(
WIN32
)
IF
(
WIN32
)
add_definitions
(
-D_MSWVC_
)
ADD_DEFINITIONS
(
-D_MSWVC_
)
else
(
WIN32
)
ELSE
(
WIN32
)
add_definitions
(
-D__UNIX__
)
ADD_DEFINITIONS
(
-D__UNIX__
)
endif
(
WIN32
)
ENDIF
(
WIN32
)
include_directories
(
${
kbool_SOURCE_DIR
}
/include
)
include_directories
(
../include
)
set
(
KBOOL_SRCS
set
(
KBOOL_SRCS
booleng.cpp
booleng.cpp
...
...
polygon/kbool/src/booleng.cpp
View file @
521f428c
/*! \file
kbool/
src/booleng.cpp
/*! \file src/booleng.cpp
\author
Probably
Klaas Holwerda
\author Klaas Holwerda
Copyright: 2001-2004 (C)
Probably
Klaas Holwerda
Copyright: 2001-2004 (C) Klaas Holwerda
Licence:
wxWidgets Licence
Licence:
see kboollicense.txt
RCS-ID: $Id: booleng.cpp,v 1.
11 2005/05/24 19:13:38
titato Exp $
RCS-ID: $Id: booleng.cpp,v 1.
3 2008/06/04 21:23:22
titato Exp $
*/
*/
#ifdef __GNUG__
#include "kbool/booleng.h"
#pragma implementation
#endif
#include <math.h>
#include <time.h>
#include <time.h>
#include "../include/booleng.h"
#include "kbool/link.h"
#include "../include/link.h"
#include "kbool/line.h"
#include "../include/line.h"
#include "kbool/node.h"
#include "../include/node.h"
#include "kbool/graph.h"
#include "../include/graph.h"
#include "kbool/graphlst.h"
#include "../include/graphlst.h"
B_INT
bmin
(
B_INT
const
value1
,
B_INT
const
value2
)
B_INT
bmin
(
B_INT
const
value1
,
B_INT
const
value2
)
{
{
return
((
value1
<
value2
)
?
value1
:
value2
);
return
(
(
value1
<
value2
)
?
value1
:
value2
);
}
}
B_INT
bmax
(
B_INT
const
value1
,
B_INT
const
value2
)
B_INT
bmax
(
B_INT
const
value1
,
B_INT
const
value2
)
{
{
return
((
value1
>
value2
)
?
value1
:
value2
);
return
(
(
value1
>
value2
)
?
value1
:
value2
);
}
}
B_INT
babs
(
B_INT
a
)
B_INT
babs
(
B_INT
a
)
{
{
if
(
a
<
0
)
a
=
-
a
;
if
(
a
<
0
)
a
=
-
a
;
return
a
;
return
a
;
}
}
...
@@ -42,38 +38,38 @@ B_INT babs(B_INT a)
...
@@ -42,38 +38,38 @@ B_INT babs(B_INT a)
//----------------- Bool_Engine_Error -------------------------------/
//----------------- Bool_Engine_Error -------------------------------/
//-------------------------------------------------------------------/
//-------------------------------------------------------------------/
Bool_Engine_Error
::
Bool_Engine_Error
(
const
char
*
message
,
const
char
*
header
,
int
degree
,
int
fatal
)
Bool_Engine_Error
::
Bool_Engine_Error
(
const
char
*
message
,
const
char
*
header
,
int
degree
,
int
fatal
)
{
{
_message
=
new
char
[
LINELENGTH
];
_message
=
new
char
[
LINELENGTH
];
_header
=
new
char
[
LINELENGTH
];
_header
=
new
char
[
LINELENGTH
];
if
(
message
)
if
(
message
)
strcpy
(
_message
,
message
);
strcpy
(
_message
,
message
);
else
else
strcpy
(
_message
,
"non specified"
);
strcpy
(
_message
,
"non specified"
);
if
(
header
)
if
(
header
)
strcpy
(
_header
,
header
);
strcpy
(
_header
,
header
);
else
else
strcpy
(
_header
,
"non specified"
);
strcpy
(
_header
,
"non specified"
);
_degree
=
degree
;
_degree
=
degree
;
_fatal
=
fatal
;
_fatal
=
fatal
;
}
}
Bool_Engine_Error
::
Bool_Engine_Error
(
const
Bool_Engine_Error
&
a
)
Bool_Engine_Error
::
Bool_Engine_Error
(
const
Bool_Engine_Error
&
a
)
{
{
_message
=
new
char
[
LINELENGTH
];
_message
=
new
char
[
LINELENGTH
];
_header
=
new
char
[
LINELENGTH
];
_header
=
new
char
[
LINELENGTH
];
if
(
a
.
_message
)
if
(
a
.
_message
)
strcpy
(
_message
,
a
.
_message
);
strcpy
(
_message
,
a
.
_message
);
else
else
strcpy
(
_message
,
"non specified"
);
strcpy
(
_message
,
"non specified"
);
if
(
a
.
_header
)
if
(
a
.
_header
)
strcpy
(
_header
,
a
.
_header
);
strcpy
(
_header
,
a
.
_header
);
else
else
strcpy
(
_header
,
"non specified"
);
strcpy
(
_header
,
"non specified"
);
_degree
=
a
.
_degree
;
_degree
=
a
.
_degree
;
_fatal
=
a
.
_fatal
;
_fatal
=
a
.
_fatal
;
...
@@ -82,8 +78,8 @@ Bool_Engine_Error::Bool_Engine_Error(const Bool_Engine_Error& a)
...
@@ -82,8 +78,8 @@ Bool_Engine_Error::Bool_Engine_Error(const Bool_Engine_Error& a)
Bool_Engine_Error
::~
Bool_Engine_Error
()
Bool_Engine_Error
::~
Bool_Engine_Error
()
{
{
strcpy
(
_message
,
""
);
strcpy
(
_message
,
""
);
strcpy
(
_header
,
""
);
strcpy
(
_header
,
""
);
delete
_message
;
delete
_message
;
delete
_header
;
delete
_header
;
}
}
...
@@ -114,13 +110,13 @@ int Bool_Engine_Error::GetFatal()
...
@@ -114,13 +110,13 @@ int Bool_Engine_Error::GetFatal()
Bool_Engine
::
Bool_Engine
()
Bool_Engine
::
Bool_Engine
()
{
{
_linkiter
=
new
TDLI
<
KBoolLink
>
();
_linkiter
=
new
TDLI
<
KBoolLink
>
();
m_intersectionruns
=
1
;
m_intersectionruns
=
1
;
m_orientationEntryMode
=
false
;
m_orientationEntryMode
=
false
;
m_doLinkHoles
=
true
;
m_doLinkHoles
=
true
;
m_graphlist
=
new
GraphList
(
this
);
m_graphlist
=
new
GraphList
(
this
);
m_ACCUR
=
1e-4
;
m_ACCUR
=
1e-4
;
m_WINDINGRULE
=
true
;
m_WINDINGRULE
=
true
;
m_GraphToAdd
=
NULL
;
m_GraphToAdd
=
NULL
;
...
@@ -138,8 +134,8 @@ Bool_Engine::Bool_Engine()
...
@@ -138,8 +134,8 @@ Bool_Engine::Bool_Engine()
Bool_Engine
::~
Bool_Engine
()
Bool_Engine
::~
Bool_Engine
()
{
{
if
(
m_logfile
!=
NULL
)
if
(
m_logfile
!=
NULL
)
fclose
(
m_logfile
);
fclose
(
m_logfile
);
delete
_linkiter
;
delete
_linkiter
;
delete
m_graphlist
;
delete
m_graphlist
;
...
@@ -153,25 +149,25 @@ void Bool_Engine::SetLog( bool OnOff )
...
@@ -153,25 +149,25 @@ void Bool_Engine::SetLog( bool OnOff )
if
(
m_logfile
==
NULL
)
if
(
m_logfile
==
NULL
)
{
{
// create a new logfile
// create a new logfile
m_logfile
=
fopen
(
KBOOL_LOGFILE
,
"w"
);
m_logfile
=
fopen
(
KBOOL_LOGFILE
,
"w"
);
if
(
m_logfile
==
NULL
)
if
(
m_logfile
==
NULL
)
fprintf
(
stderr
,
"Bool_Engine: Unable to write to Boolean Engine logfile
\n
"
);
fprintf
(
stderr
,
"Bool_Engine: Unable to write to Boolean Engine logfile
\n
"
);
else
else
{
{
time_t
timer
;
time_t
timer
;
struct
tm
*
today
;
struct
tm
*
today
;
timer
=
time
(
NULL
);
timer
=
time
(
NULL
);
today
=
localtime
(
&
timer
);
today
=
localtime
(
&
timer
);
fprintf
(
m_logfile
,
"Logfile created on:
\t\t\t
%s"
,
ctime
(
&
timer
)
);
fprintf
(
m_logfile
,
"Logfile created on:
\t\t\t
%s"
,
ctime
(
&
timer
)
);
}
}
}
}
}
}
else
else
{
{
if
(
m_logfile
!=
NULL
)
if
(
m_logfile
!=
NULL
)
{
{
fclose
(
m_logfile
);
fclose
(
m_logfile
);
m_logfile
=
NULL
;
m_logfile
=
NULL
;
}
}
}
}
...
@@ -179,26 +175,26 @@ void Bool_Engine::SetLog( bool OnOff )
...
@@ -179,26 +175,26 @@ void Bool_Engine::SetLog( bool OnOff )
void
Bool_Engine
::
SetState
(
const
char
*
process
)
void
Bool_Engine
::
SetState
(
const
char
*
process
)
{
{
Write_Log
(
process
);
Write_Log
(
process
);
}
}
void
Bool_Engine
::
error
(
const
char
*
text
,
const
char
*
title
)
void
Bool_Engine
::
error
(
const
char
*
text
,
const
char
*
title
)
{
{
Write_Log
(
"FATAL ERROR: "
,
title
);
Write_Log
(
"FATAL ERROR: "
,
title
);
Write_Log
(
"FATAL ERROR: "
,
text
);
Write_Log
(
"FATAL ERROR: "
,
text
);
throw
Bool_Engine_Error
(
" Fatal Error"
,
"Fatal Error"
,
9
,
1
);
throw
Bool_Engine_Error
(
" Fatal Error"
,
"Fatal Error"
,
9
,
1
);
};
};
void
Bool_Engine
::
info
(
const
char
*
text
,
const
char
*
title
)
void
Bool_Engine
::
info
(
const
char
*
text
,
const
char
*
title
)
{
{
Write_Log
(
"FATAL ERROR: "
,
title
);
Write_Log
(
"FATAL ERROR: "
,
title
);
Write_Log
(
"FATAL ERROR: "
,
text
);
Write_Log
(
"FATAL ERROR: "
,
text
);
};
};
void
Bool_Engine
::
SetMarge
(
double
marge
)
void
Bool_Engine
::
SetMarge
(
double
marge
)
{
{
m_MARGE
=
marge
;
m_MARGE
=
marge
;
Write_Log
(
"Bool_Engine::m_MARGE = %f
\n
"
,
m_MARGE
);
Write_Log
(
"Bool_Engine::m_MARGE = %f
\n
"
,
m_MARGE
);
}
}
double
Bool_Engine
::
GetAccur
()
double
Bool_Engine
::
GetAccur
()
...
@@ -206,10 +202,10 @@ double Bool_Engine::GetAccur()
...
@@ -206,10 +202,10 @@ double Bool_Engine::GetAccur()
return
m_ACCUR
;
return
m_ACCUR
;
}
}
void
Bool_Engine
::
SetRoundfactor
(
double
roundfac
)
void
Bool_Engine
::
SetRoundfactor
(
double
roundfac
)
{
{
m_ROUNDFACTOR
=
roundfac
;
m_ROUNDFACTOR
=
roundfac
;
Write_Log
(
"Bool_Engine::m_ROUNDFACTOR = %f
\n
"
,
m_ROUNDFACTOR
);
Write_Log
(
"Bool_Engine::m_ROUNDFACTOR = %f
\n
"
,
m_ROUNDFACTOR
);
}
}
double
Bool_Engine
::
GetRoundfactor
()
double
Bool_Engine
::
GetRoundfactor
()
...
@@ -222,10 +218,10 @@ double Bool_Engine::GetMarge()
...
@@ -222,10 +218,10 @@ double Bool_Engine::GetMarge()
return
m_MARGE
;
return
m_MARGE
;
}
}
void
Bool_Engine
::
SetDGrid
(
double
dgrid
)
void
Bool_Engine
::
SetDGrid
(
double
dgrid
)
{
{
m_DGRID
=
dgrid
;
m_DGRID
=
dgrid
;
Write_Log
(
"Bool_Engine::m_DGRID = %f
\n
"
,
m_DGRID
);
Write_Log
(
"Bool_Engine::m_DGRID = %f
\n
"
,
m_DGRID
);
}
}
double
Bool_Engine
::
GetDGrid
()
double
Bool_Engine
::
GetDGrid
()
...
@@ -233,10 +229,10 @@ double Bool_Engine::GetDGrid()
...
@@ -233,10 +229,10 @@ double Bool_Engine::GetDGrid()
return
m_DGRID
;
return
m_DGRID
;
}
}
void
Bool_Engine
::
SetGrid
(
B_INT
grid
)
void
Bool_Engine
::
SetGrid
(
B_INT
grid
)
{
{
m_GRID
=
grid
;
m_GRID
=
grid
;
Write_Log
(
"Bool_Engine::m_GRID = %lld
\n
"
,
m_GRID
);
Write_Log
(
"Bool_Engine::m_GRID = %lld
\n
"
,
m_GRID
);
}
}
B_INT
Bool_Engine
::
GetGrid
()
B_INT
Bool_Engine
::
GetGrid
()
...
@@ -244,10 +240,10 @@ B_INT Bool_Engine::GetGrid()
...
@@ -244,10 +240,10 @@ B_INT Bool_Engine::GetGrid()
return
m_GRID
;
return
m_GRID
;
}
}
void
Bool_Engine
::
SetCorrectionAber
(
double
aber
)
void
Bool_Engine
::
SetCorrectionAber
(
double
aber
)
{
{
m_CORRECTIONABER
=
aber
;
m_CORRECTIONABER
=
aber
;
Write_Log
(
"Bool_Engine::m_CORRECTIONABER = %f
\n
"
,
m_CORRECTIONABER
);
Write_Log
(
"Bool_Engine::m_CORRECTIONABER = %f
\n
"
,
m_CORRECTIONABER
);
}
}
double
Bool_Engine
::
GetCorrectionAber
()
double
Bool_Engine
::
GetCorrectionAber
()
...
@@ -255,10 +251,10 @@ double Bool_Engine::GetCorrectionAber()
...
@@ -255,10 +251,10 @@ double Bool_Engine::GetCorrectionAber()
return
m_CORRECTIONABER
;
return
m_CORRECTIONABER
;
}
}
void
Bool_Engine
::
SetCorrectionFactor
(
double
aber
)
void
Bool_Engine
::
SetCorrectionFactor
(
double
aber
)
{
{
m_CORRECTIONFACTOR
=
aber
;
m_CORRECTIONFACTOR
=
aber
;
Write_Log
(
"Bool_Engine::m_CORRECTIONFACTOR = %f
\n
"
,
m_CORRECTIONFACTOR
);
Write_Log
(
"Bool_Engine::m_CORRECTIONFACTOR = %f
\n
"
,
m_CORRECTIONFACTOR
);
}
}
double
Bool_Engine
::
GetCorrectionFactor
()
double
Bool_Engine
::
GetCorrectionFactor
()
...
@@ -266,10 +262,10 @@ double Bool_Engine::GetCorrectionFactor()
...
@@ -266,10 +262,10 @@ double Bool_Engine::GetCorrectionFactor()
return
m_CORRECTIONFACTOR
;
return
m_CORRECTIONFACTOR
;
}
}
void
Bool_Engine
::
SetSmoothAber
(
double
aber
)
void
Bool_Engine
::
SetSmoothAber
(
double
aber
)
{
{
m_SMOOTHABER
=
aber
;
m_SMOOTHABER
=
aber
;
Write_Log
(
"Bool_Engine::m_SMOOTHABER = %f
\n
"
,
m_SMOOTHABER
);
Write_Log
(
"Bool_Engine::m_SMOOTHABER = %f
\n
"
,
m_SMOOTHABER
);
}
}
double
Bool_Engine
::
GetSmoothAber
()
double
Bool_Engine
::
GetSmoothAber
()
...
@@ -277,10 +273,10 @@ double Bool_Engine::GetSmoothAber()
...
@@ -277,10 +273,10 @@ double Bool_Engine::GetSmoothAber()
return
m_SMOOTHABER
;
return
m_SMOOTHABER
;
}
}
void
Bool_Engine
::
SetMaxlinemerge
(
double
maxline
)
void
Bool_Engine
::
SetMaxlinemerge
(
double
maxline
)
{
{
m_MAXLINEMERGE
=
maxline
;
m_MAXLINEMERGE
=
maxline
;
Write_Log
(
"Bool_Engine::m_MAXLINEMERGE = %f
\n
"
,
m_MAXLINEMERGE
);
Write_Log
(
"Bool_Engine::m_MAXLINEMERGE = %f
\n
"
,
m_MAXLINEMERGE
);
}
}
double
Bool_Engine
::
GetMaxlinemerge
()
double
Bool_Engine
::
GetMaxlinemerge
()
...
@@ -288,7 +284,7 @@ double Bool_Engine::GetMaxlinemerge()
...
@@ -288,7 +284,7 @@ double Bool_Engine::GetMaxlinemerge()
return
m_MAXLINEMERGE
;
return
m_MAXLINEMERGE
;
}
}
void
Bool_Engine
::
SetWindingRule
(
bool
rule
)
void
Bool_Engine
::
SetWindingRule
(
bool
rule
)
{
{
m_WINDINGRULE
=
rule
;
m_WINDINGRULE
=
rule
;
}
}
...
@@ -301,104 +297,104 @@ bool Bool_Engine::GetWindingRule()
...
@@ -301,104 +297,104 @@ bool Bool_Engine::GetWindingRule()
void
Bool_Engine
::
SetInternalMarge
(
B_INT
marge
)
void
Bool_Engine
::
SetInternalMarge
(
B_INT
marge
)
{
{
m_MARGE
=
(
double
)
marge
/
m_GRID
/
m_DGRID
;
m_MARGE
=
(
double
)
marge
/
m_GRID
/
m_DGRID
;
}
}
B_INT
Bool_Engine
::
GetInternalMarge
()
B_INT
Bool_Engine
::
GetInternalMarge
()
{
{
return
(
B_INT
)
(
m_MARGE
*
m_GRID
*
m_DGRID
);
return
(
B_INT
)
(
m_MARGE
*
m_GRID
*
m_DGRID
);
}
}
double
Bool_Engine
::
GetInternalCorrectionAber
()
double
Bool_Engine
::
GetInternalCorrectionAber
()
{
{
return
m_CORRECTIONABER
*
m_GRID
*
m_DGRID
;
return
m_CORRECTIONABER
*
m_GRID
*
m_DGRID
;
}
}
double
Bool_Engine
::
GetInternalCorrectionFactor
()
double
Bool_Engine
::
GetInternalCorrectionFactor
()
{
{
return
m_CORRECTIONFACTOR
*
m_GRID
*
m_DGRID
;
return
m_CORRECTIONFACTOR
*
m_GRID
*
m_DGRID
;
}
}
double
Bool_Engine
::
GetInternalSmoothAber
()
double
Bool_Engine
::
GetInternalSmoothAber
()
{
{
return
m_SMOOTHABER
*
m_GRID
*
m_DGRID
;
return
m_SMOOTHABER
*
m_GRID
*
m_DGRID
;
}
}
B_INT
Bool_Engine
::
GetInternalMaxlinemerge
()
B_INT
Bool_Engine
::
GetInternalMaxlinemerge
()
{
{
return
(
B_INT
)
(
m_MAXLINEMERGE
*
m_GRID
*
m_DGRID
);
return
(
B_INT
)
(
m_MAXLINEMERGE
*
m_GRID
*
m_DGRID
);
}
}
#define TRIALS 30
#define TRIALS 30
bool
Bool_Engine
::
Do_Operation
(
BOOL_OP
operation
)
bool
Bool_Engine
::
Do_Operation
(
BOOL_OP
operation
)
{
{
#if KBOOL_DEBUG
#if KBOOL_DEBUG
GraphList
*
saveme
=
new
GraphList
(
m_graphlist
);
GraphList
*
saveme
=
new
GraphList
(
m_graphlist
);
#endif
#endif
try
try
{
{
switch
(
operation
)
switch
(
operation
)
{
{
case
(
BOOL_OR
):
case
(
BOOL_OR
):
case
(
BOOL_AND
):
case
(
BOOL_AND
):
case
(
BOOL_EXOR
):
case
(
BOOL_EXOR
):
case
(
BOOL_A_SUB_B
):
case
(
BOOL_A_SUB_B
):
case
(
BOOL_B_SUB_A
):
case
(
BOOL_B_SUB_A
):
m_graphlist
->
Boolean
(
operation
,
m_intersectionruns
);
m_graphlist
->
Boolean
(
operation
,
m_intersectionruns
);
break
;
break
;
case
(
BOOL_CORRECTION
):
case
(
BOOL_CORRECTION
):
m_graphlist
->
Correction
();
m_graphlist
->
Correction
();
break
;
break
;
case
(
BOOL_MAKERING
):
case
(
BOOL_MAKERING
):
m_graphlist
->
MakeRings
();
m_graphlist
->
MakeRings
();
break
;
break
;
case
(
BOOL_SMOOTHEN
):
case
(
BOOL_SMOOTHEN
):
m_graphlist
->
Smoothen
(
GetInternalSmoothAber
()
);
m_graphlist
->
Smoothen
(
GetInternalSmoothAber
()
);
break
;
break
;
default
:
default
:
{
{
error
(
"Wrong operation"
,
"Command Error"
);
error
(
"Wrong operation"
,
"Command Error"
);
return
false
;
return
false
;
}
}
}
}
}
}
catch
(
Bool_Engine_Error
&
error
)
catch
(
Bool_Engine_Error
&
error
)
{
{
#if KBOOL_DEBUG
#if KBOOL_DEBUG
delete
m_graphlist
;
delete
m_graphlist
;
m_graphlist
=
new
GraphList
(
saveme
);
m_graphlist
=
new
GraphList
(
saveme
);
m_graphlist
->
WriteGraphsKEY
(
this
);
m_graphlist
->
WriteGraphsKEY
(
this
);
#endif
#endif
if
(
m_logfile
!=
NULL
)
if
(
m_logfile
!=
NULL
)
{
{
fclose
(
m_logfile
);
fclose
(
m_logfile
);
m_logfile
=
NULL
;
m_logfile
=
NULL
;
}
}
info
(
error
.
GetErrorMessage
(),
"error"
);
info
(
error
.
GetErrorMessage
(),
"error"
);
throw
error
;
throw
error
;
}
}
catch
(...
)
catch
(
...
)
{
{
#if KBOOL_DEBUG
#if KBOOL_DEBUG
delete
m_graphlist
;
delete
m_graphlist
;
m_graphlist
=
new
GraphList
(
saveme
);
m_graphlist
=
new
GraphList
(
saveme
);
m_graphlist
->
WriteGraphsKEY
(
this
);
m_graphlist
->
WriteGraphsKEY
(
this
);
#endif
#endif
if
(
m_logfile
!=
NULL
)
if
(
m_logfile
!=
NULL
)
{
{
fclose
(
m_logfile
);
fclose
(
m_logfile
);
m_logfile
=
NULL
;
m_logfile
=
NULL
;
}
}
info
(
"Unknown exception"
,
"error"
);
info
(
"Unknown exception"
,
"error"
);
throw
;
throw
;
}
}
...
@@ -409,68 +405,68 @@ bool Bool_Engine::Do_Operation(BOOL_OP operation)
...
@@ -409,68 +405,68 @@ bool Bool_Engine::Do_Operation(BOOL_OP operation)
return
true
;
return
true
;
}
}
bool
Bool_Engine
::
StartPolygonAdd
(
GroupType
A_or_B
)
bool
Bool_Engine
::
StartPolygonAdd
(
GroupType
A_or_B
)
{
{
#if KBOOL_DEBUG
#if KBOOL_DEBUG
if
(
m_logfile
!=
NULL
)
if
(
m_logfile
!=
NULL
)
fprintf
(
m_logfile
,
"-> StartPolygonAdd(%d)
\n
"
,
A_or_B
);
fprintf
(
m_logfile
,
"-> StartPolygonAdd(%d)
\n
"
,
A_or_B
);
#endif
#endif
if
(
m_GraphToAdd
!=
NULL
)
if
(
m_GraphToAdd
!=
NULL
)
return
false
;
return
false
;
Graph
*
myGraph
=
new
Graph
(
this
);
Graph
*
myGraph
=
new
Graph
(
this
);
m_graphlist
->
insbegin
(
myGraph
);
m_graphlist
->
insbegin
(
myGraph
);
m_GraphToAdd
=
myGraph
;
m_GraphToAdd
=
myGraph
;
m_groupType
=
A_or_B
;
m_groupType
=
A_or_B
;
return
true
;
return
true
;
}
}
bool
Bool_Engine
::
AddPoint
(
double
x
,
double
y
)
bool
Bool_Engine
::
AddPoint
(
double
x
,
double
y
)
{
{
if
(
m_GraphToAdd
==
NULL
){
return
false
;}
if
(
m_GraphToAdd
==
NULL
){
return
false
;}
double
scaledx
=
x
*
m_DGRID
*
m_GRID
;
double
scaledx
=
x
*
m_DGRID
*
m_GRID
;
double
scaledy
=
y
*
m_DGRID
*
m_GRID
;
double
scaledy
=
y
*
m_DGRID
*
m_GRID
;
if
(
scaledx
>
MAXB_INT
||
scaledx
<
MINB_INT
)
if
(
scaledx
>
MAXB_INT
||
scaledx
<
MINB_INT
)
error
(
"X coordinate of vertex to big"
,
""
);
error
(
"X coordinate of vertex to big"
,
""
);
if
(
scaledy
>
MAXB_INT
||
scaledy
<
MINB_INT
)
if
(
scaledy
>
MAXB_INT
||
scaledy
<
MINB_INT
)
error
(
"Y coordinate of vertex to big"
,
""
);
error
(
"Y coordinate of vertex to big"
,
""
);
B_INT
rintx
=
((
B_INT
)
(
x
*
m_DGRID
)
)
*
m_GRID
;
B_INT
rintx
=
(
(
B_INT
)
(
x
*
m_DGRID
)
)
*
m_GRID
;
B_INT
rinty
=
((
B_INT
)
(
y
*
m_DGRID
)
)
*
m_GRID
;
B_INT
rinty
=
(
(
B_INT
)
(
y
*
m_DGRID
)
)
*
m_GRID
;
Node
*
myNode
=
new
Node
(
rintx
,
rinty
,
this
);
Node
*
myNode
=
new
Node
(
rintx
,
rinty
,
this
);
// adding first point to graph
// adding first point to graph
if
(
m_firstNodeToAdd
==
NULL
)
if
(
m_firstNodeToAdd
==
NULL
)
{
{
#if KBOOL_DEBUG
#if KBOOL_DEBUG
if
(
m_logfile
!=
NULL
)
if
(
m_logfile
!=
NULL
)
{
{
fprintf
(
m_logfile
,
"-> AddPt() *FIRST* :"
);
fprintf
(
m_logfile
,
"-> AddPt() *FIRST* :"
);
fprintf
(
m_logfile
,
" input: x = %f, y = %f
\n
"
,
x
,
y
);
fprintf
(
m_logfile
,
" input: x = %f, y = %f
\n
"
,
x
,
y
);
fprintf
(
m_logfile
,
" input: x = %I64d, y = %I64d
\n
"
,
rintx
,
rinty
)
;
fprintf
(
m_logfile
,
" input: x = %I64d, y = %I64d
\n
"
,
rintx
,
rinty
)
;
}
}
#endif
#endif
m_firstNodeToAdd
=
(
Node
*
)
myNode
;
m_firstNodeToAdd
=
(
Node
*
)
myNode
;
m_lastNodeToAdd
=
(
Node
*
)
myNode
;
m_lastNodeToAdd
=
(
Node
*
)
myNode
;
}
}
else
else
{
{
#if KBOOL_DEBUG
#if KBOOL_DEBUG
if
(
m_logfile
!=
NULL
)
if
(
m_logfile
!=
NULL
)
{
{
fprintf
(
m_logfile
,
"-> AddPt():"
);
fprintf
(
m_logfile
,
"-> AddPt():"
);
fprintf
(
m_logfile
,
" input: x = %f, y = %f
\n
"
,
x
,
y
);
fprintf
(
m_logfile
,
" input: x = %f, y = %f
\n
"
,
x
,
y
);
fprintf
(
m_logfile
,
" input: x = %I64d, y = %I64d
\n
"
,
rintx
,
rinty
)
;
fprintf
(
m_logfile
,
" input: x = %I64d, y = %I64d
\n
"
,
rintx
,
rinty
)
;
}
}
#endif
#endif
m_GraphToAdd
->
AddLink
(
m_lastNodeToAdd
,
myNode
);
m_GraphToAdd
->
AddLink
(
m_lastNodeToAdd
,
myNode
);
m_lastNodeToAdd
=
(
Node
*
)
myNode
;
m_lastNodeToAdd
=
(
Node
*
)
myNode
;
}
}
return
true
;
return
true
;
...
@@ -478,10 +474,10 @@ bool Bool_Engine::AddPoint(double x, double y)
...
@@ -478,10 +474,10 @@ bool Bool_Engine::AddPoint(double x, double y)
bool
Bool_Engine
::
EndPolygonAdd
()
bool
Bool_Engine
::
EndPolygonAdd
()
{
{
if
(
m_GraphToAdd
==
NULL
)
{
return
false
;}
if
(
m_GraphToAdd
==
NULL
)
{
return
false
;}
m_GraphToAdd
->
AddLink
(
m_lastNodeToAdd
,
m_firstNodeToAdd
);
m_GraphToAdd
->
AddLink
(
m_lastNodeToAdd
,
m_firstNodeToAdd
);
m_GraphToAdd
->
SetGroup
(
m_groupType
);
m_GraphToAdd
->
SetGroup
(
m_groupType
);
m_GraphToAdd
=
NULL
;
m_GraphToAdd
=
NULL
;
m_lastNodeToAdd
=
NULL
;
m_lastNodeToAdd
=
NULL
;
m_firstNodeToAdd
=
NULL
;
m_firstNodeToAdd
=
NULL
;
...
@@ -491,9 +487,9 @@ bool Bool_Engine::EndPolygonAdd()
...
@@ -491,9 +487,9 @@ bool Bool_Engine::EndPolygonAdd()
bool
Bool_Engine
::
StartPolygonGet
()
bool
Bool_Engine
::
StartPolygonGet
()
{
{
if
(
!
m_graphlist
->
empty
()
)
if
(
!
m_graphlist
->
empty
()
)
{
{
m_getGraph
=
(
Graph
*
)
m_graphlist
->
headitem
();
m_getGraph
=
(
Graph
*
)
m_graphlist
->
headitem
();
m_getLink
=
m_getGraph
->
GetFirstLink
();
m_getLink
=
m_getGraph
->
GetFirstLink
();
m_getNode
=
m_getLink
->
GetBeginNode
();
m_getNode
=
m_getLink
->
GetBeginNode
();
m_numPtsInPolygon
=
m_getGraph
->
GetNumberOfLinks
();
m_numPtsInPolygon
=
m_getGraph
->
GetNumberOfLinks
();
...
@@ -509,18 +505,18 @@ bool Bool_Engine::StartPolygonGet()
...
@@ -509,18 +505,18 @@ bool Bool_Engine::StartPolygonGet()
bool
Bool_Engine
::
PolygonHasMorePoints
()
bool
Bool_Engine
::
PolygonHasMorePoints
()
{
{
// see if first point
// see if first point
if
(
m_numNodesVisited
==
0
)
if
(
m_numNodesVisited
==
0
)
{
{
// don't need to touch the m_getNode
// don't need to touch the m_getNode
m_numNodesVisited
++
;
m_numNodesVisited
++
;
return
true
;
return
true
;
}
}
if
(
m_numNodesVisited
<
m_numPtsInPolygon
)
if
(
m_numNodesVisited
<
m_numPtsInPolygon
)
{
{
// traverse to the next node
// traverse to the next node
m_getNode
=
m_getLink
->
GetOther
(
m_getNode
);
m_getNode
=
m_getLink
->
GetOther
(
m_getNode
);
m_getLink
=
m_getLink
->
Forth
(
m_getNode
);
m_getLink
=
m_getLink
->
Forth
(
m_getNode
);
m_numNodesVisited
++
;
m_numNodesVisited
++
;
return
true
;
return
true
;
...
@@ -539,24 +535,24 @@ void Bool_Engine::EndPolygonGet()
...
@@ -539,24 +535,24 @@ void Bool_Engine::EndPolygonGet()
double
Bool_Engine
::
GetPolygonXPoint
()
double
Bool_Engine
::
GetPolygonXPoint
()
{
{
return
m_getNode
->
GetX
()
/
m_GRID
/
m_DGRID
;
return
m_getNode
->
GetX
()
/
m_GRID
/
m_DGRID
;
}
}
double
Bool_Engine
::
GetPolygonYPoint
()
double
Bool_Engine
::
GetPolygonYPoint
()
{
{
return
m_getNode
->
GetY
()
/
m_GRID
/
m_DGRID
;
return
m_getNode
->
GetY
()
/
m_GRID
/
m_DGRID
;
}
}
bool
Bool_Engine
::
GetHoleSegment
()
bool
Bool_Engine
::
GetHoleSegment
()
{
{
if
(
m_getLink
->
GetHole
()
)
if
(
m_getLink
->
GetHole
()
)
return
true
;
return
true
;
return
false
;
return
false
;
}
}
bool
Bool_Engine
::
GetHoleConnectionSegment
()
bool
Bool_Engine
::
GetHoleConnectionSegment
()
{
{
if
(
m_getLink
->
GetHoleLink
()
)
if
(
m_getLink
->
GetHoleLink
()
)
return
true
;
return
true
;
return
false
;
return
false
;
}
}
...
@@ -575,34 +571,34 @@ kbEdgeType Bool_Engine::GetPolygonPointEdgeType()
...
@@ -575,34 +571,34 @@ kbEdgeType Bool_Engine::GetPolygonPointEdgeType()
}
}
void
Bool_Engine
::
Write_Log
(
const
char
*
msg1
)
void
Bool_Engine
::
Write_Log
(
const
char
*
msg1
)
{
{
if
(
m_logfile
==
NULL
)
if
(
m_logfile
==
NULL
)
return
;
return
;
fprintf
(
m_logfile
,
"%s
\n
"
,
msg1
);
fprintf
(
m_logfile
,
"%s
\n
"
,
msg1
);
}
}
void
Bool_Engine
::
Write_Log
(
const
char
*
msg1
,
const
char
*
msg2
)
void
Bool_Engine
::
Write_Log
(
const
char
*
msg1
,
const
char
*
msg2
)
{
{
if
(
m_logfile
==
NULL
)
if
(
m_logfile
==
NULL
)
return
;
return
;
fprintf
(
m_logfile
,
"%s %s
\n
"
,
msg1
,
msg2
);
fprintf
(
m_logfile
,
"%s %s
\n
"
,
msg1
,
msg2
);
}
}
void
Bool_Engine
::
Write_Log
(
const
char
*
fmt
,
double
dval
)
void
Bool_Engine
::
Write_Log
(
const
char
*
fmt
,
double
dval
)
{
{
if
(
m_logfile
==
NULL
)
if
(
m_logfile
==
NULL
)
return
;
return
;
fprintf
(
m_logfile
,
fmt
,
dval
);
fprintf
(
m_logfile
,
fmt
,
dval
);
}
}
void
Bool_Engine
::
Write_Log
(
const
char
*
fmt
,
B_INT
bval
)
void
Bool_Engine
::
Write_Log
(
const
char
*
fmt
,
B_INT
bval
)
{
{
if
(
m_logfile
==
NULL
)
if
(
m_logfile
==
NULL
)
return
;
return
;
fprintf
(
m_logfile
,
fmt
,
bval
);
fprintf
(
m_logfile
,
fmt
,
bval
);
}
}
polygon/kbool/src/graph.cpp
View file @
521f428c
This source diff could not be displayed because it is too large. You can
view the blob
instead.
polygon/kbool/src/graphlst.cpp
View file @
521f428c
/*! \file
../
src/graphlst.cpp
/*! \file src/graphlst.cpp
\brief Implements a list of graphs
\brief Implements a list of graphs
\author
Probably
Klaas Holwerda
\author Klaas Holwerda
Copyright: 2001-2004 (C)
Probably
Klaas Holwerda
Copyright: 2001-2004 (C) Klaas Holwerda
Licence:
wxWidgets Licence
Licence:
see kboollicense.txt
RCS-ID: $Id: graphlst.cpp,v 1.
8 2005/05/24 19:13:38
titato Exp $
RCS-ID: $Id: graphlst.cpp,v 1.
3 2008/06/04 21:23:22
titato Exp $
*/
*/
#ifdef __GNUG__
#pragma implementation
#endif
//#include "debugdrv.h"
//#include "debugdrv.h"
#include "
../include
/booleng.h"
#include "
kbool
/booleng.h"
#include "
../include
/graphlst.h"
#include "
kbool
/graphlst.h"
//extern Debug_driver* _debug_driver;
//extern Debug_driver* _debug_driver;
//this here is to initialize the static iterator of graphlist
//this here is to initialize the static iterator of graphlist
...
@@ -24,9 +20,9 @@
...
@@ -24,9 +20,9 @@
int
graphsorterX
(
Graph
*
,
Graph
*
);
int
graphsorterX
(
Graph
*
,
Graph
*
);
int
graphsorterY
(
Graph
*
,
Graph
*
);
int
graphsorterY
(
Graph
*
,
Graph
*
);
GraphList
::
GraphList
(
Bool_Engine
*
GC
)
GraphList
::
GraphList
(
Bool_Engine
*
GC
)
{
{
_GC
=
GC
;
_GC
=
GC
;
}
}
GraphList
::
GraphList
(
GraphList
*
other
)
GraphList
::
GraphList
(
GraphList
*
other
)
...
@@ -35,7 +31,7 @@ GraphList::GraphList( GraphList* other )
...
@@ -35,7 +31,7 @@ GraphList::GraphList( GraphList* other )
TDLI
<
Graph
>
_LI
=
TDLI
<
Graph
>
(
other
);
TDLI
<
Graph
>
_LI
=
TDLI
<
Graph
>
(
other
);
_LI
.
tohead
();
_LI
.
tohead
();
while
(
!
_LI
.
hitroot
()
)
while
(
!
_LI
.
hitroot
()
)
{
{
insend
(
new
Graph
(
_LI
.
item
()
)
);
insend
(
new
Graph
(
_LI
.
item
()
)
);
_LI
++
;
_LI
++
;
...
@@ -44,29 +40,29 @@ GraphList::GraphList( GraphList* other )
...
@@ -44,29 +40,29 @@ GraphList::GraphList( GraphList* other )
GraphList
::~
GraphList
()
GraphList
::~
GraphList
()
{
{
TDLI
<
Graph
>
_LI
=
TDLI
<
Graph
>
(
this
);
TDLI
<
Graph
>
_LI
=
TDLI
<
Graph
>
(
this
);
//first empty the graph
//first empty the graph
_LI
.
delete_all
();
_LI
.
delete_all
();
}
}
//prepare the graphlist for the boolean operations
//prepare the graphlist for the boolean operations
//group all graphs into ONE graph
//group all graphs into ONE graph
void
GraphList
::
Prepare
(
Graph
*
total
)
void
GraphList
::
Prepare
(
Graph
*
total
)
{
{
if
(
empty
()
)
if
(
empty
()
)
return
;
return
;
//round to grid and put in one graph
//round to grid and put in one graph
_GC
->
SetState
(
"Simplify"
);
_GC
->
SetState
(
"Simplify"
);
// Simplify all graphs in the list
// Simplify all graphs in the list
Simplify
(
(
double
)
_GC
->
GetGrid
()
);
Simplify
(
(
double
)
_GC
->
GetGrid
()
);
if
(
!
_GC
->
GetOrientationEntryMode
()
)
if
(
!
_GC
->
GetOrientationEntryMode
()
)
{
{
TDLI
<
Graph
>
_LI
=
TDLI
<
Graph
>
(
this
);
TDLI
<
Graph
>
_LI
=
TDLI
<
Graph
>
(
this
);
_LI
.
tohead
();
_LI
.
tohead
();
while
(
!
_LI
.
hitroot
()
)
while
(
!
_LI
.
hitroot
()
)
{
{
_LI
.
item
()
->
MakeClockWise
();
_LI
.
item
()
->
MakeClockWise
();
_LI
++
;
_LI
++
;
...
@@ -76,19 +72,19 @@ void GraphList::Prepare(Graph* total)
...
@@ -76,19 +72,19 @@ void GraphList::Prepare(Graph* total)
Renumber
();
Renumber
();
//the graplist contents will be transferred to one graph
//the graplist contents will be transferred to one graph
MakeOneGraph
(
total
);
MakeOneGraph
(
total
);
}
}
// the function will make from all the graphs in the graphlist one graph,
// the function will make from all the graphs in the graphlist one graph,
// simply by throwing all the links in one graph, the graphnumbers will
// simply by throwing all the links in one graph, the graphnumbers will
// not be changed
// not be changed
void
GraphList
::
MakeOneGraph
(
Graph
*
total
)
void
GraphList
::
MakeOneGraph
(
Graph
*
total
)
{
{
TDLI
<
Graph
>
_LI
=
TDLI
<
Graph
>
(
this
);
TDLI
<
Graph
>
_LI
=
TDLI
<
Graph
>
(
this
);
_LI
.
tohead
();
_LI
.
tohead
();
while
(
!
_LI
.
hitroot
()
)
while
(
!
_LI
.
hitroot
()
)
{
{
total
->
TakeOver
(
_LI
.
item
()
);
total
->
TakeOver
(
_LI
.
item
()
);
delete
_LI
.
item
();
delete
_LI
.
item
();
_LI
.
remove
();
_LI
.
remove
();
}
}
...
@@ -101,25 +97,25 @@ void GraphList::Renumber()
...
@@ -101,25 +97,25 @@ void GraphList::Renumber()
{
{
if
(
_GC
->
GetOrientationEntryMode
()
)
if
(
_GC
->
GetOrientationEntryMode
()
)
{
{
TDLI
<
Graph
>
_LI
=
TDLI
<
Graph
>
(
this
);
TDLI
<
Graph
>
_LI
=
TDLI
<
Graph
>
(
this
);
_LI
.
tohead
();
_LI
.
tohead
();
while
(
!
_LI
.
hitroot
()
)
while
(
!
_LI
.
hitroot
()
)
{
{
if
(
_LI
.
item
()
->
GetFirstLink
()
->
Group
()
==
GROUP_A
)
if
(
_LI
.
item
()
->
GetFirstLink
()
->
Group
()
==
GROUP_A
)
_LI
.
item
()
->
SetNumber
(
1
);
_LI
.
item
()
->
SetNumber
(
1
);
else
else
_LI
.
item
()
->
SetNumber
(
2
);
_LI
.
item
()
->
SetNumber
(
2
);
_LI
++
;
_LI
++
;
}
}
}
}
else
else
{
{
unsigned
int
Number
=
1
;
unsigned
int
Number
=
1
;
TDLI
<
Graph
>
_LI
=
TDLI
<
Graph
>
(
this
);
TDLI
<
Graph
>
_LI
=
TDLI
<
Graph
>
(
this
);
_LI
.
tohead
();
_LI
.
tohead
();
while
(
!
_LI
.
hitroot
()
)
while
(
!
_LI
.
hitroot
()
)
{
{
_LI
.
item
()
->
SetNumber
(
Number
++
);
_LI
.
item
()
->
SetNumber
(
Number
++
);
_LI
++
;
_LI
++
;
}
}
}
}
...
@@ -127,17 +123,17 @@ void GraphList::Renumber()
...
@@ -127,17 +123,17 @@ void GraphList::Renumber()
// Simplify the graphs
// Simplify the graphs
void
GraphList
::
Simplify
(
double
marge
)
void
GraphList
::
Simplify
(
double
marge
)
{
{
TDLI
<
Graph
>
_LI
=
TDLI
<
Graph
>
(
this
);
TDLI
<
Graph
>
_LI
=
TDLI
<
Graph
>
(
this
);
_LI
.
foreach_mf
(
&
Graph
::
Reset_Mark_and_Bin
);
_LI
.
foreach_mf
(
&
Graph
::
Reset_Mark_and_Bin
);
_LI
.
tohead
();
_LI
.
tohead
();
while
(
!
_LI
.
hitroot
()
)
while
(
!
_LI
.
hitroot
()
)
{
{
if
(
_LI
.
item
()
->
Simplify
(
(
B_INT
)
marge
)
)
if
(
_LI
.
item
()
->
Simplify
(
(
B_INT
)
marge
)
)
{
{
if
(
_LI
.
item
()
->
GetNumberOfLinks
()
<
3
)
if
(
_LI
.
item
()
->
GetNumberOfLinks
()
<
3
)
// delete this graph from the graphlist
// delete this graph from the graphlist
{
{
delete
_LI
.
item
();
delete
_LI
.
item
();
...
@@ -150,17 +146,17 @@ void GraphList::Simplify(double marge)
...
@@ -150,17 +146,17 @@ void GraphList::Simplify(double marge)
}
}
// Smoothen the graphs
// Smoothen the graphs
void
GraphList
::
Smoothen
(
double
marge
)
void
GraphList
::
Smoothen
(
double
marge
)
{
{
TDLI
<
Graph
>
_LI
=
TDLI
<
Graph
>
(
this
);
TDLI
<
Graph
>
_LI
=
TDLI
<
Graph
>
(
this
);
_LI
.
foreach_mf
(
&
Graph
::
Reset_Mark_and_Bin
);
_LI
.
foreach_mf
(
&
Graph
::
Reset_Mark_and_Bin
);
_LI
.
tohead
();
_LI
.
tohead
();
while
(
!
_LI
.
hitroot
()
)
while
(
!
_LI
.
hitroot
()
)
{
{
if
(
_LI
.
item
()
->
Smoothen
(
(
B_INT
)
marge
)
)
if
(
_LI
.
item
()
->
Smoothen
(
(
B_INT
)
marge
)
)
{
{
if
(
_LI
.
item
()
->
GetNumberOfLinks
()
<
3
)
if
(
_LI
.
item
()
->
GetNumberOfLinks
()
<
3
)
// delete this graph from the graphlist
// delete this graph from the graphlist
{
{
delete
_LI
.
item
();
delete
_LI
.
item
();
...
@@ -176,8 +172,8 @@ void GraphList::Smoothen(double marge)
...
@@ -176,8 +172,8 @@ void GraphList::Smoothen(double marge)
// Turn off all markers in all the graphs
// Turn off all markers in all the graphs
void
GraphList
::
UnMarkAll
()
void
GraphList
::
UnMarkAll
()
{
{
TDLI
<
Graph
>
_LI
=
TDLI
<
Graph
>
(
this
);
TDLI
<
Graph
>
_LI
=
TDLI
<
Graph
>
(
this
);
_LI
.
foreach_mf
(
&
Graph
::
Reset_Mark_and_Bin
);
_LI
.
foreach_mf
(
&
Graph
::
Reset_Mark_and_Bin
);
}
}
//==============================================================================
//==============================================================================
...
@@ -188,59 +184,59 @@ void GraphList::UnMarkAll()
...
@@ -188,59 +184,59 @@ void GraphList::UnMarkAll()
void
GraphList
::
Correction
()
void
GraphList
::
Correction
()
{
{
TDLI
<
Graph
>
_LI
=
TDLI
<
Graph
>
(
this
);
TDLI
<
Graph
>
_LI
=
TDLI
<
Graph
>
(
this
);
int
todo
=
_LI
.
count
();
int
todo
=
_LI
.
count
();
if
(
_GC
->
GetInternalCorrectionFactor
()
)
//not zero
if
(
_GC
->
GetInternalCorrectionFactor
()
)
//not zero
{
{
_LI
.
tohead
();
_LI
.
tohead
();
for
(
int
i
=
0
;
i
<
todo
;
i
++
)
for
(
int
i
=
0
;
i
<
todo
;
i
++
)
{
{
//the input graph will be empty in the end
//the input graph will be empty in the end
GraphList
*
_correct
=
new
GraphList
(
_GC
);
GraphList
*
_correct
=
new
GraphList
(
_GC
);
{
{
_LI
.
item
()
->
MakeClockWise
();
_LI
.
item
()
->
MakeClockWise
();
_LI
.
item
()
->
Correction
(
_correct
,
_GC
->
GetInternalCorrectionFactor
()
);
_LI
.
item
()
->
Correction
(
_correct
,
_GC
->
GetInternalCorrectionFactor
()
);
delete
_LI
.
item
();
delete
_LI
.
item
();
_LI
.
remove
();
_LI
.
remove
();
//move corrected graphlist to result
//move corrected graphlist to result
while
(
!
_correct
->
empty
()
)
while
(
!
_correct
->
empty
()
)
{
{
//add to end
//add to end
_LI
.
insend
((
Graph
*
)
_correct
->
headitem
()
);
_LI
.
insend
(
(
Graph
*
)
_correct
->
headitem
()
);
_correct
->
removehead
();
_correct
->
removehead
();
}
}
}
}
delete
_correct
;
delete
_correct
;
}
}
}
}
}
}
void
GraphList
::
MakeRings
()
void
GraphList
::
MakeRings
()
{
{
TDLI
<
Graph
>
_LI
=
TDLI
<
Graph
>
(
this
);
TDLI
<
Graph
>
_LI
=
TDLI
<
Graph
>
(
this
);
int
todo
=
_LI
.
count
();
int
todo
=
_LI
.
count
();
_LI
.
tohead
();
_LI
.
tohead
();
for
(
int
i
=
0
;
i
<
todo
;
i
++
)
for
(
int
i
=
0
;
i
<
todo
;
i
++
)
{
{
//the input graph will be empty in the end
//the input graph will be empty in the end
GraphList
*
_ring
=
new
GraphList
(
_GC
);
GraphList
*
_ring
=
new
GraphList
(
_GC
);
{
{
_LI
.
item
()
->
MakeClockWise
();
_LI
.
item
()
->
MakeClockWise
();
_LI
.
item
()
->
MakeRing
(
_ring
,
_GC
->
GetInternalCorrectionFactor
()
);
_LI
.
item
()
->
MakeRing
(
_ring
,
_GC
->
GetInternalCorrectionFactor
()
);
delete
_LI
.
item
();
delete
_LI
.
item
();
_LI
.
remove
();
_LI
.
remove
();
//move created rings graphs to this
//move created rings graphs to this
while
(
!
_ring
->
empty
()
)
while
(
!
_ring
->
empty
()
)
{
{
//add to end
//add to end
((
Graph
*
)
_ring
->
headitem
()
)
->
MakeClockWise
();
(
(
Graph
*
)
_ring
->
headitem
()
)
->
MakeClockWise
();
_LI
.
insend
((
Graph
*
)
_ring
->
headitem
()
);
_LI
.
insend
(
(
Graph
*
)
_ring
->
headitem
()
);
_ring
->
removehead
();
_ring
->
removehead
();
}
}
}
}
...
@@ -252,29 +248,29 @@ void GraphList::MakeRings()
...
@@ -252,29 +248,29 @@ void GraphList::MakeRings()
//merge the graphs in the list and return the merged result
//merge the graphs in the list and return the merged result
void
GraphList
::
Merge
()
void
GraphList
::
Merge
()
{
{
if
(
count
()
<=
1
)
if
(
count
()
<=
1
)
return
;
return
;
{
{
TDLI
<
Graph
>
_LI
=
TDLI
<
Graph
>
(
this
);
TDLI
<
Graph
>
_LI
=
TDLI
<
Graph
>
(
this
);
_LI
.
tohead
();
_LI
.
tohead
();
while
(
!
_LI
.
hitroot
()
)
while
(
!
_LI
.
hitroot
()
)
{
{
_LI
.
item
()
->
SetGroup
(
GROUP_A
);
_LI
.
item
()
->
SetGroup
(
GROUP_A
);
_LI
++
;
_LI
++
;
}
}
}
}
Graph
*
_tomerge
=
new
Graph
(
_GC
);
Graph
*
_tomerge
=
new
Graph
(
_GC
);
Renumber
();
Renumber
();
//the graplist contents will be transferred to one graph
//the graplist contents will be transferred to one graph
MakeOneGraph
(
_tomerge
);
MakeOneGraph
(
_tomerge
);
//the original is empty now
//the original is empty now
_tomerge
->
Prepare
(
1
);
_tomerge
->
Prepare
(
1
);
_tomerge
->
Boolean
(
BOOL_OR
,
this
);
_tomerge
->
Boolean
(
BOOL_OR
,
this
);
delete
_tomerge
;
delete
_tomerge
;
}
}
...
@@ -283,20 +279,20 @@ void GraphList::Merge()
...
@@ -283,20 +279,20 @@ void GraphList::Merge()
#define SAVEME 1
#define SAVEME 1
//perform boolean operation on the graphs in the list
//perform boolean operation on the graphs in the list
void
GraphList
::
Boolean
(
BOOL_OP
operation
,
int
intersectionRunsMax
)
void
GraphList
::
Boolean
(
BOOL_OP
operation
,
int
intersectionRunsMax
)
{
{
_GC
->
SetState
(
"Performing Boolean Operation"
);
_GC
->
SetState
(
"Performing Boolean Operation"
);
if
(
count
()
==
0
)
if
(
count
()
==
0
)
return
;
return
;
Graph
*
_prepared
=
new
Graph
(
_GC
);
Graph
*
_prepared
=
new
Graph
(
_GC
);
if
(
empty
()
)
if
(
empty
()
)
return
;
return
;
//round to grid and put in one graph
//round to grid and put in one graph
_GC
->
SetState
(
"Simplify"
);
_GC
->
SetState
(
"Simplify"
);
int
intersectionruns
=
1
;
int
intersectionruns
=
1
;
...
@@ -306,40 +302,40 @@ void GraphList::Boolean(BOOL_OP operation, int intersectionRunsMax )
...
@@ -306,40 +302,40 @@ void GraphList::Boolean(BOOL_OP operation, int intersectionRunsMax )
{
{
Prepare
(
_prepared
);
Prepare
(
_prepared
);
if
(
_prepared
->
GetNumberOfLinks
()
)
if
(
_prepared
->
GetNumberOfLinks
()
)
{
{
//calculate intersections etc.
//calculate intersections etc.
_GC
->
SetState
(
"prepare"
);
_GC
->
SetState
(
"prepare"
);
_prepared
->
Prepare
(
intersectionruns
);
_prepared
->
Prepare
(
intersectionruns
);
//_prepared->writegraph(true);
//_prepared->writegraph(true);
_prepared
->
Boolean
(
operation
,
this
);
_prepared
->
Boolean
(
operation
,
this
);
}
}
intersectionruns
=
intersectionRunsMax
+
1
;
intersectionruns
=
intersectionRunsMax
+
1
;
}
}
catch
(
Bool_Engine_Error
&
error
)
catch
(
Bool_Engine_Error
&
error
)
{
{
#if KBOOL_DEBUG
#if KBOOL_DEBUG
_prepared
->
WriteGraphKEY
(
_GC
);
_prepared
->
WriteGraphKEY
(
_GC
);
#endif
#endif
intersectionruns
++
;
intersectionruns
++
;
if
(
intersectionruns
==
intersectionRunsMax
)
if
(
intersectionruns
==
intersectionRunsMax
)
{
{
_prepared
->
WriteGraphKEY
(
_GC
);
_prepared
->
WriteGraphKEY
(
_GC
);
_GC
->
info
(
error
.
GetErrorMessage
(),
"error"
);
_GC
->
info
(
error
.
GetErrorMessage
(),
"error"
);
throw
error
;
throw
error
;
}
}
}
}
catch
(...
)
catch
(
...
)
{
{
#if KBOOL_DEBUG
#if KBOOL_DEBUG
_prepared
->
WriteGraphKEY
(
_GC
);
_prepared
->
WriteGraphKEY
(
_GC
);
#endif
#endif
intersectionruns
++
;
intersectionruns
++
;
if
(
intersectionruns
==
intersectionRunsMax
)
if
(
intersectionruns
==
intersectionRunsMax
)
{
{
_prepared
->
WriteGraphKEY
(
_GC
);
_prepared
->
WriteGraphKEY
(
_GC
);
_GC
->
info
(
"Unknown exception"
,
"error"
);
_GC
->
info
(
"Unknown exception"
,
"error"
);
throw
;
throw
;
}
}
}
}
...
@@ -351,9 +347,9 @@ void GraphList::Boolean(BOOL_OP operation, int intersectionRunsMax )
...
@@ -351,9 +347,9 @@ void GraphList::Boolean(BOOL_OP operation, int intersectionRunsMax )
void
GraphList
::
WriteGraphs
()
void
GraphList
::
WriteGraphs
()
{
{
TDLI
<
Graph
>
_LI
=
TDLI
<
Graph
>
(
this
);
TDLI
<
Graph
>
_LI
=
TDLI
<
Graph
>
(
this
);
_LI
.
tohead
();
_LI
.
tohead
();
while
(
!
_LI
.
hitroot
()
)
while
(
!
_LI
.
hitroot
()
)
{
{
_LI
.
item
()
->
writegraph
(
false
);
_LI
.
item
()
->
writegraph
(
false
);
_LI
++
;
_LI
++
;
...
@@ -362,9 +358,9 @@ void GraphList::WriteGraphs()
...
@@ -362,9 +358,9 @@ void GraphList::WriteGraphs()
void
GraphList
::
WriteGraphsKEY
(
Bool_Engine
*
GC
)
void
GraphList
::
WriteGraphsKEY
(
Bool_Engine
*
GC
)
{
{
FILE
*
file
=
fopen
(
"graphkeyfile.key"
,
"w"
);
FILE
*
file
=
fopen
(
"graphkeyfile.key"
,
"w"
);
fprintf
(
file
,
"\
fprintf
(
file
,
"\
HEADER 5; \
HEADER 5; \
BGNLIB; \
BGNLIB; \
LASTMOD {2-11-15 15:39:21}; \
LASTMOD {2-11-15 15:39:21}; \
...
...
polygon/kbool/src/instonly.cpp
View file @
521f428c
/*! \file
..
/src/instonly.cpp
/*! \file
kbool
/src/instonly.cpp
\author Probably Klaas Holwerda
\author Probably Klaas Holwerda
Copyright: 2001-2004 (C) Probably Klaas Holwerda
Copyright: 2001-2004 (C) Probably Klaas Holwerda
Licence: wxWidgets Licence
Licence: wxWidgets Licence
RCS-ID: $Id: instonly.cpp,v 1.
5 2005/05/24 19:13:38
titato Exp $
RCS-ID: $Id: instonly.cpp,v 1.
2 2006/11/05 14:59:31
titato Exp $
*/
*/
#ifdef __GNUG__
#ifdef __GNUG__
#pragma option -Jgd
#pragma option -Jgd
#include "
../include
/_dl_itr.h"
#include "
kbool
/_dl_itr.h"
#include "
../include
/node.h"
#include "
kbool
/node.h"
#include "
../include
/record.h"
#include "
kbool
/record.h"
#include "
../include
/link.h"
#include "
kbool
/link.h"
#include "
../include
/_lnk_itr.h"
#include "
kbool
/_lnk_itr.h"
#include "
../include
/scanbeam.h"
#include "
kbool
/scanbeam.h"
#include "
../include
/graph.h"
#include "
kbool
/graph.h"
#include "
../include
/graphlst.h"
#include "
kbool
/graphlst.h"
//#include "
../include
/misc.h"
//#include "
kbool
/misc.h"
template
class
DL_Node
<
void
*>
;
template
class
DL_Node
<
void
*>
;
template
class
DL_Iter
<
void
*>
;
template
class
DL_Iter
<
void
*>
;
...
...
polygon/kbool/src/line.cpp
View file @
521f428c
/*! \file
../
src/line.cpp
/*! \file src/line.cpp
\brief Mainly used for calculating crossings
\brief Mainly used for calculating crossings
\author
Probably
Klaas Holwerda
\author Klaas Holwerda
Copyright: 2001-2004 (C)
Probably
Klaas Holwerda
Copyright: 2001-2004 (C) Klaas Holwerda
Licence:
wxWidgets Licence
Licence:
see kboollicense.txt
RCS-ID: $Id: line.cpp,v 1.
10 2005/06/17 22:48:46 kbluck
Exp $
RCS-ID: $Id: line.cpp,v 1.
3 2008/06/04 21:23:22 titato
Exp $
*/
*/
#ifdef __GNUG__
#pragma implementation
#endif
// Standard include files
// Standard include files
#include <assert.h>
#include "kbool/booleng.h"
#include <math.h>
#include "../include/booleng.h"
// Include files for forward declarations
// Include files for forward declarations
#include "
../include
/link.h"
#include "
kbool
/link.h"
#include "
../include
/node.h"
#include "
kbool
/node.h"
// header
// header
#include "
../include
/line.h"
#include "
kbool
/line.h"
#include "
../include
/graph.h"
#include "
kbool
/graph.h"
#include "
../include
/graphlst.h"
#include "
kbool
/graphlst.h"
//
//
// The default constructor
// The default constructor
//
//
KBoolLine
::
KBoolLine
(
Bool_Engine
*
GC
)
KBoolLine
::
KBoolLine
(
Bool_Engine
*
GC
)
{
{
m_GC
=
GC
;
m_GC
=
GC
;
m_AA
=
0.0
;
m_AA
=
0.0
;
m_BB
=
0.0
;
m_BB
=
0.0
;
m_CC
=
0.0
;
m_CC
=
0.0
;
...
@@ -45,18 +38,18 @@ KBoolLine::KBoolLine(Bool_Engine* GC)
...
@@ -45,18 +38,18 @@ KBoolLine::KBoolLine(Bool_Engine* GC)
KBoolLine
::~
KBoolLine
()
KBoolLine
::~
KBoolLine
()
{
{
if
(
linecrosslist
)
if
(
linecrosslist
)
delete
linecrosslist
;
delete
linecrosslist
;
}
}
//
//
// constructor with a link
// constructor with a link
//
//
KBoolLine
::
KBoolLine
(
KBoolLink
*
a_link
,
Bool_Engine
*
GC
)
KBoolLine
::
KBoolLine
(
KBoolLink
*
a_link
,
Bool_Engine
*
GC
)
{
{
m_GC
=
GC
;
m_GC
=
GC
;
// a_link must exist
// a_link must exist
assert
(
a_link
);
assert
(
a_link
);
// points may not be equal
// points may not be equal
// must be an if statement because if an assert is used there will
// must be an if statement because if an assert is used there will
// be a macro expansion error
// be a macro expansion error
...
@@ -87,61 +80,61 @@ KBoolLine::KBoolLine(KBoolLink *a_link,Bool_Engine* GC)
...
@@ -87,61 +80,61 @@ KBoolLine::KBoolLine(KBoolLink *a_link,Bool_Engine* GC)
// 4: beginnode and endnode are crosspoints, no further investigation
// 4: beginnode and endnode are crosspoints, no further investigation
// 5: beginnode is a crosspoint, need further investigation
// 5: beginnode is a crosspoint, need further investigation
// 6: endnode is a crosspoint, need further investigation
// 6: endnode is a crosspoint, need further investigation
int
KBoolLine
::
ActionOnTable1
(
PointStatus
Result_beginnode
,
PointStatus
Result_endnode
)
int
KBoolLine
::
ActionOnTable1
(
PointStatus
Result_beginnode
,
PointStatus
Result_endnode
)
{
{
// Action 1.5 beginnode and endnode are crosspoints, no further investigation needed
// Action 1.5 beginnode and endnode are crosspoints, no further investigation needed
if
(
if
(
(
Result_beginnode
==
IN_AREA
)
(
Result_beginnode
==
IN_AREA
)
&&
&&
(
Result_endnode
==
IN_AREA
)
(
Result_endnode
==
IN_AREA
)
)
)
return
4
;
return
4
;
// Action 1.1, there are no crosspoints, no action
// Action 1.1, there are no crosspoints, no action
if
(
if
(
(
(
(
Result_beginnode
==
LEFT_SIDE
)
(
Result_beginnode
==
LEFT_SIDE
)
&&
&&
(
Result_endnode
==
LEFT_SIDE
)
(
Result_endnode
==
LEFT_SIDE
)
)
)
||
||
(
(
(
Result_beginnode
==
RIGHT_SIDE
)
(
Result_beginnode
==
RIGHT_SIDE
)
&&
&&
(
Result_endnode
==
RIGHT_SIDE
)
(
Result_endnode
==
RIGHT_SIDE
)
)
)
)
)
return
0
;
return
0
;
// Action 1.2, maybe there is a crosspoint, further investigation needed
// Action 1.2, maybe there is a crosspoint, further investigation needed
if
(
if
(
(
(
(
Result_beginnode
==
LEFT_SIDE
)
(
Result_beginnode
==
LEFT_SIDE
)
&&
&&
(
(
(
Result_endnode
==
RIGHT_SIDE
)
(
Result_endnode
==
RIGHT_SIDE
)
||
||
(
Result_endnode
==
ON_AREA
)
(
Result_endnode
==
ON_AREA
)
)
)
)
)
||
||
(
(
(
Result_beginnode
==
RIGHT_SIDE
)
(
Result_beginnode
==
RIGHT_SIDE
)
&&
&&
(
(
(
Result_endnode
==
LEFT_SIDE
)
(
Result_endnode
==
LEFT_SIDE
)
||
||
(
Result_endnode
==
ON_AREA
)
(
Result_endnode
==
ON_AREA
)
)
)
)
)
||
||
(
(
(
Result_beginnode
==
ON_AREA
)
(
Result_beginnode
==
ON_AREA
)
&&
&&
(
(
(
Result_endnode
==
LEFT_SIDE
)
(
Result_endnode
==
LEFT_SIDE
)
||
||
(
Result_endnode
==
RIGHT_SIDE
)
(
Result_endnode
==
RIGHT_SIDE
)
||
||
(
Result_endnode
==
ON_AREA
)
(
Result_endnode
==
ON_AREA
)
)
)
)
)
)
)
...
@@ -149,37 +142,37 @@ int KBoolLine::ActionOnTable1(PointStatus Result_beginnode, PointStatus Result_e
...
@@ -149,37 +142,37 @@ int KBoolLine::ActionOnTable1(PointStatus Result_beginnode, PointStatus Result_e
// Action 1.3, there is a crosspoint, no further investigation
// Action 1.3, there is a crosspoint, no further investigation
if
(
if
(
(
(
(
Result_beginnode
==
LEFT_SIDE
)
(
Result_beginnode
==
LEFT_SIDE
)
||
||
(
Result_beginnode
==
RIGHT_SIDE
)
(
Result_beginnode
==
RIGHT_SIDE
)
)
)
&&
&&
(
Result_endnode
==
IN_AREA
)
(
Result_endnode
==
IN_AREA
)
)
)
return
2
;
return
2
;
// Action 1.4 there is a crosspoint, no further investigation
// Action 1.4 there is a crosspoint, no further investigation
if
(
if
(
(
Result_beginnode
==
IN_AREA
)
(
Result_beginnode
==
IN_AREA
)
&&
&&
(
(
(
Result_endnode
==
LEFT_SIDE
)
(
Result_endnode
==
LEFT_SIDE
)
||
||
(
Result_endnode
==
RIGHT_SIDE
)
(
Result_endnode
==
RIGHT_SIDE
)
)
)
)
)
return
3
;
return
3
;
// Action 1.6 beginnode is a crosspoint, further investigation needed
// Action 1.6 beginnode is a crosspoint, further investigation needed
if
(
if
(
(
Result_beginnode
==
IN_AREA
)
(
Result_beginnode
==
IN_AREA
)
&&
&&
(
Result_endnode
==
ON_AREA
)
(
Result_endnode
==
ON_AREA
)
)
)
return
5
;
return
5
;
// Action 1.7 endnode is a crosspoint, further investigation needed
// Action 1.7 endnode is a crosspoint, further investigation needed
if
(
if
(
(
Result_beginnode
==
ON_AREA
)
(
Result_beginnode
==
ON_AREA
)
&&
&&
(
Result_endnode
==
IN_AREA
)
(
Result_endnode
==
IN_AREA
)
)
)
return
6
;
return
6
;
// All other combinations are illegal
// All other combinations are illegal
...
@@ -203,88 +196,88 @@ int KBoolLine::ActionOnTable1(PointStatus Result_beginnode, PointStatus Result_e
...
@@ -203,88 +196,88 @@ int KBoolLine::ActionOnTable1(PointStatus Result_beginnode, PointStatus Result_e
// 2: endnode is a crosspoint
// 2: endnode is a crosspoint
// 3: beginnode is a crosspoint
// 3: beginnode is a crosspoint
// 4: beginnode and endnode are crosspoints
// 4: beginnode and endnode are crosspoints
int
KBoolLine
::
ActionOnTable2
(
PointStatus
Result_beginnode
,
PointStatus
Result_endnode
)
int
KBoolLine
::
ActionOnTable2
(
PointStatus
Result_beginnode
,
PointStatus
Result_endnode
)
{
{
// Action 2.5, beginnode and eindpoint are crosspoints
// Action 2.5, beginnode and eindpoint are crosspoints
if
(
if
(
(
Result_beginnode
==
IN_AREA
)
(
Result_beginnode
==
IN_AREA
)
&&
&&
(
Result_endnode
==
IN_AREA
)
(
Result_endnode
==
IN_AREA
)
)
)
return
4
;
return
4
;
// Action 2.1, there are no crosspoints
// Action 2.1, there are no crosspoints
if
(
if
(
(
(
(
Result_beginnode
==
LEFT_SIDE
)
(
Result_beginnode
==
LEFT_SIDE
)
&&
&&
(
(
(
Result_endnode
==
LEFT_SIDE
)
(
Result_endnode
==
LEFT_SIDE
)
||
||
(
Result_endnode
==
ON_AREA
)
(
Result_endnode
==
ON_AREA
)
)
)
)
)
||
||
(
(
(
Result_beginnode
==
RIGHT_SIDE
)
(
Result_beginnode
==
RIGHT_SIDE
)
&&
&&
(
(
(
Result_endnode
==
RIGHT_SIDE
)
(
Result_endnode
==
RIGHT_SIDE
)
||
||
(
Result_endnode
==
ON_AREA
)
(
Result_endnode
==
ON_AREA
)
)
)
)
)
||
||
(
(
(
Result_beginnode
==
ON_AREA
)
(
Result_beginnode
==
ON_AREA
)
&&
&&
(
(
(
Result_endnode
==
LEFT_SIDE
)
(
Result_endnode
==
LEFT_SIDE
)
||
||
(
Result_endnode
==
RIGHT_SIDE
)
(
Result_endnode
==
RIGHT_SIDE
)
||
||
(
Result_endnode
==
ON_AREA
)
(
Result_endnode
==
ON_AREA
)
)
)
)
)
)
)
return
0
;
return
0
;
// Action 2.2, there is a real intersect
ion, which must be calculated
// Action 2.2, there is a real intersect
ion, which must be calculated
if
(
if
(
(
(
(
Result_beginnode
==
LEFT_SIDE
)
(
Result_beginnode
==
LEFT_SIDE
)
&&
&&
(
Result_endnode
==
RIGHT_SIDE
)
(
Result_endnode
==
RIGHT_SIDE
)
)
)
||
||
(
(
(
Result_beginnode
==
RIGHT_SIDE
)
(
Result_beginnode
==
RIGHT_SIDE
)
&&
&&
(
Result_endnode
==
LEFT_SIDE
)
(
Result_endnode
==
LEFT_SIDE
)
)
)
)
)
return
1
;
return
1
;
// Action 2.3, endnode is a crosspoint
// Action 2.3, endnode is a crosspoint
if
(
if
(
(
(
(
Result_beginnode
==
LEFT_SIDE
)
(
Result_beginnode
==
LEFT_SIDE
)
||
||
(
Result_beginnode
==
RIGHT_SIDE
)
(
Result_beginnode
==
RIGHT_SIDE
)
||
||
(
Result_beginnode
==
ON_AREA
)
(
Result_beginnode
==
ON_AREA
)
)
)
&&
&&
(
Result_endnode
==
IN_AREA
)
(
Result_endnode
==
IN_AREA
)
)
)
return
2
;
return
2
;
// Action 2.4, beginnode is a crosspoint
// Action 2.4, beginnode is a crosspoint
if
(
if
(
(
Result_beginnode
==
IN_AREA
)
(
Result_beginnode
==
IN_AREA
)
&&
&&
(
(
(
Result_endnode
==
LEFT_SIDE
)
(
Result_endnode
==
LEFT_SIDE
)
||
||
(
Result_endnode
==
RIGHT_SIDE
)
(
Result_endnode
==
RIGHT_SIDE
)
||
||
(
Result_endnode
==
ON_AREA
)
(
Result_endnode
==
ON_AREA
)
)
)
)
)
return
3
;
return
3
;
...
@@ -297,54 +290,54 @@ int KBoolLine::ActionOnTable2(PointStatus Result_beginnode, PointStatus Result_e
...
@@ -297,54 +290,54 @@ int KBoolLine::ActionOnTable2(PointStatus Result_beginnode, PointStatus Result_e
// the crossing will be put in the link, because the line will be destructed
// the crossing will be put in the link, because the line will be destructed
// after use of the variable
// after use of the variable
//
//
void
KBoolLine
::
AddLineCrossing
(
B_INT
X
,
B_INT
Y
,
KBoolLine
*
other_line
)
void
KBoolLine
::
AddLineCrossing
(
B_INT
X
,
B_INT
Y
,
KBoolLine
*
other_line
)
{
{
// the other line must exist
// the other line must exist
assert
(
other_line
);
assert
(
other_line
);
// the links of the lines must exist
// the links of the lines must exist
assert
(
other_line
->
m_link
&&
m_link
);
assert
(
other_line
->
m_link
&&
m_link
);
other_line
->
AddCrossing
(
AddCrossing
(
X
,
Y
)
);
other_line
->
AddCrossing
(
AddCrossing
(
X
,
Y
)
);
}
}
// Calculate the Y when the X is given
// Calculate the Y when the X is given
//
//
B_INT
KBoolLine
::
Calculate_Y
(
B_INT
X
)
B_INT
KBoolLine
::
Calculate_Y
(
B_INT
X
)
{
{
// link must exist to get info about the nodes
// link must exist to get info about the nodes
assert
(
m_link
);
assert
(
m_link
);
CalculateLineParameters
();
CalculateLineParameters
();
if
(
m_AA
!=
0
)
if
(
m_AA
!=
0
)
return
(
B_INT
)(
-
(
m_AA
*
X
+
m_CC
)
/
m_BB
);
return
(
B_INT
)(
-
(
m_AA
*
X
+
m_CC
)
/
m_BB
);
else
else
// horizontal line
// horizontal line
return
m_link
->
GetBeginNode
()
->
GetY
();
return
m_link
->
GetBeginNode
()
->
GetY
();
}
}
B_INT
KBoolLine
::
Calculate_Y_from_X
(
B_INT
X
)
B_INT
KBoolLine
::
Calculate_Y_from_X
(
B_INT
X
)
{
{
// link must exist to get info about the nodes
// link must exist to get info about the nodes
assert
(
m_link
);
assert
(
m_link
);
assert
(
m_valid_parameters
);
assert
(
m_valid_parameters
);
if
(
m_AA
!=
0
)
if
(
m_AA
!=
0
)
return
(
B_INT
)
((
-
(
m_AA
*
X
+
m_CC
)
/
m_BB
)
+
0.5
);
return
(
B_INT
)
(
(
-
(
m_AA
*
X
+
m_CC
)
/
m_BB
)
+
0.5
);
else
else
// horizontal line
// horizontal line
return
m_link
->
GetBeginNode
()
->
GetY
();
return
m_link
->
GetBeginNode
()
->
GetY
();
}
}
void
KBoolLine
::
Virtual_Point
(
LPoint
*
a_point
,
double
distance
)
void
KBoolLine
::
Virtual_Point
(
LPoint
*
a_point
,
double
distance
)
{
{
// link must exist to get info about the nodes
// link must exist to get info about the nodes
assert
(
m_link
);
assert
(
m_link
);
assert
(
m_valid_parameters
);
assert
(
m_valid_parameters
);
//calculate the distance using the slope of the line
//calculate the distance using the slope of the line
//and rotate 90 degrees
//and rotate 90 degrees
a_point
->
SetY
((
B_INT
)(
a_point
->
GetY
()
+
(
distance
*
-
(
m_BB
)))
);
a_point
->
SetY
(
(
B_INT
)(
a_point
->
GetY
()
+
(
distance
*
-
(
m_BB
)
)
)
);
a_point
->
SetX
((
B_INT
)(
a_point
->
GetX
()
-
(
distance
*
m_AA
))
);
a_point
->
SetX
(
(
B_INT
)(
a_point
->
GetX
()
-
(
distance
*
m_AA
)
)
);
}
}
...
@@ -355,12 +348,12 @@ void KBoolLine::Virtual_Point(LPoint *a_point,double distance)
...
@@ -355,12 +348,12 @@ void KBoolLine::Virtual_Point(LPoint *a_point,double distance)
void
KBoolLine
::
CalculateLineParameters
()
void
KBoolLine
::
CalculateLineParameters
()
{
{
// linkmust exist to get beginnode AND endnode
// linkmust exist to get beginnode AND endnode
assert
(
m_link
);
assert
(
m_link
);
// if not valid_parameters calculate the parameters
// if not valid_parameters calculate the parameters
if
(
!
m_valid_parameters
)
if
(
!
m_valid_parameters
)
{
{
Node
*
bp
,
*
ep
;
Node
*
bp
,
*
ep
;
double
length
;
double
length
;
// get the begin and endnode via the link
// get the begin and endnode via the link
...
@@ -368,22 +361,22 @@ void KBoolLine::CalculateLineParameters()
...
@@ -368,22 +361,22 @@ void KBoolLine::CalculateLineParameters()
ep
=
m_link
->
GetEndNode
();
ep
=
m_link
->
GetEndNode
();
// bp AND ep may not be the same
// bp AND ep may not be the same
if
(
bp
==
ep
)
if
(
bp
==
ep
)
assert
(
bp
!=
ep
);
assert
(
bp
!=
ep
);
m_AA
=
(
double
)
(
ep
->
GetY
()
-
bp
->
GetY
()
);
// A = (Y2-Y1)
m_AA
=
(
double
)
(
ep
->
GetY
()
-
bp
->
GetY
()
);
// A = (Y2-Y1)
m_BB
=
(
double
)
(
bp
->
GetX
()
-
ep
->
GetX
()
);
// B = (X1-X2)
m_BB
=
(
double
)
(
bp
->
GetX
()
-
ep
->
GetX
()
);
// B = (X1-X2)
// the parameters A end B can now be normalized
// the parameters A end B can now be normalized
length
=
sqrt
(
m_AA
*
m_AA
+
m_BB
*
m_BB
);
length
=
sqrt
(
m_AA
*
m_AA
+
m_BB
*
m_BB
);
if
(
length
==
0
)
if
(
length
==
0
)
m_GC
->
error
(
"length = 0"
,
"CalculateLineParameters"
);
m_GC
->
error
(
"length = 0"
,
"CalculateLineParameters"
);
m_AA
=
(
m_AA
/
length
);
m_AA
=
(
m_AA
/
length
);
m_BB
=
(
m_BB
/
length
);
m_BB
=
(
m_BB
/
length
);
m_CC
=
-
((
m_AA
*
bp
->
GetX
())
+
(
bp
->
GetY
()
*
m_BB
)
);
m_CC
=
-
(
(
m_AA
*
bp
->
GetX
()
)
+
(
bp
->
GetY
()
*
m_BB
)
);
m_valid_parameters
=
true
;
m_valid_parameters
=
true
;
}
}
...
@@ -397,45 +390,47 @@ void KBoolLine::CalculateLineParameters()
...
@@ -397,45 +390,47 @@ void KBoolLine::CalculateLineParameters()
// return true : lines are crossing
// return true : lines are crossing
// false: lines are not crossing
// false: lines are not crossing
//
//
int
KBoolLine
::
CheckIntersect
(
KBoolLine
*
lijn
,
double
Marge
)
int
KBoolLine
::
CheckIntersect
(
KBoolLine
*
lijn
,
double
Marge
)
{
{
double
distance
=
0
;
double
distance
=
0
;
// link must exist
// link must exist
assert
(
m_link
);
assert
(
m_link
);
// lijn must exist
// lijn must exist
assert
(
lijn
);
assert
(
lijn
);
// points may not be equal
// points may not be equal
// must be an if statement because if an assert is used there will
// must be an if statement because if an assert is used there will
// be a macro expansion error
// be a macro expansion error
if
(
m_link
->
GetBeginNode
()
==
m_link
->
GetEndNode
()
)
if
(
m_link
->
GetBeginNode
()
==
m_link
->
GetEndNode
()
)
assert
(
!
m_link
);
assert
(
!
m_link
);
int
Take_Action1
,
Take_Action2
,
Total_Result
;
int
Take_Action1
,
Take_Action2
,
Total_Result
;
Node
*
bp
,
*
ep
;
Node
*
bp
,
*
ep
;
PointStatus
Result_beginnode
,
Result_endnode
;
PointStatus
Result_beginnode
,
Result_endnode
;
bp
=
lijn
->
m_link
->
GetBeginNode
();
bp
=
lijn
->
m_link
->
GetBeginNode
();
ep
=
lijn
->
m_link
->
GetEndNode
();
ep
=
lijn
->
m_link
->
GetEndNode
();
Result_beginnode
=
PointInLine
(
bp
,
distance
,
Marge
);
Result_beginnode
=
PointInLine
(
bp
,
distance
,
Marge
);
Result_endnode
=
PointInLine
(
ep
,
distance
,
Marge
);
Result_endnode
=
PointInLine
(
ep
,
distance
,
Marge
);
Take_Action1
=
ActionOnTable1
(
Result_beginnode
,
Result_endnode
);
Take_Action1
=
ActionOnTable1
(
Result_beginnode
,
Result_endnode
);
switch
(
Take_Action1
)
switch
(
Take_Action1
)
{
{
case
0
:
Total_Result
=
false
;
break
;
case
0
:
Total_Result
=
false
;
break
;
case
1
:
{
case
1
:
{
bp
=
m_link
->
GetBeginNode
();
bp
=
m_link
->
GetBeginNode
();
ep
=
m_link
->
GetEndNode
();
ep
=
m_link
->
GetEndNode
();
Result_beginnode
=
lijn
->
PointInLine
(
bp
,
distance
,
Marge
);
Result_beginnode
=
lijn
->
PointInLine
(
bp
,
distance
,
Marge
);
Result_endnode
=
lijn
->
PointInLine
(
ep
,
distance
,
Marge
);
Result_endnode
=
lijn
->
PointInLine
(
ep
,
distance
,
Marge
);
Take_Action2
=
ActionOnTable2
(
Result_beginnode
,
Result_endnode
);
Take_Action2
=
ActionOnTable2
(
Result_beginnode
,
Result_endnode
);
switch
(
Take_Action2
)
switch
(
Take_Action2
)
{
{
case
0
:
Total_Result
=
false
;
break
;
case
0
:
Total_Result
=
false
;
break
;
case
1
:
case
2
:
case
3
:
case
4
:
Total_Result
=
true
;
break
;
case
1
:
case
2
:
case
3
:
case
4
:
Total_Result
=
true
;
break
;
default
:
Total_Result
=
false
;
assert
(
Total_Result
);
default
:
Total_Result
=
false
;
assert
(
Total_Result
);
}
}
};
break
;
// This break belongs to the switch(Take_Action1)
}
;
break
;
// This break belongs to the switch(Take_Action1)
case
2
:
case
3
:
case
4
:
case
5
:
case
6
:
Total_Result
=
true
;
break
;
case
2
:
case
3
:
case
4
:
case
5
:
case
6
:
Total_Result
=
true
;
break
;
default
:
Total_Result
=
false
;
assert
(
Total_Result
);
default
:
Total_Result
=
false
;
assert
(
Total_Result
);
}
}
...
@@ -450,7 +445,7 @@ int KBoolLine::CheckIntersect (KBoolLine * lijn, double Marge)
...
@@ -450,7 +445,7 @@ int KBoolLine::CheckIntersect (KBoolLine * lijn, double Marge)
Node
*
KBoolLine
::
GetBeginNode
()
Node
*
KBoolLine
::
GetBeginNode
()
{
{
// link must exist
// link must exist
assert
(
m_link
);
assert
(
m_link
);
return
m_link
->
GetBeginNode
();
return
m_link
->
GetBeginNode
();
}
}
...
@@ -462,7 +457,7 @@ Node *KBoolLine::GetBeginNode()
...
@@ -462,7 +457,7 @@ Node *KBoolLine::GetBeginNode()
Node
*
KBoolLine
::
GetEndNode
()
Node
*
KBoolLine
::
GetEndNode
()
{
{
// link must exist
// link must exist
assert
(
m_link
);
assert
(
m_link
);
return
m_link
->
GetEndNode
();
return
m_link
->
GetEndNode
();
}
}
...
@@ -473,129 +468,131 @@ Node *KBoolLine::GetEndNode()
...
@@ -473,129 +468,131 @@ Node *KBoolLine::GetEndNode()
// return 0: If there are no crossings
// return 0: If there are no crossings
// 1: If there is one crossing
// 1: If there is one crossing
// 2: If there are two crossings
// 2: If there are two crossings
int
KBoolLine
::
Intersect
(
KBoolLine
*
lijn
,
double
Marge
)
int
KBoolLine
::
Intersect
(
KBoolLine
*
lijn
,
double
Marge
)
{
{
double
distance
=
0
;
double
distance
=
0
;
// lijn must exist
// lijn must exist
assert
(
lijn
);
assert
(
lijn
);
// points may not be equal
// points may not be equal
// must be an if statement because if an assert is used there will
// must be an if statement because if an assert is used there will
// be a macro expansion error
// be a macro expansion error
if
(
m_link
->
GetBeginNode
()
==
m_link
->
GetEndNode
()
)
if
(
m_link
->
GetBeginNode
()
==
m_link
->
GetEndNode
()
)
assert
(
!
m_link
);
assert
(
!
m_link
);
Node
*
bp
,
*
ep
;
Node
*
bp
,
*
ep
;
PointStatus
Result_beginnode
,
Result_endnode
;
PointStatus
Result_beginnode
,
Result_endnode
;
int
Take_Action1
,
Take_Action2
,
Number_of_Crossings
=
0
;
int
Take_Action1
,
Take_Action2
,
Number_of_Crossings
=
0
;
// Get the nodes from lijn via the link
// Get the nodes from lijn via the link
bp
=
lijn
->
m_link
->
GetBeginNode
();
bp
=
lijn
->
m_link
->
GetBeginNode
();
ep
=
lijn
->
m_link
->
GetEndNode
();
ep
=
lijn
->
m_link
->
GetEndNode
();
Result_beginnode
=
PointInLine
(
bp
,
distance
,
Marge
);
Result_beginnode
=
PointInLine
(
bp
,
distance
,
Marge
);
Result_endnode
=
PointInLine
(
ep
,
distance
,
Marge
);
Result_endnode
=
PointInLine
(
ep
,
distance
,
Marge
);
Take_Action1
=
ActionOnTable1
(
Result_beginnode
,
Result_endnode
);
Take_Action1
=
ActionOnTable1
(
Result_beginnode
,
Result_endnode
);
// The first switch will insert a crosspoint immediatly
// The first switch will insert a crosspoint immediatly
switch
(
Take_Action1
)
switch
(
Take_Action1
)
{
{
// for the cases see the returnvalue of ActionTable1
// for the cases see the returnvalue of ActionTable1
case
2
:
case
6
:
AddCrossing
(
ep
);
case
2
:
case
6
:
AddCrossing
(
ep
);
Number_of_Crossings
=
1
;
Number_of_Crossings
=
1
;
break
;
break
;
case
3
:
case
5
:
AddCrossing
(
bp
);
case
3
:
case
5
:
AddCrossing
(
bp
);
Number_of_Crossings
=
1
;
Number_of_Crossings
=
1
;
break
;
break
;
case
4
:
AddCrossing
(
bp
);
case
4
:
AddCrossing
(
bp
);
AddCrossing
(
ep
);
AddCrossing
(
ep
);
Number_of_Crossings
=
2
;
Number_of_Crossings
=
2
;
break
;
break
;
}
}
// This switch wil investigate the points of this line in relation to lijn
// This switch wil investigate the points of this line in relation to lijn
switch
(
Take_Action1
)
switch
(
Take_Action1
)
{
{
// for the cases see the returnvalue of ActionTable1
// for the cases see the returnvalue of ActionTable1
case
1
:
case
5
:
case
6
:
case
1
:
case
5
:
case
6
:
{
{
// Get the nodes from this line via the link
// Get the nodes from this line via the link
bp
=
m_link
->
GetBeginNode
();
bp
=
m_link
->
GetBeginNode
();
ep
=
m_link
->
GetEndNode
();
ep
=
m_link
->
GetEndNode
();
Result_beginnode
=
lijn
->
PointInLine
(
bp
,
distance
,
Marge
);
Result_beginnode
=
lijn
->
PointInLine
(
bp
,
distance
,
Marge
);
Result_endnode
=
lijn
->
PointInLine
(
ep
,
distance
,
Marge
);
Result_endnode
=
lijn
->
PointInLine
(
ep
,
distance
,
Marge
);
Take_Action2
=
ActionOnTable2
(
Result_beginnode
,
Result_endnode
);
Take_Action2
=
ActionOnTable2
(
Result_beginnode
,
Result_endnode
);
switch
(
Take_Action2
)
switch
(
Take_Action2
)
{
{
// for the cases see the returnvalue of ActionTable2
// for the cases see the returnvalue of ActionTable2
case
1
:
{
// begin of scope to calculate the intersection
case
1
:
{
// begin of scope to calculate the intersection
double
X
,
Y
,
Denominator
;
double
X
,
Y
,
Denominator
;
CalculateLineParameters
();
CalculateLineParameters
();
Denominator
=
(
m_AA
*
lijn
->
m_BB
)
-
(
lijn
->
m_AA
*
m_BB
);
Denominator
=
(
m_AA
*
lijn
->
m_BB
)
-
(
lijn
->
m_AA
*
m_BB
);
// Denominator may not be 0
// Denominator may not be 0
assert
(
Denominator
!=
0.0
);
assert
(
Denominator
!=
0.0
);
// Calculate intersection of both linesegments
// Calculate intersection of both linesegments
X
=
((
m_BB
*
lijn
->
m_CC
)
-
(
lijn
->
m_BB
*
m_CC
)
)
/
Denominator
;
X
=
(
(
m_BB
*
lijn
->
m_CC
)
-
(
lijn
->
m_BB
*
m_CC
)
)
/
Denominator
;
Y
=
((
lijn
->
m_AA
*
m_CC
)
-
(
m_AA
*
lijn
->
m_CC
)
)
/
Denominator
;
Y
=
(
(
lijn
->
m_AA
*
m_CC
)
-
(
m_AA
*
lijn
->
m_CC
)
)
/
Denominator
;
//make a decent rounding to B_INT
//make a decent rounding to B_INT
AddLineCrossing
((
B_INT
)
X
,(
B_INT
)
Y
,
lijn
);
AddLineCrossing
(
(
B_INT
)
X
,
(
B_INT
)
Y
,
lijn
);
}
// end of scope to calculate the intersection
}
// end of scope to calculate the intersection
Number_of_Crossings
++
;
Number_of_Crossings
++
;
break
;
break
;
case
2
:
lijn
->
AddCrossing
(
ep
);
case
2
:
lijn
->
AddCrossing
(
ep
);
Number_of_Crossings
++
;
Number_of_Crossings
++
;
break
;
break
;
case
3
:
lijn
->
AddCrossing
(
bp
);
case
3
:
lijn
->
AddCrossing
(
bp
);
Number_of_Crossings
++
;
Number_of_Crossings
++
;
break
;
break
;
case
4
:
lijn
->
AddCrossing
(
bp
);
case
4
:
lijn
->
AddCrossing
(
bp
);
lijn
->
AddCrossing
(
ep
);
lijn
->
AddCrossing
(
ep
);
Number_of_Crossings
=
2
;
Number_of_Crossings
=
2
;
break
;
break
;
}
}
};
break
;
// This break belongs to the outer switch
}
;
break
;
// This break belongs to the outer switch
}
}
return
Number_of_Crossings
;
//This is de final number of crossings
return
Number_of_Crossings
;
//This is de final number of crossings
}
}
// Intersects two lines there must be a crossing
// Intersects two lines there must be a crossing
int
KBoolLine
::
Intersect_simple
(
KBoolLine
*
lijn
)
int
KBoolLine
::
Intersect_simple
(
KBoolLine
*
lijn
)
{
{
// lijn must exist
// lijn must exist
assert
(
lijn
);
assert
(
lijn
);
double
X
,
Y
,
Denominator
;
double
X
,
Y
,
Denominator
;
Denominator
=
(
m_AA
*
lijn
->
m_BB
)
-
(
lijn
->
m_AA
*
m_BB
);
Denominator
=
(
m_AA
*
lijn
->
m_BB
)
-
(
lijn
->
m_AA
*
m_BB
);
// Denominator may not be 0
// Denominator may not be 0
if
(
Denominator
==
0.0
)
if
(
Denominator
==
0.0
)
m_GC
->
error
(
"colliniar lines"
,
"line"
);
m_GC
->
error
(
"colliniar lines"
,
"line"
);
// Calculate intersection of both linesegments
// Calculate intersection of both linesegments
X
=
((
m_BB
*
lijn
->
m_CC
)
-
(
lijn
->
m_BB
*
m_CC
)
)
/
Denominator
;
X
=
(
(
m_BB
*
lijn
->
m_CC
)
-
(
lijn
->
m_BB
*
m_CC
)
)
/
Denominator
;
Y
=
((
lijn
->
m_AA
*
m_CC
)
-
(
m_AA
*
lijn
->
m_CC
)
)
/
Denominator
;
Y
=
(
(
lijn
->
m_AA
*
m_CC
)
-
(
m_AA
*
lijn
->
m_CC
)
)
/
Denominator
;
AddLineCrossing
((
B_INT
)
X
,(
B_INT
)
Y
,
lijn
);
AddLineCrossing
(
(
B_INT
)
X
,
(
B_INT
)
Y
,
lijn
);
return
(
0
);
return
(
0
);
}
}
// Intersects two lines there must be a crossing
// Intersects two lines there must be a crossing
bool
KBoolLine
::
Intersect2
(
Node
*
crossing
,
KBoolLine
*
lijn
)
bool
KBoolLine
::
Intersect2
(
Node
*
crossing
,
KBoolLine
*
lijn
)
{
{
// lijn must exist
// lijn must exist
assert
(
lijn
);
assert
(
lijn
);
double
X
,
Y
,
Denominator
;
double
X
,
Y
,
Denominator
;
Denominator
=
(
m_AA
*
lijn
->
m_BB
)
-
(
lijn
->
m_AA
*
m_BB
);
Denominator
=
(
m_AA
*
lijn
->
m_BB
)
-
(
lijn
->
m_AA
*
m_BB
);
// Denominator may not be 0
// Denominator may not be 0
if
(
Denominator
==
0.0
)
if
(
Denominator
==
0.0
)
return
false
;
return
false
;
// Calculate intersection of both linesegments
// Calculate intersection of both linesegments
X
=
((
m_BB
*
lijn
->
m_CC
)
-
(
lijn
->
m_BB
*
m_CC
)
)
/
Denominator
;
X
=
(
(
m_BB
*
lijn
->
m_CC
)
-
(
lijn
->
m_BB
*
m_CC
)
)
/
Denominator
;
Y
=
((
lijn
->
m_AA
*
m_CC
)
-
(
m_AA
*
lijn
->
m_CC
)
)
/
Denominator
;
Y
=
(
(
lijn
->
m_AA
*
m_CC
)
-
(
m_AA
*
lijn
->
m_CC
)
)
/
Denominator
;
crossing
->
SetX
((
B_INT
)
X
);
crossing
->
SetX
(
(
B_INT
)
X
);
crossing
->
SetY
((
B_INT
)
Y
);
crossing
->
SetY
(
(
B_INT
)
Y
);
return
true
;
return
true
;
}
}
...
@@ -609,14 +606,14 @@ bool KBoolLine::Intersect2(Node* crossing,KBoolLine * lijn)
...
@@ -609,14 +606,14 @@ bool KBoolLine::Intersect2(Node* crossing,KBoolLine * lijn)
// ON_AREA, when point lies on the infinite line within a range
// ON_AREA, when point lies on the infinite line within a range
// IN_AREA, when point lies in the area of the linesegment
// IN_AREA, when point lies in the area of the linesegment
// the returnvalues are declared in (LINE.H)
// the returnvalues are declared in (LINE.H)
PointStatus
KBoolLine
::
PointInLine
(
Node
*
a_node
,
double
&
Distance
,
double
Marge
)
PointStatus
KBoolLine
::
PointInLine
(
Node
*
a_node
,
double
&
Distance
,
double
Marge
)
{
{
Distance
=
0
;
Distance
=
0
;
//Punt must exist
//Punt must exist
assert
(
a_node
);
assert
(
a_node
);
// link must exist to get beginnode and endnode via link
// link must exist to get beginnode and endnode via link
assert
(
m_link
);
assert
(
m_link
);
// get the nodes form the line via the link
// get the nodes form the line via the link
Node
*
bp
,
*
ep
;
Node
*
bp
,
*
ep
;
...
@@ -624,32 +621,32 @@ PointStatus KBoolLine::PointInLine(Node *a_node, double& Distance, double Marge)
...
@@ -624,32 +621,32 @@ PointStatus KBoolLine::PointInLine(Node *a_node, double& Distance, double Marge)
ep
=
m_link
->
GetEndNode
();
ep
=
m_link
->
GetEndNode
();
// both node must exist
// both node must exist
assert
(
bp
&&
ep
);
assert
(
bp
&&
ep
);
// node may not be the same
// node may not be the same
assert
(
bp
!=
ep
);
assert
(
bp
!=
ep
);
//quick test if point is begin or endpoint
//quick test if point is begin or endpoint
if
(
a_node
==
bp
||
a_node
==
ep
)
if
(
a_node
==
bp
||
a_node
==
ep
)
return
IN_AREA
;
return
IN_AREA
;
int
Result_of_BBox
=
false
;
int
Result_of_BBox
=
false
;
PointStatus
Result_of_Online
;
PointStatus
Result_of_Online
;
// Checking if point is in bounding-box with marge
// Checking if point is in bounding-box with marge
B_INT
xmin
=
bmin
(
bp
->
GetX
(),
ep
->
GetX
()
);
B_INT
xmin
=
bmin
(
bp
->
GetX
(),
ep
->
GetX
()
);
B_INT
xmax
=
bmax
(
bp
->
GetX
(),
ep
->
GetX
()
);
B_INT
xmax
=
bmax
(
bp
->
GetX
(),
ep
->
GetX
()
);
B_INT
ymin
=
bmin
(
bp
->
GetY
(),
ep
->
GetY
()
);
B_INT
ymin
=
bmin
(
bp
->
GetY
(),
ep
->
GetY
()
);
B_INT
ymax
=
bmax
(
bp
->
GetY
(),
ep
->
GetY
()
);
B_INT
ymax
=
bmax
(
bp
->
GetY
(),
ep
->
GetY
()
);
if
(
a_node
->
GetX
()
>=
(
xmin
-
Marge
)
&&
a_node
->
GetX
()
<=
(
xmax
+
Marge
)
&&
if
(
a_node
->
GetX
()
>=
(
xmin
-
Marge
)
&&
a_node
->
GetX
()
<=
(
xmax
+
Marge
)
&&
a_node
->
GetY
()
>=
(
ymin
-
Marge
)
&&
a_node
->
GetY
()
<=
(
ymax
+
Marge
)
)
a_node
->
GetY
()
>=
(
ymin
-
Marge
)
&&
a_node
->
GetY
()
<=
(
ymax
+
Marge
)
)
Result_of_BBox
=
true
;
Result_of_BBox
=
true
;
// Checking if point is on the infinite line
// Checking if point is on the infinite line
Result_of_Online
=
PointOnLine
(
a_node
,
Distance
,
Marge
);
Result_of_Online
=
PointOnLine
(
a_node
,
Distance
,
Marge
);
// point in boundingbox of the line and is on the line then the point is IN_AREA
// point in boundingbox of the line and is on the line then the point is IN_AREA
if
((
Result_of_BBox
)
&&
(
Result_of_Online
==
ON_AREA
)
)
if
(
(
Result_of_BBox
)
&&
(
Result_of_Online
==
ON_AREA
)
)
return
IN_AREA
;
return
IN_AREA
;
else
else
return
Result_of_Online
;
return
Result_of_Online
;
...
@@ -665,14 +662,14 @@ PointStatus KBoolLine::PointInLine(Node *a_node, double& Distance, double Marge)
...
@@ -665,14 +662,14 @@ PointStatus KBoolLine::PointInLine(Node *a_node, double& Distance, double Marge)
// ON_AREA, when point lies on the infinite line within a range
// ON_AREA, when point lies on the infinite line within a range
// RIGHT_SIDE, when point lies on the right side of the line
// RIGHT_SIDE, when point lies on the right side of the line
// LEFT_SIDE , RIGHT_SIDE , ON_AREA
// LEFT_SIDE , RIGHT_SIDE , ON_AREA
PointStatus
KBoolLine
::
PointOnLine
(
Node
*
a_node
,
double
&
Distance
,
double
Marge
)
PointStatus
KBoolLine
::
PointOnLine
(
Node
*
a_node
,
double
&
Distance
,
double
Marge
)
{
{
Distance
=
0
;
Distance
=
0
;
// a_node must exist
// a_node must exist
assert
(
a_node
);
assert
(
a_node
);
// link must exist to get beginnode and endnode
// link must exist to get beginnode and endnode
assert
(
m_link
);
assert
(
m_link
);
// get the nodes from the line via the link
// get the nodes from the line via the link
Node
*
bp
,
*
ep
;
Node
*
bp
,
*
ep
;
...
@@ -680,23 +677,23 @@ PointStatus KBoolLine::PointOnLine(Node *a_node, double& Distance, double Marge)
...
@@ -680,23 +677,23 @@ PointStatus KBoolLine::PointOnLine(Node *a_node, double& Distance, double Marge)
ep
=
m_link
->
GetEndNode
();
ep
=
m_link
->
GetEndNode
();
// both node must exist
// both node must exist
assert
(
bp
&&
ep
);
assert
(
bp
&&
ep
);
// node may not be queal
// node may not be queal
assert
(
bp
!=
ep
);
assert
(
bp
!=
ep
);
//quick test if point is begin or endpoint
//quick test if point is begin or endpoint
if
(
a_node
==
bp
||
a_node
==
ep
)
if
(
a_node
==
bp
||
a_node
==
ep
)
return
ON_AREA
;
return
ON_AREA
;
CalculateLineParameters
();
CalculateLineParameters
();
// calculate the distance of a_node in relation to the line
// calculate the distance of a_node in relation to the line
Distance
=
(
m_AA
*
a_node
->
GetX
())
+
(
m_BB
*
a_node
->
GetY
()
)
+
m_CC
;
Distance
=
(
m_AA
*
a_node
->
GetX
()
)
+
(
m_BB
*
a_node
->
GetY
()
)
+
m_CC
;
if
(
Distance
<
-
Marge
)
if
(
Distance
<
-
Marge
)
return
LEFT_SIDE
;
return
LEFT_SIDE
;
else
else
{
{
if
(
Distance
>
Marge
)
if
(
Distance
>
Marge
)
return
RIGHT_SIDE
;
return
RIGHT_SIDE
;
else
else
return
ON_AREA
;
return
ON_AREA
;
...
@@ -708,10 +705,10 @@ PointStatus KBoolLine::PointOnLine(Node *a_node, double& Distance, double Marge)
...
@@ -708,10 +705,10 @@ PointStatus KBoolLine::PointOnLine(Node *a_node, double& Distance, double Marge)
// Sets lines parameters
// Sets lines parameters
// usage: a_line.Set(a_pointer_to_a_link);
// usage: a_line.Set(a_pointer_to_a_link);
//
//
void
KBoolLine
::
Set
(
KBoolLink
*
a_link
)
void
KBoolLine
::
Set
(
KBoolLink
*
a_link
)
{
{
// points must exist
// points must exist
assert
(
a_link
);
assert
(
a_link
);
// points may not be equal
// points may not be equal
// must be an if statement because if an assert is used there will
// must be an if statement because if an assert is used there will
// be a macro expansion error
// be a macro expansion error
...
@@ -730,7 +727,7 @@ KBoolLink* KBoolLine::GetLink()
...
@@ -730,7 +727,7 @@ KBoolLink* KBoolLine::GetLink()
// makes a line same as these
// makes a line same as these
// usage : line1 = line2;
// usage : line1 = line2;
//
//
KBoolLine
&
KBoolLine
::
operator
=
(
const
KBoolLine
&
a_line
)
KBoolLine
&
KBoolLine
::
operator
=
(
const
KBoolLine
&
a_line
)
{
{
m_AA
=
a_line
.
m_AA
;
m_AA
=
a_line
.
m_AA
;
m_BB
=
a_line
.
m_BB
;
m_BB
=
a_line
.
m_BB
;
...
@@ -741,185 +738,187 @@ KBoolLine& KBoolLine::operator=(const KBoolLine& a_line)
...
@@ -741,185 +738,187 @@ KBoolLine& KBoolLine::operator=(const KBoolLine& a_line)
return
*
this
;
return
*
this
;
}
}
Node
*
KBoolLine
::
OffsetContour
(
KBoolLine
*
const
nextline
,
Node
*
_last_ins
,
double
factor
,
Graph
*
shape
)
Node
*
KBoolLine
::
OffsetContour
(
KBoolLine
*
const
nextline
,
Node
*
_last_ins
,
double
factor
,
Graph
*
shape
)
{
{
KBoolLink
*
offs_currentlink
;
KBoolLink
*
offs_currentlink
;
KBoolLine
offs_currentline
(
m_GC
);
KBoolLine
offs_currentline
(
m_GC
);
KBoolLink
*
offs_nextlink
;
KBoolLink
*
offs_nextlink
;
KBoolLine
offs_nextline
(
m_GC
);
KBoolLine
offs_nextline
(
m_GC
);
Node
*
offs_end
;
Node
*
offs_end
;
Node
*
offs_bgn_next
;
Node
*
offs_bgn_next
;
Node
*
offs_end_next
;
Node
*
offs_end_next
;
// make a node from this point
// make a node from this point
offs_end
=
new
Node
(
GetEndNode
(),
m_GC
);
offs_end
=
new
Node
(
GetEndNode
(),
m_GC
);
Virtual_Point
(
offs_end
,
factor
);
Virtual_Point
(
offs_end
,
factor
);
offs_currentlink
=
new
KBoolLink
(
0
,
_last_ins
,
offs_end
,
m_GC
);
offs_currentlink
=
new
KBoolLink
(
0
,
_last_ins
,
offs_end
,
m_GC
);
offs_currentline
.
Set
(
offs_currentlink
);
offs_currentline
.
Set
(
offs_currentlink
);
offs_bgn_next
=
new
Node
(
nextline
->
m_link
->
GetBeginNode
(),
m_GC
);
offs_bgn_next
=
new
Node
(
nextline
->
m_link
->
GetBeginNode
(),
m_GC
);
nextline
->
Virtual_Point
(
offs_bgn_next
,
factor
);
nextline
->
Virtual_Point
(
offs_bgn_next
,
factor
);
offs_end_next
=
new
Node
(
nextline
->
m_link
->
GetEndNode
(),
m_GC
);
offs_end_next
=
new
Node
(
nextline
->
m_link
->
GetEndNode
(),
m_GC
);
nextline
->
Virtual_Point
(
offs_end_next
,
factor
);
nextline
->
Virtual_Point
(
offs_end_next
,
factor
);
offs_nextlink
=
new
KBoolLink
(
0
,
offs_bgn_next
,
offs_end_next
,
m_GC
);
offs_nextlink
=
new
KBoolLink
(
0
,
offs_bgn_next
,
offs_end_next
,
m_GC
);
offs_nextline
.
Set
(
offs_nextlink
);
offs_nextline
.
Set
(
offs_nextlink
);
offs_currentline
.
CalculateLineParameters
();
offs_currentline
.
CalculateLineParameters
();
offs_nextline
.
CalculateLineParameters
();
offs_nextline
.
CalculateLineParameters
();
offs_currentline
.
Intersect2
(
offs_end
,
&
offs_nextline
);
offs_currentline
.
Intersect2
(
offs_end
,
&
offs_nextline
);
// make a link between the current and the previous and add this to graph
// make a link between the current and the previous and add this to graph
shape
->
AddLink
(
offs_currentlink
);
shape
->
AddLink
(
offs_currentlink
);
delete
offs_nextlink
;
delete
offs_nextlink
;
return
(
offs_end
);
return
(
offs_end
);
}
}
Node
*
KBoolLine
::
OffsetContour_rounded
(
KBoolLine
*
const
nextline
,
Node
*
_last_ins
,
double
factor
,
Graph
*
shape
)
Node
*
KBoolLine
::
OffsetContour_rounded
(
KBoolLine
*
const
nextline
,
Node
*
_last_ins
,
double
factor
,
Graph
*
shape
)
{
{
KBoolLink
*
offs_currentlink
;
KBoolLink
*
offs_currentlink
;
KBoolLine
offs_currentline
(
m_GC
);
KBoolLine
offs_currentline
(
m_GC
);
KBoolLink
*
offs_nextlink
;
KBoolLink
*
offs_nextlink
;
KBoolLine
offs_nextline
(
m_GC
);
KBoolLine
offs_nextline
(
m_GC
);
Node
*
offs_end
;
Node
*
offs_end
;
Node
*
medial_axes_point
=
new
Node
(
m_GC
);
Node
*
medial_axes_point
=
new
Node
(
m_GC
);
Node
*
bu_last_ins
=
new
Node
(
_last_ins
,
m_GC
);
Node
*
bu_last_ins
=
new
Node
(
_last_ins
,
m_GC
);
Node
*
offs_bgn_next
;
Node
*
offs_bgn_next
;
Node
*
offs_end_next
;
Node
*
offs_end_next
;
// make a node from this point
// make a node from this point
offs_end
=
new
Node
(
GetEndNode
(),
m_GC
);
offs_end
=
new
Node
(
GetEndNode
(),
m_GC
);
*
_last_ins
=
*
GetBeginNode
();
*
_last_ins
=
*
GetBeginNode
();
Virtual_Point
(
_last_ins
,
factor
);
Virtual_Point
(
_last_ins
,
factor
);
Virtual_Point
(
offs_end
,
factor
);
Virtual_Point
(
offs_end
,
factor
);
offs_currentlink
=
new
KBoolLink
(
0
,
_last_ins
,
offs_end
,
m_GC
);
offs_currentlink
=
new
KBoolLink
(
0
,
_last_ins
,
offs_end
,
m_GC
);
offs_currentline
.
Set
(
offs_currentlink
);
offs_currentline
.
Set
(
offs_currentlink
);
offs_bgn_next
=
new
Node
(
nextline
->
m_link
->
GetBeginNode
(),
m_GC
);
offs_bgn_next
=
new
Node
(
nextline
->
m_link
->
GetBeginNode
(),
m_GC
);
nextline
->
Virtual_Point
(
offs_bgn_next
,
factor
);
nextline
->
Virtual_Point
(
offs_bgn_next
,
factor
);
offs_end_next
=
new
Node
(
nextline
->
m_link
->
GetEndNode
(),
m_GC
);
offs_end_next
=
new
Node
(
nextline
->
m_link
->
GetEndNode
(),
m_GC
);
nextline
->
Virtual_Point
(
offs_end_next
,
factor
);
nextline
->
Virtual_Point
(
offs_end_next
,
factor
);
offs_nextlink
=
new
KBoolLink
(
0
,
offs_bgn_next
,
offs_end_next
,
m_GC
);
offs_nextlink
=
new
KBoolLink
(
0
,
offs_bgn_next
,
offs_end_next
,
m_GC
);
offs_nextline
.
Set
(
offs_nextlink
);
offs_nextline
.
Set
(
offs_nextlink
);
offs_currentline
.
CalculateLineParameters
();
offs_currentline
.
CalculateLineParameters
();
offs_nextline
.
CalculateLineParameters
();
offs_nextline
.
CalculateLineParameters
();
offs_currentline
.
Intersect2
(
medial_axes_point
,
&
offs_nextline
);
offs_currentline
.
Intersect2
(
medial_axes_point
,
&
offs_nextline
);
double
result_offs
=
sqrt
(
pow
((
double
)
GetEndNode
()
->
GetY
()
-
medial_axes_point
->
GetY
(),
2
)
+
double
result_offs
=
sqrt
(
pow
(
(
double
)
GetEndNode
()
->
GetY
()
-
medial_axes_point
->
GetY
(),
2
)
+
pow
((
double
)
GetEndNode
()
->
GetX
()
-
medial_axes_point
->
GetX
(),
2
)
);
pow
(
(
double
)
GetEndNode
()
->
GetX
()
-
medial_axes_point
->
GetX
(),
2
)
);
if
(
result_offs
<
fabs
(
m_GC
->
GetRoundfactor
()
*
factor
)
)
if
(
result_offs
<
fabs
(
m_GC
->
GetRoundfactor
()
*
factor
)
)
{
{
*
_last_ins
=
*
bu_last_ins
;
*
_last_ins
=
*
bu_last_ins
;
*
offs_end
=
*
medial_axes_point
;
*
offs_end
=
*
medial_axes_point
;
delete
medial_axes_point
;
delete
medial_axes_point
;
delete
bu_last_ins
;
delete
bu_last_ins
;
// make a link between the current and the previous and add this to graph
// make a link between the current and the previous and add this to graph
delete
offs_nextlink
;
delete
offs_nextlink
;
shape
->
AddLink
(
offs_currentlink
);
shape
->
AddLink
(
offs_currentlink
);
return
(
offs_end
);
return
(
offs_end
);
}
}
else
else
{
//let us create a circle
{
//let us create a circle
*
_last_ins
=
*
bu_last_ins
;
*
_last_ins
=
*
bu_last_ins
;
delete
medial_axes_point
;
delete
medial_axes_point
;
delete
bu_last_ins
;
delete
bu_last_ins
;
Node
*
endarc
=
new
Node
(
offs_bgn_next
,
m_GC
);
Node
*
endarc
=
new
Node
(
offs_bgn_next
,
m_GC
);
shape
->
AddLink
(
offs_currentlink
);
shape
->
AddLink
(
offs_currentlink
);
delete
offs_nextlink
;
delete
offs_nextlink
;
shape
->
CreateArc
(
GetEndNode
(),
&
offs_currentline
,
endarc
,
fabs
(
factor
),
m_GC
->
GetInternalCorrectionAber
()
);
shape
->
CreateArc
(
GetEndNode
(),
&
offs_currentline
,
endarc
,
fabs
(
factor
),
m_GC
->
GetInternalCorrectionAber
()
);
return
(
endarc
);
return
(
endarc
);
}
}
}
}
bool
KBoolLine
::
OkeForContour
(
KBoolLine
*
const
nextline
,
double
factor
,
Node
*
LastLeft
,
Node
*
LastRight
,
LinkStatus
&
_outproduct
)
bool
KBoolLine
::
OkeForContour
(
KBoolLine
*
const
nextline
,
double
factor
,
Node
*
LastLeft
,
Node
*
LastRight
,
LinkStatus
&
_outproduct
)
{
{
assert
(
m_link
);
assert
(
m_link
);
assert
(
m_valid_parameters
);
assert
(
m_valid_parameters
);
assert
(
nextline
->
m_link
);
assert
(
nextline
->
m_link
);
assert
(
nextline
->
m_valid_parameters
);
assert
(
nextline
->
m_valid_parameters
);
factor
=
fabs
(
factor
);
factor
=
fabs
(
factor
);
// PointStatus status=ON_AREA;
// PointStatus status=ON_AREA;
double
distance
=
0
;
double
distance
=
0
;
Node
offs_end_next
(
nextline
->
m_link
->
GetEndNode
(),
m_GC
);
Node
offs_end_next
(
nextline
->
m_link
->
GetEndNode
(),
m_GC
);
_outproduct
=
m_link
->
OutProduct
(
nextline
->
m_link
,
m_GC
->
GetAccur
()
);
_outproduct
=
m_link
->
OutProduct
(
nextline
->
m_link
,
m_GC
->
GetAccur
()
);
switch
(
_outproduct
)
switch
(
_outproduct
)
{
{
// current line lies on leftside of prev line
// current line lies on leftside of prev line
case
IS_RIGHT
:
case
IS_RIGHT
:
{
{
nextline
->
Virtual_Point
(
&
offs_end_next
,
-
factor
);
nextline
->
Virtual_Point
(
&
offs_end_next
,
-
factor
);
// status=
// status=
nextline
->
PointOnLine
(
LastRight
,
distance
,
m_GC
->
GetAccur
());
nextline
->
PointOnLine
(
LastRight
,
distance
,
m_GC
->
GetAccur
()
);
if
(
distance
>
factor
)
if
(
distance
>
factor
)
{
PointOnLine
(
&
offs_end_next
,
distance
,
m_GC
->
GetAccur
());
{
if
(
distance
>
factor
)
PointOnLine
(
&
offs_end_next
,
distance
,
m_GC
->
GetAccur
()
);
return
(
true
);
if
(
distance
>
factor
)
return
(
true
);
}
}
}
}
break
;
break
;
// current line lies on rightside of prev line
// current line lies on rightside of prev line
case
IS_LEFT
:
case
IS_LEFT
:
{
{
nextline
->
Virtual_Point
(
&
offs_end_next
,
factor
);
nextline
->
Virtual_Point
(
&
offs_end_next
,
factor
);
// status=
// status=
nextline
->
PointOnLine
(
LastLeft
,
distance
,
m_GC
->
GetAccur
());
nextline
->
PointOnLine
(
LastLeft
,
distance
,
m_GC
->
GetAccur
()
);
if
(
distance
<
-
factor
)
if
(
distance
<
-
factor
)
{
PointOnLine
(
&
offs_end_next
,
distance
,
m_GC
->
GetAccur
());
{
if
(
distance
<-
factor
)
PointOnLine
(
&
offs_end_next
,
distance
,
m_GC
->
GetAccur
()
);
return
(
true
);
if
(
distance
<
-
factor
)
return
(
true
);
}
}
}
}
break
;
break
;
// current line lies on prev line
// current line lies on prev line
case
IS_ON
:
case
IS_ON
:
{
{
return
(
true
);
return
(
true
);
}
}
}
//end switch
}
//end switch
return
(
false
);
return
(
false
);
}
}
bool
KBoolLine
::
Create_Ring_Shape
(
KBoolLine
*
nextline
,
Node
**
_last_ins_left
,
Node
**
_last_ins_right
,
double
factor
,
Graph
*
shape
)
bool
KBoolLine
::
Create_Ring_Shape
(
KBoolLine
*
nextline
,
Node
**
_last_ins_left
,
Node
**
_last_ins_right
,
double
factor
,
Graph
*
shape
)
{
{
Node
*
_current
;
Node
*
_current
;
LinkStatus
_outproduct
=
IS_ON
;
LinkStatus
_outproduct
=
IS_ON
;
if
(
OkeForContour
(
nextline
,
factor
,
*
_last_ins_left
,
*
_last_ins_right
,
_outproduct
)
)
if
(
OkeForContour
(
nextline
,
factor
,
*
_last_ins_left
,
*
_last_ins_right
,
_outproduct
)
)
{
{
switch
(
_outproduct
)
switch
(
_outproduct
)
{
{
// Line 2 lies on leftside of this line
// Line 2 lies on leftside of this line
case
IS_RIGHT
:
case
IS_RIGHT
:
{
{
*
_last_ins_left
=
OffsetContour_rounded
(
nextline
,
*
_last_ins_left
,
factor
,
shape
);
*
_last_ins_left
=
OffsetContour_rounded
(
nextline
,
*
_last_ins_left
,
factor
,
shape
);
*
_last_ins_right
=
OffsetContour
(
nextline
,
*
_last_ins_right
,
-
factor
,
shape
);
*
_last_ins_right
=
OffsetContour
(
nextline
,
*
_last_ins_right
,
-
factor
,
shape
);
}
}
break
;
break
;
case
IS_LEFT
:
case
IS_LEFT
:
{
{
*
_last_ins_left
=
OffsetContour
(
nextline
,
*
_last_ins_left
,
factor
,
shape
);
*
_last_ins_left
=
OffsetContour
(
nextline
,
*
_last_ins_left
,
factor
,
shape
);
*
_last_ins_right
=
OffsetContour_rounded
(
nextline
,
*
_last_ins_right
,
-
factor
,
shape
);
*
_last_ins_right
=
OffsetContour_rounded
(
nextline
,
*
_last_ins_right
,
-
factor
,
shape
);
}
}
break
;
break
;
...
@@ -927,24 +926,24 @@ bool KBoolLine::Create_Ring_Shape(KBoolLine* nextline,Node** _last_ins_left,Node
...
@@ -927,24 +926,24 @@ bool KBoolLine::Create_Ring_Shape(KBoolLine* nextline,Node** _last_ins_left,Node
case
IS_ON
:
case
IS_ON
:
{
{
// make a node from this point
// make a node from this point
_current
=
new
Node
(
m_link
->
GetEndNode
(),
m_GC
);
_current
=
new
Node
(
m_link
->
GetEndNode
(),
m_GC
);
Virtual_Point
(
_current
,
factor
);
Virtual_Point
(
_current
,
factor
);
// make a link between the current and the previous and add this to graph
// make a link between the current and the previous and add this to graph
shape
->
AddLink
(
*
_last_ins_left
,
_current
);
shape
->
AddLink
(
*
_last_ins_left
,
_current
);
*
_last_ins_left
=
_current
;
*
_last_ins_left
=
_current
;
_current
=
new
Node
(
m_link
->
GetEndNode
(),
m_GC
);
_current
=
new
Node
(
m_link
->
GetEndNode
(),
m_GC
);
Virtual_Point
(
_current
,
-
factor
);
Virtual_Point
(
_current
,
-
factor
);
shape
->
AddLink
(
*
_last_ins_right
,
_current
);
shape
->
AddLink
(
*
_last_ins_right
,
_current
);
*
_last_ins_right
=
_current
;
*
_last_ins_right
=
_current
;
}
}
break
;
break
;
}
//end switch
}
//end switch
return
(
true
);
return
(
true
);
}
}
/*
else
/*
else
{
{
switch (_outproduct)
switch (_outproduct)
{
{
...
@@ -983,107 +982,107 @@ bool KBoolLine::Create_Ring_Shape(KBoolLine* nextline,Node** _last_ins_left,Node
...
@@ -983,107 +982,107 @@ bool KBoolLine::Create_Ring_Shape(KBoolLine* nextline,Node** _last_ins_left,Node
}//end switch
}//end switch
return(true);
return(true);
}
}
*/
*/
return
(
false
);
return
(
false
);
}
}
void
KBoolLine
::
Create_Begin_Shape
(
KBoolLine
*
nextline
,
Node
**
_last_ins_left
,
Node
**
_last_ins_right
,
double
factor
,
Graph
*
shape
)
void
KBoolLine
::
Create_Begin_Shape
(
KBoolLine
*
nextline
,
Node
**
_last_ins_left
,
Node
**
_last_ins_right
,
double
factor
,
Graph
*
shape
)
{
{
factor
=
fabs
(
factor
);
factor
=
fabs
(
factor
);
LinkStatus
_outproduct
;
LinkStatus
_outproduct
;
_outproduct
=
m_link
->
OutProduct
(
nextline
->
m_link
,
m_GC
->
GetAccur
()
);
_outproduct
=
m_link
->
OutProduct
(
nextline
->
m_link
,
m_GC
->
GetAccur
()
);
switch
(
_outproduct
)
switch
(
_outproduct
)
{
{
case
IS_RIGHT
:
case
IS_RIGHT
:
{
{
*
_last_ins_left
=
new
Node
(
m_link
->
GetEndNode
(),
m_GC
);
*
_last_ins_left
=
new
Node
(
m_link
->
GetEndNode
(),
m_GC
);
Virtual_Point
(
*
_last_ins_left
,
factor
);
Virtual_Point
(
*
_last_ins_left
,
factor
);
*
_last_ins_right
=
new
Node
(
nextline
->
m_link
->
GetBeginNode
(),
m_GC
);
*
_last_ins_right
=
new
Node
(
nextline
->
m_link
->
GetBeginNode
(),
m_GC
);
nextline
->
Virtual_Point
(
*
_last_ins_right
,
-
factor
);
nextline
->
Virtual_Point
(
*
_last_ins_right
,
-
factor
);
shape
->
AddLink
(
*
_last_ins_left
,
*
_last_ins_right
);
shape
->
AddLink
(
*
_last_ins_left
,
*
_last_ins_right
);
*
_last_ins_left
=
OffsetContour_rounded
(
nextline
,
*
_last_ins_left
,
factor
,
shape
);
*
_last_ins_left
=
OffsetContour_rounded
(
nextline
,
*
_last_ins_left
,
factor
,
shape
);
}
}
break
;
break
;
case
IS_LEFT
:
case
IS_LEFT
:
{
{
*
_last_ins_left
=
new
Node
(
nextline
->
m_link
->
GetBeginNode
(),
m_GC
);
*
_last_ins_left
=
new
Node
(
nextline
->
m_link
->
GetBeginNode
(),
m_GC
);
nextline
->
Virtual_Point
(
*
_last_ins_left
,
factor
);
nextline
->
Virtual_Point
(
*
_last_ins_left
,
factor
);
*
_last_ins_right
=
new
Node
(
m_link
->
GetEndNode
(),
m_GC
);
*
_last_ins_right
=
new
Node
(
m_link
->
GetEndNode
(),
m_GC
);
Virtual_Point
(
*
_last_ins_right
,
-
factor
);
Virtual_Point
(
*
_last_ins_right
,
-
factor
);
shape
->
AddLink
(
*
_last_ins_left
,
*
_last_ins_right
);
shape
->
AddLink
(
*
_last_ins_left
,
*
_last_ins_right
);
*
_last_ins_right
=
OffsetContour_rounded
(
nextline
,
*
_last_ins_right
,
-
factor
,
shape
);
*
_last_ins_right
=
OffsetContour_rounded
(
nextline
,
*
_last_ins_right
,
-
factor
,
shape
);
}
}
break
;
break
;
// Line 2 lies on this line
// Line 2 lies on this line
case
IS_ON
:
case
IS_ON
:
{
{
*
_last_ins_left
=
new
Node
(
nextline
->
m_link
->
GetBeginNode
(),
m_GC
);
*
_last_ins_left
=
new
Node
(
nextline
->
m_link
->
GetBeginNode
(),
m_GC
);
Virtual_Point
(
*
_last_ins_left
,
factor
);
Virtual_Point
(
*
_last_ins_left
,
factor
);
*
_last_ins_right
=
new
Node
(
nextline
->
m_link
->
GetBeginNode
(),
m_GC
);
*
_last_ins_right
=
new
Node
(
nextline
->
m_link
->
GetBeginNode
(),
m_GC
);
Virtual_Point
(
*
_last_ins_right
,
-
factor
);
Virtual_Point
(
*
_last_ins_right
,
-
factor
);
shape
->
AddLink
(
*
_last_ins_left
,
*
_last_ins_right
);
shape
->
AddLink
(
*
_last_ins_left
,
*
_last_ins_right
);
}
}
break
;
break
;
}
//end switch
}
//end switch
}
}
void
KBoolLine
::
Create_End_Shape
(
KBoolLine
*
nextline
,
Node
*
_last_ins_left
,
Node
*
_last_ins_right
,
double
factor
,
Graph
*
shape
)
void
KBoolLine
::
Create_End_Shape
(
KBoolLine
*
nextline
,
Node
*
_last_ins_left
,
Node
*
_last_ins_right
,
double
factor
,
Graph
*
shape
)
{
{
Node
*
_current
;
Node
*
_current
;
factor
=
fabs
(
factor
);
factor
=
fabs
(
factor
);
LinkStatus
_outproduct
;
LinkStatus
_outproduct
;
_outproduct
=
m_link
->
OutProduct
(
nextline
->
m_link
,
m_GC
->
GetAccur
()
);
_outproduct
=
m_link
->
OutProduct
(
nextline
->
m_link
,
m_GC
->
GetAccur
()
);
switch
(
_outproduct
)
switch
(
_outproduct
)
{
{
case
IS_RIGHT
:
case
IS_RIGHT
:
{
{
_current
=
new
Node
(
m_link
->
GetEndNode
(),
m_GC
);
_current
=
new
Node
(
m_link
->
GetEndNode
(),
m_GC
);
Virtual_Point
(
_current
,
-
factor
);
Virtual_Point
(
_current
,
-
factor
);
shape
->
AddLink
(
_last_ins_right
,
_current
);
shape
->
AddLink
(
_last_ins_right
,
_current
);
_last_ins_right
=
_current
;
_last_ins_right
=
_current
;
_last_ins_left
=
OffsetContour_rounded
(
nextline
,
_last_ins_left
,
factor
,
shape
);
_last_ins_left
=
OffsetContour_rounded
(
nextline
,
_last_ins_left
,
factor
,
shape
);
shape
->
AddLink
(
_last_ins_left
,
_last_ins_right
);
shape
->
AddLink
(
_last_ins_left
,
_last_ins_right
);
}
}
break
;
break
;
case
IS_LEFT
:
case
IS_LEFT
:
{
{
_current
=
new
Node
(
m_link
->
GetEndNode
(),
m_GC
);
_current
=
new
Node
(
m_link
->
GetEndNode
(),
m_GC
);
Virtual_Point
(
_current
,
factor
);
Virtual_Point
(
_current
,
factor
);
shape
->
AddLink
(
_last_ins_left
,
_current
);
shape
->
AddLink
(
_last_ins_left
,
_current
);
_last_ins_left
=
_current
;
_last_ins_left
=
_current
;
_last_ins_right
=
OffsetContour_rounded
(
nextline
,
_last_ins_right
,
-
factor
,
shape
);
_last_ins_right
=
OffsetContour_rounded
(
nextline
,
_last_ins_right
,
-
factor
,
shape
);
shape
->
AddLink
(
_last_ins_right
,
_last_ins_left
);
shape
->
AddLink
(
_last_ins_right
,
_last_ins_left
);
}
}
break
;
break
;
// Line 2 lies on this line
// Line 2 lies on this line
case
IS_ON
:
case
IS_ON
:
{
{
_current
=
new
Node
(
m_link
->
GetEndNode
(),
m_GC
);
_current
=
new
Node
(
m_link
->
GetEndNode
(),
m_GC
);
Virtual_Point
(
_current
,
factor
);
Virtual_Point
(
_current
,
factor
);
shape
->
AddLink
(
_last_ins_left
,
_current
);
shape
->
AddLink
(
_last_ins_left
,
_current
);
_last_ins_left
=
_current
;
_last_ins_left
=
_current
;
_current
=
new
Node
(
m_link
->
GetEndNode
(),
m_GC
);
_current
=
new
Node
(
m_link
->
GetEndNode
(),
m_GC
);
Virtual_Point
(
_current
,
-
factor
);
Virtual_Point
(
_current
,
-
factor
);
shape
->
AddLink
(
_last_ins_right
,
_current
);
shape
->
AddLink
(
_last_ins_right
,
_current
);
_last_ins_right
=
_current
;
_last_ins_right
=
_current
;
shape
->
AddLink
(
_last_ins_left
,
_last_ins_right
);
shape
->
AddLink
(
_last_ins_left
,
_last_ins_right
);
}
}
break
;
break
;
}
//end switch
}
//end switch
...
@@ -1093,32 +1092,32 @@ void KBoolLine::Create_End_Shape(KBoolLine* nextline,Node* _last_ins_left,Node*
...
@@ -1093,32 +1092,32 @@ void KBoolLine::Create_End_Shape(KBoolLine* nextline,Node* _last_ins_left,Node*
//
//
// Generate from the found crossings a part of the graph
// Generate from the found crossings a part of the graph
//
//
bool
KBoolLine
::
ProcessCrossings
(
TDLI
<
KBoolLink
>*
_LI
)
bool
KBoolLine
::
ProcessCrossings
(
TDLI
<
KBoolLink
>*
_LI
)
{
{
Node
*
last
;
KBoolLink
*
dummy
;
Node
*
last
;
KBoolLink
*
dummy
;
// assert (beginnode && endnode);
// assert (beginnode && endnode);
if
(
!
linecrosslist
)
return
false
;
if
(
!
linecrosslist
)
return
false
;
if
(
linecrosslist
->
empty
())
return
false
;
if
(
linecrosslist
->
empty
()
)
return
false
;
if
(
linecrosslist
->
count
()
>
1
)
SortLineCrossings
();
if
(
linecrosslist
->
count
()
>
1
)
SortLineCrossings
();
m_link
->
GetEndNode
()
->
RemoveLink
(
m_link
);
m_link
->
GetEndNode
()
->
RemoveLink
(
m_link
);
last
=
m_link
->
GetEndNode
();
last
=
m_link
->
GetEndNode
();
// Make new links :
// Make new links :
while
(
!
linecrosslist
->
empty
()
)
while
(
!
linecrosslist
->
empty
()
)
{
{
dummy
=
new
KBoolLink
(
m_link
->
GetGraphNum
(),(
Node
*
)
linecrosslist
->
tailitem
(),
last
,
m_GC
);
dummy
=
new
KBoolLink
(
m_link
->
GetGraphNum
(),
(
Node
*
)
linecrosslist
->
tailitem
(),
last
,
m_GC
);
dummy
->
SetBeenHere
();
dummy
->
SetBeenHere
();
dummy
->
SetGroup
(
m_link
->
Group
()
);
dummy
->
SetGroup
(
m_link
->
Group
()
);
_LI
->
insbegin
(
dummy
);
_LI
->
insbegin
(
dummy
);
last
=
(
Node
*
)
linecrosslist
->
tailitem
();
last
=
(
Node
*
)
linecrosslist
->
tailitem
();
linecrosslist
->
removetail
();
linecrosslist
->
removetail
();
}
}
// Recycle this link :
// Recycle this link :
last
->
AddLink
(
m_link
);
last
->
AddLink
(
m_link
);
m_link
->
SetEndNode
(
last
);
m_link
->
SetEndNode
(
last
);
delete
linecrosslist
;
delete
linecrosslist
;
linecrosslist
=
NULL
;
linecrosslist
=
NULL
;
return
true
;
return
true
;
}
}
...
@@ -1355,39 +1354,39 @@ KBoolLink* KBoolLine::ProcessCrossingsSmart(TDLI<KBoolLink>* _LI)
...
@@ -1355,39 +1354,39 @@ KBoolLink* KBoolLine::ProcessCrossingsSmart(TDLI<KBoolLink>* _LI)
}
}
*/
*/
static
int
NODE_X_ASCENDING_L
(
Node
*
a
,
Node
*
b
)
static
int
NODE_X_ASCENDING_L
(
Node
*
a
,
Node
*
b
)
{
{
if
(
b
->
GetX
()
>
a
->
GetX
())
return
(
1
);
if
(
b
->
GetX
()
>
a
->
GetX
()
)
return
(
1
);
else
else
if
(
b
->
GetX
()
==
a
->
GetX
())
return
(
0
);
if
(
b
->
GetX
()
==
a
->
GetX
()
)
return
(
0
);
return
(
-
1
);
return
(
-
1
);
}
}
static
int
NODE_X_DESCENDING_L
(
Node
*
a
,
Node
*
b
)
static
int
NODE_X_DESCENDING_L
(
Node
*
a
,
Node
*
b
)
{
{
if
(
a
->
GetX
()
>
b
->
GetX
())
return
(
1
);
if
(
a
->
GetX
()
>
b
->
GetX
()
)
return
(
1
);
else
else
if
(
a
->
GetX
()
==
b
->
GetX
())
return
(
0
);
if
(
a
->
GetX
()
==
b
->
GetX
()
)
return
(
0
);
return
(
-
1
);
return
(
-
1
);
}
}
static
int
NODE_Y_ASCENDING_L
(
Node
*
a
,
Node
*
b
)
static
int
NODE_Y_ASCENDING_L
(
Node
*
a
,
Node
*
b
)
{
{
if
(
b
->
GetY
()
>
a
->
GetY
())
return
(
1
);
if
(
b
->
GetY
()
>
a
->
GetY
()
)
return
(
1
);
else
else
if
(
b
->
GetY
()
==
a
->
GetY
())
return
(
0
);
if
(
b
->
GetY
()
==
a
->
GetY
()
)
return
(
0
);
return
(
-
1
);
return
(
-
1
);
}
}
static
int
NODE_Y_DESCENDING_L
(
Node
*
a
,
Node
*
b
)
static
int
NODE_Y_DESCENDING_L
(
Node
*
a
,
Node
*
b
)
{
{
if
(
a
->
GetY
()
>
b
->
GetY
())
return
(
1
);
if
(
a
->
GetY
()
>
b
->
GetY
()
)
return
(
1
);
else
else
if
(
a
->
GetY
()
==
b
->
GetY
())
return
(
0
);
if
(
a
->
GetY
()
==
b
->
GetY
()
)
return
(
0
);
return
(
-
1
);
return
(
-
1
);
}
}
//
//
...
@@ -1396,68 +1395,68 @@ static int NODE_Y_DESCENDING_L(Node* a, Node* b)
...
@@ -1396,68 +1395,68 @@ static int NODE_Y_DESCENDING_L(Node* a, Node* b)
//
//
void
KBoolLine
::
SortLineCrossings
()
void
KBoolLine
::
SortLineCrossings
()
{
{
TDLI
<
Node
>
I
(
linecrosslist
);
TDLI
<
Node
>
I
(
linecrosslist
);
B_INT
dx
,
dy
;
B_INT
dx
,
dy
;
dx
=
babs
(
m_link
->
GetEndNode
()
->
GetX
()
-
m_link
->
GetBeginNode
()
->
GetX
()
);
dx
=
babs
(
m_link
->
GetEndNode
()
->
GetX
()
-
m_link
->
GetBeginNode
()
->
GetX
()
);
dy
=
babs
(
m_link
->
GetEndNode
()
->
GetY
()
-
m_link
->
GetBeginNode
()
->
GetY
()
);
dy
=
babs
(
m_link
->
GetEndNode
()
->
GetY
()
-
m_link
->
GetBeginNode
()
->
GetY
()
);
if
(
dx
>
dy
)
if
(
dx
>
dy
)
{
// thislink is more horizontal then vertical
{
// thislink is more horizontal then vertical
if
(
m_link
->
GetEndNode
()
->
GetX
()
>
m_link
->
GetBeginNode
()
->
GetX
()
)
if
(
m_link
->
GetEndNode
()
->
GetX
()
>
m_link
->
GetBeginNode
()
->
GetX
()
)
I
.
mergesort
(
NODE_X_ASCENDING_L
);
I
.
mergesort
(
NODE_X_ASCENDING_L
);
else
else
I
.
mergesort
(
NODE_X_DESCENDING_L
);
I
.
mergesort
(
NODE_X_DESCENDING_L
);
}
}
else
else
{
// this link is more vertical then horizontal
{
// this link is more vertical then horizontal
if
(
m_link
->
GetEndNode
()
->
GetY
()
>
m_link
->
GetBeginNode
()
->
GetY
()
)
if
(
m_link
->
GetEndNode
()
->
GetY
()
>
m_link
->
GetBeginNode
()
->
GetY
()
)
I
.
mergesort
(
NODE_Y_ASCENDING_L
);
I
.
mergesort
(
NODE_Y_ASCENDING_L
);
else
else
I
.
mergesort
(
NODE_Y_DESCENDING_L
);
I
.
mergesort
(
NODE_Y_DESCENDING_L
);
}
}
}
}
//
//
// Adds a cross Node to this. a_node may not be deleted before processing the crossings
// Adds a cross Node to this. a_node may not be deleted before processing the crossings
//
//
void
KBoolLine
::
AddCrossing
(
Node
*
a_node
)
void
KBoolLine
::
AddCrossing
(
Node
*
a_node
)
{
{
if
(
a_node
==
m_link
->
GetBeginNode
()
||
a_node
==
m_link
->
GetEndNode
())
return
;
if
(
a_node
==
m_link
->
GetBeginNode
()
||
a_node
==
m_link
->
GetEndNode
()
)
return
;
if
(
!
linecrosslist
)
if
(
!
linecrosslist
)
{
{
linecrosslist
=
new
DL_List
<
void
*>
();
linecrosslist
=
new
DL_List
<
void
*>
();
linecrosslist
->
insend
(
a_node
);
linecrosslist
->
insend
(
a_node
);
}
}
else
else
{
{
TDLI
<
Node
>
I
(
linecrosslist
);
TDLI
<
Node
>
I
(
linecrosslist
);
if
(
!
I
.
has
(
a_node
)
)
if
(
!
I
.
has
(
a_node
)
)
I
.
insend
(
a_node
);
I
.
insend
(
a_node
);
}
}
}
}
//
//
// see above
// see above
//
//
Node
*
KBoolLine
::
AddCrossing
(
B_INT
X
,
B_INT
Y
)
Node
*
KBoolLine
::
AddCrossing
(
B_INT
X
,
B_INT
Y
)
{
{
Node
*
result
=
new
Node
(
X
,
Y
,
m_GC
);
Node
*
result
=
new
Node
(
X
,
Y
,
m_GC
);
AddCrossing
(
result
);
AddCrossing
(
result
);
return
result
;
return
result
;
}
}
DL_List
<
void
*>*
KBoolLine
::
GetCrossList
()
DL_List
<
void
*>*
KBoolLine
::
GetCrossList
()
{
{
if
(
linecrosslist
)
if
(
linecrosslist
)
return
linecrosslist
;
return
linecrosslist
;
return
NULL
;
return
NULL
;
}
}
bool
KBoolLine
::
CrossListEmpty
()
bool
KBoolLine
::
CrossListEmpty
()
{
{
if
(
linecrosslist
)
if
(
linecrosslist
)
return
linecrosslist
->
empty
();
return
linecrosslist
->
empty
();
return
true
;
return
true
;
}
}
...
...
polygon/kbool/src/link.cpp
View file @
521f428c
/*! \file
../
src/link.cpp
/*! \file src/link.cpp
\author
Probably
Klaas Holwerda
\author Klaas Holwerda
Copyright: 2001-2004 (C)
Probably
Klaas Holwerda
Copyright: 2001-2004 (C) Klaas Holwerda
Licence:
wxWidgets Licence
Licence:
see kboollicense.txt
RCS-ID: $Id: link.cpp,v 1.
10 2005/06/17 22:54:37 kbluck
Exp $
RCS-ID: $Id: link.cpp,v 1.
3 2008/06/04 21:23:22 titato
Exp $
*/
*/
#ifdef __GNUG__
#include "kbool/booleng.h"
#pragma implementation
#endif
#include "../include/booleng.h"
#include "
../include
/link.h"
#include "
kbool
/link.h"
#include "
../include
/line.h"
#include "
kbool
/line.h"
#include <math.h>
#include <math.h>
#include <assert.h>
#include <assert.h>
#include "
../include
/node.h"
#include "
kbool
/node.h"
#include "
../include
/graph.h"
#include "
kbool
/graph.h"
#include "
../include
/graphlst.h"
#include "
kbool
/graphlst.h"
int
linkXYsorter
(
KBoolLink
*
,
KBoolLink
*
);
int
linkXYsorter
(
KBoolLink
*
,
KBoolLink
*
);
//
//
// Default constructor
// Default constructor
//
//
KBoolLink
::
KBoolLink
(
Bool_Engine
*
GC
)
KBoolLink
::
KBoolLink
(
Bool_Engine
*
GC
)
{
{
_GC
=
GC
;
_GC
=
GC
;
Reset
();
Reset
();
}
}
...
@@ -38,14 +34,14 @@ KBoolLink::KBoolLink(Bool_Engine* GC)
...
@@ -38,14 +34,14 @@ KBoolLink::KBoolLink(Bool_Engine* GC)
//
//
// This constructor makes this link a valid part of a graph
// This constructor makes this link a valid part of a graph
//
//
KBoolLink
::
KBoolLink
(
int
graphnr
,
Node
*
begin
,
Node
*
end
,
Bool_Engine
*
GC
)
KBoolLink
::
KBoolLink
(
int
graphnr
,
Node
*
begin
,
Node
*
end
,
Bool_Engine
*
GC
)
{
{
_GC
=
GC
;
_GC
=
GC
;
Reset
();
Reset
();
// Set the references of the node and of this link correct
// Set the references of the node and of this link correct
begin
->
AddLink
(
this
);
begin
->
AddLink
(
this
);
end
->
AddLink
(
this
);
end
->
AddLink
(
this
);
m_beginnode
=
begin
;
m_beginnode
=
begin
;
m_endnode
=
end
;
m_endnode
=
end
;
m_graphnum
=
graphnr
;
m_graphnum
=
graphnr
;
...
@@ -54,17 +50,17 @@ KBoolLink::KBoolLink(int graphnr, Node *begin, Node *end, Bool_Engine* GC)
...
@@ -54,17 +50,17 @@ KBoolLink::KBoolLink(int graphnr, Node *begin, Node *end, Bool_Engine* GC)
//
//
// This constructor makes this link a valid part of a graph
// This constructor makes this link a valid part of a graph
//
//
KBoolLink
::
KBoolLink
(
Node
*
begin
,
Node
*
end
,
Bool_Engine
*
GC
)
KBoolLink
::
KBoolLink
(
Node
*
begin
,
Node
*
end
,
Bool_Engine
*
GC
)
{
{
_GC
=
GC
;
_GC
=
GC
;
Reset
();
Reset
();
// Set the references of the node and of this link correct
// Set the references of the node and of this link correct
begin
->
AddLink
(
this
);
begin
->
AddLink
(
this
);
end
->
AddLink
(
this
);
end
->
AddLink
(
this
);
m_beginnode
=
begin
;
m_beginnode
=
begin
;
m_endnode
=
end
;
m_endnode
=
end
;
m_graphnum
=
0
;
m_graphnum
=
0
;
}
}
...
@@ -81,7 +77,7 @@ KBoolLink::~KBoolLink()
...
@@ -81,7 +77,7 @@ KBoolLink::~KBoolLink()
//
//
bool
KBoolLink
::
BeenHere
()
bool
KBoolLink
::
BeenHere
()
{
{
if
(
m_bin
)
return
true
;
if
(
m_bin
)
return
true
;
return
false
;
return
false
;
}
}
...
@@ -102,10 +98,10 @@ void KBoolLink::TakeOverOperationFlags( KBoolLink* link )
...
@@ -102,10 +98,10 @@ void KBoolLink::TakeOverOperationFlags( KBoolLink* link )
//
//
// Returns the next link from the argument
// Returns the next link from the argument
//
//
KBoolLink
*
KBoolLink
::
Forth
(
Node
*
node
)
KBoolLink
*
KBoolLink
::
Forth
(
Node
*
node
)
{
{
assert
(
node
==
m_beginnode
||
node
==
m_endnode
);
assert
(
node
==
m_beginnode
||
node
==
m_endnode
);
return
node
->
GetOtherLink
(
this
);
return
node
->
GetOtherLink
(
this
);
}
}
//
//
...
@@ -149,7 +145,7 @@ bool KBoolLink::GetInc()
...
@@ -149,7 +145,7 @@ bool KBoolLink::GetInc()
// return false;
// return false;
}
}
void
KBoolLink
::
SetInc
(
bool
inc
)
void
KBoolLink
::
SetInc
(
bool
inc
)
{
{
m_Inc
=
inc
;
m_Inc
=
inc
;
// Inc=0;
// Inc=0;
...
@@ -161,7 +157,7 @@ bool KBoolLink::GetLeftA()
...
@@ -161,7 +157,7 @@ bool KBoolLink::GetLeftA()
return
m_LeftA
;
return
m_LeftA
;
}
}
void
KBoolLink
::
SetLeftA
(
bool
la
)
void
KBoolLink
::
SetLeftA
(
bool
la
)
{
{
m_LeftA
=
la
;
m_LeftA
=
la
;
}
}
...
@@ -171,7 +167,7 @@ bool KBoolLink::GetLeftB()
...
@@ -171,7 +167,7 @@ bool KBoolLink::GetLeftB()
return
m_LeftB
;
return
m_LeftB
;
}
}
void
KBoolLink
::
SetLeftB
(
bool
lb
)
void
KBoolLink
::
SetLeftB
(
bool
lb
)
{
{
m_LeftB
=
lb
;
m_LeftB
=
lb
;
}
}
...
@@ -181,7 +177,7 @@ bool KBoolLink::GetRightA()
...
@@ -181,7 +177,7 @@ bool KBoolLink::GetRightA()
return
m_RightA
;
return
m_RightA
;
}
}
void
KBoolLink
::
SetRightA
(
bool
ra
)
void
KBoolLink
::
SetRightA
(
bool
ra
)
{
{
m_RightA
=
ra
;
m_RightA
=
ra
;
}
}
...
@@ -191,7 +187,7 @@ bool KBoolLink::GetRightB()
...
@@ -191,7 +187,7 @@ bool KBoolLink::GetRightB()
return
m_RightB
;
return
m_RightB
;
}
}
void
KBoolLink
::
SetRightB
(
bool
rb
)
void
KBoolLink
::
SetRightB
(
bool
rb
)
{
{
m_RightB
=
rb
;
m_RightB
=
rb
;
}
}
...
@@ -200,50 +196,50 @@ void KBoolLink::SetRightB(bool rb)
...
@@ -200,50 +196,50 @@ void KBoolLink::SetRightB(bool rb)
// This function is very popular by GP-faults
// This function is very popular by GP-faults
// It returns the node different from a
// It returns the node different from a
//
//
Node
*
KBoolLink
::
GetOther
(
const
Node
*
const
a
)
Node
*
KBoolLink
::
GetOther
(
const
Node
*
const
a
)
{
{
return
(
(
a
!=
m_beginnode
)
?
m_beginnode
:
m_endnode
);
return
(
(
a
!=
m_beginnode
)
?
m_beginnode
:
m_endnode
);
}
}
//
//
// Is this marked for given operation
// Is this marked for given operation
//
//
bool
KBoolLink
::
IsMarked
(
BOOL_OP
operation
)
bool
KBoolLink
::
IsMarked
(
BOOL_OP
operation
)
{
{
switch
(
operation
)
switch
(
operation
)
{
{
case
(
BOOL_OR
):
return
m_merge_L
||
m_merge_R
;
case
(
BOOL_OR
):
return
m_merge_L
||
m_merge_R
;
case
(
BOOL_AND
):
return
m_intersect_L
||
m_intersect_R
;
case
(
BOOL_AND
):
return
m_intersect_L
||
m_intersect_R
;
case
(
BOOL_A_SUB_B
):
return
m_a_substract_b_L
||
m_a_substract_b_R
;
case
(
BOOL_A_SUB_B
):
return
m_a_substract_b_L
||
m_a_substract_b_R
;
case
(
BOOL_B_SUB_A
):
return
m_b_substract_a_L
||
m_b_substract_a_R
;
case
(
BOOL_B_SUB_A
):
return
m_b_substract_a_L
||
m_b_substract_a_R
;
case
(
BOOL_EXOR
):
return
m_exor_L
||
m_exor_R
;
case
(
BOOL_EXOR
):
return
m_exor_L
||
m_exor_R
;
default
:
return
false
;
default
:
return
false
;
}
}
}
}
bool
KBoolLink
::
IsMarkedLeft
(
BOOL_OP
operation
)
bool
KBoolLink
::
IsMarkedLeft
(
BOOL_OP
operation
)
{
{
switch
(
operation
)
switch
(
operation
)
{
{
case
(
BOOL_OR
):
return
m_merge_L
;
case
(
BOOL_OR
):
return
m_merge_L
;
case
(
BOOL_AND
):
return
m_intersect_L
;
case
(
BOOL_AND
):
return
m_intersect_L
;
case
(
BOOL_A_SUB_B
):
return
m_a_substract_b_L
;
case
(
BOOL_A_SUB_B
):
return
m_a_substract_b_L
;
case
(
BOOL_B_SUB_A
):
return
m_b_substract_a_L
;
case
(
BOOL_B_SUB_A
):
return
m_b_substract_a_L
;
case
(
BOOL_EXOR
):
return
m_exor_L
;
case
(
BOOL_EXOR
):
return
m_exor_L
;
default
:
return
false
;
default
:
return
false
;
}
}
}
}
bool
KBoolLink
::
IsMarkedRight
(
BOOL_OP
operation
)
bool
KBoolLink
::
IsMarkedRight
(
BOOL_OP
operation
)
{
{
switch
(
operation
)
switch
(
operation
)
{
{
case
(
BOOL_OR
):
return
m_merge_R
;
case
(
BOOL_OR
):
return
m_merge_R
;
case
(
BOOL_AND
):
return
m_intersect_R
;
case
(
BOOL_AND
):
return
m_intersect_R
;
case
(
BOOL_A_SUB_B
):
return
m_a_substract_b_R
;
case
(
BOOL_A_SUB_B
):
return
m_a_substract_b_R
;
case
(
BOOL_B_SUB_A
):
return
m_b_substract_a_R
;
case
(
BOOL_B_SUB_A
):
return
m_b_substract_a_R
;
case
(
BOOL_EXOR
):
return
m_exor_R
;
case
(
BOOL_EXOR
):
return
m_exor_R
;
default
:
return
false
;
default
:
return
false
;
}
}
}
}
...
@@ -251,23 +247,23 @@ bool KBoolLink::IsMarkedRight(BOOL_OP operation)
...
@@ -251,23 +247,23 @@ bool KBoolLink::IsMarkedRight(BOOL_OP operation)
//
//
// Is this a hole for given operation
// Is this a hole for given operation
// beginnode must be to the left
// beginnode must be to the left
bool
KBoolLink
::
IsHole
(
BOOL_OP
operation
)
bool
KBoolLink
::
IsHole
(
BOOL_OP
operation
)
{
{
bool
topsideA
,
topsideB
;
bool
topsideA
,
topsideB
;
if
(
m_beginnode
->
GetX
()
<
m_endnode
->
GetX
()
)
//going to the right?
if
(
m_beginnode
->
GetX
()
<
m_endnode
->
GetX
()
)
//going to the right?
{
topsideA
=
m_RightA
;
topsideB
=
m_RightB
;
}
{
topsideA
=
m_RightA
;
topsideB
=
m_RightB
;
}
else
else
{
topsideA
=
m_LeftA
;
topsideB
=
m_LeftB
;
}
{
topsideA
=
m_LeftA
;
topsideB
=
m_LeftB
;
}
switch
(
operation
)
switch
(
operation
)
{
{
case
(
BOOL_OR
):
return
(
!
topsideB
&&
!
topsideA
);
case
(
BOOL_OR
):
return
(
!
topsideB
&&
!
topsideA
);
case
(
BOOL_AND
):
return
(
!
topsideB
||
!
topsideA
);
case
(
BOOL_AND
):
return
(
!
topsideB
||
!
topsideA
);
case
(
BOOL_A_SUB_B
):
return
(
topsideB
||
!
topsideA
);
case
(
BOOL_A_SUB_B
):
return
(
topsideB
||
!
topsideA
);
case
(
BOOL_B_SUB_A
):
return
(
topsideA
||
!
topsideB
);
case
(
BOOL_B_SUB_A
):
return
(
topsideA
||
!
topsideB
);
case
(
BOOL_EXOR
):
return
!
(
(
topsideB
&&
!
topsideA
)
||
(
!
topsideB
&&
topsideA
)
);
case
(
BOOL_EXOR
):
return
!
(
(
topsideB
&&
!
topsideA
)
||
(
!
topsideB
&&
topsideA
)
);
default
:
return
false
;
default
:
return
false
;
}
}
}
}
...
@@ -277,11 +273,11 @@ bool KBoolLink::IsHole(BOOL_OP operation)
...
@@ -277,11 +273,11 @@ bool KBoolLink::IsHole(BOOL_OP operation)
//
//
bool
KBoolLink
::
GetHole
()
bool
KBoolLink
::
GetHole
()
{
{
return
(
m_hole
);
return
(
m_hole
);
}
}
void
KBoolLink
::
SetHole
(
bool
h
)
void
KBoolLink
::
SetHole
(
bool
h
)
{
{
m_hole
=
h
;
m_hole
=
h
;
}
}
...
@@ -293,7 +289,7 @@ void KBoolLink::SetHole(bool h)
...
@@ -293,7 +289,7 @@ void KBoolLink::SetHole(bool h)
bool
KBoolLink
::
IsUnused
()
bool
KBoolLink
::
IsUnused
()
{
{
return
return
!
(
m_merge_L
||
m_merge_R
||
!
(
m_merge_L
||
m_merge_R
||
m_a_substract_b_L
||
m_a_substract_b_R
||
m_a_substract_b_L
||
m_a_substract_b_R
||
m_b_substract_a_L
||
m_b_substract_a_R
||
m_b_substract_a_L
||
m_b_substract_a_R
||
m_intersect_L
||
m_intersect_R
||
m_intersect_L
||
m_intersect_R
||
...
@@ -301,15 +297,15 @@ bool KBoolLink::IsUnused()
...
@@ -301,15 +297,15 @@ bool KBoolLink::IsUnused()
}
}
bool
KBoolLink
::
IsZero
(
B_INT
marge
)
bool
KBoolLink
::
IsZero
(
B_INT
marge
)
{
{
return
(
m_beginnode
->
Equal
(
m_endnode
,
marge
)
)
;
return
(
m_beginnode
->
Equal
(
m_endnode
,
marge
)
)
;
}
}
bool
KBoolLink
::
ShorterThan
(
B_INT
marge
)
bool
KBoolLink
::
ShorterThan
(
B_INT
marge
)
{
{
return
(
m_beginnode
->
ShorterThan
(
m_endnode
,
marge
)
)
;
return
(
m_beginnode
->
ShorterThan
(
m_endnode
,
marge
)
)
;
}
}
...
@@ -332,20 +328,20 @@ void KBoolLink::Mark()
...
@@ -332,20 +328,20 @@ void KBoolLink::Mark()
// The references to this link in the node will also be deleted
// The references to this link in the node will also be deleted
// After doing that, link link can be deleted or be recycled.
// After doing that, link link can be deleted or be recycled.
//
//
void
KBoolLink
::
MergeNodes
(
Node
*
const
begin_or_end_node
)
void
KBoolLink
::
MergeNodes
(
Node
*
const
begin_or_end_node
)
{
{
// assert(beginnode && endnode);
// assert(beginnode && endnode);
// assert ((begin_or_end_node == beginnode)||(begin_or_end_node == endnode));
// assert ((begin_or_end_node == beginnode)||(begin_or_end_node == endnode));
m_beginnode
->
RemoveLink
(
this
);
m_beginnode
->
RemoveLink
(
this
);
m_endnode
->
RemoveLink
(
this
);
m_endnode
->
RemoveLink
(
this
);
if
(
m_endnode
!=
m_beginnode
)
if
(
m_endnode
!=
m_beginnode
)
{
// only if beginnode and endnode are different nodes
{
// only if beginnode and endnode are different nodes
begin_or_end_node
->
Merge
(
GetOther
(
begin_or_end_node
)
);
begin_or_end_node
->
Merge
(
GetOther
(
begin_or_end_node
)
);
}
}
m_endnode
=
NULL
;
m_endnode
=
NULL
;
m_beginnode
=
NULL
;
m_beginnode
=
NULL
;
}
}
//
//
...
@@ -354,28 +350,29 @@ void KBoolLink::MergeNodes(Node *const begin_or_end_node)
...
@@ -354,28 +350,29 @@ void KBoolLink::MergeNodes(Node *const begin_or_end_node)
// Here Left and Right is defined as being left or right from
// Here Left and Right is defined as being left or right from
// the this link towards the center (common) node
// the this link towards the center (common) node
//
//
LinkStatus
KBoolLink
::
OutProduct
(
KBoolLink
*
const
two
,
double
accur
)
LinkStatus
KBoolLink
::
OutProduct
(
KBoolLink
*
const
two
,
double
accur
)
{
{
Node
*
center
;
Node
*
center
;
double
distance
;
double
distance
;
if
(
two
->
GetBeginNode
()
->
Equal
(
two
->
GetEndNode
(),
1
)
)
if
(
two
->
GetBeginNode
()
->
Equal
(
two
->
GetEndNode
(),
1
)
)
assert
(
!
two
);
assert
(
!
two
);
if
(
GetBeginNode
()
->
Equal
(
GetEndNode
(),
1
)
)
if
(
GetBeginNode
()
->
Equal
(
GetEndNode
(),
1
)
)
assert
(
!
this
);
assert
(
!
this
);
KBoolLine
*
temp_line
=
new
KBoolLine
(
this
,
_GC
);
KBoolLine
*
temp_line
=
new
KBoolLine
(
this
,
_GC
);
//the this link should connect to the other two link at at least one node
//the this link should connect to the other two link at at least one node
if
(
m_endnode
==
two
->
m_endnode
||
m_endnode
==
two
->
m_beginnode
)
if
(
m_endnode
==
two
->
m_endnode
||
m_endnode
==
two
->
m_beginnode
)
center
=
m_endnode
;
center
=
m_endnode
;
else
else
{
center
=
m_beginnode
;
{
center
=
m_beginnode
;
// assert(center==two->endnode || center==two->beginnode);
// assert(center==two->endnode || center==two->beginnode);
}
}
//here something tricky
//here something tricky
// the factor 10000.0 is needed to asure that the pointonline
// the factor 10000.0 is needed to asure that the pointonline
// is more accurate in this case compared to the intersection for graphs
// is more accurate in this case compared to the intersection for graphs
int
uitp
=
temp_line
->
PointOnLine
(
two
->
GetOther
(
center
),
distance
,
accur
);
int
uitp
=
temp_line
->
PointOnLine
(
two
->
GetOther
(
center
),
distance
,
accur
);
delete
temp_line
;
delete
temp_line
;
...
@@ -386,18 +383,18 @@ LinkStatus KBoolLink::OutProduct(KBoolLink* const two,double accur)
...
@@ -386,18 +383,18 @@ LinkStatus KBoolLink::OutProduct(KBoolLink* const two,double accur)
return IS_ON;*/
return IS_ON;*/
//depending on direction of this link (going to or coming from centre)
//depending on direction of this link (going to or coming from centre)
if
(
center
==
m_endnode
)
if
(
center
==
m_endnode
)
{
{
if
(
uitp
==
LEFT_SIDE
)
if
(
uitp
==
LEFT_SIDE
)
return
IS_LEFT
;
return
IS_LEFT
;
if
(
uitp
==
RIGHT_SIDE
)
if
(
uitp
==
RIGHT_SIDE
)
return
IS_RIGHT
;
return
IS_RIGHT
;
}
}
else
//center=beginnode
else
//center=beginnode
{
{
if
(
uitp
==
LEFT_SIDE
)
if
(
uitp
==
LEFT_SIDE
)
return
IS_RIGHT
;
return
IS_RIGHT
;
if
(
uitp
==
RIGHT_SIDE
)
if
(
uitp
==
RIGHT_SIDE
)
return
IS_LEFT
;
return
IS_LEFT
;
}
}
return
IS_ON
;
return
IS_ON
;
...
@@ -408,7 +405,7 @@ LinkStatus KBoolLink::OutProduct(KBoolLink* const two,double accur)
...
@@ -408,7 +405,7 @@ LinkStatus KBoolLink::OutProduct(KBoolLink* const two,double accur)
// the second link
// the second link
// Result = IS_ON | IS_LEFT | IS_RIGHT
// Result = IS_ON | IS_LEFT | IS_RIGHT
//
//
LinkStatus
KBoolLink
::
PointOnCorner
(
KBoolLink
*
const
two
,
KBoolLink
*
const
third
)
LinkStatus
KBoolLink
::
PointOnCorner
(
KBoolLink
*
const
two
,
KBoolLink
*
const
third
)
{
{
LinkStatus
LinkStatus
TwoToOne
,
// Position of two to this line
TwoToOne
,
// Position of two to this line
...
@@ -430,33 +427,33 @@ LinkStatus KBoolLink::PointOnCorner(KBoolLink* const two, KBoolLink* const third
...
@@ -430,33 +427,33 @@ LinkStatus KBoolLink::PointOnCorner(KBoolLink* const two, KBoolLink* const third
// Calculate the position of the links compared to eachother
// Calculate the position of the links compared to eachother
TwoToOne
=
OutProduct
(
two
,
_GC
->
GetAccur
()
);
TwoToOne
=
OutProduct
(
two
,
_GC
->
GetAccur
()
);
ThirdToOne
=
OutProduct
(
third
,
_GC
->
GetAccur
()
);
ThirdToOne
=
OutProduct
(
third
,
_GC
->
GetAccur
()
);
//center is used in outproduct to give de direction of two
//center is used in outproduct to give de direction of two
// this is why the result should be swapped
// this is why the result should be swapped
ThirdToTwo
=
two
->
OutProduct
(
third
,
_GC
->
GetAccur
()
);
ThirdToTwo
=
two
->
OutProduct
(
third
,
_GC
->
GetAccur
()
);
if
(
ThirdToTwo
==
IS_RIGHT
)
if
(
ThirdToTwo
==
IS_RIGHT
)
ThirdToTwo
=
IS_LEFT
;
ThirdToTwo
=
IS_LEFT
;
else
if
(
ThirdToTwo
==
IS_LEFT
)
else
if
(
ThirdToTwo
==
IS_LEFT
)
ThirdToTwo
=
IS_RIGHT
;
ThirdToTwo
=
IS_RIGHT
;
// Select the result
// Select the result
switch
(
TwoToOne
)
switch
(
TwoToOne
)
{
{
// Line 2 lies on leftside of this line
// Line 2 lies on leftside of this line
case
IS_LEFT
:
if
((
ThirdToOne
==
IS_RIGHT
)
||
(
ThirdToTwo
==
IS_RIGHT
))
return
IS_RIGHT
;
case
IS_LEFT
:
if
(
(
ThirdToOne
==
IS_RIGHT
)
||
(
ThirdToTwo
==
IS_RIGHT
)
)
return
IS_RIGHT
;
else
if
((
ThirdToOne
==
IS_LEFT
)
&&
(
ThirdToTwo
==
IS_LEFT
))
return
IS_LEFT
;
else
if
(
(
ThirdToOne
==
IS_LEFT
)
&&
(
ThirdToTwo
==
IS_LEFT
)
)
return
IS_LEFT
;
else
Result
=
IS_ON
;
break
;
else
Result
=
IS_ON
;
break
;
// Line 2 lies on this line
// Line 2 lies on this line
case
IS_ON
:
if
((
ThirdToOne
==
IS_RIGHT
)
&&
(
ThirdToTwo
==
IS_RIGHT
))
return
IS_RIGHT
;
case
IS_ON
:
if
(
(
ThirdToOne
==
IS_RIGHT
)
&&
(
ThirdToTwo
==
IS_RIGHT
)
)
return
IS_RIGHT
;
else
if
((
ThirdToOne
==
IS_LEFT
)
&&
(
ThirdToTwo
==
IS_LEFT
)
)
return
IS_LEFT
;
else
if
(
(
ThirdToOne
==
IS_LEFT
)
&&
(
ThirdToTwo
==
IS_LEFT
)
)
return
IS_LEFT
;
// else if ((ThirdToOne==IS_RIGHT) && (ThirdToTwo==IS_LEFT)) return IS_RIGHT;
// else if ((ThirdToOne==IS_RIGHT) && (ThirdToTwo==IS_LEFT)) return IS_RIGHT;
// else if ((ThirdToOne==IS_LEFT) && (ThirdToTwo==IS_RIGHT)) return IS_LEFT;
// else if ((ThirdToOne==IS_LEFT) && (ThirdToTwo==IS_RIGHT)) return IS_LEFT;
else
Result
=
IS_ON
;
break
;
else
Result
=
IS_ON
;
break
;
// Line 2 lies on right side of this line
// Line 2 lies on right side of this line
case
IS_RIGHT
:
if
((
ThirdToOne
==
IS_RIGHT
)
&&
(
ThirdToTwo
==
IS_RIGHT
))
return
IS_RIGHT
;
case
IS_RIGHT
:
if
(
(
ThirdToOne
==
IS_RIGHT
)
&&
(
ThirdToTwo
==
IS_RIGHT
)
)
return
IS_RIGHT
;
else
if
((
ThirdToOne
==
IS_LEFT
)
||
(
ThirdToTwo
==
IS_LEFT
)
)
return
IS_LEFT
;
else
if
(
(
ThirdToOne
==
IS_LEFT
)
||
(
ThirdToTwo
==
IS_LEFT
)
)
return
IS_LEFT
;
else
Result
=
IS_ON
;
break
;
else
Result
=
IS_ON
;
break
;
default
:
Result
=
IS_ON
;
assert
(
false
);
default
:
Result
=
IS_ON
;
assert
(
false
);
}
}
return
Result
;
return
Result
;
...
@@ -465,26 +462,27 @@ LinkStatus KBoolLink::PointOnCorner(KBoolLink* const two, KBoolLink* const third
...
@@ -465,26 +462,27 @@ LinkStatus KBoolLink::PointOnCorner(KBoolLink* const two, KBoolLink* const third
//
//
// Remove the reference from this link to a_node
// Remove the reference from this link to a_node
//
//
void
KBoolLink
::
Remove
(
Node
*
a_node
)
void
KBoolLink
::
Remove
(
Node
*
a_node
)
{
{
(
m_beginnode
==
a_node
)
?
m_beginnode
=
NULL
:
m_endnode
=
NULL
;
(
m_beginnode
==
a_node
)
?
m_beginnode
=
NULL
:
m_endnode
=
NULL
;
}
}
//
//
// Replace oldnode by newnode and correct the references
// Replace oldnode by newnode and correct the references
//
//
void
KBoolLink
::
Replace
(
Node
*
oldnode
,
Node
*
newnode
)
void
KBoolLink
::
Replace
(
Node
*
oldnode
,
Node
*
newnode
)
{
{
if
(
m_beginnode
==
oldnode
)
if
(
m_beginnode
==
oldnode
)
{
m_beginnode
->
RemoveLink
(
this
);
// remove the reference to this
{
newnode
->
AddLink
(
this
);
// let newnode refer to this
m_beginnode
->
RemoveLink
(
this
);
// remove the reference to this
newnode
->
AddLink
(
this
);
// let newnode refer to this
m_beginnode
=
newnode
;
// let this refer to newnode
m_beginnode
=
newnode
;
// let this refer to newnode
}
}
else
else
{
//assert(endnode==oldnode);
{
//assert(endnode==oldnode);
m_endnode
->
RemoveLink
(
this
);
m_endnode
->
RemoveLink
(
this
);
newnode
->
AddLink
(
this
);
newnode
->
AddLink
(
this
);
m_endnode
=
newnode
;
m_endnode
=
newnode
;
}
}
}
}
...
@@ -511,38 +509,38 @@ void KBoolLink::Reset_flags()
...
@@ -511,38 +509,38 @@ void KBoolLink::Reset_flags()
m_hole_top
=
false
;
// link that is toplink of hole?
m_hole_top
=
false
;
// link that is toplink of hole?
m_group
=
GROUP_A
;
// Does this belong to group A or B ( o.a. for boolean operations between graphs)
m_group
=
GROUP_A
;
// Does this belong to group A or B ( o.a. for boolean operations between graphs)
m_LeftA
=
false
;
// Is left in polygongroup A
m_LeftA
=
false
;
// Is left in polygongroup A
m_RightA
=
false
;
// Is right in polygon group A
m_RightA
=
false
;
// Is right in polygon group A
m_LeftB
=
false
;
// Is left in polygon group B
m_LeftB
=
false
;
// Is left in polygon group B
m_RightB
=
false
;
// Is right in polygongroup B
m_RightB
=
false
;
// Is right in polygongroup B
m_mark
=
false
;
// General purose marker, internally unused
m_mark
=
false
;
// General purose marker, internally unused
m_holelink
=
false
;
m_holelink
=
false
;
m_merge_L
=
m_merge_R
=
false
;
// Marker for Merge
m_merge_L
=
m_merge_R
=
false
;
// Marker for Merge
m_a_substract_b_L
=
m_a_substract_b_R
=
false
;
// Marker for substract
m_a_substract_b_L
=
m_a_substract_b_R
=
false
;
// Marker for substract
m_b_substract_a_L
=
m_b_substract_a_R
=
false
;
// Marker for substract
m_b_substract_a_L
=
m_b_substract_a_R
=
false
;
// Marker for substract
m_intersect_L
=
m_intersect_R
=
false
;
// Marker for intersect
m_intersect_L
=
m_intersect_R
=
false
;
// Marker for intersect
m_exor_L
=
m_exor_R
=
false
;
// Marker for Exor
m_exor_L
=
m_exor_R
=
false
;
// Marker for Exor
}
}
//
//
// Refill this link by the arguments
// Refill this link by the arguments
//
//
void
KBoolLink
::
Reset
(
Node
*
begin
,
Node
*
end
,
int
graphnr
)
void
KBoolLink
::
Reset
(
Node
*
begin
,
Node
*
end
,
int
graphnr
)
{
{
// Remove all the previous references
// Remove all the previous references
UnLink
();
UnLink
();
Reset
();
Reset
();
// Set the references of the node and of this link correct
// Set the references of the node and of this link correct
begin
->
AddLink
(
this
);
begin
->
AddLink
(
this
);
end
->
AddLink
(
this
);
end
->
AddLink
(
this
);
m_beginnode
=
begin
;
m_beginnode
=
begin
;
m_endnode
=
end
;
m_endnode
=
end
;
if
(
graphnr
!=
0
)
if
(
graphnr
!=
0
)
m_graphnum
=
graphnr
;
m_graphnum
=
graphnr
;
}
}
void
KBoolLink
::
Set
(
Node
*
begin
,
Node
*
end
)
void
KBoolLink
::
Set
(
Node
*
begin
,
Node
*
end
)
{
{
m_beginnode
=
begin
;
m_beginnode
=
begin
;
m_endnode
=
end
;
m_endnode
=
end
;
...
@@ -558,13 +556,13 @@ void KBoolLink::SetNotBeenHere()
...
@@ -558,13 +556,13 @@ void KBoolLink::SetNotBeenHere()
m_bin
=
false
;
m_bin
=
false
;
}
}
void
KBoolLink
::
SetBeginNode
(
Node
*
new_node
)
void
KBoolLink
::
SetBeginNode
(
Node
*
new_node
)
{
{
m_beginnode
=
new_node
;
m_beginnode
=
new_node
;
}
}
void
KBoolLink
::
SetEndNode
(
Node
*
new_node
)
void
KBoolLink
::
SetEndNode
(
Node
*
new_node
)
{
{
m_endnode
=
new_node
;
m_endnode
=
new_node
;
}
}
...
@@ -575,7 +573,7 @@ void KBoolLink::SetEndNode(Node* new_node)
...
@@ -575,7 +573,7 @@ void KBoolLink::SetEndNode(Node* new_node)
//
//
void
KBoolLink
::
SetGraphNum
(
int
num
)
void
KBoolLink
::
SetGraphNum
(
int
num
)
{
{
m_graphnum
=
num
;
m_graphnum
=
num
;
}
}
GroupType
KBoolLink
::
Group
()
GroupType
KBoolLink
::
Group
()
...
@@ -587,9 +585,9 @@ GroupType KBoolLink::Group()
...
@@ -587,9 +585,9 @@ GroupType KBoolLink::Group()
//
//
// Reset the groupflag to argument groep
// Reset the groupflag to argument groep
//
//
void
KBoolLink
::
SetGroup
(
GroupType
groep
)
void
KBoolLink
::
SetGroup
(
GroupType
groep
)
{
{
m_group
=
groep
;
m_group
=
groep
;
}
}
...
@@ -598,16 +596,18 @@ void KBoolLink::SetGroup(GroupType groep)
...
@@ -598,16 +596,18 @@ void KBoolLink::SetGroup(GroupType groep)
//
//
void
KBoolLink
::
UnLink
()
void
KBoolLink
::
UnLink
()
{
{
if
(
m_beginnode
)
if
(
m_beginnode
)
{
m_beginnode
->
RemoveLink
(
this
);
{
if
(
!
m_beginnode
->
GetNumberOfLinks
())
delete
m_beginnode
;
m_beginnode
->
RemoveLink
(
this
);
if
(
!
m_beginnode
->
GetNumberOfLinks
()
)
delete
m_beginnode
;
}
}
m_beginnode
=
NULL
;
m_beginnode
=
NULL
;
if
(
m_endnode
)
if
(
m_endnode
)
{
m_endnode
->
RemoveLink
(
this
);
{
if
(
!
m_endnode
->
GetNumberOfLinks
())
delete
m_endnode
;
m_endnode
->
RemoveLink
(
this
);
if
(
!
m_endnode
->
GetNumberOfLinks
()
)
delete
m_endnode
;
}
}
m_endnode
=
NULL
;
m_endnode
=
NULL
;
}
}
...
@@ -617,7 +617,7 @@ void KBoolLink::UnMark()
...
@@ -617,7 +617,7 @@ void KBoolLink::UnMark()
m_bin
=
false
;
m_bin
=
false
;
}
}
void
KBoolLink
::
SetMark
(
bool
value
)
void
KBoolLink
::
SetMark
(
bool
value
)
{
{
m_mark
=
value
;
m_mark
=
value
;
}
}
...
@@ -627,7 +627,7 @@ void KBoolLink::SetMark(bool value)
...
@@ -627,7 +627,7 @@ void KBoolLink::SetMark(bool value)
//
//
bool
KBoolLink
::
IsMarked
()
{
return
m_mark
;
}
bool
KBoolLink
::
IsMarked
()
{
return
m_mark
;
}
void
KBoolLink
::
SetTopHole
(
bool
value
)
{
m_hole_top
=
value
;
}
void
KBoolLink
::
SetTopHole
(
bool
value
)
{
m_hole_top
=
value
;
}
bool
KBoolLink
::
IsTopHole
()
{
return
m_hole_top
;
}
bool
KBoolLink
::
IsTopHole
()
{
return
m_hole_top
;
}
...
@@ -651,52 +651,52 @@ void KBoolLink::SetLineTypes()
...
@@ -651,52 +651,52 @@ void KBoolLink::SetLineTypes()
m_merge_L
=
m_LeftA
||
m_LeftB
;
m_merge_L
=
m_LeftA
||
m_LeftB
;
m_merge_R
=
m_RightA
||
m_RightB
;
m_merge_R
=
m_RightA
||
m_RightB
;
//both in mean does not add to result.
//both in mean does not add to result.
if
(
m_merge_L
&&
m_merge_R
)
if
(
m_merge_L
&&
m_merge_R
)
m_merge_L
=
m_merge_R
=
false
;
m_merge_L
=
m_merge_R
=
false
;
m_a_substract_b_L
=
m_LeftA
&&
!
m_LeftB
;
m_a_substract_b_L
=
m_LeftA
&&
!
m_LeftB
;
m_a_substract_b_R
=
m_RightA
&&
!
m_RightB
;
m_a_substract_b_R
=
m_RightA
&&
!
m_RightB
;
//both in mean does not add to result.
//both in mean does not add to result.
if
(
m_a_substract_b_L
&&
m_a_substract_b_R
)
if
(
m_a_substract_b_L
&&
m_a_substract_b_R
)
m_a_substract_b_L
=
m_a_substract_b_R
=
false
;
m_a_substract_b_L
=
m_a_substract_b_R
=
false
;
m_b_substract_a_L
=
m_LeftB
&&
!
m_LeftA
;
m_b_substract_a_L
=
m_LeftB
&&
!
m_LeftA
;
m_b_substract_a_R
=
m_RightB
&&
!
m_RightA
;
m_b_substract_a_R
=
m_RightB
&&
!
m_RightA
;
//both in mean does not add to result.
//both in mean does not add to result.
if
(
m_b_substract_a_L
&&
m_b_substract_a_R
)
if
(
m_b_substract_a_L
&&
m_b_substract_a_R
)
m_b_substract_a_L
=
m_b_substract_a_R
=
false
;
m_b_substract_a_L
=
m_b_substract_a_R
=
false
;
m_intersect_L
=
m_LeftB
&&
m_LeftA
;
m_intersect_L
=
m_LeftB
&&
m_LeftA
;
m_intersect_R
=
m_RightB
&&
m_RightA
;
m_intersect_R
=
m_RightB
&&
m_RightA
;
//both in mean does not add to result.
//both in mean does not add to result.
if
(
m_intersect_L
&&
m_intersect_R
)
if
(
m_intersect_L
&&
m_intersect_R
)
m_intersect_L
=
m_intersect_R
=
false
;
m_intersect_L
=
m_intersect_R
=
false
;
m_exor_L
=
!
(
(
m_LeftB
&&
m_LeftA
)
||
(
!
m_LeftB
&&
!
m_LeftA
)
);
m_exor_L
=
!
(
(
m_LeftB
&&
m_LeftA
)
||
(
!
m_LeftB
&&
!
m_LeftA
)
);
m_exor_R
=
!
(
(
m_RightB
&&
m_RightA
)
||
(
!
m_RightB
&&
!
m_RightA
)
);
m_exor_R
=
!
(
(
m_RightB
&&
m_RightA
)
||
(
!
m_RightB
&&
!
m_RightA
)
);
//both in mean does not add to result.
//both in mean does not add to result.
if
(
m_exor_L
&&
m_exor_R
)
if
(
m_exor_L
&&
m_exor_R
)
m_exor_L
=
m_exor_R
=
false
;
m_exor_L
=
m_exor_R
=
false
;
}
}
//put in direction with a_node as beginnode
//put in direction with a_node as beginnode
void
KBoolLink
::
Redirect
(
Node
*
a_node
)
void
KBoolLink
::
Redirect
(
Node
*
a_node
)
{
{
if
(
a_node
!=
m_beginnode
)
if
(
a_node
!=
m_beginnode
)
{
{
// swap the begin- and endnode of the current link
// swap the begin- and endnode of the current link
Node
*
dummy
=
m_beginnode
;
Node
*
dummy
=
m_beginnode
;
m_beginnode
=
m_endnode
;
m_beginnode
=
m_endnode
;
m_endnode
=
dummy
;
m_endnode
=
dummy
;
bool
swap
=
m_LeftA
;
bool
swap
=
m_LeftA
;
m_LeftA
=
m_RightA
;
m_LeftA
=
m_RightA
;
m_RightA
=
swap
;
m_RightA
=
swap
;
swap
=
m_LeftB
;
swap
=
m_LeftB
;
m_LeftB
=
m_RightB
;
m_LeftB
=
m_RightB
;
m_RightB
=
swap
;
m_RightB
=
swap
;
swap
=
m_merge_L
;
swap
=
m_merge_L
;
m_merge_L
=
m_merge_R
;
m_merge_L
=
m_merge_R
;
...
...
polygon/kbool/src/lpoint.cpp
View file @
521f428c
/*! \file
../
src/lpoint.cpp
/*! \file src/lpoint.cpp
\brief Definition of GDSII LPoint type structure
\brief Definition of GDSII LPoint type structure
\author
Probably
Klaas Holwerda
\author Klaas Holwerda
Copyright: 2001-2004 (C)
Probably
Klaas Holwerda
Copyright: 2001-2004 (C) Klaas Holwerda
Licence:
wxWidgets Licence
Licence:
see kboollicense.txt
RCS-ID: $Id: lpoint.cpp,v 1.
4 2005/05/24 19:13:39
titato Exp $
RCS-ID: $Id: lpoint.cpp,v 1.
3 2008/06/04 21:23:22
titato Exp $
*/
*/
#ifdef __GNUG__
#include "kbool/lpoint.h"
#pragma implementation
#endif
#include "../include/lpoint.h"
#include <math.h>
#include <math.h>
// Constructors
// Constructors
...
@@ -24,18 +20,18 @@ LPoint::LPoint()
...
@@ -24,18 +20,18 @@ LPoint::LPoint()
}
}
LPoint
::
LPoint
(
B_INT
const
X
,
B_INT
const
Y
)
LPoint
::
LPoint
(
B_INT
const
X
,
B_INT
const
Y
)
{
{
_x
=
X
;
_x
=
X
;
_y
=
Y
;
_y
=
Y
;
}
}
LPoint
::
LPoint
(
LPoint
*
const
a_point
)
LPoint
::
LPoint
(
LPoint
*
const
a_point
)
{
{
if
(
!
a_point
)
if
(
!
a_point
)
throw
Bool_Engine_Error
(
"Cannot copy a NULL Point Object.
\n\n
Could not create a LPoint Object."
,
throw
Bool_Engine_Error
(
"Cannot copy a NULL Point Object.
\n\n
Could not create a LPoint Object."
,
"Fatal Creation Error"
,
0
,
1
);
"Fatal Creation Error"
,
0
,
1
);
_x
=
a_point
->
_x
;
_x
=
a_point
->
_x
;
_y
=
a_point
->
_y
;
_y
=
a_point
->
_y
;
}
}
...
@@ -52,13 +48,13 @@ B_INT LPoint::GetY()
...
@@ -52,13 +48,13 @@ B_INT LPoint::GetY()
}
}
void
LPoint
::
SetX
(
B_INT
a_point_x
)
void
LPoint
::
SetX
(
B_INT
a_point_x
)
{
{
_x
=
a_point_x
;
_x
=
a_point_x
;
}
}
void
LPoint
::
SetY
(
B_INT
a_point_y
)
void
LPoint
::
SetY
(
B_INT
a_point_y
)
{
{
_y
=
a_point_y
;
_y
=
a_point_y
;
}
}
...
@@ -66,70 +62,70 @@ void LPoint::SetY(B_INT a_point_y)
...
@@ -66,70 +62,70 @@ void LPoint::SetY(B_INT a_point_y)
LPoint
LPoint
::
GetPoint
()
LPoint
LPoint
::
GetPoint
()
{
{
return
*
this
;
return
*
this
;
}
}
void
LPoint
::
Set
(
const
B_INT
X
,
const
B_INT
Y
)
void
LPoint
::
Set
(
const
B_INT
X
,
const
B_INT
Y
)
{
{
_x
=
X
;
_x
=
X
;
_y
=
Y
;
_y
=
Y
;
}
}
void
LPoint
::
Set
(
const
LPoint
&
a_point
)
void
LPoint
::
Set
(
const
LPoint
&
a_point
)
{
{
_x
=
a_point
.
_x
;
_x
=
a_point
.
_x
;
_y
=
a_point
.
_y
;
_y
=
a_point
.
_y
;
}
}
bool
LPoint
::
Equal
(
const
LPoint
a_point
,
B_INT
Marge
)
bool
LPoint
::
Equal
(
const
LPoint
a_point
,
B_INT
Marge
)
{
{
B_INT
delta_x
,
delta_y
;
B_INT
delta_x
,
delta_y
;
delta_x
=
babs
((
_x
-
a_point
.
_x
)
);
delta_x
=
babs
(
(
_x
-
a_point
.
_x
)
);
delta_y
=
babs
((
_y
-
a_point
.
_y
)
);
delta_y
=
babs
(
(
_y
-
a_point
.
_y
)
);
if
((
delta_x
<=
Marge
)
&&
(
delta_y
<=
Marge
)
)
if
(
(
delta_x
<=
Marge
)
&&
(
delta_y
<=
Marge
)
)
return
true
;
return
true
;
else
else
return
false
;
return
false
;
}
}
bool
LPoint
::
Equal
(
const
B_INT
X
,
const
B_INT
Y
,
B_INT
Marge
)
bool
LPoint
::
Equal
(
const
B_INT
X
,
const
B_INT
Y
,
B_INT
Marge
)
{
{
return
(
bool
)((
babs
(
_x
-
X
)
<=
Marge
)
&&
(
babs
(
_y
-
Y
)
<=
Marge
)
);
return
(
bool
)(
(
babs
(
_x
-
X
)
<=
Marge
)
&&
(
babs
(
_y
-
Y
)
<=
Marge
)
);
}
}
bool
LPoint
::
ShorterThan
(
const
LPoint
a_point
,
B_INT
Marge
)
bool
LPoint
::
ShorterThan
(
const
LPoint
a_point
,
B_INT
Marge
)
{
{
double
a
,
b
;
double
a
,
b
;
a
=
(
double
)
(
a_point
.
_x
-
_x
);
a
=
(
double
)
(
a_point
.
_x
-
_x
);
a
*=
a
;
a
*=
a
;
b
=
(
double
)
(
a_point
.
_y
-
_y
);
b
=
(
double
)
(
a_point
.
_y
-
_y
);
b
*=
b
;
b
*=
b
;
return
(
bool
)
(
(
a
+
b
)
<=
Marge
*
Marge
?
true
:
false
)
;
return
(
bool
)
(
(
a
+
b
)
<=
Marge
*
Marge
?
true
:
false
)
;
}
}
bool
LPoint
::
ShorterThan
(
const
B_INT
X
,
const
B_INT
Y
,
B_INT
Marge
)
bool
LPoint
::
ShorterThan
(
const
B_INT
X
,
const
B_INT
Y
,
B_INT
Marge
)
{
{
double
a
,
b
;
double
a
,
b
;
a
=
(
double
)
(
X
-
_x
);
a
=
(
double
)
(
X
-
_x
);
a
*=
a
;
a
*=
a
;
b
=
(
double
)
(
Y
-
_y
);
b
=
(
double
)
(
Y
-
_y
);
b
*=
b
;
b
*=
b
;
return
(
bool
)
(
a
+
b
<=
Marge
*
Marge
?
true
:
false
)
;
return
(
bool
)
(
a
+
b
<=
Marge
*
Marge
?
true
:
false
)
;
}
}
// overload the assign (=) operator
// overload the assign (=) operator
// usage : a_point = another_point;
// usage : a_point = another_point;
LPoint
&
LPoint
::
operator
=
(
const
LPoint
&
other_point
)
LPoint
&
LPoint
::
operator
=
(
const
LPoint
&
other_point
)
{
{
_x
=
other_point
.
_x
;
_x
=
other_point
.
_x
;
_y
=
other_point
.
_y
;
_y
=
other_point
.
_y
;
...
@@ -140,7 +136,7 @@ LPoint &LPoint::operator=(const LPoint &other_point)
...
@@ -140,7 +136,7 @@ LPoint &LPoint::operator=(const LPoint &other_point)
// overload the + operator
// overload the + operator
// usage : a_point = point1 + point2;
// usage : a_point = point1 + point2;
LPoint
&
LPoint
::
operator
+
(
const
LPoint
&
other_point
)
LPoint
&
LPoint
::
operator
+
(
const
LPoint
&
other_point
)
{
{
_x
+=
other_point
.
_x
;
_x
+=
other_point
.
_x
;
_y
+=
other_point
.
_y
;
_y
+=
other_point
.
_y
;
...
@@ -152,7 +148,7 @@ LPoint &LPoint::operator+(const LPoint &other_point)
...
@@ -152,7 +148,7 @@ LPoint &LPoint::operator+(const LPoint &other_point)
// overload the - operator
// overload the - operator
// usage : a_point = point1 - point2;
// usage : a_point = point1 - point2;
LPoint
&
LPoint
::
operator
-
(
const
LPoint
&
other_point
)
LPoint
&
LPoint
::
operator
-
(
const
LPoint
&
other_point
)
{
{
_x
-=
other_point
.
_x
;
_x
-=
other_point
.
_x
;
_y
-=
other_point
.
_y
;
_y
-=
other_point
.
_y
;
...
@@ -163,7 +159,7 @@ LPoint &LPoint::operator-(const LPoint &other_point)
...
@@ -163,7 +159,7 @@ LPoint &LPoint::operator-(const LPoint &other_point)
// overload the * operator
// overload the * operator
// usage: a_point = point1 * 100;
// usage: a_point = point1 * 100;
LPoint
&
LPoint
::
operator
*
(
int
factor
)
LPoint
&
LPoint
::
operator
*
(
int
factor
)
{
{
_x
*=
factor
;
_x
*=
factor
;
_y
*=
factor
;
_y
*=
factor
;
...
@@ -174,7 +170,7 @@ LPoint &LPoint::operator*(int factor)
...
@@ -174,7 +170,7 @@ LPoint &LPoint::operator*(int factor)
// overload the / operator
// overload the / operator
// usage: a_point = point1 / 100;
// usage: a_point = point1 / 100;
LPoint
&
LPoint
::
operator
/
(
int
factor
)
LPoint
&
LPoint
::
operator
/
(
int
factor
)
{
{
_x
/=
factor
;
_x
/=
factor
;
_y
/=
factor
;
_y
/=
factor
;
...
@@ -185,18 +181,18 @@ LPoint &LPoint::operator/(int factor)
...
@@ -185,18 +181,18 @@ LPoint &LPoint::operator/(int factor)
// overload the compare (==) operator
// overload the compare (==) operator
// usage: if (point1 == point2) { };
// usage: if (point1 == point2) { };
int
LPoint
::
operator
==
(
const
LPoint
&
other_point
)
const
int
LPoint
::
operator
==
(
const
LPoint
&
other_point
)
const
{
{
return
((
other_point
.
_x
==
_x
)
&&
(
other_point
.
_y
==
_y
)
);
return
(
(
other_point
.
_x
==
_x
)
&&
(
other_point
.
_y
==
_y
)
);
}
}
// overload the diffrent (!=) operator
// overload the diffrent (!=) operator
// usage: if (point1 != point2) { };
// usage: if (point1 != point2) { };
int
LPoint
::
operator
!=
(
const
LPoint
&
other_point
)
const
int
LPoint
::
operator
!=
(
const
LPoint
&
other_point
)
const
{
{
return
((
other_point
.
_x
!=
_x
)
||
(
other_point
.
_y
!=
_y
)
);
return
(
(
other_point
.
_x
!=
_x
)
||
(
other_point
.
_y
!=
_y
)
);
}
}
...
...
polygon/kbool/src/makefile.include
View file @
521f428c
# makefile.include for kbool
.cpp.o
:
g++
-c
-Wall
-O2
-I
../include
-o
$@
$*
.cpp
OBJECTS
=
\
OBJECTS
=
\
booleng.o
\
booleng.o
\
graph.o
\
graph.o
\
...
...
polygon/kbool/src/node.cpp
View file @
521f428c
/*! \file
../
src/node.cpp
/*! \file src/node.cpp
\brief Holds a GDSII node structure
\brief Holds a GDSII node structure
\author
Probably
Klaas Holwerda
\author Klaas Holwerda
Copyright: 2001-2004 (C)
Probably
Klaas Holwerda
Copyright: 2001-2004 (C) Klaas Holwerda
Licence:
wxWidgets Licence
Licence:
see kboollicense.txt
RCS-ID: $Id: node.cpp,v 1.
7 2005/06/17 23:01:03 kbluck
Exp $
RCS-ID: $Id: node.cpp,v 1.
3 2008/06/04 21:23:22 titato
Exp $
*/
*/
#ifdef __GNUG__
#pragma implementation
#endif
#include "
../include
/node.h"
#include "
kbool
/node.h"
#include "
../include
/link.h"
#include "
kbool
/link.h"
#include "
../include
/line.h"
#include "
kbool
/line.h"
#include <math.h>
#include <math.h>
//this here is to initialize the static iterator of node
//this here is to initialize the static iterator of node
//with NOLIST constructor
//with NOLIST constructor
//TDLI<KBoolLink> Node::_linkiter=TDLI<KBoolLink>(_GC);
//TDLI<KBoolLink> Node::_linkiter=TDLI<KBoolLink>(_GC);
Node
::
Node
(
Bool_Engine
*
GC
)
:
LPoint
(
0
,
0
)
Node
::
Node
(
Bool_Engine
*
GC
)
:
LPoint
(
0
,
0
)
{
{
_GC
=
GC
;
_GC
=
GC
;
_linklist
=
new
DL_List
<
void
*>
();
_linklist
=
new
DL_List
<
void
*>
();
}
}
Node
::
Node
(
B_INT
const
X
,
B_INT
const
Y
,
Bool_Engine
*
GC
)
:
LPoint
(
X
,
Y
)
Node
::
Node
(
B_INT
const
X
,
B_INT
const
Y
,
Bool_Engine
*
GC
)
:
LPoint
(
X
,
Y
)
{
{
_GC
=
GC
;
_GC
=
GC
;
_linklist
=
new
DL_List
<
void
*>
();
_linklist
=
new
DL_List
<
void
*>
();
}
}
Node
::
Node
(
LPoint
*
const
a_point
,
Bool_Engine
*
GC
)
:
LPoint
(
a_point
)
Node
::
Node
(
LPoint
*
const
a_point
,
Bool_Engine
*
GC
)
:
LPoint
(
a_point
)
{
{
_GC
=
GC
;
_GC
=
GC
;
_linklist
=
new
DL_List
<
void
*>
();
_linklist
=
new
DL_List
<
void
*>
();
}
}
//Node::Node(Node * const other) : LPoint(other)
//Node::Node(Node * const other) : LPoint(other)
Node
::
Node
(
Node
*
const
other
,
Bool_Engine
*
GC
)
Node
::
Node
(
Node
*
const
other
,
Bool_Engine
*
GC
)
{
{
_GC
=
GC
;
_GC
=
GC
;
_x
=
other
->
_x
;
_x
=
other
->
_x
;
_y
=
other
->
_y
;
_y
=
other
->
_y
;
_linklist
=
new
DL_List
<
void
*>
();
_linklist
=
new
DL_List
<
void
*>
();
}
}
Node
&
Node
::
operator
=
(
const
Node
&
other_node
)
Node
&
Node
::
operator
=
(
const
Node
&
other_node
)
{
{
_x
=
other_node
.
_x
;
_x
=
other_node
.
_x
;
_y
=
other_node
.
_y
;
_y
=
other_node
.
_y
;
...
@@ -62,10 +59,10 @@ Node& Node::operator=(const Node &other_node)
...
@@ -62,10 +59,10 @@ Node& Node::operator=(const Node &other_node)
// x and y of the point will be rounded to the nearest
// x and y of the point will be rounded to the nearest
// xnew=N*grid and ynew=N*grid
// xnew=N*grid and ynew=N*grid
void
Node
::
RoundInt
(
B_INT
grid
)
void
Node
::
RoundInt
(
B_INT
grid
)
{
{
_x
=
(
B_INT
)
floor
((
_x
+
grid
*
0.5
)
/
grid
)
*
grid
;
_x
=
(
B_INT
)
floor
(
(
_x
+
grid
*
0.5
)
/
grid
)
*
grid
;
_y
=
(
B_INT
)
floor
((
_y
+
grid
*
0.5
)
/
grid
)
*
grid
;
_y
=
(
B_INT
)
floor
(
(
_y
+
grid
*
0.5
)
/
grid
)
*
grid
;
}
}
Node
::~
Node
()
Node
::~
Node
()
...
@@ -78,26 +75,26 @@ DL_List<void*>* Node::GetLinklist()
...
@@ -78,26 +75,26 @@ DL_List<void*>* Node::GetLinklist()
return
_linklist
;
return
_linklist
;
}
}
void
Node
::
AddLink
(
KBoolLink
*
a_link
)
void
Node
::
AddLink
(
KBoolLink
*
a_link
)
{
{
// assert(a_link);
// assert(a_link);
_linklist
->
insbegin
(
a_link
);
_linklist
->
insbegin
(
a_link
);
}
}
KBoolLink
*
Node
::
GetIncomingLink
()
KBoolLink
*
Node
::
GetIncomingLink
()
{
{
if
(((
KBoolLink
*
)
_linklist
->
headitem
())
->
GetEndNode
()
==
this
)
if
(
(
(
KBoolLink
*
)
_linklist
->
headitem
()
)
->
GetEndNode
()
==
this
)
return
(
KBoolLink
*
)
_linklist
->
headitem
();
return
(
KBoolLink
*
)
_linklist
->
headitem
();
else
else
return
(
KBoolLink
*
)
_linklist
->
tailitem
();
return
(
KBoolLink
*
)
_linklist
->
tailitem
();
}
}
KBoolLink
*
Node
::
GetOutgoingLink
()
KBoolLink
*
Node
::
GetOutgoingLink
()
{
{
if
(((
KBoolLink
*
)
_linklist
->
headitem
())
->
GetBeginNode
()
==
this
)
if
(
(
(
KBoolLink
*
)
_linklist
->
headitem
()
)
->
GetBeginNode
()
==
this
)
return
(
KBoolLink
*
)
_linklist
->
headitem
();
return
(
KBoolLink
*
)
_linklist
->
headitem
();
else
else
return
(
KBoolLink
*
)
_linklist
->
tailitem
();
return
(
KBoolLink
*
)
_linklist
->
tailitem
();
}
}
//
//
...
@@ -108,45 +105,45 @@ int Node::GetNumberOfLinks()
...
@@ -108,45 +105,45 @@ int Node::GetNumberOfLinks()
return
_linklist
->
count
();
return
_linklist
->
count
();
}
}
KBoolLink
*
Node
::
GetOtherLink
(
KBoolLink
*
prev
)
KBoolLink
*
Node
::
GetOtherLink
(
KBoolLink
*
prev
)
{
{
if
(
prev
==
(
KBoolLink
*
)
_linklist
->
headitem
()
)
if
(
prev
==
(
KBoolLink
*
)
_linklist
->
headitem
()
)
return
(
KBoolLink
*
)
_linklist
->
tailitem
();
return
(
KBoolLink
*
)
_linklist
->
tailitem
();
if
(
prev
==
(
KBoolLink
*
)
_linklist
->
tailitem
()
)
if
(
prev
==
(
KBoolLink
*
)
_linklist
->
tailitem
()
)
return
(
KBoolLink
*
)
_linklist
->
headitem
();
return
(
KBoolLink
*
)
_linklist
->
headitem
();
return
NULL
;
return
NULL
;
}
}
int
Node
::
Merge
(
Node
*
other
)
int
Node
::
Merge
(
Node
*
other
)
{
{
if
(
this
==
other
)
//they are already merged dummy
if
(
this
==
other
)
//they are already merged dummy
return
0
;
return
0
;
_GC
->
_linkiter
->
Attach
(
_linklist
);
_GC
->
_linkiter
->
Attach
(
_linklist
);
int
Counter
;
int
Counter
;
// used to delete Iterator on other->_linklist
// used to delete Iterator on other->_linklist
// otherwise there can't be a takeover, because for takeover there can't
// otherwise there can't be a takeover, because for takeover there can't
// be an iterator on other->_linklist;
// be an iterator on other->_linklist;
{
{
TDLI
<
KBoolLink
>
Iother
(
other
->
_linklist
);
TDLI
<
KBoolLink
>
Iother
(
other
->
_linklist
);
KBoolLink
*
temp
;
KBoolLink
*
temp
;
Counter
=
Iother
.
count
();
Counter
=
Iother
.
count
();
Iother
.
tohead
();
Iother
.
tohead
();
while
(
!
Iother
.
hitroot
()
)
while
(
!
Iother
.
hitroot
()
)
{
{
temp
=
Iother
.
item
();
temp
=
Iother
.
item
();
//need to test both nodes because it may be a zero length link
//need to test both nodes because it may be a zero length link
if
(
temp
->
GetEndNode
()
==
other
)
if
(
temp
->
GetEndNode
()
==
other
)
temp
->
SetEndNode
(
this
);
temp
->
SetEndNode
(
this
);
if
(
temp
->
GetBeginNode
()
==
other
)
if
(
temp
->
GetBeginNode
()
==
other
)
temp
->
SetBeginNode
(
this
);
temp
->
SetBeginNode
(
this
);
Iother
++
;
Iother
++
;
}
}
_GC
->
_linkiter
->
takeover
(
&
Iother
);
_GC
->
_linkiter
->
takeover
(
&
Iother
);
}
}
_GC
->
_linkiter
->
Detach
();
_GC
->
_linkiter
->
Detach
();
...
@@ -156,12 +153,12 @@ int Node::Merge(Node *other)
...
@@ -156,12 +153,12 @@ int Node::Merge(Node *other)
}
}
void
Node
::
RemoveLink
(
KBoolLink
*
a_link
)
void
Node
::
RemoveLink
(
KBoolLink
*
a_link
)
{
{
// assert(a_link);
// assert(a_link);
_GC
->
_linkiter
->
Attach
(
_linklist
);
_GC
->
_linkiter
->
Attach
(
_linklist
);
if
(
_GC
->
_linkiter
->
toitem
(
a_link
))
// find the link
if
(
_GC
->
_linkiter
->
toitem
(
a_link
)
)
// find the link
_GC
->
_linkiter
->
remove
();
_GC
->
_linkiter
->
remove
();
_GC
->
_linkiter
->
Detach
();
_GC
->
_linkiter
->
Detach
();
}
}
...
@@ -175,45 +172,45 @@ void Node::RemoveLink(KBoolLink *a_link)
...
@@ -175,45 +172,45 @@ void Node::RemoveLink(KBoolLink *a_link)
// output: -
// output: -
// return: true if points can be simplified
// return: true if points can be simplified
// false if points can't be simplified
// false if points can't be simplified
bool
Node
::
Simplify
(
Node
*
First
,
Node
*
Second
,
B_INT
Marge
)
bool
Node
::
Simplify
(
Node
*
First
,
Node
*
Second
,
B_INT
Marge
)
{
{
double
distance
=
0
;
double
distance
=
0
;
// The first and second point are a zero line, if so we can
// The first and second point are a zero line, if so we can
// make a line between the first and third point
// make a line between the first and third point
if
(
First
->
Equal
(
Second
,
Marge
)
)
if
(
First
->
Equal
(
Second
,
Marge
)
)
return
true
;
return
true
;
// Are the first and third point equal, if so
// Are the first and third point equal, if so
// we can delete the second point
// we can delete the second point
if
(
First
->
Equal
(
this
,
Marge
)
)
if
(
First
->
Equal
(
this
,
Marge
)
)
return
true
;
return
true
;
// Used tmp_link.set here, because the link may not be linked in the graph,
// Used tmp_link.set here, because the link may not be linked in the graph,
// because the point of the graphs are used, after use of the line we have
// because the point of the graphs are used, after use of the line we have
//to set the link to zero so the nodes will not be destructed by exit of the function
//to set the link to zero so the nodes will not be destructed by exit of the function
KBoolLink
tmp_link
(
_GC
);
KBoolLink
tmp_link
(
_GC
);
tmp_link
.
Set
(
First
,
Second
);
tmp_link
.
Set
(
First
,
Second
);
KBoolLine
tmp_line
(
_GC
);
KBoolLine
tmp_line
(
_GC
);
tmp_line
.
Set
(
&
tmp_link
);
tmp_line
.
Set
(
&
tmp_link
);
// If third point is on the same line which is made from the first
// If third point is on the same line which is made from the first
// and second point then we can delete the second point
// and second point then we can delete the second point
if
(
tmp_line
.
PointOnLine
(
this
,
distance
,
(
double
)
Marge
)
==
ON_AREA
)
if
(
tmp_line
.
PointOnLine
(
this
,
distance
,
(
double
)
Marge
)
==
ON_AREA
)
{
{
tmp_link
.
Set
(
NULL
,
NULL
);
tmp_link
.
Set
(
NULL
,
NULL
);
return
true
;
return
true
;
}
}
//
//
//
//
tmp_link
.
Set
(
Second
,
this
);
tmp_link
.
Set
(
Second
,
this
);
tmp_line
.
Set
(
&
tmp_link
);
tmp_line
.
Set
(
&
tmp_link
);
if
(
tmp_line
.
PointOnLine
(
First
,
distance
,
(
double
)
Marge
)
==
ON_AREA
)
if
(
tmp_line
.
PointOnLine
(
First
,
distance
,
(
double
)
Marge
)
==
ON_AREA
)
{
{
tmp_link
.
Set
(
NULL
,
NULL
);
tmp_link
.
Set
(
NULL
,
NULL
);
return
true
;
return
true
;
}
}
tmp_link
.
Set
(
NULL
,
NULL
);
tmp_link
.
Set
(
NULL
,
NULL
);
return
false
;
return
false
;
}
}
...
@@ -225,32 +222,32 @@ KBoolLink* Node::GetNextLink()
...
@@ -225,32 +222,32 @@ KBoolLink* Node::GetNextLink()
// assert (Aantal != 0);
// assert (Aantal != 0);
// there is one link, so there is no previous link
// there is one link, so there is no previous link
if
(
Aantal
==
1
)
if
(
Aantal
==
1
)
return
NULL
;
return
NULL
;
int
Marked_Counter
=
0
;
int
Marked_Counter
=
0
;
KBoolLink
*
the_link
=
NULL
;
KBoolLink
*
the_link
=
NULL
;
// count the marked links
// count the marked links
_GC
->
_linkiter
->
Attach
(
_linklist
);
_GC
->
_linkiter
->
Attach
(
_linklist
);
_GC
->
_linkiter
->
tohead
();
_GC
->
_linkiter
->
tohead
();
while
(
!
_GC
->
_linkiter
->
hitroot
()
)
while
(
!
_GC
->
_linkiter
->
hitroot
()
)
{
{
if
(
_GC
->
_linkiter
->
item
()
->
IsMarked
()
)
if
(
_GC
->
_linkiter
->
item
()
->
IsMarked
()
)
Marked_Counter
++
;
Marked_Counter
++
;
else
else
{
{
if
(
!
the_link
)
if
(
!
the_link
)
the_link
=
_GC
->
_linkiter
->
item
();
the_link
=
_GC
->
_linkiter
->
item
();
}
}
(
*
_GC
->
_linkiter
)
++
;
(
*
_GC
->
_linkiter
)
++
;
}
}
_GC
->
_linkiter
->
Detach
();
_GC
->
_linkiter
->
Detach
();
if
(
Aantal
-
Marked_Counter
!=
1
)
if
(
Aantal
-
Marked_Counter
!=
1
)
// there arent two unmarked links
// there arent two unmarked links
return
NULL
;
return
NULL
;
else
else
{
{
if
(
the_link
->
GetBeginNode
()
==
this
)
if
(
the_link
->
GetBeginNode
()
==
this
)
return
the_link
;
return
the_link
;
else
else
return
NULL
;
return
NULL
;
...
@@ -261,7 +258,7 @@ KBoolLink* Node::GetNextLink()
...
@@ -261,7 +258,7 @@ KBoolLink* Node::GetNextLink()
KBoolLink
*
Node
::
GetPrevLink
()
KBoolLink
*
Node
::
GetPrevLink
()
{
{
int
Aantal
;
int
Aantal
;
if
(
!
_linklist
)
if
(
!
_linklist
)
return
NULL
;
return
NULL
;
Aantal
=
_linklist
->
count
();
Aantal
=
_linklist
->
count
();
...
@@ -269,33 +266,33 @@ KBoolLink* Node::GetPrevLink()
...
@@ -269,33 +266,33 @@ KBoolLink* Node::GetPrevLink()
// assert (Aantal != 0);
// assert (Aantal != 0);
// there is one link, so there is no previous link
// there is one link, so there is no previous link
if
(
Aantal
==
1
)
if
(
Aantal
==
1
)
return
NULL
;
return
NULL
;
int
Marked_Counter
=
0
;
int
Marked_Counter
=
0
;
KBoolLink
*
the_link
=
NULL
;
KBoolLink
*
the_link
=
NULL
;
_GC
->
_linkiter
->
Attach
(
_linklist
);
_GC
->
_linkiter
->
Attach
(
_linklist
);
// count the marked links
// count the marked links
_GC
->
_linkiter
->
tohead
();
_GC
->
_linkiter
->
tohead
();
while
(
!
_GC
->
_linkiter
->
hitroot
()
)
while
(
!
_GC
->
_linkiter
->
hitroot
()
)
{
{
if
(
_GC
->
_linkiter
->
item
()
->
IsMarked
()
)
if
(
_GC
->
_linkiter
->
item
()
->
IsMarked
()
)
Marked_Counter
++
;
Marked_Counter
++
;
else
else
{
{
if
(
!
the_link
)
if
(
!
the_link
)
the_link
=
_GC
->
_linkiter
->
item
();
the_link
=
_GC
->
_linkiter
->
item
();
}
}
(
*
_GC
->
_linkiter
)
++
;
(
*
_GC
->
_linkiter
)
++
;
}
}
_GC
->
_linkiter
->
Detach
();
_GC
->
_linkiter
->
Detach
();
if
(
Aantal
-
Marked_Counter
!=
1
)
if
(
Aantal
-
Marked_Counter
!=
1
)
// there arent two unmarked links
// there arent two unmarked links
return
NULL
;
return
NULL
;
else
else
{
{
if
(
the_link
->
GetEndNode
()
==
this
)
if
(
the_link
->
GetEndNode
()
==
this
)
return
the_link
;
return
the_link
;
else
else
return
NULL
;
return
NULL
;
...
@@ -334,26 +331,26 @@ bool Node::SameSides( KBoolLink* const prev , KBoolLink* const link, BOOL_OP ope
...
@@ -334,26 +331,26 @@ bool Node::SameSides( KBoolLink* const prev , KBoolLink* const link, BOOL_OP ope
// on the node get the link
// on the node get the link
// is the most right or left one
// is the most right or left one
// This function is used to collect the simple graphs from a graph
// This function is used to collect the simple graphs from a graph
KBoolLink
*
Node
::
GetMost
(
KBoolLink
*
const
prev
,
LinkStatus
whatside
,
BOOL_OP
operation
)
KBoolLink
*
Node
::
GetMost
(
KBoolLink
*
const
prev
,
LinkStatus
whatside
,
BOOL_OP
operation
)
{
{
KBoolLink
*
reserve
=
0
;
KBoolLink
*
reserve
=
0
;
KBoolLink
*
Result
=
NULL
,
*
link
;
KBoolLink
*
Result
=
NULL
,
*
link
;
Node
*
prevbegin
=
prev
->
GetOther
(
this
);
Node
*
prevbegin
=
prev
->
GetOther
(
this
);
if
(
_linklist
->
count
()
==
2
)
// only two links to this node take the one != prev
if
(
_linklist
->
count
()
==
2
)
// only two links to this node take the one != prev
{
{
if
(
(
link
=
(
KBoolLink
*
)
_linklist
->
headitem
()
)
==
prev
)
//this is NOT the one to go on
if
(
(
link
=
(
KBoolLink
*
)
_linklist
->
headitem
()
)
==
prev
)
//this is NOT the one to go on
link
=
(
KBoolLink
*
)
_linklist
->
tailitem
();
link
=
(
KBoolLink
*
)
_linklist
->
tailitem
();
if
(
!
link
->
BeenHere
()
&&
SameSides
(
prev
,
link
,
operation
)
)
if
(
!
link
->
BeenHere
()
&&
SameSides
(
prev
,
link
,
operation
)
)
//we are back where we started (bin is true) return Null
//we are back where we started (bin is true) return Null
return
link
;
return
link
;
return
(
0
);
return
(
0
);
}
}
_GC
->
_linkiter
->
Attach
(
_linklist
);
_GC
->
_linkiter
->
Attach
(
_linklist
);
_GC
->
_linkiter
->
tohead
();
_GC
->
_linkiter
->
tohead
();
//more then 2 links to the Node
//more then 2 links to the Node
while
(
!
_GC
->
_linkiter
->
hitroot
()
)
while
(
!
_GC
->
_linkiter
->
hitroot
()
)
{
{
link
=
_GC
->
_linkiter
->
item
();
link
=
_GC
->
_linkiter
->
item
();
if
(
!
link
->
BeenHere
()
&&
if
(
!
link
->
BeenHere
()
&&
...
@@ -361,30 +358,30 @@ KBoolLink* Node::GetMost( KBoolLink* const prev ,LinkStatus whatside, BOOL_OP op
...
@@ -361,30 +358,30 @@ KBoolLink* Node::GetMost( KBoolLink* const prev ,LinkStatus whatside, BOOL_OP op
link
!=
prev
//should be set to bin already
link
!=
prev
//should be set to bin already
)
)
{
{
if
(
prevbegin
==
link
->
GetOther
(
this
)
)
//pointers equal
if
(
prevbegin
==
link
->
GetOther
(
this
)
)
//pointers equal
//we are going back in the same direction on a parallel link
//we are going back in the same direction on a parallel link
//only take this possibility if nothing else is possible
//only take this possibility if nothing else is possible
reserve
=
link
;
reserve
=
link
;
else
else
{
//this link is in a different direction
{
//this link is in a different direction
if
(
!
Result
)
if
(
!
Result
)
Result
=
link
;
//first one found sofar
Result
=
link
;
//first one found sofar
else
else
{
{
if
(
prev
->
PointOnCorner
(
Result
,
link
)
==
whatside
)
if
(
prev
->
PointOnCorner
(
Result
,
link
)
==
whatside
)
//more to the whatside than take this one
//more to the whatside than take this one
Result
=
link
;
Result
=
link
;
}
}
}
}
}
}
(
*
_GC
->
_linkiter
)
++
;
(
*
_GC
->
_linkiter
)
++
;
}
}
// if there is a next link found return it
// if there is a next link found return it
// else if a parallel link is found return that one
// else if a parallel link is found return that one
// else return NULL
// else return NULL
_GC
->
_linkiter
->
Detach
();
_GC
->
_linkiter
->
Detach
();
return
((
Result
)
?
Result
:
reserve
);
return
(
(
Result
)
?
Result
:
reserve
);
}
}
// on the node get the link
// on the node get the link
...
@@ -392,24 +389,24 @@ KBoolLink* Node::GetMost( KBoolLink* const prev ,LinkStatus whatside, BOOL_OP op
...
@@ -392,24 +389,24 @@ KBoolLink* Node::GetMost( KBoolLink* const prev ,LinkStatus whatside, BOOL_OP op
// This function is used to collect the simple graphs from a graph
// This function is used to collect the simple graphs from a graph
KBoolLink
*
Node
::
GetMostHole
(
KBoolLink
*
const
prev
,
LinkStatus
whatside
,
BOOL_OP
operation
)
KBoolLink
*
Node
::
GetMostHole
(
KBoolLink
*
const
prev
,
LinkStatus
whatside
,
BOOL_OP
operation
)
{
{
KBoolLink
*
reserve
=
0
;
KBoolLink
*
reserve
=
0
;
KBoolLink
*
Result
=
NULL
,
*
link
;
KBoolLink
*
Result
=
NULL
,
*
link
;
Node
*
prevbegin
=
prev
->
GetOther
(
this
);
Node
*
prevbegin
=
prev
->
GetOther
(
this
);
if
(
_linklist
->
count
()
==
2
)
// only two links to this node take the one != prev
if
(
_linklist
->
count
()
==
2
)
// only two links to this node take the one != prev
{
{
if
(
(
link
=
(
KBoolLink
*
)
_linklist
->
headitem
()
)
==
prev
)
//this is NOT the one to go on
if
(
(
link
=
(
KBoolLink
*
)
_linklist
->
headitem
()
)
==
prev
)
//this is NOT the one to go on
link
=
(
KBoolLink
*
)
_linklist
->
tailitem
();
link
=
(
KBoolLink
*
)
_linklist
->
tailitem
();
if
(
link
->
GetHole
()
&&
!
link
->
GetHoleLink
()
&&
!
link
->
BeenHere
()
&&
SameSides
(
prev
,
link
,
operation
)
)
if
(
link
->
GetHole
()
&&
!
link
->
GetHoleLink
()
&&
!
link
->
BeenHere
()
&&
SameSides
(
prev
,
link
,
operation
)
)
//we are back where we started (bin is true) return Null
//we are back where we started (bin is true) return Null
return
link
;
return
link
;
return
(
0
);
return
(
0
);
}
}
_GC
->
_linkiter
->
Attach
(
_linklist
);
_GC
->
_linkiter
->
Attach
(
_linklist
);
_GC
->
_linkiter
->
tohead
();
_GC
->
_linkiter
->
tohead
();
//more then 2 links to the Node
//more then 2 links to the Node
while
(
!
_GC
->
_linkiter
->
hitroot
()
)
while
(
!
_GC
->
_linkiter
->
hitroot
()
)
{
{
link
=
_GC
->
_linkiter
->
item
();
link
=
_GC
->
_linkiter
->
item
();
if
(
!
link
->
BeenHere
()
&&
if
(
!
link
->
BeenHere
()
&&
...
@@ -419,95 +416,95 @@ KBoolLink* Node::GetMostHole( KBoolLink* const prev, LinkStatus whatside, BOOL_O
...
@@ -419,95 +416,95 @@ KBoolLink* Node::GetMostHole( KBoolLink* const prev, LinkStatus whatside, BOOL_O
link
!=
prev
//should be set to bin already
link
!=
prev
//should be set to bin already
)
)
{
{
if
(
prevbegin
==
link
->
GetOther
(
this
)
)
//pointers equal
if
(
prevbegin
==
link
->
GetOther
(
this
)
)
//pointers equal
//we are going back in the same direction on a parallel link
//we are going back in the same direction on a parallel link
//only take this possibility if nothing else is possible
//only take this possibility if nothing else is possible
reserve
=
link
;
reserve
=
link
;
else
else
{
//this link is in a different direction
{
//this link is in a different direction
if
(
!
Result
)
if
(
!
Result
)
Result
=
link
;
//first one found sofar
Result
=
link
;
//first one found sofar
else
else
{
{
if
(
prev
->
PointOnCorner
(
Result
,
link
)
==
whatside
)
if
(
prev
->
PointOnCorner
(
Result
,
link
)
==
whatside
)
//more to the whatside than take this one
//more to the whatside than take this one
Result
=
link
;
Result
=
link
;
}
}
}
}
}
}
(
*
_GC
->
_linkiter
)
++
;
(
*
_GC
->
_linkiter
)
++
;
}
}
// if there is a next link found return it
// if there is a next link found return it
// else if a parallel link is found return that one
// else if a parallel link is found return that one
// else return NULL
// else return NULL
_GC
->
_linkiter
->
Detach
();
_GC
->
_linkiter
->
Detach
();
return
((
Result
)
?
Result
:
reserve
);
return
(
(
Result
)
?
Result
:
reserve
);
}
}
// this function gets the highest not flat link
// this function gets the highest not flat link
KBoolLink
*
Node
::
GetHoleLink
(
KBoolLink
*
const
prev
,
bool
checkbin
,
BOOL_OP
operation
)
KBoolLink
*
Node
::
GetHoleLink
(
KBoolLink
*
const
prev
,
bool
checkbin
,
BOOL_OP
operation
)
{
{
KBoolLink
*
Result
=
NULL
,
*
link
;
KBoolLink
*
Result
=
NULL
,
*
link
;
_GC
->
_linkiter
->
Attach
(
_linklist
);
_GC
->
_linkiter
->
Attach
(
_linklist
);
for
(
_GC
->
_linkiter
->
tohead
();
!
_GC
->
_linkiter
->
hitroot
();(
*
_GC
->
_linkiter
)
++
)
for
(
_GC
->
_linkiter
->
tohead
();
!
_GC
->
_linkiter
->
hitroot
();(
*
_GC
->
_linkiter
)
++
)
{
{
link
=
_GC
->
_linkiter
->
item
();
link
=
_GC
->
_linkiter
->
item
();
if
(
link
->
GetHoleLink
()
&&
if
(
link
->
GetHoleLink
()
&&
(
!
checkbin
||
(
checkbin
&&
!
link
->
BeenHere
()
)
)
&&
(
!
checkbin
||
(
checkbin
&&
!
link
->
BeenHere
()
)
)
&&
SameSides
(
prev
,
link
,
operation
)
SameSides
(
prev
,
link
,
operation
)
)
)
{
{
Result
=
link
;
Result
=
link
;
break
;
break
;
}
}
}
}
_GC
->
_linkiter
->
Detach
();
_GC
->
_linkiter
->
Detach
();
return
(
Result
);
return
(
Result
);
}
}
// this function gets the highest not flat link
// this function gets the highest not flat link
KBoolLink
*
Node
::
GetNotFlat
()
KBoolLink
*
Node
::
GetNotFlat
()
{
{
KBoolLink
*
Result
=
NULL
,
*
link
;
KBoolLink
*
Result
=
NULL
,
*
link
;
_GC
->
_linkiter
->
Attach
(
_linklist
);
_GC
->
_linkiter
->
Attach
(
_linklist
);
double
tangold
=
0.0
;
double
tangold
=
0.0
;
double
tangnew
=
0.0
;
double
tangnew
=
0.0
;
for
(
_GC
->
_linkiter
->
tohead
();
!
_GC
->
_linkiter
->
hitroot
();(
*
_GC
->
_linkiter
)
++
)
for
(
_GC
->
_linkiter
->
tohead
();
!
_GC
->
_linkiter
->
hitroot
();(
*
_GC
->
_linkiter
)
++
)
{
{
link
=
_GC
->
_linkiter
->
item
();
link
=
_GC
->
_linkiter
->
item
();
if
(
!
_GC
->
_linkiter
->
item
()
->
BeenHere
()
)
if
(
!
_GC
->
_linkiter
->
item
()
->
BeenHere
()
)
{
{
B_INT
dx
=
link
->
GetOther
(
this
)
->
GetX
()
-
_x
;
B_INT
dx
=
link
->
GetOther
(
this
)
->
GetX
()
-
_x
;
B_INT
dy
=
link
->
GetOther
(
this
)
->
GetY
()
-
_y
;
B_INT
dy
=
link
->
GetOther
(
this
)
->
GetY
()
-
_y
;
if
(
dx
!=
0
)
if
(
dx
!=
0
)
{
{
tangnew
=
fabs
(
(
double
)
dy
/
(
double
)
dx
);
tangnew
=
fabs
(
(
double
)
dy
/
(
double
)
dx
);
}
}
else
else
{
{
tangnew
=
MAXDOUBLE
;
tangnew
=
MAXDOUBLE
;
}
}
if
(
!
Result
)
if
(
!
Result
)
{
{
//this link is in a different direction
//this link is in a different direction
Result
=
link
;
//first one found sofar
Result
=
link
;
//first one found sofar
tangold
=
tangnew
;
tangold
=
tangnew
;
}
}
else
else
{
{
if
(
tangnew
<
tangold
)
if
(
tangnew
<
tangold
)
{
{
//this one is higher (more horizontal) then the old Result
//this one is higher (more horizontal) then the old Result
Result
=
link
;
Result
=
link
;
tangold
=
tangnew
;
tangold
=
tangnew
;
}
}
}
}
}
}
...
@@ -517,67 +514,67 @@ KBoolLink* Node::GetNotFlat()
...
@@ -517,67 +514,67 @@ KBoolLink* Node::GetNotFlat()
// else if a parallel link is found return that one
// else if a parallel link is found return that one
// else return NULL
// else return NULL
_GC
->
_linkiter
->
Detach
();
_GC
->
_linkiter
->
Detach
();
return
(
Result
);
return
(
Result
);
}
}
// on the node get the link that is not BIN
// on the node get the link that is not BIN
// and that has the same graphnumber and is in same direction
// and that has the same graphnumber and is in same direction
KBoolLink
*
Node
::
Follow
(
KBoolLink
*
const
prev
)
KBoolLink
*
Node
::
Follow
(
KBoolLink
*
const
prev
)
{
{
KBoolLink
*
temp
;
KBoolLink
*
temp
;
_GC
->
_linkiter
->
Attach
(
_linklist
);
_GC
->
_linkiter
->
Attach
(
_linklist
);
_GC
->
_linkiter
->
tohead
();
_GC
->
_linkiter
->
tohead
();
while
(
!
_GC
->
_linkiter
->
hitroot
()
)
while
(
!
_GC
->
_linkiter
->
hitroot
()
)
{
{
if
(
(
_GC
->
_linkiter
->
item
()
!=
prev
)
&&
if
(
(
_GC
->
_linkiter
->
item
()
!=
prev
)
&&
(
!
_GC
->
_linkiter
->
item
()
->
BeenHere
()
)
&&
(
!
_GC
->
_linkiter
->
item
()
->
BeenHere
()
)
&&
(
_GC
->
_linkiter
->
item
()
->
GetGraphNum
()
==
prev
->
GetGraphNum
()
)
&&
(
_GC
->
_linkiter
->
item
()
->
GetGraphNum
()
==
prev
->
GetGraphNum
()
)
&&
(
(
(
(
prev
->
GetEndNode
()
==
this
)
&&
(
(
prev
->
GetEndNode
()
==
this
)
&&
(
_GC
->
_linkiter
->
item
()
->
GetEndNode
()
!=
this
)
(
_GC
->
_linkiter
->
item
()
->
GetEndNode
()
!=
this
)
)
)
||
||
(
(
prev
->
GetBeginNode
()
==
this
)
&&
(
(
prev
->
GetBeginNode
()
==
this
)
&&
(
_GC
->
_linkiter
->
item
()
->
GetBeginNode
()
!=
this
)
(
_GC
->
_linkiter
->
item
()
->
GetBeginNode
()
!=
this
)
)
)
)
)
)
)
{
{
temp
=
_GC
->
_linkiter
->
item
();
temp
=
_GC
->
_linkiter
->
item
();
_GC
->
_linkiter
->
Detach
();
_GC
->
_linkiter
->
Detach
();
return
(
temp
);
return
(
temp
);
}
}
(
*
_GC
->
_linkiter
)
++
;
(
*
_GC
->
_linkiter
)
++
;
}
}
_GC
->
_linkiter
->
Detach
();
_GC
->
_linkiter
->
Detach
();
return
(
0
);
return
(
0
);
}
}
// this function gets the highest (other node) link ascending from the node
// this function gets the highest (other node) link ascending from the node
// that has the bin flag set as the argument binset
// that has the bin flag set as the argument binset
// if no such link exists return 0
// if no such link exists return 0
KBoolLink
*
Node
::
GetBinHighest
(
bool
binset
)
KBoolLink
*
Node
::
GetBinHighest
(
bool
binset
)
{
{
KBoolLink
*
Result
=
NULL
,
*
link
;
KBoolLink
*
Result
=
NULL
,
*
link
;
_GC
->
_linkiter
->
Attach
(
_linklist
);
_GC
->
_linkiter
->
Attach
(
_linklist
);
double
tangold
=
0.0
;
double
tangold
=
0.0
;
double
tangnew
=
0.0
;
double
tangnew
=
0.0
;
for
(
_GC
->
_linkiter
->
tohead
();
!
_GC
->
_linkiter
->
hitroot
();(
*
_GC
->
_linkiter
)
++
)
for
(
_GC
->
_linkiter
->
tohead
();
!
_GC
->
_linkiter
->
hitroot
();(
*
_GC
->
_linkiter
)
++
)
{
{
link
=
_GC
->
_linkiter
->
item
();
link
=
_GC
->
_linkiter
->
item
();
if
(
_GC
->
_linkiter
->
item
()
->
BeenHere
()
==
binset
)
if
(
_GC
->
_linkiter
->
item
()
->
BeenHere
()
==
binset
)
{
{
B_INT
dx
=
link
->
GetOther
(
this
)
->
GetX
()
-
_x
;
B_INT
dx
=
link
->
GetOther
(
this
)
->
GetX
()
-
_x
;
B_INT
dy
=
link
->
GetOther
(
this
)
->
GetY
()
-
_y
;
B_INT
dy
=
link
->
GetOther
(
this
)
->
GetY
()
-
_y
;
if
(
dx
!=
0
)
if
(
dx
!=
0
)
{
{
tangnew
=
(
double
)
dy
/
(
double
)
dx
;
tangnew
=
(
double
)
dy
/
(
double
)
dx
;
}
}
else
if
(
dy
>
0
)
else
if
(
dy
>
0
)
{
{
tangnew
=
MAXDOUBLE
;
tangnew
=
MAXDOUBLE
;
}
}
...
@@ -586,14 +583,14 @@ KBoolLink* Node::GetBinHighest(bool binset)
...
@@ -586,14 +583,14 @@ KBoolLink* Node::GetBinHighest(bool binset)
tangnew
=
-
MAXDOUBLE
;
tangnew
=
-
MAXDOUBLE
;
}
}
if
(
!
Result
)
if
(
!
Result
)
{
{
Result
=
link
;
//first one found sofar
Result
=
link
;
//first one found sofar
tangold
=
tangnew
;
tangold
=
tangnew
;
}
}
else
else
{
{
if
(
tangnew
>
tangold
)
if
(
tangnew
>
tangold
)
{
{
//this one is higher then the old Result
//this one is higher then the old Result
Result
=
link
;
Result
=
link
;
...
@@ -606,7 +603,7 @@ KBoolLink* Node::GetBinHighest(bool binset)
...
@@ -606,7 +603,7 @@ KBoolLink* Node::GetBinHighest(bool binset)
// if there is a link found return it
// if there is a link found return it
// else return NULL
// else return NULL
_GC
->
_linkiter
->
Detach
();
_GC
->
_linkiter
->
Detach
();
return
(
Result
);
return
(
Result
);
}
}
polygon/kbool/src/record.cpp
View file @
521f428c
/*! \file
../
src/record.cpp
/*! \file src/record.cpp
\author
Probably
Klaas Holwerda or Julian Smart
\author Klaas Holwerda or Julian Smart
Copyright: 2001-2004 (C)
Probably
Klaas Holwerda
Copyright: 2001-2004 (C) Klaas Holwerda
Licence:
wxWidgets Licence
Licence:
see kboollicense.txt
RCS-ID: $Id: record.cpp,v 1.
5 2005/05/24 19:13:39
titato Exp $
RCS-ID: $Id: record.cpp,v 1.
3 2008/06/04 21:23:22
titato Exp $
*/
*/
#ifdef __GNUG__
#include "kbool/booleng.h"
#pragma implementation
#include "kbool/record.h"
#endif
#include "kbool/node.h"
#include "../include/booleng.h"
#include "../include/record.h"
#include "../include/node.h"
#include <stdlib.h>
#include <stdlib.h>
#include <math.h>
#include <math.h>
...
@@ -33,8 +29,7 @@
...
@@ -33,8 +29,7 @@
//}
//}
Record
::~
Record
()
Record
::~
Record
()
{
{}
}
//void* Record::operator new(size_t size)
//void* Record::operator new(size_t size)
...
@@ -69,60 +64,60 @@ Record::~Record()
...
@@ -69,60 +64,60 @@ Record::~Record()
// }
// }
//}
//}
Record
::
Record
(
KBoolLink
*
link
,
Bool_Engine
*
GC
)
Record
::
Record
(
KBoolLink
*
link
,
Bool_Engine
*
GC
)
:
_line
(
GC
)
:
_line
(
GC
)
{
{
_GC
=
GC
;
_GC
=
GC
;
_dir
=
GO_RIGHT
;
_dir
=
GO_RIGHT
;
_a
=
0
;
_a
=
0
;
_b
=
0
;
_b
=
0
;
_line
.
Set
(
link
);
_line
.
Set
(
link
);
_line
.
CalculateLineParameters
();
_line
.
CalculateLineParameters
();
}
}
//when the dimensions of a link for a record changes, its line parameters need to be recalculated
//when the dimensions of a link for a record changes, its line parameters need to be recalculated
void
Record
::
SetNewLink
(
KBoolLink
*
link
)
void
Record
::
SetNewLink
(
KBoolLink
*
link
)
{
{
_line
.
Set
(
link
);
_line
.
Set
(
link
);
_line
.
CalculateLineParameters
();
_line
.
CalculateLineParameters
();
}
}
//for beams calculate the ysp on the low scanline
//for beams calculate the ysp on the low scanline
void
Record
::
Calc_Ysp
(
Node
*
low
)
void
Record
::
Calc_Ysp
(
Node
*
low
)
{
{
if
((
LNK
->
GetEndNode
()
==
low
)
||
(
LNK
->
GetBeginNode
()
==
low
)
)
if
(
(
LNK
->
GetEndNode
()
==
low
)
||
(
LNK
->
GetBeginNode
()
==
low
)
)
{
{
_ysp
=
low
->
GetY
();
_ysp
=
low
->
GetY
();
return
;
return
;
}
}
if
(
LNK
->
GetEndNode
()
->
GetX
()
==
LNK
->
GetBeginNode
()
->
GetX
()
)
if
(
LNK
->
GetEndNode
()
->
GetX
()
==
LNK
->
GetBeginNode
()
->
GetX
()
)
_ysp
=
low
->
GetY
();
//flatlink only in flatbeams
_ysp
=
low
->
GetY
();
//flatlink only in flatbeams
else
if
(
LNK
->
GetEndNode
()
->
GetX
()
==
low
->
GetX
()
)
else
if
(
LNK
->
GetEndNode
()
->
GetX
()
==
low
->
GetX
()
)
_ysp
=
LNK
->
GetEndNode
()
->
GetY
();
_ysp
=
LNK
->
GetEndNode
()
->
GetY
();
else
if
(
LNK
->
GetBeginNode
()
->
GetX
()
==
low
->
GetX
()
)
else
if
(
LNK
->
GetBeginNode
()
->
GetX
()
==
low
->
GetX
()
)
_ysp
=
LNK
->
GetBeginNode
()
->
GetY
();
_ysp
=
LNK
->
GetBeginNode
()
->
GetY
();
else
else
_ysp
=
_line
.
Calculate_Y_from_X
(
low
->
GetX
()
);
_ysp
=
_line
.
Calculate_Y_from_X
(
low
->
GetX
()
);
}
}
//to set the _dir for new links in the beam
//to set the _dir for new links in the beam
void
Record
::
Set_Flags
()
void
Record
::
Set_Flags
()
{
{
if
(
LNK
->
GetEndNode
()
->
GetX
()
==
LNK
->
GetBeginNode
()
->
GetX
()
)
//flatlink ?
if
(
LNK
->
GetEndNode
()
->
GetX
()
==
LNK
->
GetBeginNode
()
->
GetX
()
)
//flatlink ?
{
//only happens in flat beams
{
//only happens in flat beams
if
(
LNK
->
GetEndNode
()
->
GetY
()
<
LNK
->
GetBeginNode
()
->
GetY
()
)
if
(
LNK
->
GetEndNode
()
->
GetY
()
<
LNK
->
GetBeginNode
()
->
GetY
()
)
_dir
=
GO_RIGHT
;
_dir
=
GO_RIGHT
;
else
else
_dir
=
GO_LEFT
;
_dir
=
GO_LEFT
;
}
}
else
else
{
{
if
(
LNK
->
GetEndNode
()
->
GetX
()
>
LNK
->
GetBeginNode
()
->
GetX
()
)
if
(
LNK
->
GetEndNode
()
->
GetX
()
>
LNK
->
GetBeginNode
()
->
GetX
()
)
_dir
=
GO_RIGHT
;
_dir
=
GO_RIGHT
;
else
else
_dir
=
GO_LEFT
;
_dir
=
GO_LEFT
;
}
}
}
}
...
@@ -136,112 +131,112 @@ B_INT Record::Ysp()
...
@@ -136,112 +131,112 @@ B_INT Record::Ysp()
return
_ysp
;
return
_ysp
;
}
}
void
Record
::
SetYsp
(
B_INT
ysp
)
void
Record
::
SetYsp
(
B_INT
ysp
)
{
{
_ysp
=
ysp
;
_ysp
=
ysp
;
}
}
DIRECTION
Record
::
Direction
()
DIRECTION
Record
::
Direction
()
{
{
return
DIRECTION
(
_dir
);
return
DIRECTION
(
_dir
);
}
}
bool
Record
::
Calc_Left_Right
(
Record
*
record_above_me
)
bool
Record
::
Calc_Left_Right
(
Record
*
record_above_me
)
{
{
bool
par
=
false
;
bool
par
=
false
;
if
(
!
record_above_me
)
//null if no record above
if
(
!
record_above_me
)
//null if no record above
{
_a
=
0
;
_b
=
0
;
}
{
_a
=
0
;
_b
=
0
;
}
else
else
{
{
_a
=
record_above_me
->
_a
;
_a
=
record_above_me
->
_a
;
_b
=
record_above_me
->
_b
;
_b
=
record_above_me
->
_b
;
}
}
switch
(
_dir
&
1
)
switch
(
_dir
&
1
)
{
{
case
GO_LEFT
:
if
(
LNK
->
Group
()
==
GROUP_A
)
case
GO_LEFT
:
if
(
LNK
->
Group
()
==
GROUP_A
)
{
{
LNK
->
SetRightA
((
bool
)(
_a
>
0
)
);
LNK
->
SetRightA
(
(
bool
)(
_a
>
0
)
);
if
(
_GC
->
GetWindingRule
()
)
if
(
_GC
->
GetWindingRule
()
)
LNK
->
GetInc
()
?
_a
++
:
_a
--
;
LNK
->
GetInc
()
?
_a
++
:
_a
--
;
else
else
{
//ALTERNATE
{
//ALTERNATE
if
(
_a
)
if
(
_a
)
_a
=
0
;
_a
=
0
;
else
else
_a
=
1
;
_a
=
1
;
}
}
LNK
->
SetLeftA
((
bool
)(
_a
>
0
)
);
LNK
->
SetLeftA
(
(
bool
)(
_a
>
0
)
);
LNK
->
SetLeftB
((
bool
)(
_b
>
0
)
);
LNK
->
SetLeftB
(
(
bool
)(
_b
>
0
)
);
LNK
->
SetRightB
((
bool
)(
_b
>
0
)
);
LNK
->
SetRightB
(
(
bool
)(
_b
>
0
)
);
}
}
else
else
{
{
LNK
->
SetRightA
((
bool
)(
_a
>
0
)
);
LNK
->
SetRightA
(
(
bool
)(
_a
>
0
)
);
LNK
->
SetLeftA
((
bool
)(
_a
>
0
)
);
LNK
->
SetLeftA
(
(
bool
)(
_a
>
0
)
);
LNK
->
SetRightB
((
bool
)(
_b
>
0
)
);
LNK
->
SetRightB
(
(
bool
)(
_b
>
0
)
);
if
(
_GC
->
GetWindingRule
()
)
if
(
_GC
->
GetWindingRule
()
)
LNK
->
GetInc
()
?
_b
++
:
_b
--
;
LNK
->
GetInc
()
?
_b
++
:
_b
--
;
else
//ALTERNATE
else
//ALTERNATE
{
{
if
(
_b
)
if
(
_b
)
_b
=
0
;
_b
=
0
;
else
else
_b
=
1
;
_b
=
1
;
}
}
LNK
->
SetLeftB
((
bool
)(
_b
>
0
)
);
LNK
->
SetLeftB
(
(
bool
)(
_b
>
0
)
);
}
}
break
;
break
;
case
GO_RIGHT
:
if
(
LNK
->
Group
()
==
GROUP_A
)
case
GO_RIGHT
:
if
(
LNK
->
Group
()
==
GROUP_A
)
{
{
LNK
->
SetLeftA
((
bool
)(
_a
>
0
)
);
LNK
->
SetLeftA
(
(
bool
)(
_a
>
0
)
);
if
(
_GC
->
GetWindingRule
()
)
if
(
_GC
->
GetWindingRule
()
)
LNK
->
GetInc
()
?
_a
++
:
_a
--
;
LNK
->
GetInc
()
?
_a
++
:
_a
--
;
else
else
{
//ALTERNATE
{
//ALTERNATE
if
(
_a
)
if
(
_a
)
_a
=
0
;
_a
=
0
;
else
else
_a
=
1
;
_a
=
1
;
}
}
LNK
->
SetRightA
((
bool
)(
_a
>
0
)
);
LNK
->
SetRightA
(
(
bool
)(
_a
>
0
)
);
LNK
->
SetLeftB
((
bool
)(
_b
>
0
)
);
LNK
->
SetLeftB
(
(
bool
)(
_b
>
0
)
);
LNK
->
SetRightB
((
bool
)(
_b
>
0
)
);
LNK
->
SetRightB
(
(
bool
)(
_b
>
0
)
);
}
}
else
else
{
{
LNK
->
SetRightA
((
bool
)(
_a
>
0
)
);
LNK
->
SetRightA
(
(
bool
)(
_a
>
0
)
);
LNK
->
SetLeftA
((
bool
)(
_a
>
0
)
);
LNK
->
SetLeftA
(
(
bool
)(
_a
>
0
)
);
LNK
->
SetLeftB
((
bool
)(
_b
>
0
)
);
LNK
->
SetLeftB
(
(
bool
)(
_b
>
0
)
);
if
(
_GC
->
GetWindingRule
()
)
if
(
_GC
->
GetWindingRule
()
)
LNK
->
GetInc
()
?
_b
++
:
_b
--
;
LNK
->
GetInc
()
?
_b
++
:
_b
--
;
else
else
{
//ALTERNATE
{
//ALTERNATE
if
(
_b
)
if
(
_b
)
_b
=
0
;
_b
=
0
;
else
else
_b
=
1
;
_b
=
1
;
}
}
LNK
->
SetRightB
((
bool
)(
_b
>
0
)
);
LNK
->
SetRightB
(
(
bool
)(
_b
>
0
)
);
}
}
break
;
break
;
default
:
_GC
->
error
(
"Undefined Direction of link"
,
"function IScanBeam::Calc_Set_Left_Right()"
);
default
:
_GC
->
error
(
"Undefined Direction of link"
,
"function IScanBeam::Calc_Set_Left_Right()"
);
break
;
break
;
}
}
//THE NEXT WILL WORK for MOST windingrule polygons,
//THE NEXT WILL WORK for MOST windingrule polygons,
//even when not taking into acount windingrule
//even when not taking into acount windingrule
// not all
// not all
/*
/*
switch (_dir&1)
switch (_dir&1)
{
{
case GO_LEFT : if (LNK->Group() == GROUP_A)
case GO_LEFT : if (LNK->Group() == GROUP_A)
...
@@ -301,57 +296,57 @@ bool Record::Calc_Left_Right(Record* record_above_me)
...
@@ -301,57 +296,57 @@ bool Record::Calc_Left_Right(Record* record_above_me)
default : _messagehandler->error("Undefined Direction of link","function IScanBeam::Calc_Set_Left_Right()");
default : _messagehandler->error("Undefined Direction of link","function IScanBeam::Calc_Set_Left_Right()");
break;
break;
}
}
*/
*/
//if the records are parallel (same begin/endnodes)
//if the records are parallel (same begin/endnodes)
//the above link a/b flag are adjusted to the current a/b depth
//the above link a/b flag are adjusted to the current a/b depth
if
(
record_above_me
&&
Equal
(
record_above_me
)
)
if
(
record_above_me
&&
Equal
(
record_above_me
)
)
{
{
par
=
true
;
par
=
true
;
LNK
->
Mark
();
LNK
->
Mark
();
record_above_me
->
_a
=
_a
;
record_above_me
->
_a
=
_a
;
record_above_me
->
_b
=
_b
;
record_above_me
->
_b
=
_b
;
if
(
Direction
()
==
GO_LEFT
)
if
(
Direction
()
==
GO_LEFT
)
{
{
//set the bottom side of the above link
//set the bottom side of the above link
if
(
record_above_me
->
Direction
()
==
GO_LEFT
)
if
(
record_above_me
->
Direction
()
==
GO_LEFT
)
{
{
record_above_me
->
LNK
->
SetLeftA
(
LNK
->
GetLeftA
()
);
record_above_me
->
LNK
->
SetLeftA
(
LNK
->
GetLeftA
()
);
record_above_me
->
LNK
->
SetLeftB
(
LNK
->
GetLeftB
()
);
record_above_me
->
LNK
->
SetLeftB
(
LNK
->
GetLeftB
()
);
}
}
else
else
{
{
record_above_me
->
LNK
->
SetRightA
(
LNK
->
GetLeftA
()
);
record_above_me
->
LNK
->
SetRightA
(
LNK
->
GetLeftA
()
);
record_above_me
->
LNK
->
SetRightB
(
LNK
->
GetLeftB
()
);
record_above_me
->
LNK
->
SetRightB
(
LNK
->
GetLeftB
()
);
}
}
}
}
else
else
{
{
//set the bottom side of the above link
//set the bottom side of the above link
if
(
record_above_me
->
Direction
()
==
GO_LEFT
)
if
(
record_above_me
->
Direction
()
==
GO_LEFT
)
{
{
record_above_me
->
LNK
->
SetLeftA
(
LNK
->
GetRightA
()
);
record_above_me
->
LNK
->
SetLeftA
(
LNK
->
GetRightA
()
);
record_above_me
->
LNK
->
SetLeftB
(
LNK
->
GetRightB
()
);
record_above_me
->
LNK
->
SetLeftB
(
LNK
->
GetRightB
()
);
}
}
else
else
{
{
record_above_me
->
LNK
->
SetRightA
(
LNK
->
GetRightA
()
);
record_above_me
->
LNK
->
SetRightA
(
LNK
->
GetRightA
()
);
record_above_me
->
LNK
->
SetRightB
(
LNK
->
GetRightB
()
);
record_above_me
->
LNK
->
SetRightB
(
LNK
->
GetRightB
()
);
}
}
}
}
}
}
return
par
;
return
par
;
}
}
bool
Record
::
Equal
(
Record
*
a
)
bool
Record
::
Equal
(
Record
*
a
)
{
{
return
((
bool
)(
(
LNK
->
GetOther
(
a
->
LNK
->
GetBeginNode
())
==
a
->
LNK
->
GetEndNode
()
)
&&
return
(
(
bool
)(
(
LNK
->
GetOther
(
a
->
LNK
->
GetBeginNode
()
)
==
a
->
LNK
->
GetEndNode
()
)
&&
(
LNK
->
GetOther
(
a
->
LNK
->
GetEndNode
())
==
a
->
LNK
->
GetBeginNode
())
)
);
(
LNK
->
GetOther
(
a
->
LNK
->
GetEndNode
()
)
==
a
->
LNK
->
GetBeginNode
()
)
)
);
}
}
KBoolLine
*
Record
::
GetLine
()
KBoolLine
*
Record
::
GetLine
()
{
{
return
&
_line
;
return
&
_line
;
}
}
polygon/kbool/src/scanbeam.cpp
View file @
521f428c
/*! \file
../
src/scanbeam.cpp
/*! \file src/scanbeam.cpp
\author
Probably
Klaas Holwerda or Julian Smart
\author Klaas Holwerda or Julian Smart
Copyright: 2001-2004 (C)
Probably
Klaas Holwerda
Copyright: 2001-2004 (C) Klaas Holwerda
Licence:
wxWidgets Licence
Licence:
see kboollicense.txt
RCS-ID: $Id: scanbeam.cpp,v 1.
10 2005/06/17 23:05:18 kbluck
Exp $
RCS-ID: $Id: scanbeam.cpp,v 1.
3 2008/06/04 21:23:22 titato
Exp $
*/
*/
#ifdef __GNUG__
#pragma implementation
#endif
// class scanbeam
// class scanbeam
// this class represents de space between two scanlines
// this class represents de space between two scanlines
#include "
../include
/scanbeam.h"
#include "
kbool
/scanbeam.h"
#include <math.h>
#include <math.h>
#include <assert.h>
#include <assert.h>
#include "
../include
/booleng.h"
#include "
kbool
/booleng.h"
#include "
../include
/graph.h"
#include "
kbool
/graph.h"
#include "
../include
/node.h"
#include "
kbool
/node.h"
//this here is to initialize the static iterator of scanbeam
//this here is to initialize the static iterator of scanbeam
//with NOLIST constructor
//with NOLIST constructor
int
recordsorter
(
Record
*
,
Record
*
);
int
recordsorter
(
Record
*
,
Record
*
);
int
recordsorter_ysp_angle
(
Record
*
,
Record
*
);
int
recordsorter_ysp_angle
(
Record
*
,
Record
*
);
int
recordsorter_ysp_angle_back
(
Record
*
rec1
,
Record
*
rec2
);
int
recordsorter_ysp_angle_back
(
Record
*
rec1
,
Record
*
rec2
);
ScanBeam
::
ScanBeam
(
Bool_Engine
*
GC
)
:
DL_List
<
Record
*>
()
ScanBeam
::
ScanBeam
(
Bool_Engine
*
GC
)
:
DL_List
<
Record
*>
()
{
{
_GC
=
GC
;
_GC
=
GC
;
_type
=
NORMAL
;
_type
=
NORMAL
;
_BI
.
Attach
(
this
);
_BI
.
Attach
(
this
);
}
}
ScanBeam
::~
ScanBeam
()
ScanBeam
::~
ScanBeam
()
...
@@ -47,12 +43,12 @@ ScanBeam::~ScanBeam()
...
@@ -47,12 +43,12 @@ ScanBeam::~ScanBeam()
//DeleteRecordPool();
//DeleteRecordPool();
}
}
void
ScanBeam
::
SetType
(
Node
*
low
,
Node
*
high
)
void
ScanBeam
::
SetType
(
Node
*
low
,
Node
*
high
)
{
{
if
(
low
->
GetX
()
<
high
->
GetX
()
)
if
(
low
->
GetX
()
<
high
->
GetX
()
)
_type
=
NORMAL
;
_type
=
NORMAL
;
else
else
_type
=
FLAT
;
_type
=
FLAT
;
}
}
/*
/*
...
@@ -268,7 +264,7 @@ bool ScanBeam::Update(TDLI<KBoolLink>* _I,Node* _lowf)
...
@@ -268,7 +264,7 @@ bool ScanBeam::Update(TDLI<KBoolLink>* _I,Node* _lowf)
}
}
*/
*/
bool
ScanBeam
::
FindNew
(
SCANTYPE
scantype
,
TDLI
<
KBoolLink
>*
_I
,
bool
&
holes
)
bool
ScanBeam
::
FindNew
(
SCANTYPE
scantype
,
TDLI
<
KBoolLink
>*
_I
,
bool
&
holes
)
{
{
bool
foundnew
=
false
;
bool
foundnew
=
false
;
...
@@ -279,33 +275,33 @@ bool ScanBeam::FindNew(SCANTYPE scantype,TDLI<KBoolLink>* _I, bool& holes )
...
@@ -279,33 +275,33 @@ bool ScanBeam::FindNew(SCANTYPE scantype,TDLI<KBoolLink>* _I, bool& holes )
//if (!checksort())
//if (!checksort())
// SortTheBeam();
// SortTheBeam();
lastinserted
=
0
;
lastinserted
=
0
;
//ONLY links towards the low node are possible to be added
//ONLY links towards the low node are possible to be added
//the bin flag will be set if it fits in the beam
//the bin flag will be set if it fits in the beam
//so for following beams it will not be checked again
//so for following beams it will not be checked again
while
(
(
link
=
_low
->
GetBinHighest
(
false
)
)
!=
NULL
)
while
(
(
link
=
_low
->
GetBinHighest
(
false
)
)
!=
NULL
)
{
{
if
(
(
link
->
GetEndNode
()
->
GetX
()
==
link
->
GetBeginNode
()
->
GetX
()
)
//flatlink in flatbeam
if
(
(
link
->
GetEndNode
()
->
GetX
()
==
link
->
GetBeginNode
()
->
GetX
()
)
//flatlink in flatbeam
&&
((
scantype
==
NODELINK
)
||
(
scantype
==
LINKLINK
)
||
(
scantype
==
LINKHOLES
)
)
&&
(
(
scantype
==
NODELINK
)
||
(
scantype
==
LINKLINK
)
||
(
scantype
==
LINKHOLES
)
)
)
)
{
{
switch
(
scantype
)
switch
(
scantype
)
{
{
case
NODELINK
:
case
NODELINK
:
{
{
//all vertical links in flatbeam are ignored
//all vertical links in flatbeam are ignored
//normal link in beam
//normal link in beam
Record
*
record
=
new
Record
(
link
,
_GC
);
Record
*
record
=
new
Record
(
link
,
_GC
);
// yp_new will always be the y of low node since all new links are
// yp_new will always be the y of low node since all new links are
// from this node
// from this node
record
->
SetYsp
(
_low
->
GetY
()
);
record
->
SetYsp
(
_low
->
GetY
()
);
record
->
Set_Flags
();
record
->
Set_Flags
();
// put new item left of the one that is lower in the beam
// put new item left of the one that is lower in the beam
// The last one inserted in this loop, is already left of the current
// The last one inserted in this loop, is already left of the current
// iterator position. So the new links are inerted in proper order.
// iterator position. So the new links are inerted in proper order.
link
->
SetRecordNode
(
_BI
.
insbefore
(
record
)
);
link
->
SetRecordNode
(
_BI
.
insbefore
(
record
)
);
_BI
--
;
_BI
--
;
foundnew
=
Process_PointToLink_Crossings
()
!=
0
||
foundnew
;
foundnew
=
Process_PointToLink_Crossings
()
!=
0
||
foundnew
;
delete
record
;
delete
record
;
_BI
.
remove
();
_BI
.
remove
();
break
;
break
;
...
@@ -313,13 +309,13 @@ bool ScanBeam::FindNew(SCANTYPE scantype,TDLI<KBoolLink>* _I, bool& holes )
...
@@ -313,13 +309,13 @@ bool ScanBeam::FindNew(SCANTYPE scantype,TDLI<KBoolLink>* _I, bool& holes )
case
LINKLINK
:
case
LINKLINK
:
//is the new record a flat link
//is the new record a flat link
{
{
KBoolLine
flatline
=
KBoolLine
(
link
,
_GC
);
KBoolLine
flatline
=
KBoolLine
(
link
,
_GC
);
foundnew
=
Process_LinkToLink_Flat
(
&
flatline
)
||
foundnew
;
foundnew
=
Process_LinkToLink_Flat
(
&
flatline
)
||
foundnew
;
//flatlinks are not part of the beams, still they are used to find new beams
//flatlinks are not part of the beams, still they are used to find new beams
//they can be processed now if the beginnode does not change, since this is used to
//they can be processed now if the beginnode does not change, since this is used to
//to find new beams. and its position does not change
//to find new beams. and its position does not change
//ProcessCrossings does take care of this
//ProcessCrossings does take care of this
flatline
.
ProcessCrossings
(
_I
);
flatline
.
ProcessCrossings
(
_I
);
break
;
break
;
}
}
case
LINKHOLES
:
//holes are never to flatlinks
case
LINKHOLES
:
//holes are never to flatlinks
...
@@ -331,32 +327,32 @@ bool ScanBeam::FindNew(SCANTYPE scantype,TDLI<KBoolLink>* _I, bool& holes )
...
@@ -331,32 +327,32 @@ bool ScanBeam::FindNew(SCANTYPE scantype,TDLI<KBoolLink>* _I, bool& holes )
else
else
{
{
//normal link in beam
//normal link in beam
Record
*
record
=
new
Record
(
link
,
_GC
);
Record
*
record
=
new
Record
(
link
,
_GC
);
// yp_new will always be the y of low node since all new links are
// yp_new will always be the y of low node since all new links are
// from this node
// from this node
record
->
SetYsp
(
_low
->
GetY
()
);
record
->
SetYsp
(
_low
->
GetY
()
);
record
->
Set_Flags
();
record
->
Set_Flags
();
// put new item left of the one that is lower in the beam
// put new item left of the one that is lower in the beam
// The last one inserted in this loop, is already left of the current
// The last one inserted in this loop, is already left of the current
// iterator position. So the new links are inserted in proper order.
// iterator position. So the new links are inserted in proper order.
link
->
SetRecordNode
(
_BI
.
insbefore
(
record
)
);
link
->
SetRecordNode
(
_BI
.
insbefore
(
record
)
);
lastinserted
++
;
lastinserted
++
;
//_GC->Write_Log( "after insert" );
//_GC->Write_Log( "after insert" );
writebeam
();
writebeam
();
switch
(
scantype
)
switch
(
scantype
)
{
{
case
NODELINK
:
case
NODELINK
:
_BI
--
;
_BI
--
;
foundnew
=
Process_PointToLink_Crossings
()
!=
0
||
foundnew
;
foundnew
=
Process_PointToLink_Crossings
()
!=
0
||
foundnew
;
_BI
++
;
_BI
++
;
break
;
break
;
case
INOUT
:
case
INOUT
:
{
{
_BI
--
;
_BI
--
;
//now we can set the _inc flag
//now we can set the _inc flag
Generate_INOUT
(
record
->
GetLink
()
->
GetGraphNum
()
);
Generate_INOUT
(
record
->
GetLink
()
->
GetGraphNum
()
);
_BI
++
;
_BI
++
;
}
}
break
;
break
;
...
@@ -365,14 +361,14 @@ bool ScanBeam::FindNew(SCANTYPE scantype,TDLI<KBoolLink>* _I, bool& holes )
...
@@ -365,14 +361,14 @@ bool ScanBeam::FindNew(SCANTYPE scantype,TDLI<KBoolLink>* _I, bool& holes )
//now we can set the a/b group flags based on the above link
//now we can set the a/b group flags based on the above link
_BI
--
;
_BI
--
;
_BI
--
;
_BI
--
;
Record
*
above
=
0
;
Record
*
above
=
0
;
if
(
!
_BI
.
hitroot
()
)
if
(
!
_BI
.
hitroot
()
)
above
=
_BI
.
item
();
above
=
_BI
.
item
();
_BI
++
;
_BI
++
;
//something to do for winding rule
//something to do for winding rule
if
(
record
->
Calc_Left_Right
(
above
)
)
if
(
record
->
Calc_Left_Right
(
above
)
)
{
{
delete
record
;
delete
record
;
_BI
.
remove
();
_BI
.
remove
();
...
@@ -384,7 +380,7 @@ bool ScanBeam::FindNew(SCANTYPE scantype,TDLI<KBoolLink>* _I, bool& holes )
...
@@ -384,7 +380,7 @@ bool ScanBeam::FindNew(SCANTYPE scantype,TDLI<KBoolLink>* _I, bool& holes )
break
;
break
;
case
LINKHOLES
:
case
LINKHOLES
:
_BI
--
;
_BI
--
;
holes
=
ProcessHoles
(
true
,
_I
)
||
holes
;
holes
=
ProcessHoles
(
true
,
_I
)
||
holes
;
_BI
++
;
_BI
++
;
break
;
break
;
...
@@ -400,131 +396,131 @@ bool ScanBeam::FindNew(SCANTYPE scantype,TDLI<KBoolLink>* _I, bool& holes )
...
@@ -400,131 +396,131 @@ bool ScanBeam::FindNew(SCANTYPE scantype,TDLI<KBoolLink>* _I, bool& holes )
return
foundnew
;
return
foundnew
;
}
}
bool
ScanBeam
::
RemoveOld
(
SCANTYPE
scantype
,
TDLI
<
KBoolLink
>*
_I
,
bool
&
holes
)
bool
ScanBeam
::
RemoveOld
(
SCANTYPE
scantype
,
TDLI
<
KBoolLink
>*
_I
,
bool
&
holes
)
{
{
bool
found
=
false
;
bool
found
=
false
;
bool
foundnew
=
false
;
bool
foundnew
=
false
;
DL_Iter
<
Record
*>
_BBI
=
DL_Iter
<
Record
*>
();
DL_Iter
<
Record
*>
_BBI
=
DL_Iter
<
Record
*>
();
bool
attached
=
false
;
bool
attached
=
false
;
_low
=
_I
->
item
()
->
GetBeginNode
();
_low
=
_I
->
item
()
->
GetBeginNode
();
switch
(
scantype
)
switch
(
scantype
)
{
{
case
INOUT
:
case
INOUT
:
case
GENLR
:
case
GENLR
:
case
LINKHOLES
:
case
LINKHOLES
:
if
(
_type
==
NORMAL
)
if
(
_type
==
NORMAL
)
{
{
if
(
_low
->
GetBinHighest
(
true
)
)
//is there something to remove
if
(
_low
->
GetBinHighest
(
true
)
)
//is there something to remove
{
{
if
(
scantype
==
LINKHOLES
)
if
(
scantype
==
LINKHOLES
)
{
{
_BI
.
tohead
();
_BI
.
tohead
();
while
(
!
_BI
.
hitroot
()
)
while
(
!
_BI
.
hitroot
()
)
{
{
Record
*
record
=
_BI
.
item
();
Record
*
record
=
_BI
.
item
();
//records containing links towards the new low node
//records containing links towards the new low node
//are links to be removed
//are links to be removed
if
((
record
->
GetLink
()
->
GetEndNode
()
==
_low
)
||
if
(
(
record
->
GetLink
()
->
GetEndNode
()
==
_low
)
||
(
record
->
GetLink
()
->
GetBeginNode
()
==
_low
)
(
record
->
GetLink
()
->
GetBeginNode
()
==
_low
)
)
)
{
{
holes
=
ProcessHoles
(
false
,
_I
)
||
holes
;
holes
=
ProcessHoles
(
false
,
_I
)
||
holes
;
}
}
_BI
++
;
_BI
++
;
}
}
}
}
_BI
.
tohead
();
_BI
.
tohead
();
while
(
!
_BI
.
hitroot
()
)
while
(
!
_BI
.
hitroot
()
)
{
{
Record
*
record
=
_BI
.
item
();
Record
*
record
=
_BI
.
item
();
//records containing links towards the new low node
//records containing links towards the new low node
//are links to be removed
//are links to be removed
if
((
record
->
GetLink
()
->
GetEndNode
()
==
_low
)
||
if
(
(
record
->
GetLink
()
->
GetEndNode
()
==
_low
)
||
(
record
->
GetLink
()
->
GetBeginNode
()
==
_low
)
(
record
->
GetLink
()
->
GetBeginNode
()
==
_low
)
)
)
{
{
if
(
attached
)
//there is a bug
if
(
attached
)
//there is a bug
{
{
_BBI
.
Detach
();
_BBI
.
Detach
();
if
(
!
checksort
()
)
if
(
!
checksort
()
)
SortTheBeam
(
true
);
SortTheBeam
(
true
);
_BI
.
tohead
();
_BI
.
tohead
();
attached
=
false
;
attached
=
false
;
}
}
delete
_BI
.
item
();
delete
_BI
.
item
();
_BI
.
remove
();
_BI
.
remove
();
found
=
true
;
found
=
true
;
}
}
else
if
(
found
)
//only once in here
else
if
(
found
)
//only once in here
{
{
attached
=
true
;
attached
=
true
;
found
=
false
;
found
=
false
;
_BBI
.
Attach
(
this
);
_BBI
.
Attach
(
this
);
_BBI
.
toiter
(
&
_BI
);
//this is the position new records will be inserted
_BBI
.
toiter
(
&
_BI
);
//this is the position new records will be inserted
//recalculate ysp for the new scanline
//recalculate ysp for the new scanline
record
->
Calc_Ysp
(
_low
);
record
->
Calc_Ysp
(
_low
);
_BI
++
;
_BI
++
;
}
}
else
else
{
{
//recalculate ysp for the new scanline
//recalculate ysp for the new scanline
record
->
Calc_Ysp
(
_low
);
record
->
Calc_Ysp
(
_low
);
_BI
++
;
_BI
++
;
}
}
}
}
if
(
attached
)
if
(
attached
)
{
{
_BI
.
toiter
(
&
_BBI
);
_BI
.
toiter
(
&
_BBI
);
_BBI
.
Detach
();
_BBI
.
Detach
();
}
}
}
}
else
else
{
{
_BBI
.
Attach
(
this
);
_BBI
.
Attach
(
this
);
_BBI
.
toroot
();
_BBI
.
toroot
();
_BI
.
tohead
();
_BI
.
tohead
();
while
(
!
_BI
.
hitroot
()
)
while
(
!
_BI
.
hitroot
()
)
{
{
Record
*
record
=
_BI
.
item
();
Record
*
record
=
_BI
.
item
();
record
->
Calc_Ysp
(
_low
);
record
->
Calc_Ysp
(
_low
);
if
(
!
found
&&
(
record
->
Ysp
()
<
_low
->
GetY
())
)
if
(
!
found
&&
(
record
->
Ysp
()
<
_low
->
GetY
()
)
)
{
{
found
=
true
;
found
=
true
;
_BBI
.
toiter
(
&
_BI
);
_BBI
.
toiter
(
&
_BI
);
}
}
_BI
++
;
_BI
++
;
}
}
_BI
.
toiter
(
&
_BBI
);
_BI
.
toiter
(
&
_BBI
);
_BBI
.
Detach
();
_BBI
.
Detach
();
}
}
}
}
else
else
{
//because the previous beam was flat the links to remove are
{
//because the previous beam was flat the links to remove are
//below the last insert position
//below the last insert position
if
(
_low
->
GetBinHighest
(
true
)
)
//is there something to remove
if
(
_low
->
GetBinHighest
(
true
)
)
//is there something to remove
{
{
if
(
scantype
==
LINKHOLES
)
if
(
scantype
==
LINKHOLES
)
{
{
_BI
.
tohead
();
_BI
.
tohead
();
while
(
!
_BI
.
hitroot
()
)
while
(
!
_BI
.
hitroot
()
)
{
{
Record
*
record
=
_BI
.
item
();
Record
*
record
=
_BI
.
item
();
//records containing links towards the new low node
//records containing links towards the new low node
//are links to be removed
//are links to be removed
if
((
record
->
GetLink
()
->
GetEndNode
()
==
_low
)
||
if
(
(
record
->
GetLink
()
->
GetEndNode
()
==
_low
)
||
(
record
->
GetLink
()
->
GetBeginNode
()
==
_low
)
(
record
->
GetLink
()
->
GetBeginNode
()
==
_low
)
)
)
{
{
holes
=
ProcessHoles
(
false
,
_I
)
||
holes
;
holes
=
ProcessHoles
(
false
,
_I
)
||
holes
;
}
}
_BI
++
;
_BI
++
;
}
}
...
@@ -540,22 +536,22 @@ bool ScanBeam::RemoveOld(SCANTYPE scantype,TDLI<KBoolLink>* _I, bool& holes )
...
@@ -540,22 +536,22 @@ bool ScanBeam::RemoveOld(SCANTYPE scantype,TDLI<KBoolLink>* _I, bool& holes )
//if (_BI.hitroot()) //only possible when at the begin of the beam
//if (_BI.hitroot()) //only possible when at the begin of the beam
_BI
.
tohead
();
_BI
.
tohead
();
while
(
!
_BI
.
hitroot
()
)
while
(
!
_BI
.
hitroot
()
)
{
{
Record
*
record
=
_BI
.
item
();
Record
*
record
=
_BI
.
item
();
//records containing links towards the new low node
//records containing links towards the new low node
//are links to be removed
//are links to be removed
if
((
record
->
GetLink
()
->
GetEndNode
()
==
_low
)
||
if
(
(
record
->
GetLink
()
->
GetEndNode
()
==
_low
)
||
(
record
->
GetLink
()
->
GetBeginNode
()
==
_low
)
(
record
->
GetLink
()
->
GetBeginNode
()
==
_low
)
)
)
{
{
delete
_BI
.
item
();
delete
_BI
.
item
();
_BI
.
remove
();
_BI
.
remove
();
found
=
true
;
found
=
true
;
}
}
else
if
(
found
)
//only once in here
else
if
(
found
)
//only once in here
break
;
break
;
else
if
(
record
->
Ysp
()
<
_low
->
GetY
()
)
else
if
(
record
->
Ysp
()
<
_low
->
GetY
()
)
//if flatlinks are not in the beam nothing will be found
//if flatlinks are not in the beam nothing will be found
//this will bring us to the right insertion point
//this will bring us to the right insertion point
break
;
break
;
...
@@ -574,10 +570,10 @@ bool ScanBeam::RemoveOld(SCANTYPE scantype,TDLI<KBoolLink>* _I, bool& holes )
...
@@ -574,10 +570,10 @@ bool ScanBeam::RemoveOld(SCANTYPE scantype,TDLI<KBoolLink>* _I, bool& holes )
//_BI--;
//_BI--;
//if (_BI.hitroot()) //only possible when at the begin of the beam
//if (_BI.hitroot()) //only possible when at the begin of the beam
_BI
.
tohead
();
_BI
.
tohead
();
while
(
!
_BI
.
hitroot
()
)
while
(
!
_BI
.
hitroot
()
)
{
{
Record
*
record
=
_BI
.
item
();
Record
*
record
=
_BI
.
item
();
if
(
record
->
Ysp
()
<
_low
->
GetY
()
)
if
(
record
->
Ysp
()
<
_low
->
GetY
()
)
break
;
break
;
_BI
++
;
_BI
++
;
}
}
...
@@ -588,11 +584,11 @@ bool ScanBeam::RemoveOld(SCANTYPE scantype,TDLI<KBoolLink>* _I, bool& holes )
...
@@ -588,11 +584,11 @@ bool ScanBeam::RemoveOld(SCANTYPE scantype,TDLI<KBoolLink>* _I, bool& holes )
case
NODELINK
:
case
NODELINK
:
case
LINKLINK
:
case
LINKLINK
:
{
{
if
(
_type
==
NORMAL
)
if
(
_type
==
NORMAL
)
{
{
Calc_Ysp
();
Calc_Ysp
();
if
(
scantype
==
LINKLINK
)
if
(
scantype
==
LINKLINK
)
foundnew
=
Process_LinkToLink_Crossings
()
!=
0
||
foundnew
;
foundnew
=
Process_LinkToLink_Crossings
()
!=
0
||
foundnew
;
else
else
SortTheBeam
(
false
);
SortTheBeam
(
false
);
}
}
...
@@ -600,29 +596,29 @@ bool ScanBeam::RemoveOld(SCANTYPE scantype,TDLI<KBoolLink>* _I, bool& holes )
...
@@ -600,29 +596,29 @@ bool ScanBeam::RemoveOld(SCANTYPE scantype,TDLI<KBoolLink>* _I, bool& holes )
//do not change the ysp of links already there, new non flat links
//do not change the ysp of links already there, new non flat links
//are inserted in order, as result the beam stays sorted
//are inserted in order, as result the beam stays sorted
if
(
_low
->
GetBinHighest
(
true
)
)
//is there something to remove
if
(
_low
->
GetBinHighest
(
true
)
)
//is there something to remove
{
{
_BI
.
tohead
();
_BI
.
tohead
();
while
(
!
_BI
.
hitroot
()
)
while
(
!
_BI
.
hitroot
()
)
{
{
Record
*
record
=
_BI
.
item
();
Record
*
record
=
_BI
.
item
();
//records containing links towards the new low node
//records containing links towards the new low node
//are links to be removed
//are links to be removed
if
((
record
->
GetLink
()
->
GetEndNode
()
==
_low
)
||
if
(
(
record
->
GetLink
()
->
GetEndNode
()
==
_low
)
||
(
record
->
GetLink
()
->
GetBeginNode
()
==
_low
)
(
record
->
GetLink
()
->
GetBeginNode
()
==
_low
)
)
)
{
{
KBoolLine
*
line
=
record
->
GetLine
();
KBoolLine
*
line
=
record
->
GetLine
();
if
(
scantype
==
NODELINK
)
if
(
scantype
==
NODELINK
)
foundnew
=
Process_PointToLink_Crossings
()
!=
0
||
foundnew
;
foundnew
=
Process_PointToLink_Crossings
()
!=
0
||
foundnew
;
line
->
ProcessCrossings
(
_I
);
line
->
ProcessCrossings
(
_I
);
delete
_BI
.
item
();
delete
_BI
.
item
();
_BI
.
remove
();
_BI
.
remove
();
found
=
true
;
found
=
true
;
}
}
//because the beam is sorted on ysp, stop when nothing can be there to remove
//because the beam is sorted on ysp, stop when nothing can be there to remove
//and the right insertion point for new links has been found
//and the right insertion point for new links has been found
else
if
((
record
->
Ysp
()
<
_low
->
GetY
())
)
else
if
(
(
record
->
Ysp
()
<
_low
->
GetY
()
)
)
break
;
break
;
else
else
_BI
++
;
_BI
++
;
...
@@ -631,12 +627,12 @@ bool ScanBeam::RemoveOld(SCANTYPE scantype,TDLI<KBoolLink>* _I, bool& holes )
...
@@ -631,12 +627,12 @@ bool ScanBeam::RemoveOld(SCANTYPE scantype,TDLI<KBoolLink>* _I, bool& holes )
else
else
{
{
_BI
.
tohead
();
_BI
.
tohead
();
while
(
!
_BI
.
hitroot
()
)
while
(
!
_BI
.
hitroot
()
)
{
{
Record
*
record
=
_BI
.
item
();
Record
*
record
=
_BI
.
item
();
//because the beam is sorted on ysp, stop when
//because the beam is sorted on ysp, stop when
//the right insertion point for new links has been found
//the right insertion point for new links has been found
if
((
record
->
Ysp
()
<
_low
->
GetY
())
)
if
(
(
record
->
Ysp
()
<
_low
->
GetY
()
)
)
break
;
break
;
_BI
++
;
_BI
++
;
}
}
...
@@ -927,11 +923,11 @@ void ScanBeam::SortTheBeam( bool backangle )
...
@@ -927,11 +923,11 @@ void ScanBeam::SortTheBeam( bool backangle )
void
ScanBeam
::
Calc_Ysp
()
void
ScanBeam
::
Calc_Ysp
()
{
{
_BI
.
tohead
();
_BI
.
tohead
();
while
(
!
_BI
.
hitroot
()
)
while
(
!
_BI
.
hitroot
()
)
{
{
Record
*
record
=
_BI
.
item
();
Record
*
record
=
_BI
.
item
();
// KBoolLink* link=_BI.item()->GetLink();
// KBoolLink* link=_BI.item()->GetLink();
record
->
Calc_Ysp
(
_low
);
record
->
Calc_Ysp
(
_low
);
_BI
++
;
_BI
++
;
}
}
}
}
...
@@ -939,42 +935,42 @@ void ScanBeam::Calc_Ysp()
...
@@ -939,42 +935,42 @@ void ScanBeam::Calc_Ysp()
// this function will set for all the records which contain a link with the
// this function will set for all the records which contain a link with the
// corresponding graphnumber the inc flag.
// corresponding graphnumber the inc flag.
// The inc flag's function is to see in a beam if we go deeper in the graph or not
// The inc flag's function is to see in a beam if we go deeper in the graph or not
void
ScanBeam
::
Generate_INOUT
(
int
graphnumber
)
void
ScanBeam
::
Generate_INOUT
(
int
graphnumber
)
{
{
DIRECTION
first_dir
=
GO_LEFT
;
DIRECTION
first_dir
=
GO_LEFT
;
int
diepte
=
0
;
int
diepte
=
0
;
DL_Iter
<
Record
*>
_BBI
=
DL_Iter
<
Record
*>
();
DL_Iter
<
Record
*>
_BBI
=
DL_Iter
<
Record
*>
();
_BBI
.
Attach
(
this
);
_BBI
.
Attach
(
this
);
for
(
_BBI
.
tohead
();
!
_BBI
.
hitroot
();
_BBI
++
)
for
(
_BBI
.
tohead
();
!
_BBI
.
hitroot
();
_BBI
++
)
{
{
// recalculate _inc again
// recalculate _inc again
if
(
_BBI
.
item
()
->
GetLink
()
->
GetGraphNum
()
==
graphnumber
)
if
(
_BBI
.
item
()
->
GetLink
()
->
GetGraphNum
()
==
graphnumber
)
{
//found a link that belongs to the graph
{
//found a link that belongs to the graph
if
(
diepte
==
0
)
if
(
diepte
==
0
)
{
// first link found or at depth zero again
{
// first link found or at depth zero again
// the direction is important since this is used to find out
// the direction is important since this is used to find out
// if we go further in or out for coming links
// if we go further in or out for coming links
first_dir
=
_BBI
.
item
()
->
Direction
();
first_dir
=
_BBI
.
item
()
->
Direction
();
_BBI
.
item
()
->
GetLink
()
->
SetInc
(
true
);
_BBI
.
item
()
->
GetLink
()
->
SetInc
(
true
);
diepte
=
1
;
diepte
=
1
;
}
}
else
else
{
// according to depth=1 links set depth
{
// according to depth=1 links set depth
// verhoog of verlaag diepte
// verhoog of verlaag diepte
if
(
_BBI
.
item
()
->
Direction
()
==
first_dir
)
if
(
_BBI
.
item
()
->
Direction
()
==
first_dir
)
{
{
diepte
++
;
diepte
++
;
_BBI
.
item
()
->
GetLink
()
->
SetInc
(
true
);
_BBI
.
item
()
->
GetLink
()
->
SetInc
(
true
);
}
}
else
else
{
{
diepte
--
;
diepte
--
;
_BBI
.
item
()
->
GetLink
()
->
SetInc
(
false
);
_BBI
.
item
()
->
GetLink
()
->
SetInc
(
false
);
}
}
}
}
}
}
if
(
_BBI
.
item
()
==
_BI
.
item
()
)
break
;
//not need to do the rest, will come in a later beam
if
(
_BBI
.
item
()
==
_BI
.
item
()
)
break
;
//not need to do the rest, will come in a later beam
}
}
_BBI
.
Detach
();
_BBI
.
Detach
();
}
}
...
@@ -1006,13 +1002,13 @@ void ScanBeam::Generate_INOUT(int graphnumber)
...
@@ -1006,13 +1002,13 @@ void ScanBeam::Generate_INOUT(int graphnumber)
bool
ScanBeam
::
ProcessHoles
(
bool
atinsert
,
TDLI
<
KBoolLink
>*
_LI
)
bool
ScanBeam
::
ProcessHoles
(
bool
atinsert
,
TDLI
<
KBoolLink
>*
_LI
)
{
{
// The scanbeam must already be sorted at this moment
// The scanbeam must already be sorted at this moment
Node
*
topnode
;
Node
*
topnode
;
bool
foundholes
=
false
;
bool
foundholes
=
false
;
Record
*
record
=
_BI
.
item
();
Record
*
record
=
_BI
.
item
();
KBoolLink
*
link
=
record
->
GetLink
();
KBoolLink
*
link
=
record
->
GetLink
();
if
(
!
record
->
GetLine
()
->
CrossListEmpty
()
)
if
(
!
record
->
GetLine
()
->
CrossListEmpty
()
)
{
{
SortTheBeam
(
atinsert
);
SortTheBeam
(
atinsert
);
...
@@ -1022,17 +1018,17 @@ bool ScanBeam::ProcessHoles( bool atinsert, TDLI<KBoolLink>* _LI )
...
@@ -1022,17 +1018,17 @@ bool ScanBeam::ProcessHoles( bool atinsert, TDLI<KBoolLink>* _LI )
// make new nodes and links and set them, re-use the old link, so the links
// make new nodes and links and set them, re-use the old link, so the links
// that still stand in the linecrosslist will not be lost.
// that still stand in the linecrosslist will not be lost.
// There is a hole that must be linked to this link !
// There is a hole that must be linked to this link !
TDLI
<
Node
>
I
(
record
->
GetLine
()
->
GetCrossList
()
);
TDLI
<
Node
>
I
(
record
->
GetLine
()
->
GetCrossList
()
);
I
.
tohead
();
I
.
tohead
();
while
(
!
I
.
hitroot
()
)
while
(
!
I
.
hitroot
()
)
{
{
topnode
=
I
.
item
();
topnode
=
I
.
item
();
I
.
remove
();
I
.
remove
();
KBoolLine
line
(
_GC
);
KBoolLine
line
(
_GC
);
line
.
Set
(
link
);
line
.
Set
(
link
);
B_INT
Y
=
line
.
Calculate_Y
(
topnode
->
GetX
()
);
B_INT
Y
=
line
.
Calculate_Y
(
topnode
->
GetX
()
);
// Now we'll create new nodes and new links to make the link between
// Now we'll create new nodes and new links to make the link between
// the graphs.
// the graphs.
...
@@ -1058,32 +1054,32 @@ bool ScanBeam::ProcessHoles( bool atinsert, TDLI<KBoolLink>* _LI )
...
@@ -1058,32 +1054,32 @@ bool ScanBeam::ProcessHoles( bool atinsert, TDLI<KBoolLink>* _LI )
Node
*
leftnode
;
//left node of clossest link
Node
*
leftnode
;
//left node of clossest link
(
link
->
GetBeginNode
()
->
GetX
()
<
link
->
GetEndNode
()
->
GetX
()
)
?
(
link
->
GetBeginNode
()
->
GetX
()
<
link
->
GetEndNode
()
->
GetX
()
)
?
leftnode
=
link
->
GetBeginNode
()
:
leftnode
=
link
->
GetBeginNode
()
:
leftnode
=
link
->
GetEndNode
();
leftnode
=
link
->
GetEndNode
();
Node
*
node_A
=
new
Node
(
topnode
->
GetX
(),
Y
,
_GC
);
Node
*
node_A
=
new
Node
(
topnode
->
GetX
(),
Y
,
_GC
);
KBoolLink
*
link_A
=
new
KBoolLink
(
0
,
leftnode
,
node_A
,
_GC
);
KBoolLink
*
link_A
=
new
KBoolLink
(
0
,
leftnode
,
node_A
,
_GC
);
KBoolLink
*
link_B
=
new
KBoolLink
(
0
,
node_A
,
topnode
,
_GC
);
KBoolLink
*
link_B
=
new
KBoolLink
(
0
,
node_A
,
topnode
,
_GC
);
KBoolLink
*
link_BB
=
new
KBoolLink
(
0
,
topnode
,
node_A
,
_GC
);
KBoolLink
*
link_BB
=
new
KBoolLink
(
0
,
topnode
,
node_A
,
_GC
);
KBoolLink
*
link_D
=
_BI
.
item
()
->
GetLink
();
KBoolLink
*
link_D
=
_BI
.
item
()
->
GetLink
();
link_D
->
Replace
(
leftnode
,
node_A
);
link_D
->
Replace
(
leftnode
,
node_A
);
_LI
->
insbegin
(
link_A
);
_LI
->
insbegin
(
link_A
);
_LI
->
insbegin
(
link_B
);
_LI
->
insbegin
(
link_B
);
_LI
->
insbegin
(
link_BB
);
_LI
->
insbegin
(
link_BB
);
//mark those two segments as hole linking segments
//mark those two segments as hole linking segments
link_B
->
SetHoleLink
(
true
);
link_B
->
SetHoleLink
(
true
);
link_BB
->
SetHoleLink
(
true
);
link_BB
->
SetHoleLink
(
true
);
//is where we come from/link to a hole
//is where we come from/link to a hole
bool
closest_is_hole
=
link
->
GetHole
();
bool
closest_is_hole
=
link
->
GetHole
();
// if the polygon linked to, is a hole, this hole here
// if the polygon linked to, is a hole, this hole here
// just gets bigger, so we take over the links its hole marking.
// just gets bigger, so we take over the links its hole marking.
link_A
->
SetHole
(
closest_is_hole
);
link_A
->
SetHole
(
closest_is_hole
);
link_B
->
SetHole
(
closest_is_hole
);
link_B
->
SetHole
(
closest_is_hole
);
link_BB
->
SetHole
(
closest_is_hole
);
link_BB
->
SetHole
(
closest_is_hole
);
// we have only one operation at the time, taking
// we have only one operation at the time, taking
// over the operation flags is enough, since the linking segments will
// over the operation flags is enough, since the linking segments will
...
@@ -1094,13 +1090,13 @@ bool ScanBeam::ProcessHoles( bool atinsert, TDLI<KBoolLink>* _LI )
...
@@ -1094,13 +1090,13 @@ bool ScanBeam::ProcessHoles( bool atinsert, TDLI<KBoolLink>* _LI )
}
}
}
}
if
(
link
->
IsTopHole
()
)
if
(
link
->
IsTopHole
()
)
{
{
SortTheBeam
(
atinsert
);
SortTheBeam
(
atinsert
);
writebeam
();
writebeam
();
}
}
if
(
link
->
IsTopHole
()
&&
!
_BI
.
athead
()
)
if
(
link
->
IsTopHole
()
&&
!
_BI
.
athead
()
)
{
{
// now we check if this hole should now be linked, or later
// now we check if this hole should now be linked, or later
// we always link on the node with the maximum y value, Why ? because i like it !
// we always link on the node with the maximum y value, Why ? because i like it !
...
@@ -1108,7 +1104,7 @@ bool ScanBeam::ProcessHoles( bool atinsert, TDLI<KBoolLink>* _LI )
...
@@ -1108,7 +1104,7 @@ bool ScanBeam::ProcessHoles( bool atinsert, TDLI<KBoolLink>* _LI )
assert
(
record
->
Direction
()
==
GO_LEFT
);
assert
(
record
->
Direction
()
==
GO_LEFT
);
// he goes to the left
// he goes to the left
if
(
atinsert
)
if
(
atinsert
)
{
{
if
(
link
->
GetBeginNode
()
->
GetY
()
<=
link
->
GetEndNode
()
->
GetY
()
)
if
(
link
->
GetBeginNode
()
->
GetY
()
<=
link
->
GetEndNode
()
->
GetY
()
)
{
{
...
@@ -1116,10 +1112,10 @@ bool ScanBeam::ProcessHoles( bool atinsert, TDLI<KBoolLink>* _LI )
...
@@ -1116,10 +1112,10 @@ bool ScanBeam::ProcessHoles( bool atinsert, TDLI<KBoolLink>* _LI )
//the previous link in the scanbeam == the closest link to the hole in vertical
//the previous link in the scanbeam == the closest link to the hole in vertical
//direction PUT this node into this link
//direction PUT this node into this link
_BI
--
;
_BI
--
;
_BI
.
item
()
->
GetLine
()
->
AddCrossing
(
topnode
);
_BI
.
item
()
->
GetLine
()
->
AddCrossing
(
topnode
);
_BI
++
;
_BI
++
;
//reset tophole flag, hole has been processed
//reset tophole flag, hole has been processed
link
->
SetTopHole
(
false
);
link
->
SetTopHole
(
false
);
foundholes
=
true
;
foundholes
=
true
;
}
}
}
}
...
@@ -1130,10 +1126,10 @@ bool ScanBeam::ProcessHoles( bool atinsert, TDLI<KBoolLink>* _LI )
...
@@ -1130,10 +1126,10 @@ bool ScanBeam::ProcessHoles( bool atinsert, TDLI<KBoolLink>* _LI )
//the previous link in the scanbeam == the closest link to the hole in vertical
//the previous link in the scanbeam == the closest link to the hole in vertical
//direction PUT this node into this link
//direction PUT this node into this link
_BI
--
;
_BI
--
;
_BI
.
item
()
->
GetLine
()
->
AddCrossing
(
topnode
);
_BI
.
item
()
->
GetLine
()
->
AddCrossing
(
topnode
);
_BI
++
;
_BI
++
;
//reset mark to flag that this hole has been processed
//reset mark to flag that this hole has been processed
link
->
SetTopHole
(
false
);
link
->
SetTopHole
(
false
);
foundholes
=
true
;
foundholes
=
true
;
}
}
}
}
...
@@ -1141,38 +1137,38 @@ bool ScanBeam::ProcessHoles( bool atinsert, TDLI<KBoolLink>* _LI )
...
@@ -1141,38 +1137,38 @@ bool ScanBeam::ProcessHoles( bool atinsert, TDLI<KBoolLink>* _LI )
}
}
//sort the records on Ysp if eqaul, sort on tangent at ysp
//sort the records on Ysp if eqaul, sort on tangent at ysp
int
recordsorter_ysp_angle
(
Record
*
rec1
,
Record
*
rec2
)
int
recordsorter_ysp_angle
(
Record
*
rec1
,
Record
*
rec2
)
{
{
if
(
rec1
->
Ysp
()
>
rec2
->
Ysp
()
)
if
(
rec1
->
Ysp
()
>
rec2
->
Ysp
()
)
return
(
1
);
return
(
1
);
if
(
rec1
->
Ysp
()
<
rec2
->
Ysp
()
)
if
(
rec1
->
Ysp
()
<
rec2
->
Ysp
()
)
return
(
-
1
);
return
(
-
1
);
//it seems they are equal
//it seems they are equal
B_INT
rightY1
;
B_INT
rightY1
;
if
(
rec1
->
Direction
()
==
GO_LEFT
)
if
(
rec1
->
Direction
()
==
GO_LEFT
)
rightY1
=
rec1
->
GetLink
()
->
GetBeginNode
()
->
GetY
();
rightY1
=
rec1
->
GetLink
()
->
GetBeginNode
()
->
GetY
();
else
else
rightY1
=
rec1
->
GetLink
()
->
GetEndNode
()
->
GetY
();
rightY1
=
rec1
->
GetLink
()
->
GetEndNode
()
->
GetY
();
B_INT
rightY2
;
B_INT
rightY2
;
if
(
rec2
->
Direction
()
==
GO_LEFT
)
if
(
rec2
->
Direction
()
==
GO_LEFT
)
rightY2
=
rec2
->
GetLink
()
->
GetBeginNode
()
->
GetY
();
rightY2
=
rec2
->
GetLink
()
->
GetBeginNode
()
->
GetY
();
else
else
rightY2
=
rec2
->
GetLink
()
->
GetEndNode
()
->
GetY
();
rightY2
=
rec2
->
GetLink
()
->
GetEndNode
()
->
GetY
();
if
(
rightY1
>
rightY2
)
if
(
rightY1
>
rightY2
)
return
(
1
);
return
(
1
);
if
(
rightY1
<
rightY2
)
if
(
rightY1
<
rightY2
)
return
(
-
1
);
return
(
-
1
);
return
(
0
);
return
(
0
);
}
}
//sort the records on Ysp if eqaul, sort on tangent at ysp
//sort the records on Ysp if eqaul, sort on tangent at ysp
int
recordsorter_ysp_angle_back
(
Record
*
rec1
,
Record
*
rec2
)
int
recordsorter_ysp_angle_back
(
Record
*
rec1
,
Record
*
rec2
)
{
{
if
(
rec1
->
Ysp
()
>
rec2
->
Ysp
()
)
if
(
rec1
->
Ysp
()
>
rec2
->
Ysp
()
)
return
(
1
);
return
(
1
);
if
(
rec1
->
Ysp
()
<
rec2
->
Ysp
()
)
if
(
rec1
->
Ysp
()
<
rec2
->
Ysp
()
)
return
(
-
1
);
return
(
-
1
);
//it seems they are equal
//it seems they are equal
B_INT
leftY1
;
B_INT
leftY1
;
if
(
rec1
->
Direction
()
==
GO_RIGHT
)
if
(
rec1
->
Direction
()
==
GO_RIGHT
)
...
@@ -1186,16 +1182,16 @@ int recordsorter_ysp_angle_back(Record* rec1, Record* rec2)
...
@@ -1186,16 +1182,16 @@ int recordsorter_ysp_angle_back(Record* rec1, Record* rec2)
leftY2
=
rec2
->
GetLink
()
->
GetEndNode
()
->
GetY
();
leftY2
=
rec2
->
GetLink
()
->
GetEndNode
()
->
GetY
();
if
(
leftY1
>
leftY2
)
if
(
leftY1
>
leftY2
)
return
(
1
);
return
(
1
);
if
(
leftY1
<
leftY2
)
if
(
leftY1
<
leftY2
)
return
(
-
1
);
return
(
-
1
);
return
(
0
);
return
(
0
);
}
}
// swap functie for cocktailsort ==> each swap means an intersection of links
// swap functie for cocktailsort ==> each swap means an intersection of links
bool
swap_crossing_normal
(
Record
*
a
,
Record
*
b
)
bool
swap_crossing_normal
(
Record
*
a
,
Record
*
b
)
{
{
if
(
!
a
->
Equal
(
b
)
)
// records NOT parallel
if
(
!
a
->
Equal
(
b
)
)
// records NOT parallel
{
{
a
->
GetLine
()
->
Intersect_simple
(
b
->
GetLine
()
);
a
->
GetLine
()
->
Intersect_simple
(
b
->
GetLine
()
);
return
true
;
return
true
;
...
@@ -1216,47 +1212,47 @@ int ScanBeam::Process_PointToLink_Crossings()
...
@@ -1216,47 +1212,47 @@ int ScanBeam::Process_PointToLink_Crossings()
int
merges
=
0
;
int
merges
=
0
;
Record
*
record
;
Record
*
record
;
if
(
_BI
.
count
()
>
1
)
if
(
_BI
.
count
()
>
1
)
{
{
DL_Iter
<
Record
*>
IL
=
DL_Iter
<
Record
*>
(
this
);
DL_Iter
<
Record
*>
IL
=
DL_Iter
<
Record
*>
(
this
);
IL
.
toiter
(
&
_BI
);
IL
.
toiter
(
&
_BI
);
//from IL search back for close links
//from IL search back for close links
IL
--
;
IL
--
;
while
(
!
IL
.
hitroot
()
)
while
(
!
IL
.
hitroot
()
)
{
{
record
=
IL
.
item
();
record
=
IL
.
item
();
if
(
record
->
Ysp
()
>
_low
->
GetY
()
+
_GC
->
GetInternalMarge
()
)
if
(
record
->
Ysp
()
>
_low
->
GetY
()
+
_GC
->
GetInternalMarge
()
)
break
;
break
;
// the distance to the lo/hi node is smaller then the _GC->GetInternalMarge()
// the distance to the lo/hi node is smaller then the _GC->GetInternalMarge()
if
(
(
record
->
GetLink
()
->
GetBeginNode
()
!=
_low
)
&&
if
(
(
record
->
GetLink
()
->
GetBeginNode
()
!=
_low
)
&&
(
record
->
GetLink
()
->
GetEndNode
()
!=
_low
)
(
record
->
GetLink
()
->
GetEndNode
()
!=
_low
)
)
)
{
// the link is not towards the lohi node
{
// the link is not towards the lohi node
record
->
GetLine
()
->
AddCrossing
(
_low
);
record
->
GetLine
()
->
AddCrossing
(
_low
);
merges
++
;
merges
++
;
}
}
IL
--
;
IL
--
;
}
}
//from IL search forward for close links
//from IL search forward for close links
IL
.
toiter
(
&
_BI
);
IL
.
toiter
(
&
_BI
);
IL
++
;
IL
++
;
while
(
!
IL
.
hitroot
()
)
while
(
!
IL
.
hitroot
()
)
{
{
record
=
IL
.
item
();
record
=
IL
.
item
();
if
(
record
->
Ysp
()
<
_low
->
GetY
()
-
_GC
->
GetInternalMarge
()
)
if
(
record
->
Ysp
()
<
_low
->
GetY
()
-
_GC
->
GetInternalMarge
()
)
break
;
break
;
// the distance to the lohi node is smaller then the booleng->Get_Marge()
// the distance to the lohi node is smaller then the booleng->Get_Marge()
if
(
(
record
->
GetLink
()
->
GetBeginNode
()
!=
_low
)
&&
if
(
(
record
->
GetLink
()
->
GetBeginNode
()
!=
_low
)
&&
(
record
->
GetLink
()
->
GetEndNode
()
!=
_low
)
(
record
->
GetLink
()
->
GetEndNode
()
!=
_low
)
)
)
{
// the link is not towards the low node
{
// the link is not towards the low node
record
->
GetLine
()
->
AddCrossing
(
_low
);
record
->
GetLine
()
->
AddCrossing
(
_low
);
merges
++
;
merges
++
;
}
}
IL
++
;
IL
++
;
...
@@ -1267,44 +1263,44 @@ int ScanBeam::Process_PointToLink_Crossings()
...
@@ -1267,44 +1263,44 @@ int ScanBeam::Process_PointToLink_Crossings()
return
merges
;
return
merges
;
}
}
int
ScanBeam
::
Process_LinkToLink_Flat
(
KBoolLine
*
flatline
)
int
ScanBeam
::
Process_LinkToLink_Flat
(
KBoolLine
*
flatline
)
{
{
int
crossfound
=
0
;
int
crossfound
=
0
;
Record
*
record
;
Record
*
record
;
DL_Iter
<
Record
*>
_BBI
=
DL_Iter
<
Record
*>
();
DL_Iter
<
Record
*>
_BBI
=
DL_Iter
<
Record
*>
();
_BBI
.
Attach
(
this
);
_BBI
.
Attach
(
this
);
_BBI
.
toiter
(
&
_BI
);
_BBI
.
toiter
(
&
_BI
);
for
(
_BI
.
tohead
();
!
_BI
.
hitroot
();
_BI
++
)
for
(
_BI
.
tohead
();
!
_BI
.
hitroot
();
_BI
++
)
{
{
record
=
_BI
.
item
();
record
=
_BI
.
item
();
if
(
record
->
Ysp
()
<
(
flatline
->
GetLink
()
->
GetLowNode
()
->
GetY
()
-
_GC
->
GetInternalMarge
())
)
if
(
record
->
Ysp
()
<
(
flatline
->
GetLink
()
->
GetLowNode
()
->
GetY
()
-
_GC
->
GetInternalMarge
()
)
)
break
;
//they are sorted so no other can be there
break
;
//they are sorted so no other can be there
if
((
record
->
Ysp
()
>
(
flatline
->
GetLink
()
->
GetLowNode
()
->
GetY
()
-
_GC
->
GetInternalMarge
())
)
if
(
(
record
->
Ysp
()
>
(
flatline
->
GetLink
()
->
GetLowNode
()
->
GetY
()
-
_GC
->
GetInternalMarge
()
)
)
&&
&&
(
record
->
Ysp
()
<
(
flatline
->
GetLink
()
->
GetHighNode
()
->
GetY
()
+
_GC
->
GetInternalMarge
())
)
(
record
->
Ysp
()
<
(
flatline
->
GetLink
()
->
GetHighNode
()
->
GetY
()
+
_GC
->
GetInternalMarge
()
)
)
)
)
{
//it is in between the flat link region
{
//it is in between the flat link region
//create a new node at ysp and insert it in both the flatlink and the crossing link
//create a new node at ysp and insert it in both the flatlink and the crossing link
if
(
if
(
(
record
->
GetLink
()
->
GetEndNode
()
!=
flatline
->
GetLink
()
->
GetHighNode
()
)
&&
(
record
->
GetLink
()
->
GetEndNode
()
!=
flatline
->
GetLink
()
->
GetHighNode
()
)
&&
(
record
->
GetLink
()
->
GetEndNode
()
!=
flatline
->
GetLink
()
->
GetLowNode
()
)
&&
(
record
->
GetLink
()
->
GetEndNode
()
!=
flatline
->
GetLink
()
->
GetLowNode
()
)
&&
(
record
->
GetLink
()
->
GetBeginNode
()
!=
flatline
->
GetLink
()
->
GetHighNode
()
)
&&
(
record
->
GetLink
()
->
GetBeginNode
()
!=
flatline
->
GetLink
()
->
GetHighNode
()
)
&&
(
record
->
GetLink
()
->
GetBeginNode
()
!=
flatline
->
GetLink
()
->
GetLowNode
()
)
(
record
->
GetLink
()
->
GetBeginNode
()
!=
flatline
->
GetLink
()
->
GetLowNode
()
)
)
)
{
{
Node
*
newnode
=
new
Node
(
_low
->
GetX
(),
_BI
.
item
()
->
Ysp
(),
_GC
);
Node
*
newnode
=
new
Node
(
_low
->
GetX
(),
_BI
.
item
()
->
Ysp
(),
_GC
);
flatline
->
AddCrossing
(
newnode
);
flatline
->
AddCrossing
(
newnode
);
record
->
GetLine
()
->
AddCrossing
(
newnode
);
record
->
GetLine
()
->
AddCrossing
(
newnode
);
crossfound
++
;
crossfound
++
;
}
}
}
}
}
}
_BI
.
toiter
(
&
_BBI
);
_BI
.
toiter
(
&
_BBI
);
_BBI
.
Detach
();
_BBI
.
Detach
();
return
crossfound
;
return
crossfound
;
}
}
...
@@ -1312,22 +1308,22 @@ int ScanBeam::Process_LinkToLink_Flat(KBoolLine* flatline)
...
@@ -1312,22 +1308,22 @@ int ScanBeam::Process_LinkToLink_Flat(KBoolLine* flatline)
bool
ScanBeam
::
checksort
()
bool
ScanBeam
::
checksort
()
{
{
// if empty then just insert
// if empty then just insert
if
(
empty
()
)
if
(
empty
()
)
return
true
;
return
true
;
// put new item left of the one that is bigger
// put new item left of the one that is bigger
_BI
.
tohead
();
_BI
.
tohead
();
Record
*
prev
=
_BI
.
item
();
Record
*
prev
=
_BI
.
item
();
_BI
++
;
_BI
++
;
while
(
!
_BI
.
hitroot
()
)
while
(
!
_BI
.
hitroot
()
)
{
{
Record
*
curr
=
_BI
.
item
();
Record
*
curr
=
_BI
.
item
();
if
(
recordsorter_ysp_angle
(
prev
,
curr
)
==-
1
)
if
(
recordsorter_ysp_angle
(
prev
,
curr
)
==
-
1
)
{
{
recordsorter_ysp_angle
(
prev
,
curr
);
recordsorter_ysp_angle
(
prev
,
curr
);
return
false
;
return
false
;
}
}
prev
=
_BI
.
item
();
prev
=
_BI
.
item
();
_BI
++
;
_BI
++
;
}
}
return
true
;
return
true
;
...
@@ -1336,16 +1332,16 @@ bool ScanBeam::checksort()
...
@@ -1336,16 +1332,16 @@ bool ScanBeam::checksort()
bool
ScanBeam
::
writebeam
()
bool
ScanBeam
::
writebeam
()
{
{
#if KBOOL_DEBUG == 1
#if KBOOL_DEBUG == 1
FILE
*
file
=
_GC
->
GetLogFile
();
FILE
*
file
=
_GC
->
GetLogFile
();
if
(
file
==
NULL
)
if
(
file
==
NULL
)
return
true
;
return
true
;
fprintf
(
file
,
"# beam %d
\n
"
,
count
()
);
fprintf
(
file
,
"# beam %d
\n
"
,
count
()
);
fprintf
(
file
,
" low %I64d %I64d
\n
"
,
_low
->
GetX
()
,
_low
->
GetY
()
);
fprintf
(
file
,
" low %I64d %I64d
\n
"
,
_low
->
GetX
()
,
_low
->
GetY
()
);
fprintf
(
file
,
" type %d
\n
"
,
_type
);
fprintf
(
file
,
" type %d
\n
"
,
_type
);
if
(
empty
()
)
if
(
empty
()
)
{
{
fprintf
(
file
,
" empty
\n
"
);
fprintf
(
file
,
" empty
\n
"
);
return
true
;
return
true
;
...
@@ -1355,17 +1351,20 @@ bool ScanBeam::writebeam()
...
@@ -1355,17 +1351,20 @@ bool ScanBeam::writebeam()
// put new item left of the one that is bigger
// put new item left of the one that is bigger
_BI
.
tohead
();
_BI
.
tohead
();
while
(
!
_BI
.
hitroot
()
)
while
(
!
_BI
.
hitroot
()
)
{
{
Record
*
cur
=
_BI
.
item
();
Record
*
cur
=
_BI
.
item
();
fprintf
(
file
,
" ysp %I64d
\n
"
,
cur
->
Ysp
()
);
fprintf
(
file
,
" ysp %I64d
\n
"
,
cur
->
Ysp
()
);
KBoolLink
*
curl
=
cur
->
GetLink
();
KBoolLink
*
curl
=
cur
->
GetLink
();
fprintf
(
file
,
" linkbegin %I64d %I64d
\n
"
,
curl
->
GetBeginNode
()
->
GetX
(),
curl
->
GetBeginNode
()
->
GetY
()
);
fprintf
(
file
,
" linkbegin %I64d %I64d
\n
"
,
curl
->
GetBeginNode
()
->
GetX
(),
curl
->
GetBeginNode
()
->
GetY
()
);
fprintf
(
file
,
" linkend %I64d %I64d
\n
"
,
curl
->
GetEndNode
()
->
GetX
(),
curl
->
GetEndNode
()
->
GetY
()
);
fprintf
(
file
,
" linkend %I64d %I64d
\n
"
,
curl
->
GetEndNode
()
->
GetX
(),
curl
->
GetEndNode
()
->
GetY
()
);
if
(
curl
->
GetEndNode
()
->
GetX
()
==
-
2459565876494606883
)
fprintf
(
file
,
" linkend %I64d %I64d
\n
"
,
curl
->
GetEndNode
()
->
GetX
(),
curl
->
GetEndNode
()
->
GetY
()
);
_BI
++
;
_BI
++
;
}
}
#endif
#endif
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment