Replace TTL delauney triangulator
Removes the TTL triangulator in favor of the delaunator triangulator. This removes the only AGPL code in the KiCad codebase and therefore allows the full project to be licensed under the GPLv3.
This commit is contained in:
parent
c9715ce304
commit
4ef02fd699
661
LICENSE.AGPLv3
661
LICENSE.AGPLv3
|
@ -1,661 +0,0 @@
|
|||
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
Version 3, 19 November 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU Affero General Public License is a free, copyleft license for
|
||||
software and other kinds of works, specifically designed to ensure
|
||||
cooperation with the community in the case of network server software.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
our General Public Licenses are 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.
|
||||
|
||||
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.
|
||||
|
||||
Developers that use our General Public Licenses protect your rights
|
||||
with two steps: (1) assert copyright on the software, and (2) offer
|
||||
you this License which gives you legal permission to copy, distribute
|
||||
and/or modify the software.
|
||||
|
||||
A secondary benefit of defending all users' freedom is that
|
||||
improvements made in alternate versions of the program, if they
|
||||
receive widespread use, become available for other developers to
|
||||
incorporate. Many developers of free software are heartened and
|
||||
encouraged by the resulting cooperation. However, in the case of
|
||||
software used on network servers, this result may fail to come about.
|
||||
The GNU General Public License permits making a modified version and
|
||||
letting the public access it on a server without ever releasing its
|
||||
source code to the public.
|
||||
|
||||
The GNU Affero General Public License is designed specifically to
|
||||
ensure that, in such cases, the modified source code becomes available
|
||||
to the community. It requires the operator of a network server to
|
||||
provide the source code of the modified version running there to the
|
||||
users of that server. Therefore, public use of a modified version, on
|
||||
a publicly accessible server, gives the public access to the source
|
||||
code of the modified version.
|
||||
|
||||
An older license, called the Affero General Public License and
|
||||
published by Affero, was designed to accomplish similar goals. This is
|
||||
a different license, not a version of the Affero GPL, but Affero has
|
||||
released a new version of the Affero GPL which permits relicensing under
|
||||
this license.
|
||||
|
||||
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 Affero 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. Remote Network Interaction; Use with the GNU General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, if you modify the
|
||||
Program, your modified version must prominently offer all users
|
||||
interacting with it remotely through a computer network (if your version
|
||||
supports such interaction) an opportunity to receive the Corresponding
|
||||
Source of your version by providing access to the Corresponding Source
|
||||
from a network server at no charge, through some standard or customary
|
||||
means of facilitating copying of software. This Corresponding Source
|
||||
shall include the Corresponding Source for any work covered by version 3
|
||||
of the GNU General Public License that is incorporated pursuant to the
|
||||
following paragraph.
|
||||
|
||||
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 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 work with which it is combined will remain governed by version
|
||||
3 of the GNU General Public License.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU Affero 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 Affero 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 Affero 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 Affero 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 Affero 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 Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If your software can interact with users remotely through a computer
|
||||
network, you should also make sure that it provides a way for users to
|
||||
get its source. For example, if your program is a web application, its
|
||||
interface could display a "Source" link that leads users to an archive
|
||||
of the code. There are many ways you could offer source, and different
|
||||
solutions will be better for different programs; see section 13 for the
|
||||
specific requirements.
|
||||
|
||||
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 AGPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
|
@ -1,22 +1,20 @@
|
|||
The majority of KiCad's source code is developed and distributed under the terms
|
||||
of the GPLv3 or later. However, It does include some third-party code licensed
|
||||
under AGPLv3 or later as well as sections licensed under the BOOST license v1.0,
|
||||
the ISC license and the MIT license.
|
||||
under licensed under the BOOST license v1.0, the ISC license and the MIT license.
|
||||
|
||||
These licenses are compatible, but a combined works as is will be governed under
|
||||
the terms of the AGPLv3 (or later). This includes any binary distribution of the
|
||||
the terms of the GPLv3 (or later). This includes any binary distribution of the
|
||||
KiCad EDA suite by the KiCad project or any third party, e.g. Linux distributor.
|
||||
|
||||
You are free to use the *sources* under the terms of their respective licenses.
|
||||
|
||||
Licensed under AGPLv3 (or later):
|
||||
- TTL [https://www.sintef.no/projectweb/geometry-toolkits/ttl/], sources in include/ttl/*
|
||||
Licensed under BOOSTv1:
|
||||
- libcontext [https://github.com/boostorg/context] in thirdparty/libcontext
|
||||
- clipper in thirdparty/clipper
|
||||
Licensed under ISC:
|
||||
- portions of code in include/geometry/polygon_triangulation.h
|
||||
Licensed under MIT:
|
||||
- delaunator in thirdparty/delaunator
|
||||
- tinyspline_lib in thirdparty/tinyspline_lib
|
||||
- nlohmann/json in thirdparty/nlohmann_json
|
||||
- nlohmann/fifo_map in thirdparty/nlohmann_json
|
||||
|
|
|
@ -67,7 +67,6 @@ set( GAL_SRCS
|
|||
add_library( gal STATIC ${GAL_SRCS} )
|
||||
|
||||
target_link_libraries( gal
|
||||
ttl
|
||||
kimath
|
||||
bitmaps
|
||||
${GLEW_LIBRARIES}
|
||||
|
@ -511,14 +510,17 @@ set_source_files_properties( ${PCB_COMMON_SRCS} PROPERTIES
|
|||
add_library( pcbcommon STATIC ${PCB_COMMON_SRCS} )
|
||||
|
||||
target_include_directories( pcbcommon PUBLIC
|
||||
$<TARGET_PROPERTY:delaunator,INTERFACE_INCLUDE_DIRECTORIES>
|
||||
)
|
||||
|
||||
target_link_libraries( pcbcommon PUBLIC
|
||||
common
|
||||
delaunator
|
||||
kimath
|
||||
kiplatform
|
||||
)
|
||||
|
||||
add_dependencies( pcbcommon delaunator )
|
||||
|
||||
# auto-generate netlist_lexer.h and netlist_keywords.cpp
|
||||
make_lexer(
|
||||
|
|
|
@ -179,7 +179,7 @@ static void buildKicadAboutBanner( EDA_BASE_FRAME* aParent, ABOUT_APP_INFO& aInf
|
|||
<< HtmlNewline( 4 )
|
||||
<< _( "The complete KiCad EDA Suite is released under the" ) << HtmlNewline( 2 )
|
||||
<< HtmlHyperlink( "http://www.gnu.org/licenses",
|
||||
_( "GNU Affero General Public License (AGPL) version 3 or any later version" ) )
|
||||
_( "GNU General Public License (GPL) version 3 or any later version" ) )
|
||||
<< "</div>";
|
||||
|
||||
aInfo.SetLicense( license );
|
||||
|
|
|
@ -623,7 +623,6 @@ target_include_directories( pcbnew_kiface_objects PRIVATE
|
|||
$<TARGET_PROPERTY:common,INTERFACE_INCLUDE_DIRECTORIES>
|
||||
$<TARGET_PROPERTY:dxflib_qcad,INTERFACE_INCLUDE_DIRECTORIES>
|
||||
$<TARGET_PROPERTY:nanosvg,INTERFACE_INCLUDE_DIRECTORIES>
|
||||
$<TARGET_PROPERTY:ttl,INTERFACE_INCLUDE_DIRECTORIES>
|
||||
$<TARGET_PROPERTY:tinyspline_lib,INTERFACE_INCLUDE_DIRECTORIES>
|
||||
$<TARGET_PROPERTY:nlohmann_json,INTERFACE_INCLUDE_DIRECTORIES>
|
||||
)
|
||||
|
@ -633,7 +632,6 @@ target_include_directories( pcbnew_kiface_objects PRIVATE
|
|||
add_dependencies( pcbnew_kiface_objects common )
|
||||
add_dependencies( pcbnew_kiface_objects dxflib_qcad )
|
||||
add_dependencies( pcbnew_kiface_objects tinyspline_lib )
|
||||
add_dependencies( pcbnew_kiface_objects ttl )
|
||||
add_dependencies( pcbnew_kiface_objects nanosvg )
|
||||
|
||||
add_library( pcbnew_kiface MODULE $<TARGET_OBJECTS:pcbnew_kiface_objects> )
|
||||
|
@ -670,7 +668,6 @@ set( PCBNEW_KIFACE_LIBRARIES
|
|||
gal
|
||||
dxflib_qcad
|
||||
tinyspline_lib
|
||||
ttl
|
||||
idf3
|
||||
nanosvg
|
||||
${wxWidgets_LIBRARIES}
|
||||
|
|
|
@ -68,14 +68,13 @@ public:
|
|||
{}
|
||||
|
||||
/**
|
||||
* This sort operator implements the reverse sort such that the smallest weight will be placed first
|
||||
* in a priority queue
|
||||
* This sort operator provides a sort-by-weight for the ratsnest operation
|
||||
* @param aOther Other edge to compare
|
||||
* @return true if our weight is larger than the other weight
|
||||
* @return true if our weight is smaller than the other weight
|
||||
*/
|
||||
bool operator<( CN_EDGE aOther ) const
|
||||
{
|
||||
return m_weight > aOther.m_weight;
|
||||
return m_weight < aOther.m_weight;
|
||||
}
|
||||
|
||||
CN_ANCHOR_PTR GetSourceNode() const { return m_source; }
|
||||
|
|
|
@ -0,0 +1,789 @@
|
|||
/*
|
||||
* delauney.h
|
||||
*
|
||||
* Created on: Jun 19, 2020
|
||||
* Author: seth
|
||||
*/
|
||||
|
||||
#ifndef PCBNEW_RATSNEST_DELAUNEY_H_
|
||||
#define PCBNEW_RATSNEST_DELAUNEY_H_
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
#include <limits>
|
||||
#include <numeric>
|
||||
#include <stdexcept>
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
|
||||
constexpr std::size_t INVALID_INDEX =
|
||||
(std::numeric_limits<std::size_t>::max)();
|
||||
|
||||
class Point
|
||||
{
|
||||
public:
|
||||
Point(double x, double y) : m_x(x), m_y(y)
|
||||
{}
|
||||
Point() : m_x(0), m_y(0)
|
||||
{}
|
||||
|
||||
double x() const
|
||||
{ return m_x; }
|
||||
|
||||
double y() const
|
||||
{ return m_y; }
|
||||
|
||||
double magnitude2() const
|
||||
{ return m_x * m_x + m_y * m_y; }
|
||||
|
||||
static double determinant(const Point& p1, const Point& p2)
|
||||
{
|
||||
return p1.m_x * p2.m_y - p1.m_y * p2.m_x;
|
||||
}
|
||||
|
||||
static Point vector(const Point& p1, const Point& p2)
|
||||
{
|
||||
return Point(p2.m_x - p1.m_x, p2.m_y - p1.m_y);
|
||||
}
|
||||
|
||||
static double dist2(const Point& p1, const Point& p2)
|
||||
{
|
||||
Point vec = vector(p1, p2);
|
||||
return vec.m_x * vec.m_x + vec.m_y * vec.m_y;
|
||||
}
|
||||
|
||||
static bool equal(const Point& p1, const Point& p2, double span)
|
||||
{
|
||||
double dist = dist2(p1, p2) / span;
|
||||
|
||||
// ABELL - This number should be examined to figure how how
|
||||
// it correlates with the breakdown of calculating determinants.
|
||||
return dist < 1e-20;
|
||||
}
|
||||
|
||||
private:
|
||||
double m_x;
|
||||
double m_y;
|
||||
};
|
||||
|
||||
inline std::ostream& operator<<(std::ostream& out, const Point& p)
|
||||
{
|
||||
out << p.x() << "/" << p.y();
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
class Points
|
||||
{
|
||||
public:
|
||||
using const_iterator = Point const *;
|
||||
|
||||
Points(const std::vector<double>& coords) : m_coords(coords)
|
||||
{}
|
||||
|
||||
const Point& operator[](size_t offset)
|
||||
{
|
||||
return reinterpret_cast<const Point&>(
|
||||
*(m_coords.data() + (offset * 2)));
|
||||
};
|
||||
|
||||
Points::const_iterator begin() const
|
||||
{ return reinterpret_cast<const Point *>(m_coords.data()); }
|
||||
Points::const_iterator end() const
|
||||
{ return reinterpret_cast<const Point *>(
|
||||
m_coords.data() + m_coords.size()); }
|
||||
size_t size() const
|
||||
{ return m_coords.size() / 2; }
|
||||
|
||||
private:
|
||||
const std::vector<double>& m_coords;
|
||||
};
|
||||
|
||||
class Delaunator
|
||||
{
|
||||
|
||||
public:
|
||||
std::vector<double> const &coords;
|
||||
Points m_points;
|
||||
|
||||
// 'triangles' stores the indices to the 'X's of the input
|
||||
// 'coords'.
|
||||
std::vector<std::size_t> triangles;
|
||||
|
||||
// 'halfedges' store indices into 'triangles'. If halfedges[X] = Y,
|
||||
// It says that there's an edge from X to Y where a) X and Y are
|
||||
// both indices into triangles and b) X and Y are indices into different
|
||||
// triangles in the array. This allows you to get from a triangle to
|
||||
// its adjacent triangle. If the a triangle edge has no adjacent triangle,
|
||||
// its half edge will be INVALID_INDEX.
|
||||
std::vector<std::size_t> halfedges;
|
||||
|
||||
std::vector<std::size_t> hull_prev;
|
||||
std::vector<std::size_t> hull_next;
|
||||
|
||||
// This contains indexes into the triangles array.
|
||||
std::vector<std::size_t> hull_tri;
|
||||
std::size_t hull_start;
|
||||
|
||||
inline Delaunator( std::vector<double> const &in_coords );
|
||||
inline double get_hull_area();
|
||||
inline double get_triangle_area();
|
||||
|
||||
private:
|
||||
std::vector<std::size_t> m_hash;
|
||||
Point m_center;
|
||||
std::size_t m_hash_size;
|
||||
std::vector<std::size_t> m_edge_stack;
|
||||
|
||||
inline std::size_t legalize( std::size_t a );
|
||||
inline std::size_t hash_key( double x, double y ) const;
|
||||
inline std::size_t add_triangle( std::size_t i0, std::size_t i1, std::size_t i2, std::size_t a,
|
||||
std::size_t b, std::size_t c );
|
||||
inline void link( std::size_t a, std::size_t b );
|
||||
};
|
||||
|
||||
//@see https://stackoverflow.com/questions/33333363/built-in-mod-vs-custom-mod-function-improve-the-performance-of-modulus-op/33333636#33333636
|
||||
inline size_t fast_mod( const size_t i, const size_t c )
|
||||
{
|
||||
return i >= c ? i % c : i;
|
||||
}
|
||||
|
||||
// Kahan and Babuska summation, Neumaier variant; accumulates less FP error
|
||||
inline double sum( const std::vector<double> &x )
|
||||
{
|
||||
double sum = x[0];
|
||||
double err = 0.0;
|
||||
|
||||
for( size_t i = 1; i < x.size(); i++ )
|
||||
{
|
||||
const double k = x[i];
|
||||
const double m = sum + k;
|
||||
err += std::fabs( sum ) >= std::fabs( k ) ? sum - m + k : k - m + sum;
|
||||
sum = m;
|
||||
}
|
||||
return sum + err;
|
||||
}
|
||||
|
||||
inline double dist( const double ax, const double ay, const double bx, const double by )
|
||||
{
|
||||
const double dx = ax - bx;
|
||||
const double dy = ay - by;
|
||||
return dx * dx + dy * dy;
|
||||
}
|
||||
|
||||
inline double circumradius( const Point &p1, const Point &p2, const Point &p3 )
|
||||
{
|
||||
Point d = Point::vector( p1, p2 );
|
||||
Point e = Point::vector( p1, p3 );
|
||||
|
||||
const double bl = d.magnitude2();
|
||||
const double cl = e.magnitude2();
|
||||
const double det = Point::determinant( d, e );
|
||||
|
||||
Point radius( ( e.y() * bl - d.y() * cl ) * 0.5 / det,
|
||||
( d.x() * cl - e.x() * bl ) * 0.5 / det );
|
||||
|
||||
if( ( bl > 0.0 || bl < 0.0 ) && ( cl > 0.0 || cl < 0.0 ) && ( det > 0.0 || det < 0.0 ) )
|
||||
return radius.magnitude2();
|
||||
return ( std::numeric_limits<double>::max )();
|
||||
}
|
||||
|
||||
inline double circumradius( const double ax, const double ay, const double bx, const double by,
|
||||
const double cx, const double cy )
|
||||
{
|
||||
const double dx = bx - ax;
|
||||
const double dy = by - ay;
|
||||
const double ex = cx - ax;
|
||||
const double ey = cy - ay;
|
||||
|
||||
const double bl = dx * dx + dy * dy;
|
||||
const double cl = ex * ex + ey * ey;
|
||||
const double d = dx * ey - dy * ex;
|
||||
|
||||
const double x = ( ey * bl - dy * cl ) * 0.5 / d;
|
||||
const double y = ( dx * cl - ex * bl ) * 0.5 / d;
|
||||
|
||||
if( ( bl > 0.0 || bl < 0.0 ) && ( cl > 0.0 || cl < 0.0 ) && ( d > 0.0 || d < 0.0 ) )
|
||||
{
|
||||
return x * x + y * y;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ( std::numeric_limits<double>::max )();
|
||||
}
|
||||
}
|
||||
|
||||
inline bool clockwise( const Point &p0, const Point &p1, const Point &p2 )
|
||||
{
|
||||
Point v0 = Point::vector( p0, p1 );
|
||||
Point v1 = Point::vector( p0, p2 );
|
||||
double det = Point::determinant( v0, v1 );
|
||||
double dist = v0.magnitude2() + v1.magnitude2();
|
||||
double dist2 = Point::dist2( v0, v1 );
|
||||
if( det == 0 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
double reldet = std::abs( dist / det );
|
||||
if( reldet > 1e14 )
|
||||
return false;
|
||||
return det < 0;
|
||||
}
|
||||
|
||||
inline bool clockwise( double px, double py, double qx, double qy, double rx, double ry )
|
||||
{
|
||||
Point p0( px, py );
|
||||
Point p1( qx, qy );
|
||||
Point p2( rx, ry );
|
||||
return clockwise( p0, p1, p2 );
|
||||
}
|
||||
|
||||
inline bool counterclockwise( const Point &p0, const Point &p1, const Point &p2 )
|
||||
{
|
||||
Point v0 = Point::vector( p0, p1 );
|
||||
Point v1 = Point::vector( p0, p2 );
|
||||
double det = Point::determinant( v0, v1 );
|
||||
double dist = v0.magnitude2() + v1.magnitude2();
|
||||
double dist2 = Point::dist2( v0, v1 );
|
||||
if( det == 0 )
|
||||
return false;
|
||||
double reldet = std::abs( dist / det );
|
||||
if( reldet > 1e14 )
|
||||
return false;
|
||||
return det > 0;
|
||||
}
|
||||
|
||||
inline bool counterclockwise( double px, double py, double qx, double qy, double rx, double ry )
|
||||
{
|
||||
Point p0( px, py );
|
||||
Point p1( qx, qy );
|
||||
Point p2( rx, ry );
|
||||
return counterclockwise( p0, p1, p2 );
|
||||
}
|
||||
|
||||
inline Point circumcenter( const double ax, const double ay, const double bx, const double by,
|
||||
const double cx, const double cy )
|
||||
{
|
||||
const double dx = bx - ax;
|
||||
const double dy = by - ay;
|
||||
const double ex = cx - ax;
|
||||
const double ey = cy - ay;
|
||||
|
||||
const double bl = dx * dx + dy * dy;
|
||||
const double cl = ex * ex + ey * ey;
|
||||
//ABELL - This is suspect for div-by-0.
|
||||
const double d = dx * ey - dy * ex;
|
||||
|
||||
const double x = ax + ( ey * bl - dy * cl ) * 0.5 / d;
|
||||
const double y = ay + ( dx * cl - ex * bl ) * 0.5 / d;
|
||||
|
||||
return Point( x, y );
|
||||
}
|
||||
|
||||
inline bool in_circle( const double ax, const double ay, const double bx, const double by,
|
||||
const double cx, const double cy, const double px, const double py )
|
||||
{
|
||||
const double dx = ax - px;
|
||||
const double dy = ay - py;
|
||||
const double ex = bx - px;
|
||||
const double ey = by - py;
|
||||
const double fx = cx - px;
|
||||
const double fy = cy - py;
|
||||
|
||||
const double ap = dx * dx + dy * dy;
|
||||
const double bp = ex * ex + ey * ey;
|
||||
const double cp = fx * fx + fy * fy;
|
||||
|
||||
return ( dx * ( ey * cp - bp * fy ) - dy * ( ex * cp - bp * fx ) + ap * ( ex * fy - ey * fx ) )
|
||||
< 0.0;
|
||||
}
|
||||
|
||||
constexpr double EPSILON = std::numeric_limits<double>::epsilon();
|
||||
|
||||
inline bool check_pts_equal( double x1, double y1, double x2, double y2 )
|
||||
{
|
||||
return std::fabs( x1 - x2 ) <= EPSILON && std::fabs( y1 - y2 ) <= EPSILON;
|
||||
}
|
||||
|
||||
// monotonically increases with real angle, but doesn't need expensive trigonometry
|
||||
inline double pseudo_angle( const double dx, const double dy )
|
||||
{
|
||||
const double p = dx / ( std::abs( dx ) + std::abs( dy ) );
|
||||
return ( dy > 0.0 ? 3.0 - p : 1.0 + p ) / 4.0; // [0..1)
|
||||
}
|
||||
|
||||
Delaunator::Delaunator( std::vector<double> const &in_coords ) :
|
||||
coords( in_coords ), m_points( in_coords )
|
||||
{
|
||||
std::size_t n = coords.size() >> 1;
|
||||
|
||||
std::vector<std::size_t> ids( n );
|
||||
std::iota( ids.begin(), ids.end(), 0 );
|
||||
|
||||
double max_x = std::numeric_limits<double>::lowest();
|
||||
double max_y = std::numeric_limits<double>::lowest();
|
||||
double min_x = ( std::numeric_limits<double>::max )();
|
||||
double min_y = ( std::numeric_limits<double>::max )();
|
||||
for( const Point &p : m_points )
|
||||
{
|
||||
min_x = std::min( p.x(), min_x );
|
||||
min_y = std::min( p.y(), min_y );
|
||||
max_x = std::max( p.x(), max_x );
|
||||
max_y = std::max( p.y(), max_y );
|
||||
}
|
||||
double width = max_x - min_x;
|
||||
double height = max_y - min_y;
|
||||
double span = width * width + height * height; // Everything is square dist.
|
||||
|
||||
Point center( ( min_x + max_x ) / 2, ( min_y + max_y ) / 2 );
|
||||
|
||||
std::size_t i0 = INVALID_INDEX;
|
||||
std::size_t i1 = INVALID_INDEX;
|
||||
std::size_t i2 = INVALID_INDEX;
|
||||
|
||||
// pick a seed point close to the centroid
|
||||
double min_dist = ( std::numeric_limits<double>::max )();
|
||||
for( size_t i = 0; i < m_points.size(); ++i )
|
||||
{
|
||||
const Point &p = m_points[i];
|
||||
const double d = Point::dist2( center, p );
|
||||
if( d < min_dist )
|
||||
{
|
||||
i0 = i;
|
||||
min_dist = d;
|
||||
}
|
||||
}
|
||||
|
||||
const Point &p0 = m_points[i0];
|
||||
|
||||
min_dist = ( std::numeric_limits<double>::max )();
|
||||
|
||||
// find the point closest to the seed
|
||||
for( std::size_t i = 0; i < n; i++ )
|
||||
{
|
||||
if( i == i0 )
|
||||
continue;
|
||||
const double d = Point::dist2( p0, m_points[i] );
|
||||
if( d < min_dist && d > 0.0 )
|
||||
{
|
||||
i1 = i;
|
||||
min_dist = d;
|
||||
}
|
||||
}
|
||||
|
||||
const Point &p1 = m_points[i1];
|
||||
|
||||
double min_radius = ( std::numeric_limits<double>::max )();
|
||||
|
||||
// find the third point which forms the smallest circumcircle
|
||||
// with the first two
|
||||
for( std::size_t i = 0; i < n; i++ )
|
||||
{
|
||||
if( i == i0 || i == i1 )
|
||||
continue;
|
||||
|
||||
const double r = circumradius( p0, p1, m_points[i] );
|
||||
if( r < min_radius )
|
||||
{
|
||||
i2 = i;
|
||||
min_radius = r;
|
||||
}
|
||||
}
|
||||
|
||||
if( !( min_radius < ( std::numeric_limits<double>::max )() ) )
|
||||
{
|
||||
throw std::runtime_error( "not triangulation" );
|
||||
}
|
||||
|
||||
const Point &p2 = m_points[i2];
|
||||
|
||||
if( counterclockwise( p0, p1, p2 ) )
|
||||
std::swap( i1, i2 );
|
||||
|
||||
double i0x = p0.x();
|
||||
double i0y = p0.y();
|
||||
double i1x = m_points[i1].x();
|
||||
double i1y = m_points[i1].y();
|
||||
double i2x = m_points[i2].x();
|
||||
double i2y = m_points[i2].y();
|
||||
|
||||
m_center = circumcenter( i0x, i0y, i1x, i1y, i2x, i2y );
|
||||
|
||||
// Calculate the distances from the center once to avoid having to
|
||||
// calculate for each compare. This used to be done in the comparator,
|
||||
// but GCC 7.5+ would copy the comparator to iterators used in the
|
||||
// sort, and this was excruciatingly slow when there were many points
|
||||
// because you had to copy the vector of distances.
|
||||
std::vector<double> dists;
|
||||
dists.reserve( m_points.size() );
|
||||
for( const Point &p : m_points )
|
||||
dists.push_back( dist( p.x(), p.y(), m_center.x(), m_center.y() ) );
|
||||
|
||||
// sort the points by distance from the seed triangle circumcenter
|
||||
std::sort( ids.begin(), ids.end(), [ &dists ]( std::size_t i, std::size_t j )
|
||||
{ return dists[i] < dists[j];} );
|
||||
|
||||
// initialize a hash table for storing edges of the advancing convex hull
|
||||
m_hash_size = static_cast<std::size_t>( std::ceil( std::sqrt( n ) ) );
|
||||
m_hash.resize( m_hash_size );
|
||||
std::fill( m_hash.begin(), m_hash.end(), INVALID_INDEX );
|
||||
|
||||
// initialize arrays for tracking the edges of the advancing convex hull
|
||||
hull_prev.resize( n );
|
||||
hull_next.resize( n );
|
||||
hull_tri.resize( n );
|
||||
|
||||
hull_start = i0;
|
||||
|
||||
size_t hull_size = 3;
|
||||
|
||||
hull_next[i0] = hull_prev[i2] = i1;
|
||||
hull_next[i1] = hull_prev[i0] = i2;
|
||||
hull_next[i2] = hull_prev[i1] = i0;
|
||||
|
||||
hull_tri[i0] = 0;
|
||||
hull_tri[i1] = 1;
|
||||
hull_tri[i2] = 2;
|
||||
|
||||
m_hash[hash_key( i0x, i0y )] = i0;
|
||||
m_hash[hash_key( i1x, i1y )] = i1;
|
||||
m_hash[hash_key( i2x, i2y )] = i2;
|
||||
|
||||
// ABELL - Why are we doing this is n < 3? There is no triangulation if
|
||||
// there is no triangle.
|
||||
|
||||
std::size_t max_triangles = n < 3 ? 1 : 2 * n - 5;
|
||||
triangles.reserve( max_triangles * 3 );
|
||||
halfedges.reserve( max_triangles * 3 );
|
||||
add_triangle( i0, i1, i2, INVALID_INDEX, INVALID_INDEX, INVALID_INDEX );
|
||||
double xp = std::numeric_limits<double>::quiet_NaN();
|
||||
double yp = std::numeric_limits<double>::quiet_NaN();
|
||||
|
||||
// Go through points based on distance from the center.
|
||||
for( std::size_t k = 0; k < n; k++ )
|
||||
{
|
||||
const std::size_t i = ids[k];
|
||||
const double x = coords[2 * i];
|
||||
const double y = coords[2 * i + 1];
|
||||
|
||||
// skip near-duplicate points
|
||||
if( k > 0 && check_pts_equal( x, y, xp, yp ) )
|
||||
continue;
|
||||
xp = x;
|
||||
yp = y;
|
||||
|
||||
//ABELL - This is dumb. We have the indices. Use them.
|
||||
// skip seed triangle points
|
||||
if( check_pts_equal( x, y, i0x, i0y ) || check_pts_equal( x, y, i1x, i1y )
|
||||
|| check_pts_equal( x, y, i2x, i2y ) )
|
||||
continue;
|
||||
|
||||
// find a visible edge on the convex hull using edge hash
|
||||
std::size_t start = 0;
|
||||
|
||||
size_t key = hash_key( x, y );
|
||||
for( size_t j = 0; j < m_hash_size; j++ )
|
||||
{
|
||||
start = m_hash[fast_mod( key + j, m_hash_size )];
|
||||
|
||||
// ABELL - Not sure how hull_next[start] could ever equal start
|
||||
// I *think* hull_next is just a representation of the hull in one
|
||||
// direction.
|
||||
if( start != INVALID_INDEX && start != hull_next[start] )
|
||||
break;
|
||||
}
|
||||
|
||||
//ABELL
|
||||
// Make sure what we found is on the hull.
|
||||
assert( hull_prev[start] != start );
|
||||
assert( hull_prev[start] != INVALID_INDEX );
|
||||
|
||||
start = hull_prev[start];
|
||||
size_t e = start;
|
||||
size_t q;
|
||||
|
||||
// Advance until we find a place in the hull where our current point
|
||||
// can be added.
|
||||
while( true )
|
||||
{
|
||||
q = hull_next[e];
|
||||
if( Point::equal( m_points[i], m_points[e], span )
|
||||
|| Point::equal( m_points[i], m_points[q], span ) )
|
||||
{
|
||||
e = INVALID_INDEX;
|
||||
break;
|
||||
}
|
||||
if( counterclockwise( x, y, coords[2 * e], coords[2 * e + 1], coords[2 * q],
|
||||
coords[2 * q + 1] ) )
|
||||
break;
|
||||
e = q;
|
||||
if( e == start )
|
||||
{
|
||||
e = INVALID_INDEX;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// ABELL
|
||||
// This seems wrong. Perhaps we should check what's going on?
|
||||
if( e == INVALID_INDEX ) // likely a near-duplicate point; skip it
|
||||
continue;
|
||||
|
||||
// add the first triangle from the point
|
||||
std::size_t t = add_triangle( e, i, hull_next[e], INVALID_INDEX, INVALID_INDEX,
|
||||
hull_tri[e] );
|
||||
|
||||
hull_tri[i] = legalize( t + 2 ); // Legalize the triangle we just added.
|
||||
hull_tri[e] = t;
|
||||
hull_size++;
|
||||
|
||||
// walk forward through the hull, adding more triangles and
|
||||
// flipping recursively
|
||||
std::size_t next = hull_next[e];
|
||||
while( true )
|
||||
{
|
||||
q = hull_next[next];
|
||||
if( !counterclockwise( x, y, coords[2 * next], coords[2 * next + 1], coords[2 * q],
|
||||
coords[2 * q + 1] ) )
|
||||
break;
|
||||
t = add_triangle( next, i, q, hull_tri[i], INVALID_INDEX, hull_tri[next] );
|
||||
hull_tri[i] = legalize( t + 2 );
|
||||
hull_next[next] = next; // mark as removed
|
||||
hull_size--;
|
||||
next = q;
|
||||
}
|
||||
|
||||
// walk backward from the other side, adding more triangles and flipping
|
||||
if( e == start )
|
||||
{
|
||||
while( true )
|
||||
{
|
||||
q = hull_prev[e];
|
||||
if( !counterclockwise( x, y, coords[2 * q], coords[2 * q + 1], coords[2 * e],
|
||||
coords[2 * e + 1] ) )
|
||||
break;
|
||||
t = add_triangle( q, i, e, INVALID_INDEX, hull_tri[e], hull_tri[q] );
|
||||
legalize( t + 2 );
|
||||
hull_tri[q] = t;
|
||||
hull_next[e] = e; // mark as removed
|
||||
hull_size--;
|
||||
e = q;
|
||||
}
|
||||
}
|
||||
|
||||
// update the hull indices
|
||||
hull_prev[i] = e;
|
||||
hull_start = e;
|
||||
hull_prev[next] = i;
|
||||
hull_next[e] = i;
|
||||
hull_next[i] = next;
|
||||
|
||||
m_hash[hash_key( x, y )] = i;
|
||||
m_hash[hash_key( coords[2 * e], coords[2 * e + 1] )] = e;
|
||||
}
|
||||
}
|
||||
|
||||
double Delaunator::get_hull_area()
|
||||
{
|
||||
std::vector<double> hull_area;
|
||||
size_t e = hull_start;
|
||||
size_t cnt = 1;
|
||||
do
|
||||
{
|
||||
hull_area.push_back(
|
||||
( coords[2 * e] - coords[2 * hull_prev[e]] )
|
||||
* ( coords[2 * e + 1] + coords[2 * hull_prev[e] + 1] ) );
|
||||
cnt++;
|
||||
e = hull_next[e];
|
||||
} while( e != hull_start );
|
||||
return sum( hull_area );
|
||||
}
|
||||
|
||||
double Delaunator::get_triangle_area()
|
||||
{
|
||||
std::vector<double> vals;
|
||||
for( size_t i = 0; i < triangles.size(); i += 3 )
|
||||
{
|
||||
const double ax = coords[2 * triangles[i]];
|
||||
const double ay = coords[2 * triangles[i] + 1];
|
||||
const double bx = coords[2 * triangles[i + 1]];
|
||||
const double by = coords[2 * triangles[i + 1] + 1];
|
||||
const double cx = coords[2 * triangles[i + 2]];
|
||||
const double cy = coords[2 * triangles[i + 2] + 1];
|
||||
double val = std::fabs( ( by - ay ) * ( cx - bx ) - ( bx - ax ) * ( cy - by ) );
|
||||
vals.push_back( val );
|
||||
}
|
||||
return sum( vals );
|
||||
}
|
||||
|
||||
std::size_t Delaunator::legalize( std::size_t a )
|
||||
{
|
||||
std::size_t i = 0;
|
||||
std::size_t ar = 0;
|
||||
m_edge_stack.clear();
|
||||
|
||||
// recursion eliminated with a fixed-size stack
|
||||
while( true )
|
||||
{
|
||||
const size_t b = halfedges[a];
|
||||
|
||||
/* if the pair of triangles doesn't satisfy the Delaunay condition
|
||||
* (p1 is inside the circumcircle of [p0, pl, pr]), flip them,
|
||||
* then do the same check/flip recursively for the new pair of triangles
|
||||
*
|
||||
* pl pl
|
||||
* /||\ / \
|
||||
* al/ || \bl al/ \a
|
||||
* / || \ / \
|
||||
* / a||b \ flip /___ar___\
|
||||
* p0\ || /p1 => p0\---bl---/p1
|
||||
* \ || / \ /
|
||||
* ar\ || /br b\ /br
|
||||
* \||/ \ /
|
||||
* pr pr
|
||||
*/
|
||||
const size_t a0 = 3 * ( a / 3 );
|
||||
ar = a0 + ( a + 2 ) % 3;
|
||||
|
||||
if( b == INVALID_INDEX )
|
||||
{
|
||||
if( i > 0 )
|
||||
{
|
||||
i--;
|
||||
a = m_edge_stack[i];
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
//i = INVALID_INDEX;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const size_t b0 = 3 * ( b / 3 );
|
||||
const size_t al = a0 + ( a + 1 ) % 3;
|
||||
const size_t bl = b0 + ( b + 2 ) % 3;
|
||||
|
||||
const std::size_t p0 = triangles[ar];
|
||||
const std::size_t pr = triangles[a];
|
||||
const std::size_t pl = triangles[al];
|
||||
const std::size_t p1 = triangles[bl];
|
||||
|
||||
const bool illegal = in_circle( coords[2 * p0], coords[2 * p0 + 1], coords[2 * pr],
|
||||
coords[2 * pr + 1], coords[2 * pl], coords[2 * pl + 1], coords[2 * p1],
|
||||
coords[2 * p1 + 1] );
|
||||
|
||||
if( illegal )
|
||||
{
|
||||
triangles[a] = p1;
|
||||
triangles[b] = p0;
|
||||
|
||||
auto hbl = halfedges[bl];
|
||||
|
||||
// Edge swapped on the other side of the hull (rare).
|
||||
// Fix the halfedge reference
|
||||
if( hbl == INVALID_INDEX )
|
||||
{
|
||||
std::size_t e = hull_start;
|
||||
do
|
||||
{
|
||||
if( hull_tri[e] == bl )
|
||||
{
|
||||
hull_tri[e] = a;
|
||||
break;
|
||||
}
|
||||
e = hull_prev[e];
|
||||
} while( e != hull_start );
|
||||
}
|
||||
link( a, hbl );
|
||||
link( b, halfedges[ar] );
|
||||
link( ar, bl );
|
||||
std::size_t br = b0 + ( b + 1 ) % 3;
|
||||
|
||||
if( i < m_edge_stack.size() )
|
||||
{
|
||||
m_edge_stack[i] = br;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_edge_stack.push_back( br );
|
||||
}
|
||||
i++;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if( i > 0 )
|
||||
{
|
||||
i--;
|
||||
a = m_edge_stack[i];
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ar;
|
||||
}
|
||||
|
||||
std::size_t Delaunator::hash_key( const double x, const double y ) const
|
||||
{
|
||||
const double dx = x - m_center.x();
|
||||
const double dy = y - m_center.y();
|
||||
return fast_mod(
|
||||
static_cast<std::size_t>( std::llround(
|
||||
std::floor( pseudo_angle( dx, dy ) * static_cast<double>( m_hash_size ) ) ) ),
|
||||
m_hash_size );
|
||||
}
|
||||
|
||||
std::size_t Delaunator::add_triangle( std::size_t i0, std::size_t i1, std::size_t i2,
|
||||
std::size_t a, std::size_t b, std::size_t c )
|
||||
{
|
||||
std::size_t t = triangles.size();
|
||||
triangles.push_back( i0 );
|
||||
triangles.push_back( i1 );
|
||||
triangles.push_back( i2 );
|
||||
link( t, a );
|
||||
link( t + 1, b );
|
||||
link( t + 2, c );
|
||||
return t;
|
||||
}
|
||||
|
||||
void Delaunator::link( const std::size_t a, const std::size_t b )
|
||||
{
|
||||
std::size_t s = halfedges.size();
|
||||
if( a == s )
|
||||
{
|
||||
halfedges.push_back( b );
|
||||
}
|
||||
else if( a < s )
|
||||
{
|
||||
halfedges[a] = b;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw std::runtime_error( "Cannot link edge" );
|
||||
}
|
||||
if( b != INVALID_INDEX )
|
||||
{
|
||||
std::size_t s2 = halfedges.size();
|
||||
if( b == s2 )
|
||||
{
|
||||
halfedges.push_back( a );
|
||||
}
|
||||
else if( b < s2 )
|
||||
{
|
||||
halfedges[b] = a;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw std::runtime_error( "Cannot link edge" );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif /* PCBNEW_RATSNEST_DELAUNEY_H_ */
|
|
@ -41,7 +41,8 @@ using namespace std::placeholders;
|
|||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <limits>
|
||||
#include <queue>
|
||||
|
||||
#include <delaunator.hpp>
|
||||
|
||||
class disjoint_set
|
||||
{
|
||||
|
@ -105,7 +106,7 @@ private:
|
|||
std::vector<int> m_depth;
|
||||
};
|
||||
|
||||
void RN_NET::kruskalMST( std::priority_queue<CN_EDGE> &aEdges )
|
||||
void RN_NET::kruskalMST( const std::vector<CN_EDGE> &aEdges )
|
||||
{
|
||||
disjoint_set dset( m_nodes.size() );
|
||||
|
||||
|
@ -116,10 +117,8 @@ void RN_NET::kruskalMST( std::priority_queue<CN_EDGE> &aEdges )
|
|||
for( auto& node : m_nodes )
|
||||
node->SetTag( i++ );
|
||||
|
||||
while( !aEdges.empty() )
|
||||
for( auto& tmp : aEdges )
|
||||
{
|
||||
auto& tmp = aEdges.top();
|
||||
|
||||
int u = tmp.GetSourceNode()->GetTag();
|
||||
int v = tmp.GetTargetNode()->GetTag();
|
||||
|
||||
|
@ -128,8 +127,6 @@ void RN_NET::kruskalMST( std::priority_queue<CN_EDGE> &aEdges )
|
|||
if( tmp.GetWeight() > 0 )
|
||||
m_rnEdges.push_back( tmp );
|
||||
}
|
||||
|
||||
aEdges.pop();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -137,37 +134,25 @@ void RN_NET::kruskalMST( std::priority_queue<CN_EDGE> &aEdges )
|
|||
class RN_NET::TRIANGULATOR_STATE
|
||||
{
|
||||
private:
|
||||
std::vector<CN_ANCHOR_PTR> m_allNodes;
|
||||
|
||||
std::list<hed::EDGE_PTR> hedTriangulation( std::vector<hed::NODE_PTR>& aNodes )
|
||||
{
|
||||
hed::TRIANGULATION triangulator;
|
||||
triangulator.CreateDelaunay( aNodes.begin(), aNodes.end() );
|
||||
std::list<hed::EDGE_PTR> edges;
|
||||
triangulator.GetEdges( edges );
|
||||
|
||||
return edges;
|
||||
}
|
||||
std::multiset<CN_ANCHOR_PTR, CN_PTR_CMP> m_allNodes;
|
||||
|
||||
|
||||
// Checks if all nodes in aNodes lie on a single line. Requires the nodes to
|
||||
// have unique coordinates!
|
||||
bool areNodesColinear( const std::vector<hed::NODE_PTR>& aNodes ) const
|
||||
bool areNodesColinear( const std::vector<CN_ANCHOR_PTR>& aNodes ) const
|
||||
{
|
||||
if ( aNodes.size() <= 2 )
|
||||
return true;
|
||||
|
||||
const auto p0 = aNodes[0]->Pos();
|
||||
const auto v0 = aNodes[1]->Pos() - p0;
|
||||
const VECTOR2I p0( aNodes[0]->Pos() );
|
||||
const VECTOR2I v0( aNodes[1]->Pos() - p0 );
|
||||
|
||||
for( unsigned i = 2; i < aNodes.size(); i++ )
|
||||
{
|
||||
const auto v1 = aNodes[i]->Pos() - p0;
|
||||
const VECTOR2I v1 = aNodes[i]->Pos() - p0;
|
||||
|
||||
if( v0.Cross( v1 ) != 0 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -182,97 +167,84 @@ public:
|
|||
|
||||
void AddNode( CN_ANCHOR_PTR aNode )
|
||||
{
|
||||
m_allNodes.push_back( aNode );
|
||||
m_allNodes.insert( aNode );
|
||||
}
|
||||
|
||||
const std::priority_queue<CN_EDGE> Triangulate()
|
||||
void Triangulate( std::vector<CN_EDGE>& mstEdges)
|
||||
{
|
||||
std::priority_queue<CN_EDGE> mstEdges;
|
||||
std::list<hed::EDGE_PTR> triangEdges;
|
||||
std::vector<hed::NODE_PTR> triNodes;
|
||||
std::vector<double> node_pts;
|
||||
|
||||
using ANCHOR_LIST = std::vector<CN_ANCHOR_PTR>;
|
||||
std::vector<ANCHOR_LIST> anchorChains;
|
||||
|
||||
triNodes.reserve( m_allNodes.size() );
|
||||
anchorChains.resize( m_allNodes.size() );
|
||||
ANCHOR_LIST anchors;
|
||||
std::vector<ANCHOR_LIST> anchorChains( m_allNodes.size() );
|
||||
|
||||
std::sort( m_allNodes.begin(), m_allNodes.end(),
|
||||
[] ( const CN_ANCHOR_PTR& aNode1, const CN_ANCHOR_PTR& aNode2 )
|
||||
{
|
||||
if( aNode1->Pos().y < aNode2->Pos().y )
|
||||
return true;
|
||||
else if( aNode1->Pos().y == aNode2->Pos().y )
|
||||
{
|
||||
return aNode1->Pos().x < aNode2->Pos().x;
|
||||
}
|
||||
node_pts.reserve( 2 * m_allNodes.size() );
|
||||
anchors.reserve( m_allNodes.size() );
|
||||
|
||||
return false;
|
||||
}
|
||||
);
|
||||
|
||||
CN_ANCHOR_PTR prev, last;
|
||||
int id = 0;
|
||||
CN_ANCHOR_PTR prev = nullptr;
|
||||
|
||||
for( const auto& n : m_allNodes )
|
||||
{
|
||||
if( !prev || prev->Pos() != n->Pos() )
|
||||
{
|
||||
auto tn = std::make_shared<hed::NODE> ( n->Pos().x, n->Pos().y );
|
||||
|
||||
tn->SetId( id );
|
||||
triNodes.push_back( tn );
|
||||
node_pts.push_back( n->Pos().x );
|
||||
node_pts.push_back( n->Pos().y );
|
||||
anchors.push_back( n );
|
||||
prev = n;
|
||||
}
|
||||
|
||||
id++;
|
||||
prev = n;
|
||||
anchorChains[anchors.size() - 1].push_back( n );
|
||||
}
|
||||
|
||||
int prevId = 0;
|
||||
|
||||
for( const auto& n : triNodes )
|
||||
if( anchors.size() < 2 )
|
||||
{
|
||||
for( int i = prevId; i < n->Id(); i++ )
|
||||
anchorChains[prevId].push_back( m_allNodes[ i ] );
|
||||
|
||||
prevId = n->Id();
|
||||
return;
|
||||
}
|
||||
|
||||
for( int i = prevId; i < id; i++ )
|
||||
anchorChains[prevId].push_back( m_allNodes[ i ] );
|
||||
|
||||
if( triNodes.size() == 1 )
|
||||
{
|
||||
return mstEdges;
|
||||
}
|
||||
else if( areNodesColinear( triNodes ) )
|
||||
else if( areNodesColinear( anchors ) )
|
||||
{
|
||||
// special case: all nodes are on the same line - there's no
|
||||
// triangulation for such set. In this case, we sort along any coordinate
|
||||
// and chain the nodes together.
|
||||
for(int i = 0; i < (int)triNodes.size() - 1; i++ )
|
||||
for( size_t i = 0; i < anchors.size() - 1; i++ )
|
||||
{
|
||||
auto src = m_allNodes[ triNodes[i]->Id() ];
|
||||
auto dst = m_allNodes[ triNodes[i + 1]->Id() ];
|
||||
mstEdges.emplace( src, dst, src->Dist( *dst ) );
|
||||
auto src = anchors[i];
|
||||
auto dst = anchors[i + 1];
|
||||
mstEdges.emplace_back( src, dst, src->Dist( *dst ) );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
hed::TRIANGULATION triangulator;
|
||||
triangulator.CreateDelaunay( triNodes.begin(), triNodes.end() );
|
||||
triangulator.GetEdges( triangEdges );
|
||||
delaunator::Delaunator delaunator( node_pts );
|
||||
auto& triangles = delaunator.triangles;
|
||||
|
||||
for( const auto& e : triangEdges )
|
||||
for( size_t i = 0; i < triangles.size(); i += 3 )
|
||||
{
|
||||
auto src = m_allNodes[ e->GetSourceNode()->Id() ];
|
||||
auto dst = m_allNodes[ e->GetTargetNode()->Id() ];
|
||||
auto src = anchors[triangles[i]];
|
||||
auto dst = anchors[triangles[i + 1]];
|
||||
mstEdges.emplace_back( src, dst, src->Dist( *dst ) );
|
||||
|
||||
mstEdges.emplace( src, dst, src->Dist( *dst ) );
|
||||
src = anchors[triangles[i + 1]];
|
||||
dst = anchors[triangles[i + 2]];
|
||||
mstEdges.emplace_back( src, dst, src->Dist( *dst ) );
|
||||
|
||||
src = anchors[triangles[i + 2]];
|
||||
dst = anchors[triangles[i]];
|
||||
mstEdges.emplace_back( src, dst, src->Dist( *dst ) );
|
||||
}
|
||||
|
||||
for( size_t i = 0; i < delaunator.halfedges.size(); i++ )
|
||||
{
|
||||
if( delaunator.halfedges[i] == delaunator::INVALID_INDEX )
|
||||
continue;
|
||||
|
||||
auto src = anchors[triangles[i]];
|
||||
auto dst = anchors[triangles[delaunator.halfedges[i]]];
|
||||
mstEdges.emplace_back( src, dst, src->Dist( *dst ) );
|
||||
}
|
||||
}
|
||||
|
||||
for( unsigned int i = 0; i < anchorChains.size(); i++ )
|
||||
for( size_t i = 0; i < anchorChains.size(); i++ )
|
||||
{
|
||||
auto& chain = anchorChains[i];
|
||||
|
||||
|
@ -289,11 +261,9 @@ public:
|
|||
const auto& prevNode = chain[j - 1];
|
||||
const auto& curNode = chain[j];
|
||||
int weight = prevNode->GetCluster() != curNode->GetCluster() ? 1 : 0;
|
||||
mstEdges.emplace( prevNode, curNode, weight );
|
||||
mstEdges.emplace_back( prevNode, curNode, weight );
|
||||
}
|
||||
}
|
||||
|
||||
return mstEdges;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -342,16 +312,21 @@ void RN_NET::compute()
|
|||
m_triangulator->AddNode( n );
|
||||
}
|
||||
|
||||
std::vector<CN_EDGE> triangEdges;
|
||||
triangEdges.reserve( m_nodes.size() + m_boardEdges.size() );
|
||||
|
||||
#ifdef PROFILE
|
||||
PROF_COUNTER cnt("triangulate");
|
||||
#endif
|
||||
auto triangEdges = m_triangulator->Triangulate();
|
||||
m_triangulator->Triangulate( triangEdges );
|
||||
#ifdef PROFILE
|
||||
cnt.Show();
|
||||
#endif
|
||||
|
||||
for( const auto& e : m_boardEdges )
|
||||
triangEdges.push( e );
|
||||
triangEdges.emplace_back( e );
|
||||
|
||||
std::sort( triangEdges.begin(), triangEdges.end() );
|
||||
|
||||
// Get the minimal spanning tree
|
||||
#ifdef PROFILE
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
* This program source code file is part of KICAD, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2013-2015 CERN
|
||||
* Copyright (C) 2019-2020 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
|
@ -33,24 +34,14 @@
|
|||
#include <core/typeinfo.h>
|
||||
#include <math/box2.h>
|
||||
|
||||
#include <deque>
|
||||
#include <set>
|
||||
#include <unordered_set>
|
||||
#include <unordered_map>
|
||||
|
||||
#include <ttl/halfedge/hetriang.h>
|
||||
#include <ttl/halfedge/hetraits.h>
|
||||
#include <vector>
|
||||
|
||||
#include <connectivity/connectivity_algo.h>
|
||||
|
||||
class BOARD;
|
||||
class BOARD_ITEM;
|
||||
class BOARD_CONNECTED_ITEM;
|
||||
class CN_CLUSTER;
|
||||
class CN_CONNECTIVITY_ALGO;
|
||||
|
||||
struct RN_NODE_OR_FILTER;
|
||||
struct RN_NODE_AND_FILTER;
|
||||
|
||||
struct CN_PTR_CMP
|
||||
{
|
||||
|
@ -160,7 +151,7 @@ protected:
|
|||
void compute();
|
||||
|
||||
///> Compute the minimum spanning tree using Kruskal's algorithm
|
||||
void kruskalMST( std::priority_queue<CN_EDGE> &aEdges );
|
||||
void kruskalMST( const std::vector<CN_EDGE> &aEdges );
|
||||
|
||||
///> Vector of nodes
|
||||
std::multiset<CN_ANCHOR_PTR, CN_PTR_CMP> m_nodes;
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Copyright (C) 2016-2017 Lubomir Rintel <lkundrak@v3.sk> -->
|
||||
<!-- Copyright (C) 2016-2019 KiCad Developers, see AUTHORS.txt for contributors. -->
|
||||
<!-- Copyright (C) 2016-2020 KiCad Developers, see AUTHORS.txt for contributors. -->
|
||||
<component type="desktop">
|
||||
<id>org.kicad_pcb.kicad</id>
|
||||
<name>KiCad</name>
|
||||
|
||||
<project_license>AGPL-3.0-or-later</project_license>
|
||||
<project_license>GPL-3.0-or-later</project_license>
|
||||
<metadata_license>CC-BY-SA-4.0</metadata_license>
|
||||
|
||||
<summary>EDA Suite</summary>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#
|
||||
# This program source code file is part of KICAD, a free EDA CAD application.
|
||||
#
|
||||
# Copyright (C) 2007-2018 Kicad Developers, see AUTHORS.txt for contributors.
|
||||
# Copyright (C) 2007-2020 Kicad Developers, see AUTHORS.txt for contributors.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
|
@ -23,6 +23,7 @@
|
|||
|
||||
add_subdirectory( clipper )
|
||||
add_subdirectory( compoundfilereader )
|
||||
add_subdirectory( delaunator )
|
||||
add_subdirectory( dxflib_qcad )
|
||||
add_subdirectory( libcontext )
|
||||
add_subdirectory( markdown2html )
|
||||
|
@ -30,6 +31,5 @@ add_subdirectory( nanosvg )
|
|||
add_subdirectory( other_math )
|
||||
add_subdirectory( rtree )
|
||||
add_subdirectory( tinyspline_lib )
|
||||
add_subdirectory( ttl )
|
||||
add_subdirectory( potrace )
|
||||
add_subdirectory( nlohmann_json )
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
set(DELAUNATOR_SRCS
|
||||
delaunator.cpp
|
||||
)
|
||||
|
||||
add_library(delaunator STATIC ${DELAUNATOR_SRCS})
|
||||
|
||||
target_include_directories( delaunator
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
|
@ -0,0 +1,17 @@
|
|||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
|
@ -0,0 +1,4 @@
|
|||
This directory contains the delaunator-cpp project from https://github.com/abellgithub/delaunator-cpp
|
||||
|
||||
It is licensed under MIT, with the license text in this directory.
|
||||
|
|
@ -0,0 +1,648 @@
|
|||
|
||||
#include "delaunator.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <algorithm>
|
||||
#include <assert.h>
|
||||
#include <cmath>
|
||||
#include <numeric>
|
||||
#include <limits>
|
||||
#include <stdexcept>
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
|
||||
namespace delaunator {
|
||||
|
||||
//@see https://stackoverflow.com/questions/33333363/built-in-mod-vs-custom-mod-function-improve-the-performance-of-modulus-op/33333636#33333636
|
||||
inline size_t fast_mod(const size_t i, const size_t c) {
|
||||
return i >= c ? i % c : i;
|
||||
}
|
||||
|
||||
// Kahan and Babuska summation, Neumaier variant; accumulates less FP error
|
||||
inline double sum(const std::vector<double>& x) {
|
||||
double sum = x[0];
|
||||
double err = 0.0;
|
||||
|
||||
for (size_t i = 1; i < x.size(); i++) {
|
||||
const double k = x[i];
|
||||
const double m = sum + k;
|
||||
err += std::fabs(sum) >= std::fabs(k) ? sum - m + k : k - m + sum;
|
||||
sum = m;
|
||||
}
|
||||
return sum + err;
|
||||
}
|
||||
|
||||
inline double dist(
|
||||
const double ax,
|
||||
const double ay,
|
||||
const double bx,
|
||||
const double by) {
|
||||
const double dx = ax - bx;
|
||||
const double dy = ay - by;
|
||||
return dx * dx + dy * dy;
|
||||
}
|
||||
|
||||
inline double circumradius(const Point& p1, const Point& p2, const Point& p3)
|
||||
{
|
||||
Point d = Point::vector(p1, p2);
|
||||
Point e = Point::vector(p1, p3);
|
||||
|
||||
const double bl = d.magnitude2();
|
||||
const double cl = e.magnitude2();
|
||||
const double det = Point::determinant(d, e);
|
||||
|
||||
Point radius((e.y() * bl - d.y() * cl) * 0.5 / det,
|
||||
(d.x() * cl - e.x() * bl) * 0.5 / det);
|
||||
|
||||
if ((bl > 0.0 || bl < 0.0) &&
|
||||
(cl > 0.0 || cl < 0.0) &&
|
||||
(det > 0.0 || det < 0.0))
|
||||
return radius.magnitude2();
|
||||
return (std::numeric_limits<double>::max)();
|
||||
}
|
||||
|
||||
inline double circumradius(
|
||||
const double ax,
|
||||
const double ay,
|
||||
const double bx,
|
||||
const double by,
|
||||
const double cx,
|
||||
const double cy) {
|
||||
const double dx = bx - ax;
|
||||
const double dy = by - ay;
|
||||
const double ex = cx - ax;
|
||||
const double ey = cy - ay;
|
||||
|
||||
const double bl = dx * dx + dy * dy;
|
||||
const double cl = ex * ex + ey * ey;
|
||||
const double d = dx * ey - dy * ex;
|
||||
|
||||
const double x = (ey * bl - dy * cl) * 0.5 / d;
|
||||
const double y = (dx * cl - ex * bl) * 0.5 / d;
|
||||
|
||||
if ((bl > 0.0 || bl < 0.0) && (cl > 0.0 || cl < 0.0) && (d > 0.0 || d < 0.0)) {
|
||||
return x * x + y * y;
|
||||
} else {
|
||||
return (std::numeric_limits<double>::max)();
|
||||
}
|
||||
}
|
||||
|
||||
inline bool clockwise(const Point& p0, const Point& p1, const Point& p2)
|
||||
{
|
||||
Point v0 = Point::vector(p0, p1);
|
||||
Point v1 = Point::vector(p0, p2);
|
||||
double det = Point::determinant(v0, v1);
|
||||
double dist = v0.magnitude2() + v1.magnitude2();
|
||||
double dist2 = Point::dist2(v0, v1);
|
||||
if (det == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
double reldet = std::abs(dist / det);
|
||||
if (reldet > 1e14)
|
||||
return false;
|
||||
return det < 0;
|
||||
}
|
||||
|
||||
inline bool clockwise(double px, double py, double qx, double qy,
|
||||
double rx, double ry)
|
||||
{
|
||||
Point p0(px, py);
|
||||
Point p1(qx, qy);
|
||||
Point p2(rx, ry);
|
||||
return clockwise(p0, p1, p2);
|
||||
}
|
||||
|
||||
inline bool counterclockwise(const Point& p0, const Point& p1, const Point& p2)
|
||||
{
|
||||
Point v0 = Point::vector(p0, p1);
|
||||
Point v1 = Point::vector(p0, p2);
|
||||
double det = Point::determinant(v0, v1);
|
||||
double dist = v0.magnitude2() + v1.magnitude2();
|
||||
double dist2 = Point::dist2(v0, v1);
|
||||
if (det == 0)
|
||||
return false;
|
||||
double reldet = std::abs(dist / det);
|
||||
if (reldet > 1e14)
|
||||
return false;
|
||||
return det > 0;
|
||||
}
|
||||
|
||||
inline bool counterclockwise(double px, double py, double qx, double qy,
|
||||
double rx, double ry)
|
||||
{
|
||||
Point p0(px, py);
|
||||
Point p1(qx, qy);
|
||||
Point p2(rx, ry);
|
||||
return counterclockwise(p0, p1, p2);
|
||||
}
|
||||
|
||||
|
||||
inline Point circumcenter(
|
||||
const double ax,
|
||||
const double ay,
|
||||
const double bx,
|
||||
const double by,
|
||||
const double cx,
|
||||
const double cy) {
|
||||
const double dx = bx - ax;
|
||||
const double dy = by - ay;
|
||||
const double ex = cx - ax;
|
||||
const double ey = cy - ay;
|
||||
|
||||
const double bl = dx * dx + dy * dy;
|
||||
const double cl = ex * ex + ey * ey;
|
||||
//ABELL - This is suspect for div-by-0.
|
||||
const double d = dx * ey - dy * ex;
|
||||
|
||||
const double x = ax + (ey * bl - dy * cl) * 0.5 / d;
|
||||
const double y = ay + (dx * cl - ex * bl) * 0.5 / d;
|
||||
|
||||
return Point(x, y);
|
||||
}
|
||||
|
||||
inline bool in_circle(
|
||||
const double ax,
|
||||
const double ay,
|
||||
const double bx,
|
||||
const double by,
|
||||
const double cx,
|
||||
const double cy,
|
||||
const double px,
|
||||
const double py) {
|
||||
const double dx = ax - px;
|
||||
const double dy = ay - py;
|
||||
const double ex = bx - px;
|
||||
const double ey = by - py;
|
||||
const double fx = cx - px;
|
||||
const double fy = cy - py;
|
||||
|
||||
const double ap = dx * dx + dy * dy;
|
||||
const double bp = ex * ex + ey * ey;
|
||||
const double cp = fx * fx + fy * fy;
|
||||
|
||||
return (dx * (ey * cp - bp * fy) -
|
||||
dy * (ex * cp - bp * fx) +
|
||||
ap * (ex * fy - ey * fx)) < 0.0;
|
||||
}
|
||||
|
||||
constexpr double EPSILON = std::numeric_limits<double>::epsilon();
|
||||
|
||||
inline bool check_pts_equal(double x1, double y1, double x2, double y2) {
|
||||
return std::fabs(x1 - x2) <= EPSILON &&
|
||||
std::fabs(y1 - y2) <= EPSILON;
|
||||
}
|
||||
|
||||
// monotonically increases with real angle, but doesn't need expensive trigonometry
|
||||
inline double pseudo_angle(const double dx, const double dy) {
|
||||
const double p = dx / (std::abs(dx) + std::abs(dy));
|
||||
return (dy > 0.0 ? 3.0 - p : 1.0 + p) / 4.0; // [0..1)
|
||||
}
|
||||
|
||||
|
||||
Delaunator::Delaunator(std::vector<double> const& in_coords)
|
||||
: coords(in_coords), m_points(in_coords)
|
||||
{
|
||||
std::size_t n = coords.size() >> 1;
|
||||
|
||||
std::vector<std::size_t> ids(n);
|
||||
std::iota(ids.begin(), ids.end(), 0);
|
||||
|
||||
double max_x = std::numeric_limits<double>::lowest();
|
||||
double max_y = std::numeric_limits<double>::lowest();
|
||||
double min_x = (std::numeric_limits<double>::max)();
|
||||
double min_y = (std::numeric_limits<double>::max)();
|
||||
for (const Point& p : m_points)
|
||||
{
|
||||
min_x = std::min(p.x(), min_x);
|
||||
min_y = std::min(p.y(), min_y);
|
||||
max_x = std::max(p.x(), max_x);
|
||||
max_y = std::max(p.y(), max_y);
|
||||
}
|
||||
double width = max_x - min_x;
|
||||
double height = max_y - min_y;
|
||||
double span = width * width + height * height; // Everything is square dist.
|
||||
|
||||
Point center((min_x + max_x) / 2, (min_y + max_y) / 2);
|
||||
|
||||
std::size_t i0 = INVALID_INDEX;
|
||||
std::size_t i1 = INVALID_INDEX;
|
||||
std::size_t i2 = INVALID_INDEX;
|
||||
|
||||
// pick a seed point close to the centroid
|
||||
double min_dist = (std::numeric_limits<double>::max)();
|
||||
for (size_t i = 0; i < m_points.size(); ++i)
|
||||
{
|
||||
const Point& p = m_points[i];
|
||||
const double d = Point::dist2(center, p);
|
||||
if (d < min_dist) {
|
||||
i0 = i;
|
||||
min_dist = d;
|
||||
}
|
||||
}
|
||||
|
||||
const Point& p0 = m_points[i0];
|
||||
|
||||
min_dist = (std::numeric_limits<double>::max)();
|
||||
|
||||
// find the point closest to the seed
|
||||
for (std::size_t i = 0; i < n; i++) {
|
||||
if (i == i0) continue;
|
||||
const double d = Point::dist2(p0, m_points[i]);
|
||||
if (d < min_dist && d > 0.0) {
|
||||
i1 = i;
|
||||
min_dist = d;
|
||||
}
|
||||
}
|
||||
|
||||
const Point& p1 = m_points[i1];
|
||||
|
||||
double min_radius = (std::numeric_limits<double>::max)();
|
||||
|
||||
// find the third point which forms the smallest circumcircle
|
||||
// with the first two
|
||||
for (std::size_t i = 0; i < n; i++) {
|
||||
if (i == i0 || i == i1) continue;
|
||||
|
||||
const double r = circumradius(p0, p1, m_points[i]);
|
||||
if (r < min_radius) {
|
||||
i2 = i;
|
||||
min_radius = r;
|
||||
}
|
||||
}
|
||||
|
||||
if (!(min_radius < (std::numeric_limits<double>::max)())) {
|
||||
throw std::runtime_error("not triangulation");
|
||||
}
|
||||
|
||||
const Point& p2 = m_points[i2];
|
||||
|
||||
if (counterclockwise(p0, p1, p2))
|
||||
std::swap(i1, i2);
|
||||
|
||||
double i0x = p0.x();
|
||||
double i0y = p0.y();
|
||||
double i1x = m_points[i1].x();
|
||||
double i1y = m_points[i1].y();
|
||||
double i2x = m_points[i2].x();
|
||||
double i2y = m_points[i2].y();
|
||||
|
||||
m_center = circumcenter(i0x, i0y, i1x, i1y, i2x, i2y);
|
||||
|
||||
// Calculate the distances from the center once to avoid having to
|
||||
// calculate for each compare. This used to be done in the comparator,
|
||||
// but GCC 7.5+ would copy the comparator to iterators used in the
|
||||
// sort, and this was excruciatingly slow when there were many points
|
||||
// because you had to copy the vector of distances.
|
||||
std::vector<double> dists;
|
||||
dists.reserve(m_points.size());
|
||||
for (const Point& p : m_points)
|
||||
dists.push_back(dist(p.x(), p.y(), m_center.x(), m_center.y()));
|
||||
|
||||
// sort the points by distance from the seed triangle circumcenter
|
||||
std::sort(ids.begin(), ids.end(),
|
||||
[&dists](std::size_t i, std::size_t j)
|
||||
{ return dists[i] < dists[j]; });
|
||||
|
||||
// initialize a hash table for storing edges of the advancing convex hull
|
||||
m_hash_size = static_cast<std::size_t>(std::ceil(std::sqrt(n)));
|
||||
m_hash.resize(m_hash_size);
|
||||
std::fill(m_hash.begin(), m_hash.end(), INVALID_INDEX);
|
||||
|
||||
// initialize arrays for tracking the edges of the advancing convex hull
|
||||
hull_prev.resize(n);
|
||||
hull_next.resize(n);
|
||||
hull_tri.resize(n);
|
||||
|
||||
hull_start = i0;
|
||||
|
||||
size_t hull_size = 3;
|
||||
|
||||
hull_next[i0] = hull_prev[i2] = i1;
|
||||
hull_next[i1] = hull_prev[i0] = i2;
|
||||
hull_next[i2] = hull_prev[i1] = i0;
|
||||
|
||||
hull_tri[i0] = 0;
|
||||
hull_tri[i1] = 1;
|
||||
hull_tri[i2] = 2;
|
||||
|
||||
m_hash[hash_key(i0x, i0y)] = i0;
|
||||
m_hash[hash_key(i1x, i1y)] = i1;
|
||||
m_hash[hash_key(i2x, i2y)] = i2;
|
||||
|
||||
// ABELL - Why are we doing this is n < 3? There is no triangulation if
|
||||
// there is no triangle.
|
||||
|
||||
std::size_t max_triangles = n < 3 ? 1 : 2 * n - 5;
|
||||
triangles.reserve(max_triangles * 3);
|
||||
halfedges.reserve(max_triangles * 3);
|
||||
add_triangle(i0, i1, i2, INVALID_INDEX, INVALID_INDEX, INVALID_INDEX);
|
||||
double xp = std::numeric_limits<double>::quiet_NaN();
|
||||
double yp = std::numeric_limits<double>::quiet_NaN();
|
||||
|
||||
// Go through points based on distance from the center.
|
||||
for (std::size_t k = 0; k < n; k++) {
|
||||
const std::size_t i = ids[k];
|
||||
const double x = coords[2 * i];
|
||||
const double y = coords[2 * i + 1];
|
||||
|
||||
// skip near-duplicate points
|
||||
if (k > 0 && check_pts_equal(x, y, xp, yp))
|
||||
continue;
|
||||
xp = x;
|
||||
yp = y;
|
||||
|
||||
//ABELL - This is dumb. We have the indices. Use them.
|
||||
// skip seed triangle points
|
||||
if (check_pts_equal(x, y, i0x, i0y) ||
|
||||
check_pts_equal(x, y, i1x, i1y) ||
|
||||
check_pts_equal(x, y, i2x, i2y)) continue;
|
||||
|
||||
// find a visible edge on the convex hull using edge hash
|
||||
std::size_t start = 0;
|
||||
|
||||
size_t key = hash_key(x, y);
|
||||
for (size_t j = 0; j < m_hash_size; j++) {
|
||||
start = m_hash[fast_mod(key + j, m_hash_size)];
|
||||
|
||||
// ABELL - Not sure how hull_next[start] could ever equal start
|
||||
// I *think* hull_next is just a representation of the hull in one
|
||||
// direction.
|
||||
if (start != INVALID_INDEX && start != hull_next[start])
|
||||
break;
|
||||
}
|
||||
|
||||
//ABELL
|
||||
// Make sure what we found is on the hull.
|
||||
assert(hull_prev[start] != start);
|
||||
assert(hull_prev[start] != INVALID_INDEX);
|
||||
|
||||
start = hull_prev[start];
|
||||
size_t e = start;
|
||||
size_t q;
|
||||
|
||||
// Advance until we find a place in the hull where our current point
|
||||
// can be added.
|
||||
while (true)
|
||||
{
|
||||
q = hull_next[e];
|
||||
if (Point::equal(m_points[i], m_points[e], span) ||
|
||||
Point::equal(m_points[i], m_points[q], span))
|
||||
{
|
||||
e = INVALID_INDEX;
|
||||
break;
|
||||
}
|
||||
if (counterclockwise(x, y, coords[2 * e], coords[2 * e + 1],
|
||||
coords[2 * q], coords[2 * q + 1]))
|
||||
break;
|
||||
e = q;
|
||||
if (e == start) {
|
||||
e = INVALID_INDEX;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// ABELL
|
||||
// This seems wrong. Perhaps we should check what's going on?
|
||||
if (e == INVALID_INDEX) // likely a near-duplicate point; skip it
|
||||
continue;
|
||||
|
||||
// add the first triangle from the point
|
||||
std::size_t t = add_triangle(
|
||||
e,
|
||||
i,
|
||||
hull_next[e],
|
||||
INVALID_INDEX,
|
||||
INVALID_INDEX,
|
||||
hull_tri[e]);
|
||||
|
||||
hull_tri[i] = legalize(t + 2); // Legalize the triangle we just added.
|
||||
hull_tri[e] = t;
|
||||
hull_size++;
|
||||
|
||||
// walk forward through the hull, adding more triangles and
|
||||
// flipping recursively
|
||||
std::size_t next = hull_next[e];
|
||||
while (true)
|
||||
{
|
||||
q = hull_next[next];
|
||||
if (!counterclockwise(x, y, coords[2 * next], coords[2 * next + 1],
|
||||
coords[2 * q], coords[2 * q + 1]))
|
||||
break;
|
||||
t = add_triangle(next, i, q,
|
||||
hull_tri[i], INVALID_INDEX, hull_tri[next]);
|
||||
hull_tri[i] = legalize(t + 2);
|
||||
hull_next[next] = next; // mark as removed
|
||||
hull_size--;
|
||||
next = q;
|
||||
}
|
||||
|
||||
// walk backward from the other side, adding more triangles and flipping
|
||||
if (e == start) {
|
||||
while (true)
|
||||
{
|
||||
q = hull_prev[e];
|
||||
if (!counterclockwise(x, y, coords[2 * q], coords[2 * q + 1],
|
||||
coords[2 * e], coords[2 * e + 1]))
|
||||
break;
|
||||
t = add_triangle(q, i, e,
|
||||
INVALID_INDEX, hull_tri[e], hull_tri[q]);
|
||||
legalize(t + 2);
|
||||
hull_tri[q] = t;
|
||||
hull_next[e] = e; // mark as removed
|
||||
hull_size--;
|
||||
e = q;
|
||||
}
|
||||
}
|
||||
|
||||
// update the hull indices
|
||||
hull_prev[i] = e;
|
||||
hull_start = e;
|
||||
hull_prev[next] = i;
|
||||
hull_next[e] = i;
|
||||
hull_next[i] = next;
|
||||
|
||||
m_hash[hash_key(x, y)] = i;
|
||||
m_hash[hash_key(coords[2 * e], coords[2 * e + 1])] = e;
|
||||
}
|
||||
}
|
||||
|
||||
double Delaunator::get_hull_area()
|
||||
{
|
||||
std::vector<double> hull_area;
|
||||
size_t e = hull_start;
|
||||
size_t cnt = 1;
|
||||
do {
|
||||
hull_area.push_back((coords[2 * e] - coords[2 * hull_prev[e]]) *
|
||||
(coords[2 * e + 1] + coords[2 * hull_prev[e] + 1]));
|
||||
cnt++;
|
||||
e = hull_next[e];
|
||||
} while (e != hull_start);
|
||||
return sum(hull_area);
|
||||
}
|
||||
|
||||
double Delaunator::get_triangle_area()
|
||||
{
|
||||
std::vector<double> vals;
|
||||
for (size_t i = 0; i < triangles.size(); i += 3)
|
||||
{
|
||||
const double ax = coords[2 * triangles[i]];
|
||||
const double ay = coords[2 * triangles[i] + 1];
|
||||
const double bx = coords[2 * triangles[i + 1]];
|
||||
const double by = coords[2 * triangles[i + 1] + 1];
|
||||
const double cx = coords[2 * triangles[i + 2]];
|
||||
const double cy = coords[2 * triangles[i + 2] + 1];
|
||||
double val = std::fabs((by - ay) * (cx - bx) - (bx - ax) * (cy - by));
|
||||
vals.push_back(val);
|
||||
}
|
||||
return sum(vals);
|
||||
}
|
||||
|
||||
std::size_t Delaunator::legalize(std::size_t a) {
|
||||
std::size_t i = 0;
|
||||
std::size_t ar = 0;
|
||||
m_edge_stack.clear();
|
||||
|
||||
// recursion eliminated with a fixed-size stack
|
||||
while (true) {
|
||||
const size_t b = halfedges[a];
|
||||
|
||||
/* if the pair of triangles doesn't satisfy the Delaunay condition
|
||||
* (p1 is inside the circumcircle of [p0, pl, pr]), flip them,
|
||||
* then do the same check/flip recursively for the new pair of triangles
|
||||
*
|
||||
* pl pl
|
||||
* /||\ / \
|
||||
* al/ || \bl al/ \a
|
||||
* / || \ / \
|
||||
* / a||b \ flip /___ar___\
|
||||
* p0\ || /p1 => p0\---bl---/p1
|
||||
* \ || / \ /
|
||||
* ar\ || /br b\ /br
|
||||
* \||/ \ /
|
||||
* pr pr
|
||||
*/
|
||||
const size_t a0 = 3 * (a / 3);
|
||||
ar = a0 + (a + 2) % 3;
|
||||
|
||||
if (b == INVALID_INDEX) {
|
||||
if (i > 0) {
|
||||
i--;
|
||||
a = m_edge_stack[i];
|
||||
continue;
|
||||
} else {
|
||||
//i = INVALID_INDEX;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const size_t b0 = 3 * (b / 3);
|
||||
const size_t al = a0 + (a + 1) % 3;
|
||||
const size_t bl = b0 + (b + 2) % 3;
|
||||
|
||||
const std::size_t p0 = triangles[ar];
|
||||
const std::size_t pr = triangles[a];
|
||||
const std::size_t pl = triangles[al];
|
||||
const std::size_t p1 = triangles[bl];
|
||||
|
||||
const bool illegal = in_circle(
|
||||
coords[2 * p0],
|
||||
coords[2 * p0 + 1],
|
||||
coords[2 * pr],
|
||||
coords[2 * pr + 1],
|
||||
coords[2 * pl],
|
||||
coords[2 * pl + 1],
|
||||
coords[2 * p1],
|
||||
coords[2 * p1 + 1]);
|
||||
|
||||
if (illegal) {
|
||||
triangles[a] = p1;
|
||||
triangles[b] = p0;
|
||||
|
||||
auto hbl = halfedges[bl];
|
||||
|
||||
// Edge swapped on the other side of the hull (rare).
|
||||
// Fix the halfedge reference
|
||||
if (hbl == INVALID_INDEX) {
|
||||
std::size_t e = hull_start;
|
||||
do {
|
||||
if (hull_tri[e] == bl) {
|
||||
hull_tri[e] = a;
|
||||
break;
|
||||
}
|
||||
e = hull_prev[e];
|
||||
} while (e != hull_start);
|
||||
}
|
||||
link(a, hbl);
|
||||
link(b, halfedges[ar]);
|
||||
link(ar, bl);
|
||||
std::size_t br = b0 + (b + 1) % 3;
|
||||
|
||||
if (i < m_edge_stack.size()) {
|
||||
m_edge_stack[i] = br;
|
||||
} else {
|
||||
m_edge_stack.push_back(br);
|
||||
}
|
||||
i++;
|
||||
|
||||
} else {
|
||||
if (i > 0) {
|
||||
i--;
|
||||
a = m_edge_stack[i];
|
||||
continue;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ar;
|
||||
}
|
||||
|
||||
std::size_t Delaunator::hash_key(const double x, const double y) const {
|
||||
const double dx = x - m_center.x();
|
||||
const double dy = y - m_center.y();
|
||||
return fast_mod(
|
||||
static_cast<std::size_t>(std::llround(std::floor(pseudo_angle(dx, dy) * static_cast<double>(m_hash_size)))),
|
||||
m_hash_size);
|
||||
}
|
||||
|
||||
std::size_t Delaunator::add_triangle(
|
||||
std::size_t i0,
|
||||
std::size_t i1,
|
||||
std::size_t i2,
|
||||
std::size_t a,
|
||||
std::size_t b,
|
||||
std::size_t c) {
|
||||
std::size_t t = triangles.size();
|
||||
triangles.push_back(i0);
|
||||
triangles.push_back(i1);
|
||||
triangles.push_back(i2);
|
||||
link(t, a);
|
||||
link(t + 1, b);
|
||||
link(t + 2, c);
|
||||
return t;
|
||||
}
|
||||
|
||||
void Delaunator::link(const std::size_t a, const std::size_t b) {
|
||||
std::size_t s = halfedges.size();
|
||||
if (a == s) {
|
||||
halfedges.push_back(b);
|
||||
} else if (a < s) {
|
||||
halfedges[a] = b;
|
||||
} else {
|
||||
throw std::runtime_error("Cannot link edge");
|
||||
}
|
||||
if (b != INVALID_INDEX) {
|
||||
std::size_t s2 = halfedges.size();
|
||||
if (b == s2) {
|
||||
halfedges.push_back(a);
|
||||
} else if (b < s2) {
|
||||
halfedges[b] = a;
|
||||
} else {
|
||||
throw std::runtime_error("Cannot link edge");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} //namespace delaunator
|
|
@ -0,0 +1,147 @@
|
|||
#pragma once
|
||||
|
||||
#ifdef DELAUNATOR_HEADER_ONLY
|
||||
#define INLINE inline
|
||||
#else
|
||||
#define INLINE
|
||||
#endif
|
||||
|
||||
#include <limits>
|
||||
#include <vector>
|
||||
#include <ostream>
|
||||
|
||||
namespace delaunator {
|
||||
|
||||
constexpr std::size_t INVALID_INDEX =
|
||||
(std::numeric_limits<std::size_t>::max)();
|
||||
|
||||
class Point
|
||||
{
|
||||
public:
|
||||
Point(double x, double y) : m_x(x), m_y(y)
|
||||
{}
|
||||
Point() : m_x(0), m_y(0)
|
||||
{}
|
||||
|
||||
double x() const
|
||||
{ return m_x; }
|
||||
|
||||
double y() const
|
||||
{ return m_y; }
|
||||
|
||||
double magnitude2() const
|
||||
{ return m_x * m_x + m_y * m_y; }
|
||||
|
||||
static double determinant(const Point& p1, const Point& p2)
|
||||
{
|
||||
return p1.m_x * p2.m_y - p1.m_y * p2.m_x;
|
||||
}
|
||||
|
||||
static Point vector(const Point& p1, const Point& p2)
|
||||
{
|
||||
return Point(p2.m_x - p1.m_x, p2.m_y - p1.m_y);
|
||||
}
|
||||
|
||||
static double dist2(const Point& p1, const Point& p2)
|
||||
{
|
||||
Point vec = vector(p1, p2);
|
||||
return vec.m_x * vec.m_x + vec.m_y * vec.m_y;
|
||||
}
|
||||
|
||||
static bool equal(const Point& p1, const Point& p2, double span)
|
||||
{
|
||||
double dist = dist2(p1, p2) / span;
|
||||
|
||||
// ABELL - This number should be examined to figure how how
|
||||
// it correlates with the breakdown of calculating determinants.
|
||||
return dist < 1e-20;
|
||||
}
|
||||
|
||||
private:
|
||||
double m_x;
|
||||
double m_y;
|
||||
};
|
||||
|
||||
inline std::ostream& operator<<(std::ostream& out, const Point& p)
|
||||
{
|
||||
out << p.x() << "/" << p.y();
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
class Points
|
||||
{
|
||||
public:
|
||||
using const_iterator = Point const *;
|
||||
|
||||
Points(const std::vector<double>& coords) : m_coords(coords)
|
||||
{}
|
||||
|
||||
const Point& operator[](size_t offset)
|
||||
{
|
||||
return reinterpret_cast<const Point&>(
|
||||
*(m_coords.data() + (offset * 2)));
|
||||
};
|
||||
|
||||
Points::const_iterator begin() const
|
||||
{ return reinterpret_cast<const Point *>(m_coords.data()); }
|
||||
Points::const_iterator end() const
|
||||
{ return reinterpret_cast<const Point *>(
|
||||
m_coords.data() + m_coords.size()); }
|
||||
size_t size() const
|
||||
{ return m_coords.size() / 2; }
|
||||
|
||||
private:
|
||||
const std::vector<double>& m_coords;
|
||||
};
|
||||
|
||||
class Delaunator {
|
||||
|
||||
public:
|
||||
std::vector<double> const& coords;
|
||||
Points m_points;
|
||||
|
||||
// 'triangles' stores the indices to the 'X's of the input
|
||||
// 'coords'.
|
||||
std::vector<std::size_t> triangles;
|
||||
|
||||
// 'halfedges' store indices into 'triangles'. If halfedges[X] = Y,
|
||||
// It says that there's an edge from X to Y where a) X and Y are
|
||||
// both indices into triangles and b) X and Y are indices into different
|
||||
// triangles in the array. This allows you to get from a triangle to
|
||||
// its adjacent triangle. If the a triangle edge has no adjacent triangle,
|
||||
// its half edge will be INVALID_INDEX.
|
||||
std::vector<std::size_t> halfedges;
|
||||
|
||||
std::vector<std::size_t> hull_prev;
|
||||
std::vector<std::size_t> hull_next;
|
||||
|
||||
// This contains indexes into the triangles array.
|
||||
std::vector<std::size_t> hull_tri;
|
||||
std::size_t hull_start;
|
||||
|
||||
INLINE Delaunator(std::vector<double> const& in_coords);
|
||||
INLINE double get_hull_area();
|
||||
INLINE double get_triangle_area();
|
||||
|
||||
private:
|
||||
std::vector<std::size_t> m_hash;
|
||||
Point m_center;
|
||||
std::size_t m_hash_size;
|
||||
std::vector<std::size_t> m_edge_stack;
|
||||
|
||||
INLINE std::size_t legalize(std::size_t a);
|
||||
INLINE std::size_t hash_key(double x, double y) const;
|
||||
INLINE std::size_t add_triangle(
|
||||
std::size_t i0,
|
||||
std::size_t i1,
|
||||
std::size_t i2,
|
||||
std::size_t a,
|
||||
std::size_t b,
|
||||
std::size_t c);
|
||||
INLINE void link(std::size_t a, std::size_t b);
|
||||
};
|
||||
|
||||
} //namespace delaunator
|
||||
|
||||
#undef INLINE
|
|
@ -1,20 +0,0 @@
|
|||
|
||||
set( TTL_SRCS
|
||||
src/halfedge/hetriang.cpp
|
||||
)
|
||||
|
||||
add_library( ttl STATIC
|
||||
${TTL_SRCS}
|
||||
)
|
||||
|
||||
target_include_directories( ttl
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
)
|
||||
|
||||
# It needs VECTOR2D from the math library
|
||||
# Luckily that is header-only
|
||||
target_include_directories( ttl
|
||||
PRIVATE
|
||||
${PROJECT_SOURCE_DIR}/libs/kimath/include
|
||||
)
|
|
@ -1,661 +0,0 @@
|
|||
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
Version 3, 19 November 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU Affero General Public License is a free, copyleft license for
|
||||
software and other kinds of works, specifically designed to ensure
|
||||
cooperation with the community in the case of network server software.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
our General Public Licenses are 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.
|
||||
|
||||
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.
|
||||
|
||||
Developers that use our General Public Licenses protect your rights
|
||||
with two steps: (1) assert copyright on the software, and (2) offer
|
||||
you this License which gives you legal permission to copy, distribute
|
||||
and/or modify the software.
|
||||
|
||||
A secondary benefit of defending all users' freedom is that
|
||||
improvements made in alternate versions of the program, if they
|
||||
receive widespread use, become available for other developers to
|
||||
incorporate. Many developers of free software are heartened and
|
||||
encouraged by the resulting cooperation. However, in the case of
|
||||
software used on network servers, this result may fail to come about.
|
||||
The GNU General Public License permits making a modified version and
|
||||
letting the public access it on a server without ever releasing its
|
||||
source code to the public.
|
||||
|
||||
The GNU Affero General Public License is designed specifically to
|
||||
ensure that, in such cases, the modified source code becomes available
|
||||
to the community. It requires the operator of a network server to
|
||||
provide the source code of the modified version running there to the
|
||||
users of that server. Therefore, public use of a modified version, on
|
||||
a publicly accessible server, gives the public access to the source
|
||||
code of the modified version.
|
||||
|
||||
An older license, called the Affero General Public License and
|
||||
published by Affero, was designed to accomplish similar goals. This is
|
||||
a different license, not a version of the Affero GPL, but Affero has
|
||||
released a new version of the Affero GPL which permits relicensing under
|
||||
this license.
|
||||
|
||||
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 Affero 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. Remote Network Interaction; Use with the GNU General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, if you modify the
|
||||
Program, your modified version must prominently offer all users
|
||||
interacting with it remotely through a computer network (if your version
|
||||
supports such interaction) an opportunity to receive the Corresponding
|
||||
Source of your version by providing access to the Corresponding Source
|
||||
from a network server at no charge, through some standard or customary
|
||||
means of facilitating copying of software. This Corresponding Source
|
||||
shall include the Corresponding Source for any work covered by version 3
|
||||
of the GNU General Public License that is incorporated pursuant to the
|
||||
following paragraph.
|
||||
|
||||
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 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 work with which it is combined will remain governed by version
|
||||
3 of the GNU General Public License.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU Affero 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 Affero 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 Affero 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 Affero 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 Affero 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 Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If your software can interact with users remotely through a computer
|
||||
network, you should also make sure that it provides a way for users to
|
||||
get its source. For example, if your program is a web application, its
|
||||
interface could display a "Source" link that leads users to an archive
|
||||
of the code. There are many ways you could offer source, and different
|
||||
solutions will be better for different programs; see section 13 for the
|
||||
specific requirements.
|
||||
|
||||
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 AGPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
|
@ -1,3 +0,0 @@
|
|||
This directory contains the Triangulation Template Library (TTL) from https://github.com/SINTEF-Geometry/TTL.
|
||||
|
||||
It is licensed under the AGPLv3, with the license text in this directory.
|
|
@ -1,198 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 1998, 2000-2007, 2010, 2011, 2012, 2013 SINTEF ICT,
|
||||
* Applied Mathematics, Norway.
|
||||
*
|
||||
* Contact information: E-mail: tor.dokken@sintef.no
|
||||
* SINTEF ICT, Department of Applied Mathematics,
|
||||
* P.O. Box 124 Blindern,
|
||||
* 0314 Oslo, Norway.
|
||||
*
|
||||
* This file is part of TTL.
|
||||
*
|
||||
* TTL is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* TTL 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public
|
||||
* License along with TTL. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public
|
||||
* License, a covered work must retain the producer line in every data
|
||||
* file that is created or manipulated using TTL.
|
||||
*
|
||||
* Other Usage
|
||||
* You can be released from the requirements of the license by purchasing
|
||||
* a commercial license. Buying such a license is mandatory as soon as you
|
||||
* develop commercial activities involving the TTL library without
|
||||
* disclosing the source code of your own applications.
|
||||
*
|
||||
* This file may be used in accordance with the terms contained in a
|
||||
* written agreement between you and SINTEF ICT.
|
||||
*/
|
||||
|
||||
#ifndef _HALF_EDGE_DART_
|
||||
#define _HALF_EDGE_DART_
|
||||
|
||||
#include <ttl/halfedge/hetriang.h>
|
||||
|
||||
namespace hed
|
||||
{
|
||||
/**
|
||||
* \class Dart
|
||||
* \brief \b %Dart class for the half-edge data structure.
|
||||
*
|
||||
* See \ref api for a detailed description of how the member functions
|
||||
* should be implemented.
|
||||
*/
|
||||
class DART
|
||||
{
|
||||
EDGE_PTR m_edge;
|
||||
|
||||
/// Dart direction: true if dart is counterclockwise in face
|
||||
bool m_dir;
|
||||
|
||||
public:
|
||||
/// Default constructor
|
||||
DART()
|
||||
{
|
||||
m_dir = true;
|
||||
}
|
||||
|
||||
/// Constructor
|
||||
DART( const EDGE_PTR& aEdge, bool aDir = true )
|
||||
{
|
||||
m_edge = aEdge;
|
||||
assert ( m_edge );
|
||||
m_dir = aDir;
|
||||
}
|
||||
|
||||
/// Copy constructor
|
||||
DART( const DART& aDart )
|
||||
{
|
||||
m_edge = aDart.m_edge;
|
||||
assert ( m_edge );
|
||||
m_dir = aDart.m_dir;
|
||||
}
|
||||
|
||||
/// Destructor
|
||||
~DART()
|
||||
{
|
||||
}
|
||||
|
||||
/// Assignment operator
|
||||
DART& operator=( const DART& aDart )
|
||||
{
|
||||
if( this == &aDart )
|
||||
return *this;
|
||||
|
||||
m_edge = aDart.m_edge;
|
||||
assert ( m_edge );
|
||||
m_dir = aDart.m_dir;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Comparing dart objects
|
||||
bool operator==( const DART& aDart ) const
|
||||
{
|
||||
return ( aDart.m_edge == m_edge && aDart.m_dir == m_dir );
|
||||
}
|
||||
|
||||
/// Comparing dart objects
|
||||
bool operator!=( const DART& aDart ) const
|
||||
{
|
||||
return !( aDart == *this );
|
||||
}
|
||||
|
||||
/// Maps the dart to a different node
|
||||
DART& Alpha0()
|
||||
{
|
||||
m_dir = !m_dir;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Maps the dart to a different edge
|
||||
DART& Alpha1()
|
||||
{
|
||||
if( m_dir )
|
||||
{
|
||||
m_edge = m_edge->GetNextEdgeInFace()->GetNextEdgeInFace();
|
||||
assert ( m_edge );
|
||||
m_dir = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_edge = m_edge->GetNextEdgeInFace();
|
||||
assert ( m_edge );
|
||||
m_dir = true;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Maps the dart to a different triangle. \b Note: the dart is not changed if it is at the boundary!
|
||||
DART& Alpha2()
|
||||
{
|
||||
if( m_edge->GetTwinEdge() )
|
||||
{
|
||||
m_edge = m_edge->GetTwinEdge();
|
||||
assert ( m_edge );
|
||||
m_dir = !m_dir;
|
||||
}
|
||||
|
||||
// else, the dart is at the boundary and should not be changed
|
||||
return *this;
|
||||
}
|
||||
|
||||
/** @name Utilities not required by TTL */
|
||||
//@{
|
||||
void Init( const EDGE_PTR& aEdge, bool aDir = true )
|
||||
{
|
||||
m_edge = aEdge;
|
||||
assert(m_edge);
|
||||
m_dir = aDir;
|
||||
}
|
||||
|
||||
double X() const
|
||||
{
|
||||
return GetNode()->GetX();
|
||||
}
|
||||
|
||||
double Y() const
|
||||
{
|
||||
return GetNode()->GetY();
|
||||
}
|
||||
|
||||
bool IsCCW() const
|
||||
{
|
||||
return m_dir;
|
||||
}
|
||||
|
||||
const NODE_PTR& GetNode() const
|
||||
{
|
||||
return m_dir ? m_edge->GetSourceNode() : m_edge->GetTargetNode();
|
||||
}
|
||||
|
||||
const NODE_PTR& GetOppositeNode() const
|
||||
{
|
||||
return m_dir ? m_edge->GetTargetNode() : m_edge->GetSourceNode();
|
||||
}
|
||||
|
||||
EDGE_PTR& GetEdge()
|
||||
{
|
||||
return m_edge;
|
||||
}
|
||||
|
||||
//@} // End of Utilities not required by TTL
|
||||
};
|
||||
|
||||
} // End of hed namespace
|
||||
|
||||
#endif
|
|
@ -1,189 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 1998, 2000-2007, 2010, 2011, 2012, 2013 SINTEF ICT,
|
||||
* Applied Mathematics, Norway.
|
||||
*
|
||||
* Contact information: E-mail: tor.dokken@sintef.no
|
||||
* SINTEF ICT, Department of Applied Mathematics,
|
||||
* P.O. Box 124 Blindern,
|
||||
* 0314 Oslo, Norway.
|
||||
*
|
||||
* This file is part of TTL.
|
||||
*
|
||||
* TTL is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* TTL 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public
|
||||
* License along with TTL. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public
|
||||
* License, a covered work must retain the producer line in every data
|
||||
* file that is created or manipulated using TTL.
|
||||
*
|
||||
* Other Usage
|
||||
* You can be released from the requirements of the license by purchasing
|
||||
* a commercial license. Buying such a license is mandatory as soon as you
|
||||
* develop commercial activities involving the TTL library without
|
||||
* disclosing the source code of your own applications.
|
||||
*
|
||||
* This file may be used in accordance with the terms contained in a
|
||||
* written agreement between you and SINTEF ICT.
|
||||
*/
|
||||
|
||||
#ifndef _HALF_EDGE_TRAITS_
|
||||
#define _HALF_EDGE_TRAITS_
|
||||
|
||||
#include <ttl/halfedge/hetriang.h>
|
||||
#include <ttl/halfedge/hedart.h>
|
||||
|
||||
namespace hed
|
||||
{
|
||||
/**
|
||||
* \struct TTLtraits
|
||||
* \brief \b Traits class (static struct) for the half-edge data structure.
|
||||
*
|
||||
* The member functions are those required by different function templates
|
||||
* in the TTL. Documentation is given here to explain what actions
|
||||
* should be carried out on the actual data structure as required by the functions
|
||||
* in the \ref ttl namespace.
|
||||
*
|
||||
* The source code of \c %HeTraits.h shows how the traits class is implemented for the
|
||||
* half-edge data structure.
|
||||
*
|
||||
* \see \ref api
|
||||
*/
|
||||
struct TTLtraits
|
||||
{
|
||||
/**
|
||||
* The floating point type used in calculations involving scalar products and cross products.
|
||||
*/
|
||||
typedef double REAL_TYPE;
|
||||
|
||||
/** @name Geometric Predicates */
|
||||
//@{
|
||||
/**
|
||||
* Scalar product between two 2D vectors represented as darts.\n
|
||||
*
|
||||
* ttl_util::scalarProduct2d can be used.
|
||||
*/
|
||||
static REAL_TYPE ScalarProduct2D( const DART& aV1, const DART& aV2 )
|
||||
{
|
||||
DART v10 = aV1;
|
||||
v10.Alpha0();
|
||||
|
||||
DART v20 = aV2;
|
||||
v20.Alpha0();
|
||||
|
||||
return ttl_util::ScalarProduct2D( v10.X() - aV1.X(), v10.Y() - aV1.Y(),
|
||||
v20.X() - aV2.X(), v20.Y() - aV2.Y() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Scalar product between two 2D vectors.
|
||||
* The first vector is represented by a dart \e v, and the second
|
||||
* vector has direction from the source node of \e v to the point \e p.\n
|
||||
*
|
||||
* ttl_util::ScalarProduct2D can be used.
|
||||
*/
|
||||
static REAL_TYPE ScalarProduct2D( const DART& aV, const NODE_PTR& aP )
|
||||
{
|
||||
DART d0 = aV;
|
||||
d0.Alpha0();
|
||||
|
||||
return ttl_util::ScalarProduct2D( d0.X() - aV.X(), d0.Y() - aV.Y(),
|
||||
aP->GetX() - aV.X(), aP->GetY() - aV.Y() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Cross product between two vectors in the plane represented as darts.
|
||||
* The z-component of the cross product is returned.\n
|
||||
*
|
||||
* ttl_util::CrossProduct2D can be used.
|
||||
*/
|
||||
static REAL_TYPE CrossProduct2D( const DART& aV1, const DART& aV2 )
|
||||
{
|
||||
DART v10 = aV1;
|
||||
v10.Alpha0();
|
||||
|
||||
DART v20 = aV2;
|
||||
v20.Alpha0();
|
||||
|
||||
return ttl_util::CrossProduct2D( v10.X() - aV1.X(), v10.Y() - aV1.Y(),
|
||||
v20.X() - aV2.X(), v20.Y() - aV2.Y() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Cross product between two vectors in the plane.
|
||||
* The first vector is represented by a dart \e v, and the second
|
||||
* vector has direction from the source node of \e v to the point \e p.
|
||||
* The z-component of the cross product is returned.\n
|
||||
*
|
||||
* ttl_util::CrossProduct2d can be used.
|
||||
*/
|
||||
static REAL_TYPE CrossProduct2D( const DART& aV, const NODE_PTR& aP )
|
||||
{
|
||||
DART d0 = aV;
|
||||
d0.Alpha0();
|
||||
|
||||
return ttl_util::CrossProduct2D( d0.X() - aV.X(), d0.Y() - aV.Y(),
|
||||
aP->GetX() - aV.X(), aP->GetY() - aV.Y() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Let \e n1 and \e n2 be the nodes associated with two darts, and let \e p
|
||||
* be a point in the plane. Return a positive value if \e n1, \e n2,
|
||||
* and \e p occur in counterclockwise order; a negative value if they occur
|
||||
* in clockwise order; and zero if they are collinear.
|
||||
*/
|
||||
static REAL_TYPE Orient2D( const DART& aN1, const DART& aN2, const NODE_PTR& aP )
|
||||
{
|
||||
REAL_TYPE pa[2];
|
||||
REAL_TYPE pb[2];
|
||||
REAL_TYPE pc[2];
|
||||
|
||||
pa[0] = aN1.X();
|
||||
pa[1] = aN1.Y();
|
||||
pb[0] = aN2.X();
|
||||
pb[1] = aN2.Y();
|
||||
pc[0] = aP->GetX();
|
||||
pc[1] = aP->GetY();
|
||||
|
||||
return ttl_util::Orient2DFast( pa, pb, pc );
|
||||
}
|
||||
|
||||
/**
|
||||
* This is the same predicate as represented with the function above,
|
||||
* but with a slighty different interface:
|
||||
* The last parameter is given as a dart where the source node of the dart
|
||||
* represents a point in the plane.
|
||||
* This function is required for constrained triangulation.
|
||||
*/
|
||||
static REAL_TYPE Orient2D( const DART& aN1, const DART& aN2, const DART& aP )
|
||||
{
|
||||
REAL_TYPE pa[2];
|
||||
REAL_TYPE pb[2];
|
||||
REAL_TYPE pc[2];
|
||||
|
||||
pa[0] = aN1.X();
|
||||
pa[1] = aN1.Y();
|
||||
pb[0] = aN2.X();
|
||||
pb[1] = aN2.Y();
|
||||
pc[0] = aP.X();
|
||||
pc[1] = aP.Y();
|
||||
|
||||
return ttl_util::Orient2DFast( pa, pb, pc );
|
||||
}
|
||||
|
||||
//@} // End of Geometric Predicates Group
|
||||
};
|
||||
|
||||
} // End of hed namespace
|
||||
|
||||
#endif
|
|
@ -1,430 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 1998, 2000-2007, 2010, 2011, 2012, 2013 SINTEF ICT,
|
||||
* Applied Mathematics, Norway.
|
||||
* Copyright (C) 2013 CERN
|
||||
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
||||
*
|
||||
* Contact information: E-mail: tor.dokken@sintef.no
|
||||
* SINTEF ICT, Department of Applied Mathematics,
|
||||
* P.O. Box 124 Blindern,
|
||||
* 0314 Oslo, Norway.
|
||||
*
|
||||
* This file is part of TTL.
|
||||
*
|
||||
* TTL is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* TTL 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public
|
||||
* License along with TTL. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public
|
||||
* License, a covered work must retain the producer line in every data
|
||||
* file that is created or manipulated using TTL.
|
||||
*
|
||||
* Other Usage
|
||||
* You can be released from the requirements of the license by purchasing
|
||||
* a commercial license. Buying such a license is mandatory as soon as you
|
||||
* develop commercial activities involving the TTL library without
|
||||
* disclosing the source code of your own applications.
|
||||
*
|
||||
* This file may be used in accordance with the terms contained in a
|
||||
* written agreement between you and SINTEF ICT.
|
||||
*/
|
||||
|
||||
#ifndef _HE_TRIANG_H_
|
||||
#define _HE_TRIANG_H_
|
||||
|
||||
#define TTL_USE_NODE_ID // Each node gets it's own unique id
|
||||
#define TTL_USE_NODE_FLAG // Each node gets a flag (can be set to true or false)
|
||||
|
||||
#include <list>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <ttl/ttl_util.h>
|
||||
#include <memory>
|
||||
#include <math/vector2d.h>
|
||||
|
||||
class BOARD_CONNECTED_ITEM;
|
||||
class CN_CLUSTER;
|
||||
|
||||
namespace ttl
|
||||
{
|
||||
class TRIANGULATION_HELPER;
|
||||
}
|
||||
|
||||
/**
|
||||
* The half-edge data structure
|
||||
*/
|
||||
namespace hed
|
||||
{
|
||||
// Helper typedefs
|
||||
class NODE;
|
||||
class EDGE;
|
||||
typedef std::shared_ptr<NODE> NODE_PTR;
|
||||
typedef std::shared_ptr<EDGE> EDGE_PTR;
|
||||
typedef std::weak_ptr<EDGE> EDGE_WEAK_PTR;
|
||||
typedef std::vector<NODE_PTR> NODES_CONTAINER;
|
||||
|
||||
/**
|
||||
* \class NODE
|
||||
* \brief \b Node class for data structures (Inherits from HandleId)
|
||||
*
|
||||
* \note
|
||||
* - To enable node IDs, TTL_USE_NODE_ID must be defined.
|
||||
* - To enable node flags, TTL_USE_NODE_FLAG must be defined.
|
||||
* - TTL_USE_NODE_ID and TTL_USE_NODE_FLAG should only be enabled if this functionality is
|
||||
* required by the application, because they increase the memory usage for each Node object.
|
||||
*/
|
||||
class NODE
|
||||
{
|
||||
protected:
|
||||
#ifdef TTL_USE_NODE_FLAG
|
||||
/// TTL_USE_NODE_FLAG must be defined
|
||||
bool m_flag;
|
||||
#endif
|
||||
|
||||
#ifdef TTL_USE_NODE_ID
|
||||
/// TTL_USE_NODE_ID must be defined
|
||||
static int id_count;
|
||||
|
||||
/// A unique id for each node (TTL_USE_NODE_ID must be defined)
|
||||
int m_id;
|
||||
#endif
|
||||
|
||||
/// Node coordinates
|
||||
const int m_x, m_y;
|
||||
|
||||
public:
|
||||
/// Constructor
|
||||
NODE( int aX = 0, int aY = 0, std::shared_ptr<CN_CLUSTER> aCluster = nullptr ) :
|
||||
#ifdef TTL_USE_NODE_FLAG
|
||||
m_flag( false ),
|
||||
#endif
|
||||
#ifdef TTL_USE_NODE_ID
|
||||
m_id( id_count++ ),
|
||||
#endif
|
||||
m_x( aX ), m_y( aY )
|
||||
{
|
||||
}
|
||||
|
||||
/// Destructor
|
||||
~NODE() {
|
||||
|
||||
}
|
||||
|
||||
const VECTOR2D Pos() const { return VECTOR2D( m_x, m_y ); }
|
||||
|
||||
/// Returns the x-coordinate
|
||||
inline int GetX() const
|
||||
{
|
||||
return m_x;
|
||||
}
|
||||
|
||||
/// Returns the y-coordinate
|
||||
inline int GetY() const
|
||||
{
|
||||
return m_y;
|
||||
}
|
||||
|
||||
inline VECTOR2I GetPos() const
|
||||
{
|
||||
return VECTOR2I( m_x, m_y );
|
||||
}
|
||||
|
||||
#ifdef TTL_USE_NODE_ID
|
||||
/// Returns the id (TTL_USE_NODE_ID must be defined)
|
||||
|
||||
inline void SetId( int aId )
|
||||
{
|
||||
m_id = aId;
|
||||
}
|
||||
|
||||
inline int Id() const
|
||||
{
|
||||
return m_id;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef TTL_USE_NODE_FLAG
|
||||
/// Sets the flag (TTL_USE_NODE_FLAG must be defined)
|
||||
inline void SetFlag( bool aFlag )
|
||||
{
|
||||
m_flag = aFlag;
|
||||
}
|
||||
|
||||
/// Returns the flag (TTL_USE_NODE_FLAG must be defined)
|
||||
inline const bool& GetFlag() const
|
||||
{
|
||||
return m_flag;
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* \class EDGE
|
||||
* \brief \b %Edge class in the in the half-edge data structure.
|
||||
*/
|
||||
class EDGE
|
||||
{
|
||||
public:
|
||||
/// Constructor
|
||||
EDGE() : m_isLeadingEdge( false )
|
||||
{
|
||||
}
|
||||
|
||||
/// Destructor
|
||||
virtual ~EDGE()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// Sets the source node
|
||||
inline void SetSourceNode( const NODE_PTR& aNode )
|
||||
{
|
||||
m_sourceNode = aNode;
|
||||
}
|
||||
|
||||
/// Sets the next edge in face
|
||||
inline void SetNextEdgeInFace( const EDGE_PTR& aEdge )
|
||||
{
|
||||
m_nextEdgeInFace = aEdge;
|
||||
}
|
||||
|
||||
/// Sets the twin edge
|
||||
inline void SetTwinEdge( const EDGE_PTR& aEdge )
|
||||
{
|
||||
m_twinEdge = aEdge;
|
||||
}
|
||||
|
||||
/// Sets the edge as a leading edge
|
||||
inline void SetAsLeadingEdge( bool aLeading = true )
|
||||
{
|
||||
m_isLeadingEdge = aLeading;
|
||||
}
|
||||
|
||||
/// Checks if an edge is a leading edge
|
||||
inline bool IsLeadingEdge() const
|
||||
{
|
||||
return m_isLeadingEdge;
|
||||
}
|
||||
|
||||
/// Returns the twin edge
|
||||
inline EDGE_PTR GetTwinEdge() const
|
||||
{
|
||||
if( m_twinEdge.expired() )
|
||||
return nullptr;
|
||||
|
||||
return m_twinEdge.lock();
|
||||
}
|
||||
|
||||
inline void ClearTwinEdge()
|
||||
{
|
||||
m_twinEdge.reset();
|
||||
}
|
||||
|
||||
/// Returns the next edge in face
|
||||
inline const EDGE_PTR& GetNextEdgeInFace() const
|
||||
{
|
||||
assert ( m_nextEdgeInFace );
|
||||
return m_nextEdgeInFace;
|
||||
}
|
||||
|
||||
/// Retuns the source node
|
||||
inline const NODE_PTR& GetSourceNode() const
|
||||
{
|
||||
return m_sourceNode;
|
||||
}
|
||||
|
||||
/// Returns the target node
|
||||
virtual const NODE_PTR& GetTargetNode() const
|
||||
{
|
||||
return m_nextEdgeInFace->GetSourceNode();
|
||||
}
|
||||
|
||||
void Clear()
|
||||
{
|
||||
m_sourceNode.reset();
|
||||
m_nextEdgeInFace.reset();
|
||||
|
||||
if( !m_twinEdge.expired() )
|
||||
{
|
||||
m_twinEdge.lock()->ClearTwinEdge();
|
||||
m_twinEdge.reset();
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
NODE_PTR m_sourceNode;
|
||||
EDGE_WEAK_PTR m_twinEdge;
|
||||
EDGE_PTR m_nextEdgeInFace;
|
||||
bool m_isLeadingEdge;
|
||||
};
|
||||
|
||||
class DART; // Forward declaration (class in this namespace)
|
||||
|
||||
/**
|
||||
* \class TRIANGULATION
|
||||
* \brief \b %Triangulation class for the half-edge data structure with adaption to TTL.
|
||||
*/
|
||||
class TRIANGULATION
|
||||
{
|
||||
protected:
|
||||
/// One half-edge for each arc
|
||||
std::list<EDGE_PTR> m_leadingEdges;
|
||||
|
||||
ttl::TRIANGULATION_HELPER* m_helper;
|
||||
|
||||
void addLeadingEdge( EDGE_PTR& aEdge )
|
||||
{
|
||||
aEdge->SetAsLeadingEdge();
|
||||
m_leadingEdges.push_front( aEdge );
|
||||
}
|
||||
|
||||
bool removeLeadingEdgeFromList( EDGE_PTR& aLeadingEdge );
|
||||
|
||||
void cleanAll();
|
||||
|
||||
/** Swaps the edge associated with \e dart in the actual data structure.
|
||||
*
|
||||
* <center>
|
||||
* \image html swapEdge.gif
|
||||
* </center>
|
||||
*
|
||||
* \param aDart
|
||||
* Some of the functions require a dart as output.
|
||||
* If this is required by the actual function, the dart should be delivered
|
||||
* back in a position as seen if it was glued to the edge when swapping (rotating)
|
||||
* the edge CCW; see the figure.
|
||||
*
|
||||
* \note
|
||||
* - If the edge is \e constrained, or if it should not be swapped for
|
||||
* some other reason, this function need not do the actual swap of the edge.
|
||||
* - Some functions in TTL require that \c swapEdge is implemented such that
|
||||
* darts outside the quadrilateral are not affected by the swap.
|
||||
*/
|
||||
void swapEdge( DART& aDart );
|
||||
|
||||
/**
|
||||
* Splits the triangle associated with \e dart in the actual data structure into
|
||||
* three new triangles joining at \e point.
|
||||
*
|
||||
* <center>
|
||||
* \image html splitTriangle.gif
|
||||
* </center>
|
||||
*
|
||||
* \param aDart
|
||||
* Output: A CCW dart incident with the new node; see the figure.
|
||||
*/
|
||||
void splitTriangle( DART& aDart, const NODE_PTR& aPoint );
|
||||
|
||||
/**
|
||||
* The reverse operation of TTLtraits::splitTriangle.
|
||||
* This function is only required for functions that involve
|
||||
* removal of interior nodes; see for example TrinagulationHelper::RemoveInteriorNode.
|
||||
*
|
||||
* <center>
|
||||
* \image html reverse_splitTriangle.gif
|
||||
* </center>
|
||||
*/
|
||||
void reverseSplitTriangle( DART& aDart );
|
||||
|
||||
/**
|
||||
* Removes a triangle with an edge at the boundary of the triangulation
|
||||
* in the actual data structure
|
||||
*/
|
||||
void removeBoundaryTriangle( DART& aDart );
|
||||
|
||||
public:
|
||||
/// Default constructor
|
||||
TRIANGULATION();
|
||||
|
||||
/// Copy constructor
|
||||
TRIANGULATION( const TRIANGULATION& aTriangulation );
|
||||
|
||||
/// Destructor
|
||||
~TRIANGULATION();
|
||||
|
||||
/// Creates a Delaunay triangulation from a set of points
|
||||
void CreateDelaunay( NODES_CONTAINER::iterator aFirst, NODES_CONTAINER::iterator aLast );
|
||||
|
||||
/// Creates an initial Delaunay triangulation from two enclosing triangles
|
||||
// When using rectangular boundary - loop through all points and expand.
|
||||
// (Called from createDelaunay(...) when starting)
|
||||
EDGE_PTR InitTwoEnclosingTriangles( NODES_CONTAINER::iterator aFirst,
|
||||
NODES_CONTAINER::iterator aLast );
|
||||
|
||||
// These two functions are required by TTL for Delaunay triangulation
|
||||
|
||||
/// Swaps the edge associated with diagonal
|
||||
void SwapEdge( EDGE_PTR& aDiagonal );
|
||||
|
||||
/// Splits the triangle associated with edge into three new triangles joining at point
|
||||
EDGE_PTR SplitTriangle( EDGE_PTR& aEdge, const NODE_PTR& aPoint );
|
||||
|
||||
// Functions required by TTL for removing nodes in a Delaunay triangulation
|
||||
|
||||
/// Removes the boundary triangle associated with edge
|
||||
void RemoveTriangle( EDGE_PTR& aEdge ); // boundary triangle required
|
||||
|
||||
/// The reverse operation of removeTriangle
|
||||
void ReverseSplitTriangle( EDGE_PTR& aEdge );
|
||||
|
||||
/// Creates an arbitrary CCW dart
|
||||
DART CreateDart();
|
||||
|
||||
/// Returns a list of "triangles" (one leading half-edge for each triangle)
|
||||
const std::list<EDGE_PTR>& GetLeadingEdges() const
|
||||
{
|
||||
return m_leadingEdges;
|
||||
}
|
||||
|
||||
/// Returns the number of triangles
|
||||
int NoTriangles() const
|
||||
{
|
||||
return (int) m_leadingEdges.size();
|
||||
}
|
||||
|
||||
/// Returns a list of half-edges (one half-edge for each arc)
|
||||
void GetEdges( std::list<EDGE_PTR>& aEdges, bool aSkipBoundaryEdges = false ) const;
|
||||
|
||||
#ifdef TTL_USE_NODE_FLAG
|
||||
/// Sets flag in all the nodes
|
||||
void FlagNodes( bool aFlag ) const;
|
||||
|
||||
/// Returns a list of nodes. This function requires TTL_USE_NODE_FLAG to be defined. \see Node.
|
||||
std::list<NODE_PTR>* GetNodes() const;
|
||||
#endif
|
||||
|
||||
/// Swaps edges until the triangulation is Delaunay (constrained edges are not swapped)
|
||||
void OptimizeDelaunay();
|
||||
|
||||
/// Checks if the triangulation is Delaunay
|
||||
bool CheckDelaunay() const;
|
||||
|
||||
/// Returns an arbitrary interior node (as the source node of the returned edge)
|
||||
EDGE_PTR GetInteriorNode() const;
|
||||
|
||||
EDGE_PTR GetBoundaryEdgeInTriangle( const EDGE_PTR& aEdge ) const;
|
||||
|
||||
/// Returns an arbitrary boundary edge
|
||||
EDGE_PTR GetBoundaryEdge() const;
|
||||
|
||||
/// Print edges for plotting with, e.g., gnuplot
|
||||
void PrintEdges( std::ofstream& aOutput ) const;
|
||||
|
||||
friend class ttl::TRIANGULATION_HELPER;
|
||||
};
|
||||
} // End of hed namespace
|
||||
|
||||
#endif
|
File diff suppressed because it is too large
Load Diff
|
@ -1,129 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 1998, 2000-2007, 2010, 2011, 2012, 2013 SINTEF ICT,
|
||||
* Applied Mathematics, Norway.
|
||||
*
|
||||
* Contact information: E-mail: tor.dokken@sintef.no
|
||||
* SINTEF ICT, DeaPArtment of Applied Mathematics,
|
||||
* P.O. Box 124 Blindern,
|
||||
* 0314 Oslo, Norway.
|
||||
*
|
||||
* This file is aPArt of TTL.
|
||||
*
|
||||
* TTL is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* TTL 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 aPARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public
|
||||
* License along with TTL. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public
|
||||
* License, a covered work must retain the producer line in every data
|
||||
* file that is created or manipulated using TTL.
|
||||
*
|
||||
* Other Usage
|
||||
* You can be released from the requirements of the license by purchasing
|
||||
* a commercial license. Buying such a license is mandatory as soon as you
|
||||
* develop commercial activities involving the TTL library without
|
||||
* disclosing the source code of your own applications.
|
||||
*
|
||||
* This file may be used in accordance with the terms contained in a
|
||||
* written agreement between you and SINTEF ICT.
|
||||
*/
|
||||
|
||||
#ifndef _TTL_UTIL_H_
|
||||
#define _TTL_UTIL_H_
|
||||
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# if _MSC_VER < 1300
|
||||
# include <minmax.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/** \brief Utilities
|
||||
*
|
||||
* This name saPAce contains utility functions for TTL.\n
|
||||
*
|
||||
* Point and vector algebra such as scalar product and cross product
|
||||
* between vectors are implemented here.
|
||||
* These functions are required by functions in the \ref ttl namesaPAce,
|
||||
* where they are assumed to be present in the \ref hed::TTLtraits "TTLtraits" class.
|
||||
* Thus, the user can call these functions from the traits class.
|
||||
* For efficiency reasons, the user may consider implementing these
|
||||
* functions in the the API directly on the actual data structure;
|
||||
* see \ref api.
|
||||
*
|
||||
* \note
|
||||
* - Cross product between vectors in the xy-plane delivers a scalar,
|
||||
* which is the z-component of the actual cross product
|
||||
* (the x and y components are both zero).
|
||||
*
|
||||
* \see
|
||||
* ttl and \ref api
|
||||
*
|
||||
* \author
|
||||
* <EFBFBD>yvind Hjelle, oyvindhj@ifi.uio.no
|
||||
*/
|
||||
|
||||
namespace ttl_util
|
||||
{
|
||||
/** @name Computational geometry */
|
||||
//@{
|
||||
/** Scalar product between two 2D vectors.
|
||||
*
|
||||
* \a Returns:
|
||||
* \code
|
||||
* aDX1*aDX2 + aDY1*aDY2
|
||||
* \endcode
|
||||
*/
|
||||
template <class REAL_TYPE>
|
||||
REAL_TYPE ScalarProduct2D( REAL_TYPE aDX1, REAL_TYPE aDY1, REAL_TYPE aDX2, REAL_TYPE aDY2 )
|
||||
{
|
||||
return aDX1 * aDX2 + aDY1 * aDY2;
|
||||
}
|
||||
|
||||
/** Cross product between two 2D vectors. (The z-component of the actual cross product.)
|
||||
*
|
||||
* \a Returns:
|
||||
* \code
|
||||
* aDX1*aDY2 - aDY1*aDX2
|
||||
* \endcode
|
||||
*/
|
||||
template <class REAL_TYPE>
|
||||
REAL_TYPE CrossProduct2D( REAL_TYPE aDX1, REAL_TYPE aDY1, REAL_TYPE aDX2, REAL_TYPE aDY2 )
|
||||
{
|
||||
return aDX1 * aDY2 - aDY1 * aDX2;
|
||||
}
|
||||
|
||||
/** Returns a positive value if the 2D nodes/points \e aPA, \e aPB, and
|
||||
* \e aPC occur in counterclockwise order; a negative value if they occur
|
||||
* in clockwise order; and zero if they are collinear.
|
||||
*
|
||||
* \note
|
||||
* - This is a finite arithmetic fast version. It can be made more robust using
|
||||
* exact arithmetic schemes by Jonathan Richard Shewchuk. See
|
||||
* http://www-2.cs.cmu.edu/~quake/robust.html
|
||||
*/
|
||||
template <class REAL_TYPE>
|
||||
REAL_TYPE Orient2DFast( REAL_TYPE aPA[2], REAL_TYPE aPB[2], REAL_TYPE aPC[2] )
|
||||
{
|
||||
REAL_TYPE acx = aPA[0] - aPC[0];
|
||||
REAL_TYPE bcx = aPB[0] - aPC[0];
|
||||
REAL_TYPE acy = aPA[1] - aPC[1];
|
||||
REAL_TYPE bcy = aPB[1] - aPC[1];
|
||||
|
||||
return acx * bcy - acy * bcx;
|
||||
}
|
||||
|
||||
} // namespace ttl_util
|
||||
|
||||
#endif // _TTL_UTIL_H_
|
|
@ -1,727 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 1998, 2000-2007, 2010, 2011, 2012, 2013 SINTEF ICT,
|
||||
* Applied Mathematics, Norway.
|
||||
* Copyright (C) 2013 CERN
|
||||
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
||||
*
|
||||
* Contact information: E-mail: tor.dokken@sintef.no
|
||||
* SINTEF ICT, Department of Applied Mathematics,
|
||||
* P.O. Box 124 Blindern,
|
||||
* 0314 Oslo, Norway.
|
||||
*
|
||||
* This file is part of TTL.
|
||||
*
|
||||
* TTL is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* TTL 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public
|
||||
* License along with TTL. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public
|
||||
* License, a covered work must retain the producer line in every data
|
||||
* file that is created or manipulated using TTL.
|
||||
*
|
||||
* Other Usage
|
||||
* You can be released from the requirements of the license by purchasing
|
||||
* a commercial license. Buying such a license is mandatory as soon as you
|
||||
* develop commercial activities involving the TTL library without
|
||||
* disclosing the source code of your own applications.
|
||||
*
|
||||
* This file may be used in accordance with the terms contained in a
|
||||
* written agreement between you and SINTEF ICT.
|
||||
*/
|
||||
|
||||
#include <ttl/halfedge/hetriang.h>
|
||||
#include <ttl/halfedge/hetraits.h>
|
||||
#include <ttl/ttl.h>
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
|
||||
using namespace hed;
|
||||
|
||||
#ifdef TTL_USE_NODE_ID
|
||||
int NODE::id_count = 0;
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
//#define DEBUG_HE
|
||||
#ifdef DEBUG_HE
|
||||
#include <iostream>
|
||||
static void errorAndExit( char* aMessage )
|
||||
{
|
||||
cout << "\n!!! ERROR: "<< aMessage << " !!!\n" << endl;
|
||||
exit( -1 );
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
static EDGE_PTR getLeadingEdgeInTriangle( const EDGE_PTR& aEdge )
|
||||
{
|
||||
EDGE_PTR edge = aEdge;
|
||||
|
||||
// Code: 3EF (assumes triangle)
|
||||
if( !edge->IsLeadingEdge() )
|
||||
{
|
||||
edge = edge->GetNextEdgeInFace();
|
||||
|
||||
if( !edge->IsLeadingEdge() )
|
||||
edge = edge->GetNextEdgeInFace();
|
||||
}
|
||||
|
||||
if( !edge->IsLeadingEdge() )
|
||||
{
|
||||
return EDGE_PTR();
|
||||
}
|
||||
|
||||
return edge;
|
||||
}
|
||||
|
||||
|
||||
static void getLimits( NODES_CONTAINER::iterator aFirst, NODES_CONTAINER::iterator aLast,
|
||||
int& aXmin, int& aYmin, int& aXmax, int& aYmax)
|
||||
{
|
||||
aXmin = aYmin = std::numeric_limits<int>::min();
|
||||
aXmax = aYmax = std::numeric_limits<int>::max();
|
||||
|
||||
NODES_CONTAINER::iterator it;
|
||||
|
||||
for( it = aFirst; it != aLast; ++it )
|
||||
{
|
||||
aXmin = std::min( aXmin, ( *it )->GetX() );
|
||||
aYmin = std::min( aYmin, ( *it )->GetY() );
|
||||
aXmax = std::max( aXmax, ( *it )->GetX() );
|
||||
aYmax = std::max( aYmax, ( *it )->GetY() );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
EDGE_PTR TRIANGULATION::InitTwoEnclosingTriangles( NODES_CONTAINER::iterator aFirst,
|
||||
NODES_CONTAINER::iterator aLast)
|
||||
{
|
||||
int xmin, ymin, xmax, ymax;
|
||||
getLimits( aFirst, aLast, xmin, ymin, xmax, ymax );
|
||||
|
||||
// Add 10% of range:
|
||||
double fac = 10.0;
|
||||
double dx = ( xmax - xmin ) / fac;
|
||||
double dy = ( ymax - ymin ) / fac;
|
||||
|
||||
NODE_PTR n1 = std::make_shared<NODE>( xmin - dx, ymin - dy );
|
||||
NODE_PTR n2 = std::make_shared<NODE>( xmax + dx, ymin - dy );
|
||||
NODE_PTR n3 = std::make_shared<NODE>( xmax + dx, ymax + dy );
|
||||
NODE_PTR n4 = std::make_shared<NODE>( xmin - dx, ymax + dy );
|
||||
|
||||
// diagonal
|
||||
EDGE_PTR e1d = std::make_shared<EDGE>();
|
||||
EDGE_PTR e2d = std::make_shared<EDGE>();
|
||||
|
||||
// lower triangle
|
||||
EDGE_PTR e11 = std::make_shared<EDGE>();
|
||||
EDGE_PTR e12 = std::make_shared<EDGE>();
|
||||
|
||||
// upper triangle
|
||||
EDGE_PTR e21 = std::make_shared<EDGE>();
|
||||
EDGE_PTR e22 = std::make_shared<EDGE>();
|
||||
|
||||
// lower triangle
|
||||
e1d->SetSourceNode( n3 );
|
||||
e1d->SetNextEdgeInFace( e11 );
|
||||
e1d->SetTwinEdge( e2d );
|
||||
addLeadingEdge( e1d );
|
||||
|
||||
e11->SetSourceNode( n1 );
|
||||
e11->SetNextEdgeInFace( e12 );
|
||||
|
||||
e12->SetSourceNode( n2 );
|
||||
e12->SetNextEdgeInFace( e1d );
|
||||
|
||||
// upper triangle
|
||||
e2d->SetSourceNode( n1 );
|
||||
e2d->SetNextEdgeInFace( e21 );
|
||||
e2d->SetTwinEdge( e1d );
|
||||
addLeadingEdge( e2d );
|
||||
|
||||
e21->SetSourceNode( n3 );
|
||||
e21->SetNextEdgeInFace( e22 );
|
||||
|
||||
e22->SetSourceNode( n4 );
|
||||
e22->SetNextEdgeInFace( e2d );
|
||||
|
||||
return e11;
|
||||
}
|
||||
|
||||
|
||||
TRIANGULATION::TRIANGULATION()
|
||||
{
|
||||
m_helper = new ttl::TRIANGULATION_HELPER( *this );
|
||||
}
|
||||
|
||||
|
||||
TRIANGULATION::TRIANGULATION( const TRIANGULATION& aTriangulation )
|
||||
{
|
||||
m_helper = 0; // make coverity and static analysers quiet.
|
||||
// Triangulation: Copy constructor not present
|
||||
assert( false );
|
||||
}
|
||||
|
||||
|
||||
TRIANGULATION::~TRIANGULATION()
|
||||
{
|
||||
cleanAll();
|
||||
delete m_helper;
|
||||
}
|
||||
|
||||
|
||||
void TRIANGULATION::CreateDelaunay( NODES_CONTAINER::iterator aFirst,
|
||||
NODES_CONTAINER::iterator aLast )
|
||||
{
|
||||
cleanAll();
|
||||
|
||||
EDGE_PTR bedge = InitTwoEnclosingTriangles( aFirst, aLast );
|
||||
DART dc( bedge );
|
||||
|
||||
DART d_iter = dc;
|
||||
|
||||
NODES_CONTAINER::iterator it;
|
||||
for( it = aFirst; it != aLast; ++it )
|
||||
{
|
||||
m_helper->InsertNode<TTLtraits>( d_iter, *it );
|
||||
}
|
||||
|
||||
// In general (e.g. for the triangle based data structure), the initial dart
|
||||
// may have been changed.
|
||||
// It is the users responsibility to get a valid boundary dart here.
|
||||
// The half-edge data structure preserves the initial dart.
|
||||
// (A dart at the boundary can also be found by trying to locate a
|
||||
// triangle "outside" the triangulation.)
|
||||
|
||||
// Assumes rectangular domain
|
||||
m_helper->RemoveRectangularBoundary<TTLtraits>( dc );
|
||||
}
|
||||
|
||||
|
||||
void TRIANGULATION::RemoveTriangle( EDGE_PTR& aEdge )
|
||||
{
|
||||
EDGE_PTR e1 = getLeadingEdgeInTriangle( aEdge );
|
||||
|
||||
#ifdef DEBUG_HE
|
||||
if( !e1 )
|
||||
errorAndExit( "Triangulation::removeTriangle: could not find leading aEdge" );
|
||||
#endif
|
||||
|
||||
removeLeadingEdgeFromList( e1 );
|
||||
// cout << "No leading edges = " << leadingEdges_.size() << endl;
|
||||
// Remove the triangle
|
||||
EDGE_PTR e2( e1->GetNextEdgeInFace() );
|
||||
EDGE_PTR e3( e2->GetNextEdgeInFace() );
|
||||
|
||||
e1->Clear();
|
||||
e2->Clear();
|
||||
e3->Clear();
|
||||
}
|
||||
|
||||
|
||||
void TRIANGULATION::ReverseSplitTriangle( EDGE_PTR& aEdge )
|
||||
{
|
||||
// Reverse operation of splitTriangle
|
||||
EDGE_PTR e1( aEdge->GetNextEdgeInFace() );
|
||||
EDGE_PTR le( getLeadingEdgeInTriangle( e1 ) );
|
||||
#ifdef DEBUG_HE
|
||||
if (!le)
|
||||
errorAndExit("Triangulation::removeTriangle: could not find leading edge");
|
||||
#endif
|
||||
removeLeadingEdgeFromList( le );
|
||||
|
||||
EDGE_PTR e2( e1->GetNextEdgeInFace()->GetTwinEdge()->GetNextEdgeInFace() );
|
||||
le = getLeadingEdgeInTriangle( e2 );
|
||||
#ifdef DEBUG_HE
|
||||
if (!le)
|
||||
errorAndExit("Triangulation::removeTriangle: could not find leading edge");
|
||||
#endif
|
||||
removeLeadingEdgeFromList( le );
|
||||
|
||||
EDGE_PTR e3( aEdge->GetTwinEdge()->GetNextEdgeInFace()->GetNextEdgeInFace() );
|
||||
le = getLeadingEdgeInTriangle( e3 );
|
||||
#ifdef DEBUG_HE
|
||||
if (!le)
|
||||
errorAndExit("Triangulation::removeTriangle: could not find leading edge");
|
||||
#endif
|
||||
removeLeadingEdgeFromList( le );
|
||||
|
||||
// The three triangles at the node have now been removed
|
||||
// from the triangulation, but the arcs have not been deleted.
|
||||
// Next delete the 6 half edges radiating from the node
|
||||
// The node is maintained by handle and need not be deleted explicitly
|
||||
EDGE_PTR estar = aEdge;
|
||||
EDGE_PTR enext = estar->GetTwinEdge()->GetNextEdgeInFace();
|
||||
estar->GetTwinEdge()->Clear();
|
||||
estar->Clear();
|
||||
|
||||
estar = enext;
|
||||
enext = estar->GetTwinEdge()->GetNextEdgeInFace();
|
||||
estar->GetTwinEdge()->Clear();
|
||||
estar->Clear();
|
||||
|
||||
enext->GetTwinEdge()->Clear();
|
||||
enext->Clear();
|
||||
|
||||
// Create the new triangle
|
||||
e1->SetNextEdgeInFace( e2 );
|
||||
e2->SetNextEdgeInFace( e3 );
|
||||
e3->SetNextEdgeInFace( e1 );
|
||||
addLeadingEdge( e1 );
|
||||
}
|
||||
|
||||
|
||||
DART TRIANGULATION::CreateDart()
|
||||
{
|
||||
// Return an arbitrary CCW dart
|
||||
return DART( *m_leadingEdges.begin() );
|
||||
}
|
||||
|
||||
|
||||
bool TRIANGULATION::removeLeadingEdgeFromList( EDGE_PTR& aLeadingEdge )
|
||||
{
|
||||
// Remove the edge from the list of leading edges,
|
||||
// but don't delete it.
|
||||
// Also set flag for leading edge to false.
|
||||
// Must search from start of list. Since edges are added to the
|
||||
// start of the list during triangulation, this operation will
|
||||
// normally be fast (when used in the triangulation algorithm)
|
||||
std::list<EDGE_PTR>::iterator it;
|
||||
for( it = m_leadingEdges.begin(); it != m_leadingEdges.end(); ++it )
|
||||
{
|
||||
EDGE_PTR edge = *it;
|
||||
|
||||
if( edge == aLeadingEdge )
|
||||
{
|
||||
edge->SetAsLeadingEdge( false );
|
||||
it = m_leadingEdges.erase( it );
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void TRIANGULATION::cleanAll()
|
||||
{
|
||||
for( EDGE_PTR& edge : m_leadingEdges )
|
||||
edge->SetNextEdgeInFace( EDGE_PTR() );
|
||||
}
|
||||
|
||||
|
||||
void TRIANGULATION::swapEdge( DART& aDart )
|
||||
{
|
||||
SwapEdge( aDart.GetEdge() );
|
||||
}
|
||||
|
||||
|
||||
void TRIANGULATION::splitTriangle( DART& aDart, const NODE_PTR& aPoint )
|
||||
{
|
||||
EDGE_PTR edge = SplitTriangle( aDart.GetEdge(), aPoint );
|
||||
aDart.Init( edge );
|
||||
}
|
||||
|
||||
|
||||
void TRIANGULATION::reverseSplitTriangle( DART& aDart )
|
||||
{
|
||||
ReverseSplitTriangle( aDart.GetEdge() );
|
||||
}
|
||||
|
||||
|
||||
void TRIANGULATION::removeBoundaryTriangle( DART& aDart )
|
||||
{
|
||||
RemoveTriangle( aDart.GetEdge() );
|
||||
}
|
||||
|
||||
|
||||
#ifdef TTL_USE_NODE_FLAG
|
||||
void TRIANGULATION::FlagNodes( bool aFlag ) const
|
||||
{
|
||||
std::list<EDGE_PTR>::const_iterator it;
|
||||
for( it = m_leadingEdges.begin(); it != m_leadingEdges.end(); ++it )
|
||||
{
|
||||
EDGE_PTR edge = *it;
|
||||
|
||||
for( int i = 0; i < 3; ++i )
|
||||
{
|
||||
edge->GetSourceNode()->SetFlag( aFlag );
|
||||
edge = edge->GetNextEdgeInFace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::list<NODE_PTR>* TRIANGULATION::GetNodes() const
|
||||
{
|
||||
FlagNodes( false );
|
||||
std::list<NODE_PTR>* nodeList = new std::list<NODE_PTR>;
|
||||
std::list<EDGE_PTR>::const_iterator it;
|
||||
|
||||
for( it = m_leadingEdges.begin(); it != m_leadingEdges.end(); ++it )
|
||||
{
|
||||
EDGE_PTR edge = *it;
|
||||
|
||||
for( int i = 0; i < 3; ++i )
|
||||
{
|
||||
const NODE_PTR& node = edge->GetSourceNode();
|
||||
|
||||
if( node->GetFlag() == false )
|
||||
{
|
||||
nodeList->push_back( node );
|
||||
node->SetFlag( true );
|
||||
}
|
||||
edge = edge->GetNextEdgeInFace();
|
||||
}
|
||||
}
|
||||
return nodeList;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void TRIANGULATION::GetEdges( std::list<EDGE_PTR>& aEdges, bool aSkipBoundaryEdges ) const
|
||||
{
|
||||
// collect all arcs (one half edge for each arc)
|
||||
// (boundary edges are also collected).
|
||||
std::list<EDGE_PTR>::const_iterator it;
|
||||
|
||||
for( it = m_leadingEdges.begin(); it != m_leadingEdges.end(); ++it )
|
||||
{
|
||||
EDGE_PTR edge = *it;
|
||||
for( int i = 0; i < 3; ++i )
|
||||
{
|
||||
EDGE_PTR twinedge = edge->GetTwinEdge();
|
||||
// only one of the half-edges
|
||||
|
||||
if( ( !twinedge && !aSkipBoundaryEdges )
|
||||
|| ( twinedge && ( (size_t) edge.get() > (size_t) twinedge.get() ) ) )
|
||||
{
|
||||
aEdges.push_front( edge );
|
||||
}
|
||||
|
||||
edge = edge->GetNextEdgeInFace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
EDGE_PTR TRIANGULATION::SplitTriangle( EDGE_PTR& aEdge, const NODE_PTR& aPoint )
|
||||
{
|
||||
// Add a node by just splitting a triangle into three triangles
|
||||
// Assumes the half aEdge is located in the triangle
|
||||
// Returns a half aEdge with source node as the new node
|
||||
|
||||
// e#_n are new edges
|
||||
// e# are existing edges
|
||||
// e#_n and e##_n are new twin edges
|
||||
// e##_n are edges incident to the new node
|
||||
|
||||
// Add the node to the structure
|
||||
//NODE_PTR new_node(new Node(x,y,z));
|
||||
|
||||
NODE_PTR n1( aEdge->GetSourceNode() );
|
||||
EDGE_PTR e1( aEdge );
|
||||
|
||||
EDGE_PTR e2( aEdge->GetNextEdgeInFace() );
|
||||
NODE_PTR n2( e2->GetSourceNode() );
|
||||
|
||||
EDGE_PTR e3( e2->GetNextEdgeInFace() );
|
||||
NODE_PTR n3( e3->GetSourceNode() );
|
||||
|
||||
EDGE_PTR e1_n = std::make_shared<EDGE>();
|
||||
EDGE_PTR e11_n = std::make_shared<EDGE>();
|
||||
EDGE_PTR e2_n = std::make_shared<EDGE>();
|
||||
EDGE_PTR e22_n = std::make_shared<EDGE>();
|
||||
EDGE_PTR e3_n = std::make_shared<EDGE>();
|
||||
EDGE_PTR e33_n = std::make_shared<EDGE>();
|
||||
|
||||
e1_n->SetSourceNode( n1 );
|
||||
e11_n->SetSourceNode( aPoint );
|
||||
e2_n->SetSourceNode( n2 );
|
||||
e22_n->SetSourceNode( aPoint );
|
||||
e3_n->SetSourceNode( n3 );
|
||||
e33_n->SetSourceNode( aPoint );
|
||||
|
||||
e1_n->SetTwinEdge( e11_n );
|
||||
e11_n->SetTwinEdge( e1_n );
|
||||
e2_n->SetTwinEdge( e22_n );
|
||||
e22_n->SetTwinEdge( e2_n );
|
||||
e3_n->SetTwinEdge( e33_n );
|
||||
e33_n->SetTwinEdge( e3_n );
|
||||
|
||||
e1_n->SetNextEdgeInFace( e33_n );
|
||||
e2_n->SetNextEdgeInFace( e11_n );
|
||||
e3_n->SetNextEdgeInFace( e22_n );
|
||||
|
||||
e11_n->SetNextEdgeInFace( e1 );
|
||||
e22_n->SetNextEdgeInFace( e2 );
|
||||
e33_n->SetNextEdgeInFace( e3 );
|
||||
|
||||
// and update old's next aEdge
|
||||
e1->SetNextEdgeInFace( e2_n );
|
||||
e2->SetNextEdgeInFace( e3_n );
|
||||
e3->SetNextEdgeInFace( e1_n );
|
||||
|
||||
// add the three new leading edges,
|
||||
// Must remove the old leading aEdge from the list.
|
||||
// Use the field telling if an aEdge is a leading aEdge
|
||||
// NOTE: Must search in the list!!!
|
||||
|
||||
if( e1->IsLeadingEdge() )
|
||||
removeLeadingEdgeFromList( e1 );
|
||||
else if( e2->IsLeadingEdge() )
|
||||
removeLeadingEdgeFromList( e2 );
|
||||
else if( e3->IsLeadingEdge() )
|
||||
removeLeadingEdgeFromList( e3 );
|
||||
else
|
||||
assert( false ); // one of the edges should be leading
|
||||
|
||||
addLeadingEdge( e1_n );
|
||||
addLeadingEdge( e2_n );
|
||||
addLeadingEdge( e3_n );
|
||||
|
||||
// Return a half aEdge incident to the new node (with the new node as source node)
|
||||
|
||||
return e11_n;
|
||||
}
|
||||
|
||||
|
||||
void TRIANGULATION::SwapEdge( EDGE_PTR& aDiagonal )
|
||||
{
|
||||
// Note that diagonal is both input and output and it is always
|
||||
// kept in counterclockwise direction (this is not required by all
|
||||
// functions in TriangulationHelper now)
|
||||
|
||||
// Swap by rotating counterclockwise
|
||||
// Use the same objects - no deletion or new objects
|
||||
EDGE_PTR eL( aDiagonal );
|
||||
EDGE_PTR eR( eL->GetTwinEdge() );
|
||||
EDGE_PTR eL_1( eL->GetNextEdgeInFace() );
|
||||
EDGE_PTR eL_2( eL_1->GetNextEdgeInFace() );
|
||||
EDGE_PTR eR_1( eR->GetNextEdgeInFace() );
|
||||
EDGE_PTR eR_2( eR_1->GetNextEdgeInFace() );
|
||||
|
||||
// avoid node to be dereferenced to zero and deleted
|
||||
NODE_PTR nR( eR_2->GetSourceNode() );
|
||||
NODE_PTR nL( eL_2->GetSourceNode() );
|
||||
|
||||
eL->SetSourceNode( nR );
|
||||
eR->SetSourceNode( nL );
|
||||
|
||||
// and now 6 1-sewings
|
||||
eL->SetNextEdgeInFace( eL_2 );
|
||||
eL_2->SetNextEdgeInFace( eR_1 );
|
||||
eR_1->SetNextEdgeInFace( eL );
|
||||
|
||||
eR->SetNextEdgeInFace( eR_2 );
|
||||
eR_2->SetNextEdgeInFace( eL_1 );
|
||||
eL_1->SetNextEdgeInFace( eR );
|
||||
|
||||
if( eL->IsLeadingEdge() )
|
||||
removeLeadingEdgeFromList( eL );
|
||||
else if( eL_1->IsLeadingEdge() )
|
||||
removeLeadingEdgeFromList( eL_1 );
|
||||
else if( eL_2->IsLeadingEdge() )
|
||||
removeLeadingEdgeFromList( eL_2 );
|
||||
|
||||
if( eR->IsLeadingEdge() )
|
||||
removeLeadingEdgeFromList( eR );
|
||||
else if( eR_1->IsLeadingEdge() )
|
||||
removeLeadingEdgeFromList( eR_1 );
|
||||
else if( eR_2->IsLeadingEdge() )
|
||||
removeLeadingEdgeFromList( eR_2 );
|
||||
|
||||
addLeadingEdge( eL );
|
||||
addLeadingEdge( eR );
|
||||
}
|
||||
|
||||
|
||||
bool TRIANGULATION::CheckDelaunay() const
|
||||
{
|
||||
// ???? outputs !!!!
|
||||
// ofstream os("qweND.dat");
|
||||
const std::list<EDGE_PTR>& leadingEdges = GetLeadingEdges();
|
||||
|
||||
std::list<EDGE_PTR>::const_iterator it;
|
||||
bool ok = true;
|
||||
int noNotDelaunay = 0;
|
||||
|
||||
for( it = leadingEdges.begin(); it != leadingEdges.end(); ++it )
|
||||
{
|
||||
EDGE_PTR edge = *it;
|
||||
|
||||
for( int i = 0; i < 3; ++i )
|
||||
{
|
||||
EDGE_PTR twinedge = edge->GetTwinEdge();
|
||||
|
||||
// only one of the half-edges
|
||||
if( !twinedge || (size_t) edge.get() > (size_t) twinedge.get() )
|
||||
{
|
||||
DART dart( edge );
|
||||
if( m_helper->SwapTestDelaunay<TTLtraits>( dart ) )
|
||||
{
|
||||
noNotDelaunay++;
|
||||
|
||||
//printEdge(dart,os); os << "\n";
|
||||
ok = false;
|
||||
//cout << "............. not Delaunay .... " << endl;
|
||||
}
|
||||
}
|
||||
|
||||
edge = edge->GetNextEdgeInFace();
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUG_HE
|
||||
cout << "!!! Triangulation is NOT Delaunay: " << noNotDelaunay << " edges\n" << endl;
|
||||
#endif
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
void TRIANGULATION::OptimizeDelaunay()
|
||||
{
|
||||
// This function is also present in ttl where it is implemented
|
||||
// generically.
|
||||
// The implementation below is tailored for the half-edge data structure,
|
||||
// and is thus more efficient
|
||||
|
||||
// Collect all interior edges (one half edge for each arc)
|
||||
bool skip_boundary_edges = true;
|
||||
std::list<EDGE_PTR> elist;
|
||||
GetEdges( elist, skip_boundary_edges );
|
||||
|
||||
// Assumes that elist has only one half-edge for each arc.
|
||||
bool cycling_check = true;
|
||||
bool optimal = false;
|
||||
std::list<EDGE_PTR>::const_iterator it;
|
||||
|
||||
while( !optimal )
|
||||
{
|
||||
optimal = true;
|
||||
|
||||
for( it = elist.begin(); it != elist.end(); ++it )
|
||||
{
|
||||
EDGE_PTR edge = *it;
|
||||
|
||||
DART dart( edge );
|
||||
// Constrained edges should not be swapped
|
||||
if( m_helper->SwapTestDelaunay<TTLtraits>( dart, cycling_check ) )
|
||||
{
|
||||
optimal = false;
|
||||
SwapEdge( edge );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
EDGE_PTR TRIANGULATION::GetInteriorNode() const
|
||||
{
|
||||
const std::list<EDGE_PTR>& leadingEdges = GetLeadingEdges();
|
||||
std::list<EDGE_PTR>::const_iterator it;
|
||||
|
||||
for( it = leadingEdges.begin(); it != leadingEdges.end(); ++it )
|
||||
{
|
||||
EDGE_PTR edge = *it;
|
||||
|
||||
// multiple checks, but only until found
|
||||
for( int i = 0; i < 3; ++i )
|
||||
{
|
||||
if( edge->GetTwinEdge() )
|
||||
{
|
||||
if( !m_helper->IsBoundaryNode( DART( edge ) ) )
|
||||
return edge;
|
||||
}
|
||||
|
||||
edge = edge->GetNextEdgeInFace();
|
||||
}
|
||||
}
|
||||
|
||||
return EDGE_PTR(); // no boundary nodes
|
||||
}
|
||||
|
||||
|
||||
EDGE_PTR TRIANGULATION::GetBoundaryEdgeInTriangle( const EDGE_PTR& aEdge ) const
|
||||
{
|
||||
EDGE_PTR edge = aEdge;
|
||||
|
||||
if( m_helper->IsBoundaryEdge( DART( edge ) ) )
|
||||
return edge;
|
||||
|
||||
edge = edge->GetNextEdgeInFace();
|
||||
if( m_helper->IsBoundaryEdge( DART( edge ) ) )
|
||||
return edge;
|
||||
|
||||
edge = edge->GetNextEdgeInFace();
|
||||
if( m_helper->IsBoundaryEdge( DART( edge ) ) )
|
||||
return edge;
|
||||
|
||||
return EDGE_PTR();
|
||||
}
|
||||
|
||||
|
||||
EDGE_PTR TRIANGULATION::GetBoundaryEdge() const
|
||||
{
|
||||
// Get an arbitrary (CCW) boundary edge
|
||||
// If the triangulation is closed, NULL is returned
|
||||
const std::list<EDGE_PTR>& leadingEdges = GetLeadingEdges();
|
||||
std::list<EDGE_PTR>::const_iterator it;
|
||||
EDGE_PTR edge;
|
||||
|
||||
for( it = leadingEdges.begin(); it != leadingEdges.end(); ++it )
|
||||
{
|
||||
edge = GetBoundaryEdgeInTriangle( *it );
|
||||
|
||||
if( edge )
|
||||
return edge;
|
||||
}
|
||||
return EDGE_PTR();
|
||||
}
|
||||
|
||||
|
||||
void TRIANGULATION::PrintEdges( std::ofstream& aOutput ) const
|
||||
{
|
||||
// Print source node and target node for each edge face by face,
|
||||
// but only one of the half-edges.
|
||||
const std::list<EDGE_PTR>& leadingEdges = GetLeadingEdges();
|
||||
std::list<EDGE_PTR>::const_iterator it;
|
||||
|
||||
for( it = leadingEdges.begin(); it != leadingEdges.end(); ++it )
|
||||
{
|
||||
EDGE_PTR edge = *it;
|
||||
|
||||
for( int i = 0; i < 3; ++i )
|
||||
{
|
||||
EDGE_PTR twinedge = edge->GetTwinEdge();
|
||||
|
||||
// Print only one edge (the highest value of the pointer)
|
||||
if( !twinedge || (size_t) edge.get() > (size_t) twinedge.get() )
|
||||
{
|
||||
// Print source node and target node
|
||||
NODE_PTR node = edge->GetSourceNode();
|
||||
aOutput << node->GetX() << " " << node->GetY() << std::endl;
|
||||
node = edge->GetTargetNode();
|
||||
aOutput << node->GetX() << " " << node->GetY() << std::endl;
|
||||
aOutput << '\n'; // blank line
|
||||
}
|
||||
|
||||
edge = edge->GetNextEdgeInFace();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue