From ea0e9e73fc5234b66ff519da2851a941828bfb0a Mon Sep 17 00:00:00 2001 From: Patrick Brosi Date: Tue, 12 Jun 2018 12:59:25 +0200 Subject: [PATCH 001/251] update readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 40173c8..4b9c7d0 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ # pfaedle -Precise map-matching for public transit feeds. +Precise map-matching for public transit schedules (GTFS data). ## Requirements From ea32f7c2500b17c6c446e1250c1ecee11ed26f0f Mon Sep 17 00:00:00 2001 From: Patrick Brosi Date: Tue, 12 Jun 2018 16:11:04 +0200 Subject: [PATCH 002/251] license --- LICENSE | 674 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 674 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..94a9ed0 --- /dev/null +++ b/LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. From 95e60a0833d05ea5dab01f0bd7de45ecb31234bb Mon Sep 17 00:00:00 2001 From: Patrick Brosi Date: Tue, 12 Jun 2018 16:17:08 +0200 Subject: [PATCH 003/251] add travis file --- .travis.yml | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..dc5952b --- /dev/null +++ b/.travis.yml @@ -0,0 +1,29 @@ +language: generic +sudo: false +dist: trusty + +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - gcc + - g++ + - libboost-system-dev + - libboost-filesystem-dev + - libboost-geometry-dev + - cmake + +before_script: + - mkdir build + - cd build + - cmake .. + +script: + - make -j + - make test + +notifications: + email: + on_success: never + on_failure: never From dacf7b29dfc239c0be3b3bb98540ae29c4725532 Mon Sep 17 00:00:00 2001 From: Patrick Brosi Date: Tue, 12 Jun 2018 16:23:04 +0200 Subject: [PATCH 004/251] install libboost all --- .travis.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index dc5952b..5c286a3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,9 +9,7 @@ addons: packages: - gcc - g++ - - libboost-system-dev - - libboost-filesystem-dev - - libboost-geometry-dev + - libboost-all-dev - cmake before_script: From 314a22c57520bdaab030b02d4f75f7895940dfb9 Mon Sep 17 00:00:00 2001 From: Patrick Brosi Date: Tue, 12 Jun 2018 16:35:56 +0200 Subject: [PATCH 005/251] remove travis file, have to solve TLS issues in ubuntu 14.04 with ad-git first --- .travis.yml | 27 --------------------------- 1 file changed, 27 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 5c286a3..0000000 --- a/.travis.yml +++ /dev/null @@ -1,27 +0,0 @@ -language: generic -sudo: false -dist: trusty - -addons: - apt: - sources: - - ubuntu-toolchain-r-test - packages: - - gcc - - g++ - - libboost-all-dev - - cmake - -before_script: - - mkdir build - - cd build - - cmake .. - -script: - - make -j - - make test - -notifications: - email: - on_success: never - on_failure: never From a6886d99d741ec7d34e03ffe9ed7b0a73cef0b3a Mon Sep 17 00:00:00 2001 From: Patrick Brosi Date: Tue, 12 Jun 2018 22:06:02 +0200 Subject: [PATCH 006/251] add evaluation makefile --- eval/Makefile | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 eval/Makefile diff --git a/eval/Makefile b/eval/Makefile new file mode 100644 index 0000000..b802467 --- /dev/null +++ b/eval/Makefile @@ -0,0 +1,117 @@ +EVAL_DF_BINS=10,20,30,40,50,60,70,80,90,100 + +all: eval lighteval + +lighteval: vitoria.lighteval stuttgart.lighteval paris.lighteval switzerland.lighteval + +eval: vitoria.eval stuttgart.eval paris.eval switzerland.eval + +clean: + rm -f *.eval + rm -rf gtfs + rf -rf osm + rm -rf evalout + +osmconvert: + wget -O - http://m.m.i24.cc/osmconvert.c | cc -x c - -lz -O3 -o osmconvert + +%.lighteval: osm/%.osm gtfs/%/stops.txt gtfs/%/stop_times.txt gtfs/%/trips.txt gtfs/%/routes.txt eval.cfg eval-wo-osm.cfg + mkdir -p gtfs/$*/shaped + rm -f gtfs/$*/shaped/* + ../build/pfaedle -x $< -i gtfs/$* -c eval.cfg -o gtfs/$*/shaped -D -m all 2>&1 | tee $@ + +%.eval: osm/%.osm gtfs/%/stops.txt gtfs/%/stop_times.txt gtfs/%/trips.txt gtfs/%/routes.txt eval.cfg eval-wo-osm.cfg + mkdir -p gtfs/$*/shaped + rm -f gtfs/$*/shaped/* + mkdir -p evalout/ + mkdir -p evalout/$*/ + mkdir -p evalout/$*/hmm+osm + ../build/pfaedle -x $< -i gtfs/$* -c eval.cfg --eval-path evalout/$*/hmm+osm -o gtfs/$*/shaped -D -m all --eval --eval-df-bins $(EVAL_DF_BINS) 2>&1 | tee $@ + find evalout/$*/hmm+osm/ -name "*.json" -print0 | xargs -0 rm + + mkdir -p evalout/$*/hmm + ../build/pfaedle -x $< -i gtfs/$* -c eval-wo-osm.cfg --eval-path evalout/$*/hmm -o gtfs/$*/shaped -D -m all --eval --eval-df-bins $(EVAL_DF_BINS) 2>&1 | tee $@ + find evalout/$*/hmm/ -name "*.json" -print0 | xargs -0 rm + + mkdir -p evalout/$*/greedy + ../build/pfaedle -x $< -i gtfs/$* -c eval.cfg --method greedy --eval-path evalout/$*/greedy -o gtfs/$*/shaped -D -m all --eval --eval-df-bins $(EVAL_DF_BINS) 2>&1 | tee $@ + find evalout/$*/greedy/ -name "*.json" -print0 | xargs -0 rm + + mkdir -p evalout/$*/greedy2 + ../build/pfaedle -x $< -i gtfs/$* -c eval.cfg --method greedy2 --eval-path evalout/$*/greedy2 -o gtfs/$*/shaped -D -m all --eval --eval-df-bins $(EVAL_DF_BINS) 2>&1 | tee $@ + find evalout/$*/greedy2/ -name "*.json" -print0 | xargs -0 rm + +osm/spain-latest.osm.pbf: + mkdir -p osm + wget http://download.geofabrik.de/europe/spain-latest.osm.pbf -O $@ + +osm/spain-latest.osm: osm/spain-latest.osm.pbf osmconvert + @# pre-filter to vitoria gasteiz + osmconvert -b=-2.8661,42.7480,-2.4788,43.0237 $< > $@ + +osm/baden-wuerttemberg-latest.osm.pbf: + mkdir -p osm + wget http://download.geofabrik.de/europe/germany/baden-wuerttemberg-latest.osm.pbf -O $@ + +osm/baden-wuerttemberg-latest.osm: osm/baden-wuerttemberg-latest.osm.pbf osmconvert + osmconvert $< > $@ + +osm/france-latest.osm.pbf: + mkdir -p osm + wget http://download.geofabrik.de/europe/france-latest.osm.pbf -O $@ + +osm/paris-latest.osm: osm/france-latest.osm.pbf osmconvert + @# pre-filter to greater ile de france + osmconvert -b=0.374,47.651,4.241,50.261 $< > $@ + +osm/europe-latest.osm.pbf: + mkdir -p osm + wget http://download.geofabrik.de/europe-latest.osm.pbf -O $@ + +osm/switzerland-latest.osm: osm/europe-latest.osm.pbf osmconvert + @# pre-filter to greater switzerland + osmconvert -b=3.757,44.245,15.579,52.670 $< > $@ + +gtfs/vitoria/%.txt: + mkdir -p gtfs + mkdir -p gtfs/vitoria + wget https://transitfeeds.com/p/tuvisa-euskotran/239/latest/download -O gtfs/vitoria/gtfs.zip + cd gtfs/vitoria && unzip -o gtfs.zip + rm gtfs/vitoria/gtfs.zip + +gtfs/stuttgart/%.txt: + mkdir -p gtfs + mkdir -p gtfs/stuttgart + echo "******************************************************************" + echo "* A password is required to access the VVS dataset. Send a mail *" + echo "* to brosi@cs.informatik.uni-freiburg.de to receive the password. " + echo "******************************************************************" + wget http://www.vvs.de/download/opendata/VVS_GTFS.zip --ask-password --user vvsopendata01 -O gtfs/stuttgart/gtfs.zip + cd gtfs/stuttgart && unzip gtfs.zip + rm gtfs/stuttgart/gtfs.zip + +gtfs/paris/%.txt: + mkdir -p gtfs + mkdir -p gtfs/paris + wget https://transitfeeds.com/p/stif/822/latest/download -O gtfs/paris/gtfs.zip + cd gtfs/paris && unzip gtfs.zip + rm gtfs/paris/gtfs.zip + +gtfs/switzerland/%.txt: + mkdir -p gtfs + mkdir -p gtfs/switzerland + wget http://gtfs.geops.ch/dl/gtfs_complete.zip -O gtfs/switzerland/gtfs.zip + cd gtfs/switzerland && unzip gtfs.zip + rm gtfs/switzerland/gtfs.zip + +osm/vitoria.osm: osm/spain-latest.osm gtfs/vitoria/stops.txt eval.cfg + ../build/pfaedle -x $< -i gtfs/vitoria/ -c eval.cfg -m all -X $@ + +osm/stuttgart.osm: osm/baden-wuerttemberg-latest.osm gtfs/stuttgart/stops.txt eval.cfg + ../build/pfaedle -x $< -i gtfs/stuttgart/ -c eval.cfg -m all -X $@ + +osm/paris.osm: osm/paris-latest.osm gtfs/paris/stops.txt eval.cfg + ../build/pfaedle -x $< -i gtfs/paris/ -c eval.cfg -m all -X $@ + +osm/switzerland.osm: osm/switzerland-latest.osm gtfs/switzerland/stops.txt eval.cfg + ../build/pfaedle -x $< -i gtfs/switzerland/ -c eval.cfg -m all -X $@ From a47ccde984703c84125faa1fffc500611bf1c5bb Mon Sep 17 00:00:00 2001 From: Patrick Brosi Date: Sun, 1 Jul 2018 20:14:24 +0200 Subject: [PATCH 007/251] add missing cfg file --- pfaedle.cfg | 993 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 993 insertions(+) create mode 100644 pfaedle.cfg diff --git a/pfaedle.cfg b/pfaedle.cfg new file mode 100644 index 0000000..6ad4ae9 --- /dev/null +++ b/pfaedle.cfg @@ -0,0 +1,993 @@ +# Copyright 2018, University of Freiburg +# Chair of Algorithms and Datastructures +# Authors: Patrick Brosi + +[rail] + +# OSM entities to keep on different levels, as k=v. Applies +# to nodes, edges and relations. +# Nodes included in kept ways are always kept. +# Ways included in kept relations are always kept. + +osm_filter_keep: + railway=rail + railway=light_rail + railway=narrow_gauge + route=rail + route=train + public_transport=stop_area|rel_flat + +osm_filter_lvl1: + usage=branch + +osm_filter_lvl2: + +osm_filter_lvl3: + service=crossover + service=siding + # we cannot completely drop service=yard, because it is often used + # incorrectly for crossovers + service=yard + +osm_filter_lvl4: + +osm_filter_lvl5: + usage=industrial + usage=military + usage=test + service=spur + railway:traffic_mode=freight + +# OSM entities to drop, as k=v. Applies to nodes, edges and +# relations. +# Nodes included in non-dropped ways are kept regardless of +# a matching drop filter. +# Ways included in non-dropped relations are kept regardless of +# a matching drop filter. + +osm_filter_drop: + railway=abandoned + railway=construction + railway=disused + railway=miniature + railway=signal + railway=razed + railway=proposed + metro=yes + area=yes + # access=no + type=multipolygon + railway=platform + public_transport=platform + building=yes + building=train_station + amenity=shelter + amenity=bus_station + building=roof + +# Nodes that should act as "no-hup" nodes. These are nodes +# that are contained in multiple ways, but cannot be used +# to switch from one way to another (for example, a +# track crossing in rail networks) + +osm_filter_nohup: + railway:switch=no + railway=railway_crossing + +# Edges that should act as one-way nodes. + +osm_filter_oneway: + oneway=yes + railway:preferred_direction=forward + +osm_filter_oneway_reverse: + railway:preferred_direction=backward + +# Edges that may explicitely be used in +# both directions. May be used to set exception +# to "osm_filter_oneway" + +osm_filter_undirected: + oneway=false + oneway=no + oneway=-1 + railway:preferred_direction=both + railway:bidirectional=regular + +# Nodes that are stations. +# Only nodes that have been kept during the filtering above will be +# checked. +osm_filter_station: + public_transport=stop_position + railway=stop + railway=halt + railway=station + #railway=tram_stop + railway=subway_stop + tram_stop=* + stop=* + +# Relation fields that should be used for catching the lines that +# occur on an edge. Only relations that have been kept during the +# filtering above will be checked. The 'linename' will be normalized +# according to the rules in line_normalization_chain. +# The 'from_name' and 'to_name' will be normalized according to the +# rules in station_normalization_chain. +# The relations tags are given in the order of their relevance - +# the first normalized tag-value that is not null/empty will be +# taken. +osm_line_relation_tags: + line_name=ref,name # careful, no space after/before comma allowed! + from_name=from + to_name=to + +# attr name together with the +# max distance in meters between any of the groups members and +# a potential new member +# first matching rule will be taken +# only applies to nodes that match osm_filter_station! +osm_station_group_attrs: + uic_ref=500 + wikidata=500 + [public_transport=stop_area]uic_ref=500 + [public_transport=stop_area]wikidata=500 + name=100 + [public_transport=stop_area]name=100 + +# max distance in meters between a snapped station position and the +# original station position +osm_max_snap_distance: 10, 100, 200 + +# max edge level to which station will be snapped +osm_max_snap_level: 2 + +# sorted by priority, first found attr will be taken +osm_station_name_attrs: + name + [public_transport=stop_area]name + uic_name + +# the track number tag in edges, first match is taken +osm_edge_track_number_tags: + railway:track_ref + local_ref + ref + +# the track number tag in stop nodes, first match is taken, +# overwrites osm_edge_track_number_tags +osm_track_number_tags: + local_ref + ref + +routing_lvl0_fac: 1 # default level +routing_lvl1_fac: 1.25 +routing_lvl2_fac: 1.5 +routing_lvl3_fac: 2 +routing_lvl4_fac: 2.5 +routing_lvl5_fac: 3.5 +routing_lvl6_fac: 5 +routing_lvl7_fac: 7 + +# Punishment (in meters) to add to the distance +# function if a vehicle performans a full turn +routing_full_turn_punish: 3000 + +routing_station_distance_punish_fac: 3.14 + +routing_non_osm_station_punish: 100 + +routing_platform_unmatched_punish: 2000 + +# Max angle that should be counted as a full turn +routing_full_turn_angle: 100 + +# Max angle in a route from a station to an already reachable neighbar +routing_snap_full_turn_angle: 100 + +# Punishment (in meters) to add to the distance +# function if a vehicle passes a station node without +# stopping there +routing_pass_thru_station_punish: 100 + +# Punishment factor for every meter a vehicle +# travels through a one-way edge +routing_one_way_meter_punish_fac: 1 + +# Punishment factor for every meter a vehicle +# travels through an edge without any matching line +# information +routing_line_unmatched_punish_fac: 1 + +# special line normalization for trains +line_normalize_chain: + , -> ' '; + - -> ' '; + _ -> ' '; + " -> ''; + ' -> ''; + ` -> ''; + / -> ' '; + < -> ' '; + > -> ' '; + & -> '+'; + ä -> ae; + ö -> oe; + ü -> ue; + ß -> ss; + è -> e; + é -> e; + á -> a; + à -> a; + ó -> o; + ò -> o; + í -> i; + ú -> u; + ù -> u; + ë -> e; + ç -> c; + å -> ae; + â -> a; + ê -> e; + ï -> i; + œ -> oe; + ø -> oe; + ^line -> ''; + ^linie -> ''; + ^metro -> ''; + ^tram -> ''; + ^strassenbahn -> ''; + ^bus -> ''; + + # delete everything in brackets + \(.+\) -> ' '; + \[.+\] -> ' '; + + # whitespace + \s+ -> ' '; + ^\s -> ''; + \s$ -> ''; + + # line/number combs ALWAYS with whitespace (ICE101 -> ICE 101) + ^([a-zA-Z]+)([0-9]+)$ -> \1 \2; + + # if a character line number is present, delete the numeric part + ^([a-zA-Z]+) [0-9]+$ -> \1; + +[bus] + +# OSM entities to keep on different levels, as k=v. Applies +# to nodes, edges and relations. +# Nodes included in kept ways are always kept. +# Ways included in kept relations are always kept. + +osm_filter_keep: + # highways + highway=motorway + highway=trunk + highway=primary + highway=secondary + highway=tertiary + highway=residential + highway=living_street + highway=unclassified + + # highway links + highway=motorway_link + highway=trunk_link + highway=primary_link + highway=secondary_link + highway=tertiary_link + highway=residential_link + + way=primary + way=seconday + way=bus_guideway + highway=bus_guideway + busway=* + psv=yes + psv=designated + + trolley_wire=yes + trolleywire=yes + trolleybus=yes + trolley_bus=yes + + route=bus + route=trolleybus + bus=yes + + public_transport=stop_position + bus_stop=* + stop=* + highway=bus_stop + amenity=bus_station|no_match_ways|no_match_rels + + # relations for the restriction system + type=restriction + type=restriction:bus + type=restriction:motorcar + +osm_filter_lvl1: + highway=secondary + highway=secondary_link + bus=yes + psv=yes + access=psv + access=bus + trolley_wire=yes + trolleywire=yes + trolleybus=yes + trolley_bus=yes + psv=designated + +osm_filter_lvl2: + highway=tertiary + highway=tertiary_link + +osm_filter_lvl3: + highway=unclassified + highway=residential + highway=road + +osm_filter_lvl4: + highway=living_street + highway=pedestrian + highway=service + +osm_filter_lvl5: + service=siding + access=permissive + access=private + access=no + service=parking_aisle + highway=footway + +# OSM entities to drop, as k=v. Applies to nodes, edges and +# relations. +# Nodes included in non-dropped ways are kept regardless of +# a matching drop filter. +# Ways included in non-dropped relations are kept regardless of +# a matching drop filter. + +osm_filter_drop: + area=yes + train=yes|no_match_ways + # access=no + public_transport=stop_area|no_match_nds|no_match_rels + type=multipolygon + railway=platform + railway=station + # service=parking_aisle + highway=proposed + highway=footway + highway=construction + building=yes + building=train_station + leisure=garden + leisure=park + +# Nodes that should act as "no-hup" nodes. These are nodes +# that are contained in multiple ways, but cannot be used +# to switch from one way to another (for example, a +# track crossing in rail networks) + +osm_filter_nohup: + +# Configuration of the OSM road restriction system +# We only support restriction with a single via node +# atm + +osm_node_negative_restriction: + restriction=no_right_turn + restriction=no_left_turn + restriction=no_u_turn + restriction=no_straight_on + restriction:bus=no_right_turn + restriction:bus=no_left_turn + restriction:bus=no_u_turn + restriction:bus=no_straight_on + +osm_node_positive_restriction: + restriction=only_left_turn + restriction=only_straight_on + restriction=only_right_turn + restriction:bus=only_left_turn + restriction:bus=only_straight_on + restriction:bus=only_right_turn + +osm_filter_no_restriction: + except=psv|mult_val_match + except=bus|mult_val_match + +# Edges that should act as one-way nodes. + +osm_filter_oneway: + junction=roundabout # oneway=yes is implied + highway=motorway # oneway=yes is implied + oneway=yes + oneway=1 + oneway=true + oneway:bus=yes + oneway:bus=1 + oneway:bus=true + oneway:psv=yes + oneway:psv=1 + oneway:psv=true + +osm_filter_oneway_reverse: + oneway=-1 + +# Edges that may explicitely be used in +# both directions. May be used to set exception +# to "osm_filter_oneway" + +osm_filter_undirected: + oneway=false + oneway=0 + oneway=alternating + oneway=reversible + oneway=no + oneway:bus=no + oneway:bus=0 + oneway:bus=false + oneway:psv=no + oneway:psv=0 + oneway:psv=false + busway=opposite_lane + busway=opposite + busway:left=opposite_lane + busway:right=opposite_lane + psv=opposite_lane + psv=opposite + +# Nodes that are stations. +# Only nodes that have been kept during the filtering above will be +# checked. +osm_filter_station: + public_transport=stop_position + bus_stop=* + stop=* + highway=bus_stop + amenity=bus_station + +# Relation fields that should be used for catching the lines that +# occur on an edge. Only relations that have been kept during the +# filtering above will be checked. The 'linename' will be normalized +# according to the rules in line_normalization_chain. +# The 'from_name' and 'to_name' will be normalized according to the +# rules in station_normalization_chain. +# The relations tags are given in the order of their relevance - +# the first normalized tag-value that is not null/empty will be +# taken. +osm_line_relation_tags: + line_name=ref,name # careful, no space after/before comma allowed! + from_name=from + to_name=to + + +# attr name together with the +# max distance in meters between any of the groups members and +# a potential new member +# first matching rule will be taken +# only applies to nodes that match osm_filter_station! +osm_station_group_attrs: + uic_ref=500 + wikidata=500 + name=100 + +# max distance in meters between a snapped station position and the +# original station position +osm_max_snap_distance: 10 , 50, 100 + +osm_max_snap_level: 5 + +osm_max_osm_station_distance: 7.5 + +# sorted by priority, first found attr will be taken +osm_station_name_attrs: + name + uic_name + +# the track number tag in stop nodes, first one is taken +osm_track_number_tags: local_ref + +routing_lvl0_fac: 1 # default level +routing_lvl1_fac: 1.25 +routing_lvl2_fac: 1.5 +routing_lvl3_fac: 1.75 +routing_lvl4_fac: 2.25 +routing_lvl5_fac: 3 +routing_lvl6_fac: 4 +routing_lvl7_fac: 5 + +# Punishment (in meters) to add to the distance +# function if a vehicle performans a full turn +routing_full_turn_punish: 500 + +routing_station_distance_punish_fac: 2.5 + +routing_non_osm_station_punish: 500 + +# Max angle that should be counted as a full turn +routing_full_turn_angle: 20 + +# Max angle in a route from a station to an already reachable neighbor +routing_snap_full_turn_angle: 110 + +osm_max_node_block_distance: 10 + +# Punishment (in meters) to add to the distance +# function if a vehicle passes a station node without +# stopping there +routing_pass_thru_station_punish: 0 + +# Punishment factor for every meter a vehicle +# travels through a one-way edge +routing_one_way_meter_punish_fac: 4 + +routing_one_way_edge_punish: 5000 + +# Punishment factor for every meter a vehicle +# travels through an edge without any matching line +# information +# routing_line_unmatched_punish_fac: 1.75 + +[tram, subway, funicular] + +# OSM entities to keep on different levels, as k=v. Applies +# to nodes, edges and relations. +# Nodes included in kept ways are always kept. +# Ways included in kept relations are always kept. + +osm_filter_keep: + route=tram + railway=subway + railway=light_rail + railway=tram + railway=funicular + railway=station + railway=halt + railway=tram_stop + route=subway + route=light_rail + subway=yes + tram=yes + +osm_filter_lv2: + service=siding + +osm_filter_lvl5: + service=crossover + service=yard + +# OSM entities to drop, as k=v. Applies to nodes, edges and +# relations. +# Nodes included in non-dropped ways are kept regardless of +# a matching drop filter. +# Ways included in non-dropped relations are kept regardless of +# a matching drop filter. + +osm_filter_drop: + area=yes + public_transport=stop_area + type=multipolygon + railway=platform + public_transport=platform + service=alley + +# Nodes that should act as "no-hup" nodes. These are nodes +# that are contained in multiple ways, but cannot be used +# to switch from one way to another (for example, a +# track crossing in rail networks) + +osm_filter_nohup: + railway:switch=no + railway=railway_crossing + +# Edges that should act as one-way nodes. + +osm_filter_oneway: + oneway=yes + +# Edges that may explicitely be used in +# both directions. May be used to set exception +# to "osm_filter_oneway" + +osm_filter_undirected: + +# Nodes that are stations. +# Only nodes that have been kept during the filtering above will be +# checked. +osm_filter_station: + public_transport=stop_position + station=subway + station=tram + railway=stop + railway=halt + railway=station + railway=tram_stop + railway=subway_stop + tram_stop=* + stop=* + +# Relation fields that should be used for catching the lines that +# occur on an edge. Only relations that have been kept during the +# filtering above will be checked. The 'linename' will be normalized +# according to the rules in line_normalization_chain. +# The 'from_name' and 'to_name' will be normalized according to the +# rules in station_normalization_chain. +# The relations tags are given in the order of their relevance - +# the first normalized tag-value that is not null/empty will be +# taken. +osm_line_relation_tags: + line_name=ref,name # careful, no space after/before comma allowed! + from_name=from + to_name=to + + +# attr name together with the +# max distance in meters between any of the groups members and +# a potential new member +# first matching rule will be taken +# only applies to nodes that match osm_filter_station! +osm_station_group_attrs: + uic_ref=500 + wikidata=500 + name=100 + +# max distance in meters between a snapped station position and the +# original station position +osm_max_snap_distance: 10, 50, 100 + +osm_max_snap_level: 4 + + +# sorted by priority, first found attr will be taken +osm_station_name_attrs: + name + uic_name + +# the track number tag in stop nodes, first one is taken +osm_track_number_tags: local_ref + +routing_lvl0_fac: 1 # default level +routing_lvl1_fac: 1.5 +routing_lvl2_fac: 2 +routing_lvl3_fac: 2.5 +routing_lvl4_fac: 3.5 +routing_lvl5_fac: 5 +routing_lvl6_fac: 5 +routing_lvl7_fac: 5 + +# Punishment (in meters) to add to the distance +# function if a vehicle performans a full turn +routing_full_turn_punish: 2000 + +routing_station_distance_punish_fac: 3.14 + +routing_non_osm_station_punish: 235 + +# Max angle that should be counted as a full turn +routing_full_turn_angle: 80 + +# Max angle in a route from a station to an already reachable neighbar +routing_snap_full_turn_angle: 80 + +# Punishment (in meters) to add to the distance +# function if a vehicle passes a station node without +# stopping there +routing_pass_thru_station_punish: 100 + +# Punishment factor for every meter a vehicle +# travels through a one-way edge +routing_one_way_meter_punish_fac: 1 + +# Punishment factor for every meter a vehicle +# travels through an edge without any matching line +# information +routing_line_unmatched_punish_fac: 0.5 + +[ferry] + +# OSM entities to keep on different levels, as k=v. Applies +# to nodes, edges and relations. +# Nodes included in kept ways are always kept. +# Ways included in kept relations are always kept. + +osm_filter_keep: + route=ferry + waterway=river + motorboat=yes + ferry=yes + +# Nodes that are stations. +# Only nodes that have been kept during the filtering above will be +# checked. +osm_filter_station: + public_transport=stop_position + station=ferry + railway=stop + railway=halt + railway=station + stop=* + +# Relation fields that should be used for catching the lines that +# occur on an edge. Only relations that have been kept during the +# filtering above will be checked. The 'linename' will be normalized +# according to the rules in line_normalization_chain. +# The 'from_name' and 'to_name' will be normalized according to the +# rules in station_normalization_chain. +# The relations tags are given in the order of their relevance - +# the first normalized tag-value that is not null/empty will be +# taken. +osm_line_relation_tags: + line_name=ref,name # careful, no space after/before comma allowed! + from_name=from + to_name=to + + +# attr name together with the +# max distance in meters between any of the groups members and +# a potential new member +# first matching rule will be taken +# only applies to nodes that match osm_filter_station! +osm_station_group_attrs: + uic_ref=500 + wikidata=500 + name=100 + +# max distance in meters between a snapped station position and the +# original station position +osm_max_snap_distance: 10, 100, 200 + +osm_max_snap_level: 4 + + +# sorted by priority, first found attr will be taken +osm_station_name_attrs: + name + uic_name + +# the track number tag in stop nodes, first one is taken +osm_track_number_tags: local_ref + +routing_lvl0_fac: 1 # default level +routing_lvl1_fac: 1.5 +routing_lvl2_fac: 2 +routing_lvl3_fac: 2.5 +routing_lvl4_fac: 3.5 +routing_lvl5_fac: 5 +routing_lvl6_fac: 5 +routing_lvl7_fac: 5 + +# Punishment (in meters) to add to the distance +# function if a vehicle performans a full turn +routing_full_turn_punish: 100 + +routing_station_distance_punish_fac: 3.14 + +routing_non_osm_station_punish: 50 + +# Max angle that should be counted as a full turn +routing_full_turn_angle: 45 + +# Max angle in a route from a station to an already reachable neighbar +routing_snap_full_turn_angle: 0 + +# Punishment (in meters) to add to the distance +# function if a vehicle passes a station node without +# stopping there +routing_pass_thru_station_punish: 0 + +# Punishment factor for every meter a vehicle +# travels through a one-way edge +routing_one_way_meter_punish_fac: 1 + +# Punishment factor for every meter a vehicle +# travels through an edge without any matching line +# information +routing_line_unmatched_punish_fac: 0.5 + +[tram, bus, subway, rail, gondola, funicular, ferry] +# Regular expressions and station comparision is +# always case insensitive! +station_normalize_chain: + , -> ' '; + - -> ' '; + — -> ' '; + _ -> ' '; + " -> ''; + ' -> ''; + ` -> ''; + \( -> ' '; + \) -> ' '; + \[ -> ' '; + \] -> ' '; + / -> ' '; + '\\' -> ' '; + < -> ' '; + > -> ' '; + & -> '+'; + ä -> ae; + ö -> oe; + ü -> ue; + ß -> ss; + è -> e; + é -> e; + á -> a; + à -> a; + ó -> o; + ò -> o; + ô -> o; + ç -> c; + í -> i; + ú -> u; + ù -> u; + ë -> e; + å -> ae; + â -> a; + ê -> e; + ï -> i; + œ -> oe; + ø -> oe; + str\. -> strasse; + av\. -> avenue; + + # always separate 'street', 'strasse' + '([a-zA-Z])strasse($| )' -> '\1 strasse\2'; + '([a-zA-Z])street($| )' -> '\1 street\2'; + + # always use "street" + '(^| )strasse($| )' -> '\1street\2'; + + # always use "avenue" + '(^| )avenida($| )' -> '\1avenue\2'; + '(^| )avenu($| )' -> '\1avenue\2'; + + # normalize every possible abbr. of german "Bahnhof", "Hauptbahnhof", "Busbahnhof" + '(^| )hauptbf\.($| )' -> '\1hauptbahnhof\2'; + '(^| )hauptbf($| )' -> '\1hauptbahnhof\2'; + '(^| )hauptbhf\.($| )' -> '\1hauptbahnhof\2'; + '(^| )hauptbhf($| )' -> '\1hauptbahnhof\2'; + '(^| )zentraler busbahnhof($| )$' -> \1busbahnhof\2; + '(^| )zentraler omnibusbahnhof($| )$' -> \1busbahnhof\2; + '(^| )omnibusbahnhof($| )' -> '\1busbahnhof\2'; + '(^| )omnibusbhf($| )' -> '\1busbahnhof\2'; + '(^| )busbf\.($| )' -> '\1busbahnhof\2'; + '(^| )busbf($| )' -> '\1busbahnhof\2'; + '(^| )bus bf\.($| )' -> '\1busbahnhof\2'; + '(^| )bus bf($| )' -> '\1busbahnhof\2'; + '(^| )busbhf\.($| )' -> '\1busbahnhof\2'; + '(^| )busbhf($| )' -> '\1busbahnhof\2'; + '(^| )bus bhf\.($| )' -> '\1busbahnhof\2'; + '(^| )bus bhf($| )' -> '\1busbahnhof\2'; + '(^| )zob($| )' -> '\1busbahnhof\2'; + '(^| )hbf\.($| )' -> '\1hauptbahnhof\2'; + '(^| )hbf($| )' -> '\1hauptbahnhof\2'; + '(^| )hb\.($| )' -> '\1hauptbahnhof\2'; + '(^| )hb($| )' -> '\1hauptbahnhof\2'; + '(^| )bf\.($| )' -> '\1bahnhof\2'; + '(^| )bf($| )' -> '\1bahnhof\2'; + '(^| )bhf\.($| )' -> '\1bahnhof\2'; + '(^| )bhf($| )' -> '\1bahnhof\2'; + '(^| )bhfeingang($| )' -> '\1bahnhofeingang\2'; + '(^| )gare de($| )' -> '\1gare\2'; + + + # if a stations starts with single station identifier + # always put it at the end (for example, "hauptbahnhof freiburg" becomes "freiburg hauptbahnhof") + '^hauptbahnhof (.+)$' -> \1 hauptbahnhof; + '^bahnhof (.+)$' -> \1 bahnhof; + '^busbahnhof (.+)$' -> \1 busbahnhof; + '^gare (.+)$' -> \1 gare; + '^station (.+)$' -> \1 station; + + '(^| )busbahnhof($| )' -> '\1bbahnhof\2'; + + # normalize line types in station names + '(^| )u bahn\.($| )' -> '\1ubahn\2'; + '(^| )metro\.($| )' -> '\1ubahn\2'; + '(^| )subway\.($| )' -> '\1ubahn\2'; + '(^| )underground\.($| )' -> '\1ubahn\2'; + '(^| )ubahn($| )' -> '\1u\2'; + '(^| )s bahn\.($| )' -> '\1sbahn\2'; + '(^| )sbahn($| )' -> '\1s\2'; + '(^| )tramway($| )' -> '\1tram\2'; + '(^| )stadtbahn($| )' -> '\1tram\2'; + '(^| )strassenbahn($| )' -> '\1tram\2'; + '(^| )streetcar($| )' -> '\1tram\2'; + '(^| )tram($| )' -> '\1t\2'; + + # delete track information from name + '(^| )kante [a-zA-Z0-9]{1,2}($| )' -> ' '; + '(^| )gleis [a-zA-Z0-9]{1,2}($| )' -> ' '; + '(^| )track [a-zA-Z0-9]{1,2}($| )' -> ' '; + '(^| )voie [a-zA-Z0-9]{1,2}($| )' -> ' '; + + # abbrv + '(^| )und($| )' -> '\1+\2'; + '(^| )and($| )' -> '\1+\2'; + '(^| )et($| )' -> '\1+\2'; + + # noise + '\sde\s' -> ' '; + '\sda\s' -> ' '; + '\sdi\s' -> ' '; + '\sdel\s' -> ' '; + '\sdal\s' -> ' '; + + # abbrv in most western languages + '(^| )saint ' -> '\1st. '; + '(^| )sankt ' -> '\1st. '; + '(^| )sanct ' -> '\1st. '; + + \. -> ' '; + + # whitespace + \s+ -> ' '; + ^\s -> ''; + \s$ -> ''; + +line_normalize_chain: + , -> ' '; + - -> ' '; + _ -> ' '; + " -> ''; + ' -> ''; + ` -> ''; + / -> ' '; + < -> ' '; + > -> ' '; + & -> '+'; + ä -> ae; + ö -> oe; + ü -> ue; + ß -> ss; + è -> e; + é -> e; + á -> a; + à -> a; + ó -> o; + ò -> o; + í -> i; + ú -> u; + ù -> u; + ë -> e; + å -> ae; + ç -> c; + â -> a; + ê -> e; + ï -> i; + œ -> oe; + ø -> oe; + ^line -> ''; + ^linie -> ''; + ^metro -> ''; + ^tram -> ''; + ^strassenbahn -> ''; + ^bus -> ''; + + # delete everything in brackets + \(.+\) -> ' '; + \[.+\] -> ' '; + + # whitespace + \s+ -> ' '; + ^\s -> ''; + \s$ -> ''; + + # line/number combs ALWAYS without whitespace (T 2 -> T2) + ^([a-zA-Z]+) ([0-9]+)$ -> \1\2; + +track_normalize_chain: + '(^| )gleis($| )' -> ''; + '(^| )gl\.($| )' -> ''; + '(^| )platform($| )' -> ''; + '(^| )track($| )' -> ''; + '(^| )rail($| )' -> ''; + # line/number combs ALWAYS without whitespace (1 A -> 1A) + ^([a-zA-Z]+) ([0-9]+)$ -> \1\2; + ^([0-9]+) ([a-zA-Z]+)$ -> \1\2; + + # delete track numbers greater than 999 + ^[0-9]{4,}$ -> ''; From 871bdc97c4406c023d27d5ee432b585bd6dca87d Mon Sep 17 00:00:00 2001 From: Patrick Brosi Date: Tue, 3 Jul 2018 18:49:21 +0200 Subject: [PATCH 008/251] Revert "remove travis file, have to solve TLS issues in ubuntu 14.04 with ad-git first" This reverts commit 314a22c57520bdaab030b02d4f75f7895940dfb9. --- .travis.yml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..5c286a3 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,27 @@ +language: generic +sudo: false +dist: trusty + +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - gcc + - g++ + - libboost-all-dev + - cmake + +before_script: + - mkdir build + - cd build + - cmake .. + +script: + - make -j + - make test + +notifications: + email: + on_success: never + on_failure: never From 7ff625ffe26f4cb9e27a02f1a529109e7e5f0923 Mon Sep 17 00:00:00 2001 From: Patrick Brosi Date: Tue, 3 Jul 2018 18:52:28 +0200 Subject: [PATCH 009/251] only use 4 threads in travis build --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 5c286a3..09348e3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,7 +18,7 @@ before_script: - cmake .. script: - - make -j + - make -j4 - make test notifications: From a0c7d3a238c2bd26253a21c8aa51955a3daf9df8 Mon Sep 17 00:00:00 2001 From: Patrick Brosi Date: Tue, 3 Jul 2018 18:58:25 +0200 Subject: [PATCH 010/251] use gcc5 in travis build --- .travis.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 09348e3..4a3e0ab 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,11 +7,14 @@ addons: sources: - ubuntu-toolchain-r-test packages: - - gcc - - g++ + - gcc-5 + - g++-5 - libboost-all-dev - cmake +env: + - CC=gcc-5 CXX=g++-5 + before_script: - mkdir build - cd build From 4fb31679d9ed2c3044a14d4ecd1c294e840ca6fd Mon Sep 17 00:00:00 2001 From: Patrick Brosi Date: Tue, 3 Jul 2018 19:27:20 +0200 Subject: [PATCH 011/251] use boost 1.56 in travis build --- .travis.yml | 3 ++- README.md | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4a3e0ab..d88334a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,11 +5,12 @@ dist: trusty addons: apt: sources: + - boost-latest - ubuntu-toolchain-r-test packages: - gcc-5 - g++-5 - - libboost-all-dev + - libboost1.56-all-dev - cmake env: diff --git a/README.md b/README.md index 4b9c7d0..e4ad293 100644 --- a/README.md +++ b/README.md @@ -18,8 +18,8 @@ Precise map-matching for public transit schedules (GTFS data). ## Requirements * `cmake` - * `gcc` - * `libboost-system`, `libboost-filesystem`, `libboost-geometry` + * `gcc` >= 5 + * `libboost-system` >= 1.56, `libboost-filesystem` >= 1.56, `libboost-geometry` >= 1.56 ## Building and Installation @@ -115,4 +115,4 @@ On Debianesque systems, type sudo apt-get install zlib1g-dev ``` -to install the dependencies. \ No newline at end of file +to install the dependencies. From 73d159f449a0eef15ab76fea07039f2046fabd27 Mon Sep 17 00:00:00 2001 From: Patrick Brosi Date: Tue, 3 Jul 2018 19:32:57 +0200 Subject: [PATCH 012/251] remove .travis.yml until issues with boost 1.54 (default on ubuntu 14.04) have been fixed --- .travis.yml | 31 ------------------------------- 1 file changed, 31 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index d88334a..0000000 --- a/.travis.yml +++ /dev/null @@ -1,31 +0,0 @@ -language: generic -sudo: false -dist: trusty - -addons: - apt: - sources: - - boost-latest - - ubuntu-toolchain-r-test - packages: - - gcc-5 - - g++-5 - - libboost1.56-all-dev - - cmake - -env: - - CC=gcc-5 CXX=g++-5 - -before_script: - - mkdir build - - cd build - - cmake .. - -script: - - make -j4 - - make test - -notifications: - email: - on_success: never - on_failure: never From 80b4922b026a07569d48731c46d10f9d5dd415f4 Mon Sep 17 00:00:00 2001 From: Patrick Brosi Date: Wed, 4 Jul 2018 14:36:29 +0200 Subject: [PATCH 013/251] require gcc 4.8 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e4ad293..1241e6e 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Precise map-matching for public transit schedules (GTFS data). ## Requirements * `cmake` - * `gcc` >= 5 + * `gcc` >= 4.8 * `libboost-system` >= 1.56, `libboost-filesystem` >= 1.56, `libboost-geometry` >= 1.56 ## Building and Installation From 73eb2c16da7d8982fe498987658b7e94fa256cf0 Mon Sep 17 00:00:00 2001 From: Patrick Brosi Date: Fri, 6 Jul 2018 16:22:06 +0200 Subject: [PATCH 014/251] changes --- src/util/geo/BezierCurve.h | 2 +- src/util/geo/BezierCurve.tpp | 8 +- src/util/geo/Geo.h | 6 +- src/util/geo/GeoNew.h | 741 +++++++++++++++++++++++++++++++++++ src/util/geo/Point.h | 32 ++ src/util/geo/PolyLine.tpp | 11 +- src/util/tests/TestMain.cpp | 5 + 7 files changed, 792 insertions(+), 13 deletions(-) create mode 100644 src/util/geo/GeoNew.h create mode 100644 src/util/geo/Point.h diff --git a/src/util/geo/BezierCurve.h b/src/util/geo/BezierCurve.h index 29f669d..f3d25c5 100644 --- a/src/util/geo/BezierCurve.h +++ b/src/util/geo/BezierCurve.h @@ -47,7 +47,7 @@ class BezierCurve { Point valueAt(double t) const; }; -#include "util/geo/PolyLine.tpp" +#include "util/geo/BezierCurve.tpp" } } diff --git a/src/util/geo/BezierCurve.tpp b/src/util/geo/BezierCurve.tpp index 6e7ed14..da27f83 100644 --- a/src/util/geo/BezierCurve.tpp +++ b/src/util/geo/BezierCurve.tpp @@ -4,8 +4,8 @@ // _____________________________________________________________________________ template -BezierCurve::BezierCurve(const Point& a, const Point& b, const Point& c, - const Point& d) +BezierCurve::BezierCurve(const Point& a, const Point& b, + const Point& c, const Point& d) : _d(dist(a, d)) { assert(_d > 0); recalcPolynoms(a, b, c, d); @@ -13,8 +13,8 @@ BezierCurve::BezierCurve(const Point& a, const Point& b, const Point // _____________________________________________________________________________ template -void BezierCurve::recalcPolynoms(const Point& a, const Point& b, const Point& c, - const Point& d) { +void BezierCurve::recalcPolynoms(const Point& a, const Point& b, + const Point& c, const Point& d) { _xp.a = a.template get<0>(); _xp.b = 3.0 * (b.template get<0>() - a.template get<0>()); _xp.c = 3.0 * (c.template get<0>() - b.template get<0>()) - _xp.b; diff --git a/src/util/geo/Geo.h b/src/util/geo/Geo.h index db34ed4..f8ca8d7 100644 --- a/src/util/geo/Geo.h +++ b/src/util/geo/Geo.h @@ -52,6 +52,10 @@ typedef Box DBox; typedef Box FBox; typedef Box IBox; +typedef Polygon DPolygon; +typedef Polygon FPolygon; +typedef Polygon IPolygon; + // _____________________________________________________________________________ template inline Line rotate(const Line& geo, double deg, const Point& center) { @@ -605,7 +609,7 @@ template inline RotatedBox getOrientedEnvelopeAvg(MultiLine ml) { MultiLine orig = ml; // get oriented envelope for hull - RotatedBox rbox = getFullEnvelope(ml); + RotatedBox rbox = getFullEnvelope(ml); Point center; bgeo::centroid(rbox.b, center); diff --git a/src/util/geo/GeoNew.h b/src/util/geo/GeoNew.h new file mode 100644 index 0000000..f274525 --- /dev/null +++ b/src/util/geo/GeoNew.h @@ -0,0 +1,741 @@ +// Copyright 2016, University of Freiburg, +// Chair of Algorithms and Data Structures. +// Authors: Patrick Brosi +#ifndef UTIL_GEO_GEON_H_ +#define UTIL_GEO_GEON_H_ + +#define _USE_MATH_DEFINES + +#include +#include "util/Misc.h" +#include "util/geo/Point.h" + +// ------------------- +// Geometry stuff +// ------------------ + +namespace util { +namespace geon { + +// convenience aliases + +typedef Point DPoint; +typedef Point FPoint; +typedef Point IPoint; + +// typedef Line DLine; +// typedef Line FLine; +// typedef Line ILine; + +// typedef Box DBox; +// typedef Box FBox; +// typedef Box IBox; + +// typedef Polygon DPolygon; +// typedef Polygon FPolygon; +// typedef Polygon IPolygon; + +// _____________________________________________________________________________ +// template +// inline Line rotate(const Line& geo, double deg, const Point& center) { + // Line ret; + + // bgeo::strategy::transform::translate_transformer translate( + // -center.getX(), -center.getY()); + // bgeo::strategy::transform::rotate_transformer rotate( + // deg); + // bgeo::strategy::transform::translate_transformer translateBack( + // center.getX(), center.getY()); + + // bgeo::strategy::transform::ublas_transformer translateRotate( + // prod(rotate.matrix(), translate.matrix())); + // bgeo::strategy::transform::ublas_transformer all( + // prod(translateBack.matrix(), translateRotate.matrix())); + + // bgeo::transform(geo, ret, all); + + // return ret; +// } + +// _____________________________________________________________________________ +// template +// inline MultiLine rotate(const MultiLine& geo, double deg, + // const Point& center) { + // MultiLine ret; + + // bgeo::strategy::transform::translate_transformer translate( + // -center.getX(), -center.getY()); + // bgeo::strategy::transform::rotate_transformer rotate( + // deg); + // bgeo::strategy::transform::translate_transformer translateBack( + // center.getX(), center.getY()); + + // bgeo::strategy::transform::ublas_transformer translateRotate( + // prod(rotate.matrix(), translate.matrix())); + // bgeo::strategy::transform::ublas_transformer all( + // prod(translateBack.matrix(), translateRotate.matrix())); + + // bgeo::transform(geo, ret, all); + + // return ret; +// } + +// _____________________________________________________________________________ +// template +// inline Box pad(const Box& box, double padding) { + // return Box(Point(box.min_corner().getX() - padding, + // box.min_corner().getY() - padding), + // Point(box.max_corner().getX() + padding, + // box.max_corner().getY() + padding)); +// } + +// _____________________________________________________________________________ +template +inline Point rotate(const Point& p, double deg) { + return p; +} + +// _____________________________________________________________________________ +// template +// inline Line rotate(const Line& geo, double deg) { + // Point center; + // bgeo::centroid(geo, center); + // return rotate(geo, deg, center); +// } + +// _____________________________________________________________________________ +// template +// inline MultiLine rotate(const MultiLine& geo, double deg) { + // Point center; + // bgeo::centroid(geo, center); + // return rotate(geo, deg, center); +// } + +// _____________________________________________________________________________ +template +inline Point move(const Point& geo, T x, T y) { + return Point(geo.getX() + x, geo.getY() + y); +} + +// TODO: outfactor + +// template +// struct RotatedBox { + // RotatedBox(const Box& b, double rot, const Point& center) + // : b(b), rotateDeg(rot), center(center) {} + // RotatedBox(const Box& b, double rot) : b(b), rotateDeg(rot) { + // bgeo::centroid(b, center); + // } + + // Box b; + // double rotateDeg; + // Point center; + + // Polygon getPolygon() { + // Polygon hull; + // bgeo::convex_hull(b, hull); + // return rotate(hull, rotateDeg, center); + // } +// }; + +// _____________________________________________________________________________ +template +inline Box minbox() { + //return bgeo::make_inverse>(); +} + +// _____________________________________________________________________________ +// template +// inline RotatedBox shrink(const RotatedBox& b, double d) { + // double xd = + // b.b.max_corner().getX() - b.b.min_corner().getX(); + // double yd = + // b.b.max_corner().getY() - b.b.min_corner().getY(); + + // if (xd <= 2 * d) d = xd / 2 - 1; + // if (yd <= 2 * d) d = yd / 2 - 1; + + // Box r(Point(b.b.min_corner().getX() + d, + // b.b.min_corner().getY() + d), + // Point(b.b.max_corner().getX() - d, + // b.b.max_corner().getY() - d)); + + // return RotatedBox(r, b.rotateDeg, b.center); +// } + +// _____________________________________________________________________________ +inline bool doubleEq(double a, double b) { return fabs(a - b) < 0.000001; } + +// _____________________________________________________________________________ +// template +// inline bool contains(const Geometry& geom, const Box& box) { + // return bgeo::within(geom, box); +// } + +// _____________________________________________________________________________ +// template +// inline bool contains(const Point& p1, const Point& q1, const Point& p2, + // const Point& q2) { + // Line a, b; + // a.push_back(p1); + // a.push_back(q1); + // b.push_back(p2); + // b.push_back(q2); + + // return bgeo::covered_by(a, b); +// } + +// _____________________________________________________________________________ +// template +// inline bool contains(T p1x, T p1y, T q1x, T q1y, T p2x, T p2y, T q2x, T q2y) { + // Point p1(p1x, p1y); + // Point q1(q1x, q1y); + // Point p2(p2x, p2y); + // Point q2(q2x, q2y); + + // return contains(p1, q1, p2, q2); +// } + +// _____________________________________________________________________________ +// template +// inline bool intersects(const Point& p1, const Point& q1, + // const Point& p2, const Point& q2) { + /* + * checks whether two line segments intersect + */ + // Line a, b; + // a.push_back(p1); + // a.push_back(q1); + // b.push_back(p2); + // b.push_back(q2); + + // return !(contains(p1, q1, p2, q2) || contains(p2, q2, p1, q1)) && + // bgeo::intersects(a, b); +// } + +// _____________________________________________________________________________ +// template +// inline bool intersects(T p1x, T p1y, T q1x, T q1y, T p2x, T p2y, T q2x, T q2y) { + /* + * checks whether two line segments intersect + */ + // Point p1(p1x, p1y); + // Point q1(q1x, q1y); + // Point p2(p2x, p2y); + // Point q2(q2x, q2y); + + // return intersects(p1, q1, p2, q2); +// } + +// _____________________________________________________________________________ +template +inline Point intersection(T p1x, T p1y, T q1x, T q1y, T p2x, T p2y, T q2x, + T q2y) { + /* + * calculates the intersection between two line segments + */ + if (doubleEq(p1x, q1x) && doubleEq(p1y, q1y)) + return Point(p1x, p1y); // TODO: <-- intersecting with a point?? + if (doubleEq(p2x, q1x) && doubleEq(p2y, q1y)) return Point(p2x, p2y); + if (doubleEq(p2x, q2x) && doubleEq(p2y, q2y)) + return Point(p2x, p2y); // TODO: <-- intersecting with a point?? + if (doubleEq(p1x, q2x) && doubleEq(p1y, q2y)) return Point(p1x, p1y); + + double a = ((q2y - p2y) * (q1x - p1x)) - ((q2x - p2x) * (q1y - p1y)); + double u = (((q2x - p2x) * (p1y - p2y)) - ((q2y - p2y) * (p1x - p2x))) / a; + + return Point(p1x + (q1x - p1x) * u, p1y + (q1y - p1y) * u); +} + +// _____________________________________________________________________________ +template +inline Point intersection(const Point& p1, const Point& q1, + const Point& p2, const Point& q2) { + /* + * calculates the intersection between two line segments + */ + return intersection(p1.getX(), p1.getY(), + q1.getX(), q1.getY(), + p2.getX(), p2.getY(), + q2.getX(), q2.getY()); +} + +// _____________________________________________________________________________ +template +inline bool lineIntersects(T p1x, T p1y, T q1x, T q1y, T p2x, T p2y, T q2x, + T q2y) { + /* + * checks whether two lines intersect + */ + double EPSILON = 0.0000001; + double a = ((q2y - p2y) * (q1x - p1x)) - ((q2x - p2x) * (q1y - p1y)); + + return a > EPSILON || a < -EPSILON; +} + +// _____________________________________________________________________________ +template +inline bool lineIntersects(const Point& p1, const Point& q1, + const Point& p2, const Point& q2) { + /* + * checks whether two lines intersect + */ + return lineIntersects(p1.getX(), p1.getY(), + q1.getX(), q1.getY(), + p2.getX(), p2.getY(), + q2.getX(), q2.getY()); +} + +// _____________________________________________________________________________ +inline double angBetween(double p1x, double p1y, double q1x, double q1y) { + double dY = q1y - p1y; + double dX = q1x - p1x; + return atan2(dY, dX); +} + +// _____________________________________________________________________________ +template +inline double angBetween(const Point& p1, const Point& q1) { + return angBetween(p1.getX(), p1.getY(), + q1.getX(), q1.getY()); +} + +// _____________________________________________________________________________ +inline double dist(double x1, double y1, double x2, double y2) { + return sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)); +} + +// _____________________________________________________________________________ +inline double innerProd(double x1, double y1, double x2, double y2, double x3, + double y3) { + double dx21 = x2 - x1; + double dx31 = x3 - x1; + double dy21 = y2 - y1; + double dy31 = y3 - y1; + double m12 = sqrt(dx21 * dx21 + dy21 * dy21); + double m13 = sqrt(dx31 * dx31 + dy31 * dy31); + double theta = acos(std::min((dx21 * dx31 + dy21 * dy31) / (m12 * m13), 1.0)); + + return theta * (180 / M_PI); +} + +// _____________________________________________________________________________ +template +inline double innerProd(const Point& a, const Point& b, const Point& c) { + return innerProd(a.template getX(), a.template getY(), + b.template getX(), b.template getY(), + c.template getX(), c.template getY()); +} + +// _____________________________________________________________________________ +template +inline double dist(const Point& p1, const Point& p2) { + return 0; // TODo +} + +// _____________________________________________________________________________ +template +inline std::string getWKT(const Point* p) { + std::stringstream ss; + // TODO + return ss.str(); +} + +// _____________________________________________________________________________ +template +inline double len(const Point& g) { + return 0; +} + +// _____________________________________________________________________________ +template +inline Point simplify(const Point& g, double d) { + return g; +} + +// _____________________________________________________________________________ +inline double distToSegment(double lax, double lay, double lbx, double lby, + double px, double py) { + double d = dist(lax, lay, lbx, lby) * dist(lax, lay, lbx, lby); + if (d == 0) return dist(px, py, lax, lay); + + double t = ((px - lax) * (lbx - lax) + (py - lay) * (lby - lay)) / d; + + if (t < 0) { + return dist(px, py, lax, lay); + } else if (t > 1) { + return dist(px, py, lbx, lby); + } + + return dist(px, py, lax + t * (lbx - lax), lay + t * (lby - lay)); +} + +// _____________________________________________________________________________ +template +inline double distToSegment(const Point& la, const Point& lb, + const Point& p) { + return distToSegment(la.getX(), la.getY(), + lb.getX(), lb.getY(), + p.getX(), p.getY()); +} + +// _____________________________________________________________________________ +template +inline Point projectOn(const Point& a, const Point& b, + const Point& c) { + if (doubleEq(a.getX(), b.getX()) && + doubleEq(a.getY(), b.getY())) + return a; + if (doubleEq(a.getX(), c.getX()) && + doubleEq(a.getY(), c.getY())) + return a; + if (doubleEq(b.getX(), c.getX()) && + doubleEq(b.getY(), c.getY())) + return b; + + double x, y; + + if (c.getX() == a.getX()) { + // infinite slope + x = a.getX(); + y = b.getY(); + } else { + double m = (double)(c.getY() - a.getY()) / + (c.getX() - a.getX()); + double bb = (double)a.getY() - (m * a.getX()); + + x = (m * b.getY() + b.getX() - m * bb) / (m * m + 1); + y = (m * m * b.getY() + m * b.getX() + bb) / + (m * m + 1); + } + + Point ret = Point(x, y); + + bool isBetween = dist(a, c) > dist(a, ret) && dist(a, c) > dist(c, ret); + bool nearer = dist(a, ret) < dist(c, ret); + + if (!isBetween) return nearer ? a : c; + + return ret; +} + +// _____________________________________________________________________________ +template +inline double parallelity(const Box& box, const Line& line) { + double ret = M_PI; + + double a = angBetween(box.min_corner(), + Point(box.min_corner().getX(), + box.max_corner().getY())); + double b = angBetween(box.min_corner(), + Point(box.max_corner().getX(), + box.min_corner().getY())); + double c = angBetween(box.max_corner(), + Point(box.min_corner().getX(), + box.max_corner().getY())); + double d = angBetween(box.max_corner(), + Point(box.max_corner().getX(), + box.min_corner().getY())); + + double e = angBetween(line.front(), line.back()); + + double vals[] = {a, b, c, d}; + + for (double ang : vals) { + double v = fabs(ang - e); + if (v > M_PI) v = 2 * M_PI - v; + if (v > M_PI / 2) v = M_PI - v; + if (v < ret) ret = v; + } + + return 1 - (ret / (M_PI / 4)); +} + +// _____________________________________________________________________________ +// template +// inline double parallelity(const Box& box, const MultiLine& multiline) { + // double ret = 0; + // for (const Line& l : multiline) { + // ret += parallelity(box, l); + // } + + // return ret / multiline.size(); +// } + +// _____________________________________________________________________________ +// template +// inline bool intersects(const GeomA& a, const GeomB& b) { + // return bgeo::intersects(a, b); +// } + +// _____________________________________________________________________________ +// template typename Geometry> +// inline RotatedBox getOrientedEnvelope(Geometry pol) { + // // TODO: implement this nicer, works for now, but inefficient + // // see + // // https://geidav.wordpress.com/tag/gift-wrapping/#fn-1057-FreemanShapira1975 + // // for a nicer algorithm + + // Point center; + // bgeo::centroid(pol, center); + + // Box tmpBox = getBoundingBox(pol); + // double rotateDeg = 0; + + // // rotate in 5 deg steps + // for (int i = 1; i < 360; i += 1) { + // pol = rotate(pol, 1, center); + // Box e; + // bgeo::envelope(pol, e); + // if (bgeo::area(tmpBox) > bgeo::area(e)) { + // tmpBox = e; + // rotateDeg = i; + // } + // } + + // return RotatedBox(tmpBox, -rotateDeg, center); +// } + +// _____________________________________________________________________________ +template +// inline Box getBoundingBox(Point pol) { + // Box tmpBox; + // bgeo::envelope(pol, tmpBox); + // return tmpBox; +// } + +// _____________________________________________________________________________ +// template +// inline Box extendBox(const Box& a, Box b) { + // bgeo::expand(b, a); + // return b; +// } + +// _____________________________________________________________________________ +template +inline Box extendBox(G pol, Box b) { + Box tmp; + bgeo::envelope(pol, tmp); + bgeo::expand(b, tmp); + return b; +} + +// _____________________________________________________________________________ +// template +// inline double commonArea(const Box& ba, const Box& bb) { + // T l = std::max(ba.min_corner().getX(), + // bb.min_corner().getX()); + // T r = std::min(ba.max_corner().getX(), + // bb.max_corner().getX()); + // T b = std::max(ba.min_corner().getY(), + // bb.min_corner().getY()); + // T t = std::min(ba.max_corner().getY(), + // bb.max_corner().getY()); + + // if (l > r || b > t) return 0; + + // return (r - l) * (t - b); +// } + +// _____________________________________________________________________________ +// template typename Geometry> +// inline RotatedBox getFullEnvelope(Geometry pol) { + // Point center; + // bgeo::centroid(pol, center); + + // Box tmpBox; + // bgeo::envelope(pol, tmpBox); + // double rotateDeg = 0; + + // MultiPolygon ml; + + // // rotate in 5 deg steps + // for (int i = 1; i < 360; i += 1) { + // pol = rotate(pol, 1, center); + // Polygon hull; + // bgeo::convex_hull(pol, hull); + // ml.push_back(hull); + // Box e; + // bgeo::envelope(pol, e); + // if (bgeo::area(tmpBox) > bgeo::area(e)) { + // tmpBox = e; + // rotateDeg = i; + // } + // } + + // bgeo::envelope(ml, tmpBox); + + // return RotatedBox(tmpBox, rotateDeg, center); +// } + +// _____________________________________________________________________________ +// template +// inline RotatedBox getOrientedEnvelopeAvg(MultiLine ml) { + // MultiLine orig = ml; + // // get oriented envelope for hull + // RotatedBox rbox = getFullEnvelope(ml); + // Point center; + // bgeo::centroid(rbox.b, center); + + // ml = rotate(ml, -rbox.rotateDeg - 45, center); + + // double bestDeg = -45; + // double score = parallelity(rbox.b, ml); + + // for (double i = -45; i <= 45; i += .5) { + // ml = rotate(ml, -.5, center); + // double p = parallelity(rbox.b, ml); + // if (parallelity(rbox.b, ml) > score) { + // bestDeg = i; + // score = p; + // } + // } + + // rbox.rotateDeg += bestDeg; + + // // move the box along 45deg angles from its origin until it fits the ml + // // = until the intersection of its hull and the box is largest + // Polygon p = rbox.getPolygon(); + // p = rotate(p, -rbox.rotateDeg, rbox.center); + + // Polygon hull; + // bgeo::convex_hull(orig, hull); + // hull = rotate(hull, -rbox.rotateDeg, rbox.center); + + // Box box; + // bgeo::envelope(hull, box); + // rbox = RotatedBox(box, rbox.rotateDeg, rbox.center); + + // return rbox; +// } + +// _____________________________________________________________________________ +template +inline Line densify(const Line& l, double d) { + if (!l.size()) return l; + + Line ret; + ret.reserve(l.size()); + ret.push_back(l.front()); + + for (size_t i = 1; i < l.size(); i++) { + double segd = dist(l[i-1], l[i]); + double dx = + (l[i].getX() - l[i-1].getX()) / segd; + double dy = + (l[i].getY() - l[i-1].getY()) / segd; + double curd = d; + while (curd < segd) { + ret.push_back(Point(l[i-1].getX() + dx * curd, + l[i-1].getY() + dy * curd)); + curd += d; + } + + ret.push_back(l[i]); + } + + return ret; +} + +// _____________________________________________________________________________ +template +inline double frechetDistC(size_t i, size_t j, const Line& p, + const Line& q, + std::vector>& ca) { + // based on Eiter / Mannila + // http://www.kr.tuwien.ac.at/staff/eiter/et-archive/cdtr9464.pdf + + if (ca[i][j] > -1) + return ca[i][j]; + else if (i == 0 && j == 0) + ca[i][j] = dist(p[0], q[0]); + else if (i > 0 && j == 0) + ca[i][j] = std::max(frechetDistC(i - 1, 0, p, q, ca), dist(p[i], q[0])); + else if (i == 0 && j > 0) + ca[i][j] = std::max(frechetDistC(0, j - 1, p, q, ca), dist(p[0], q[j])); + else if (i > 0 && j > 0) + ca[i][j] = std::max(std::min(std::min(frechetDistC(i - 1, j, p, q, ca), + frechetDistC(i - 1, j - 1, p, q, ca)), + frechetDistC(i, j - 1, p, q, ca)), + dist(p[i], q[j])); + else + ca[i][j] = std::numeric_limits::infinity(); + + return ca[i][j]; +} + +// _____________________________________________________________________________ +template +inline double frechetDist(const Line& a, const Line& b, double d) { + // based on Eiter / Mannila + // http://www.kr.tuwien.ac.at/staff/eiter/et-archive/cdtr9464.pdf + + auto p = densify(a, d); + auto q = densify(b, d); + + std::vector> ca(p.size(), + std::vector(q.size(), -1.0)); + double fd = frechetDistC(p.size() - 1, q.size() - 1, p, q, ca); + + return fd; +} + +// _____________________________________________________________________________ +template +inline double accFrechetDistC(const Line& a, const Line& b, double d) { + + auto p = densify(a, d); + auto q = densify(b, d); + + std::vector> ca(p.size(), + std::vector(q.size(), 0)); + + for (size_t i = 0; i < p.size(); i++) ca[i][0] = std::numeric_limits::infinity(); + for (size_t j = 0; j < q.size(); j++) ca[0][j] = std::numeric_limits::infinity(); + ca[0][0] = 0; + + for (size_t i = 1; i < p.size(); i++) { + for (size_t j = 1; j < q.size(); j++) { + double d = util::geo::dist(p[i], q[j]) * util::geo::dist(p[i], p[i-1]); + ca[i][j] = d + std::min(ca[i-1][j], std::min(ca[i][j-1], ca[i-1][j-1])); + } + } + + return ca[p.size() - 1][q.size() - 1]; +} + + + +// _____________________________________________________________________________ +template +inline Point latLngToWebMerc(double lat, double lng) { + double x = 6378137.0 * lng * 0.017453292519943295; + double a = lat * 0.017453292519943295; + + double y = 3189068.5 * log((1.0 + sin(a)) / (1.0 - sin(a))); + return Point(x, y); +} + +// _____________________________________________________________________________ +template +inline Point webMercToLatLng(double x, double y) { + double lat = 114.591559026 * (atan(exp(y / 6378137.0)) - 0.78539825); + double lon = x / 111319.4907932735677; + return Point(lon, lat); +} + +// _____________________________________________________________________________ +template +inline double webMercMeterDist(const G1& a, const G2& b) { + // euclidean distance on web mercator is in meters on equator, + // and proportional to cos(lat) in both y directions + + double latA = 2 * atan(exp(a.getY() / 6378137.0)) - 1.5707965; + double latB = 2 * atan(exp(b.getY() / 6378137.0)) - 1.5707965; + + return util::geo::dist(a, b) * cos((latA + latB) / 2.0); +} +} +} + +#endif // UTIL_GEO_GEON_H_ diff --git a/src/util/geo/Point.h b/src/util/geo/Point.h new file mode 100644 index 0000000..2b859b9 --- /dev/null +++ b/src/util/geo/Point.h @@ -0,0 +1,32 @@ +// Copyright 2016, University of Freiburg, +// Chair of Algorithms and Data Structures. +// Author: Patrick Brosi + +#ifndef UTIL_GEO_POINT_H_ +#define UTIL_GEO_POINT_H_ + +#include +#include + +namespace util { +namespace geon { + +template +class Point { + public: + Point(T x, T y) : _x(x), _y(y) {} + T getX() const { return _x; } + T getY() const { return _y; } + + void setX(T x) { _x = x; } + void setY(T y) { _y = y; } + + private: + T _x, _y; + +}; + +} // namespace geon +} // namespace util + +#endif // UTIL_GEO_POINT_H_ diff --git a/src/util/geo/PolyLine.tpp b/src/util/geo/PolyLine.tpp index 2da1525..7ace68a 100644 --- a/src/util/geo/PolyLine.tpp +++ b/src/util/geo/PolyLine.tpp @@ -2,9 +2,6 @@ // Chair of Algorithms and Data Structures. // Authors: Patrick Brosi -#include "util/geo/Geo.h" -#include "util/geo/PolyLine.h" - // _____________________________________________________________________________ template PolyLine::PolyLine() {} @@ -101,11 +98,11 @@ void PolyLine::offsetPerp(double units) { n1 = n1 / n; n2 = n2 / n; - lastP.set<0>(lastP.template get<0>() + (n1 * units)); - lastP.set<1>(lastP.template get<1>() + (n2 * units)); + lastP.template set<0>(lastP.template get<0>() + (n1 * units)); + lastP.template set<1>(lastP.template get<1>() + (n2 * units)); - curP.set<0>(curP.template get<0>() + (n1 * units)); - curP.set<1>(curP.template get<1>() + (n2 * units)); + curP.template set<0>(curP.template get<0>() + (n1 * units)); + curP.template set<1>(curP.template get<1>() + (n2 * units)); if (lastIns && befLastIns && lineIntersects(*lastIns, *befLastIns, lastP, curP)) { diff --git a/src/util/tests/TestMain.cpp b/src/util/tests/TestMain.cpp index 3e6fbc2..67f2f0c 100644 --- a/src/util/tests/TestMain.cpp +++ b/src/util/tests/TestMain.cpp @@ -7,6 +7,7 @@ #include "util/Nullable.h" #include "util/String.h" #include "util/geo/Geo.h" +#include "util/geo/GeoNew.h" #include "util/graph/DirGraph.h" #include "util/graph/UndirGraph.h" #include "util/graph/Dijkstra.h" @@ -841,6 +842,10 @@ CASE("nullable") { EXPECT_THROWS(nullable == voidnull); } +}, + +// ___________________________________________________________________________ +CASE("geometry") { } }; From cf79e676314defe7c17c3818efd51c75364d928e Mon Sep 17 00:00:00 2001 From: Patrick Brosi Date: Tue, 10 Jul 2018 17:04:59 +0200 Subject: [PATCH 015/251] changes --- src/util/geo/Box.h | 39 +++ src/util/geo/GeoNew.h | 591 +++++++++++++++++++----------------- src/util/geo/Line.h | 21 ++ src/util/geo/Point.h | 16 +- src/util/tests/TestMain.cpp | 37 +++ 5 files changed, 424 insertions(+), 280 deletions(-) create mode 100644 src/util/geo/Box.h create mode 100644 src/util/geo/Line.h diff --git a/src/util/geo/Box.h b/src/util/geo/Box.h new file mode 100644 index 0000000..5eef056 --- /dev/null +++ b/src/util/geo/Box.h @@ -0,0 +1,39 @@ +// Copyright 2016, University of Freiburg, +// Chair of Algorithms and Data Structures. +// Author: Patrick Brosi + +#ifndef UTIL_GEO_BOX_H_ +#define UTIL_GEO_BOX_H_ + +#include "./Point.h" + +namespace util { +namespace geon { + +template +class Box { + public: + // maximum inverse box as default value of box + Box() : _ll(std::numeric_limits::max), _ur(std::numeric_limits::min) {} + Box(const Point& ll, const Point& ur) : _ll(ll), _ur(ur) {} + const Point& getLowerLeft() const { return _ll; } + const Point& getUpperRight() const { return _ur; } + + void setLowerLeft(const Point& ll) { _ll = ll; } + void setUpperRight(const Point& ur) { _ur = ur; } + + bool operator==(const Box& b) const { + return getLowerLeft() == b.getLowerLeft() && + getUpperRight == b.getUpperRight(); + } + + bool operator!=(const Box& p) const { return !(*this == p); } + + private: + Point _ll, _ur; +}; + +} // namespace geon +} // namespace util + +#endif // UTIL_GEO_BOX_H_ diff --git a/src/util/geo/GeoNew.h b/src/util/geo/GeoNew.h index f274525..29f8dda 100644 --- a/src/util/geo/GeoNew.h +++ b/src/util/geo/GeoNew.h @@ -8,6 +8,8 @@ #include #include "util/Misc.h" +#include "util/geo/Box.h" +#include "util/geo/Line.h" #include "util/geo/Point.h" // ------------------- @@ -23,13 +25,13 @@ typedef Point DPoint; typedef Point FPoint; typedef Point IPoint; -// typedef Line DLine; -// typedef Line FLine; -// typedef Line ILine; +typedef Line DLine; +typedef Line FLine; +typedef Line ILine; -// typedef Box DBox; -// typedef Box FBox; -// typedef Box IBox; +typedef Box DBox; +typedef Box FBox; +typedef Box IBox; // typedef Polygon DPolygon; // typedef Polygon FPolygon; @@ -37,57 +39,58 @@ typedef Point IPoint; // _____________________________________________________________________________ // template -// inline Line rotate(const Line& geo, double deg, const Point& center) { - // Line ret; +// inline Line rotate(const Line& geo, double deg, const Point& center) +// { +// Line ret; - // bgeo::strategy::transform::translate_transformer translate( - // -center.getX(), -center.getY()); - // bgeo::strategy::transform::rotate_transformer rotate( - // deg); - // bgeo::strategy::transform::translate_transformer translateBack( - // center.getX(), center.getY()); +// bgeo::strategy::transform::translate_transformer translate( +// -center.getX(), -center.getY()); +// bgeo::strategy::transform::rotate_transformer rotate( +// deg); +// bgeo::strategy::transform::translate_transformer translateBack( +// center.getX(), center.getY()); - // bgeo::strategy::transform::ublas_transformer translateRotate( - // prod(rotate.matrix(), translate.matrix())); - // bgeo::strategy::transform::ublas_transformer all( - // prod(translateBack.matrix(), translateRotate.matrix())); +// bgeo::strategy::transform::ublas_transformer translateRotate( +// prod(rotate.matrix(), translate.matrix())); +// bgeo::strategy::transform::ublas_transformer all( +// prod(translateBack.matrix(), translateRotate.matrix())); - // bgeo::transform(geo, ret, all); +// bgeo::transform(geo, ret, all); - // return ret; +// return ret; // } // _____________________________________________________________________________ // template // inline MultiLine rotate(const MultiLine& geo, double deg, - // const Point& center) { - // MultiLine ret; +// const Point& center) { +// MultiLine ret; - // bgeo::strategy::transform::translate_transformer translate( - // -center.getX(), -center.getY()); - // bgeo::strategy::transform::rotate_transformer rotate( - // deg); - // bgeo::strategy::transform::translate_transformer translateBack( - // center.getX(), center.getY()); +// bgeo::strategy::transform::translate_transformer translate( +// -center.getX(), -center.getY()); +// bgeo::strategy::transform::rotate_transformer rotate( +// deg); +// bgeo::strategy::transform::translate_transformer translateBack( +// center.getX(), center.getY()); - // bgeo::strategy::transform::ublas_transformer translateRotate( - // prod(rotate.matrix(), translate.matrix())); - // bgeo::strategy::transform::ublas_transformer all( - // prod(translateBack.matrix(), translateRotate.matrix())); +// bgeo::strategy::transform::ublas_transformer translateRotate( +// prod(rotate.matrix(), translate.matrix())); +// bgeo::strategy::transform::ublas_transformer all( +// prod(translateBack.matrix(), translateRotate.matrix())); - // bgeo::transform(geo, ret, all); +// bgeo::transform(geo, ret, all); - // return ret; +// return ret; // } // _____________________________________________________________________________ -// template -// inline Box pad(const Box& box, double padding) { - // return Box(Point(box.min_corner().getX() - padding, - // box.min_corner().getY() - padding), - // Point(box.max_corner().getX() + padding, - // box.max_corner().getY() + padding)); -// } +template +inline Box pad(const Box& box, double padding) { + return Box(Point(box.getLowerLeft().getX() - padding, + box.getLowerLeft().getY() - padding), + Point(box.getUpperRight().getX() + padding, + box.getUpperRight().getY() + padding)); +} // _____________________________________________________________________________ template @@ -98,17 +101,17 @@ inline Point rotate(const Point& p, double deg) { // _____________________________________________________________________________ // template // inline Line rotate(const Line& geo, double deg) { - // Point center; - // bgeo::centroid(geo, center); - // return rotate(geo, deg, center); +// Point center; +// bgeo::centroid(geo, center); +// return rotate(geo, deg, center); // } // _____________________________________________________________________________ // template // inline MultiLine rotate(const MultiLine& geo, double deg) { - // Point center; - // bgeo::centroid(geo, center); - // return rotate(geo, deg, center); +// Point center; +// bgeo::centroid(geo, center); +// return rotate(geo, deg, center); // } // _____________________________________________________________________________ @@ -121,110 +124,124 @@ inline Point move(const Point& geo, T x, T y) { // template // struct RotatedBox { - // RotatedBox(const Box& b, double rot, const Point& center) - // : b(b), rotateDeg(rot), center(center) {} - // RotatedBox(const Box& b, double rot) : b(b), rotateDeg(rot) { - // bgeo::centroid(b, center); - // } +// RotatedBox(const Box& b, double rot, const Point& center) +// : b(b), rotateDeg(rot), center(center) {} +// RotatedBox(const Box& b, double rot) : b(b), rotateDeg(rot) { +// bgeo::centroid(b, center); +// } - // Box b; - // double rotateDeg; - // Point center; +// Box b; +// double rotateDeg; +// Point center; - // Polygon getPolygon() { - // Polygon hull; - // bgeo::convex_hull(b, hull); - // return rotate(hull, rotateDeg, center); - // } +// Polygon getPolygon() { +// Polygon hull; +// bgeo::convex_hull(b, hull); +// return rotate(hull, rotateDeg, center); +// } // }; // _____________________________________________________________________________ template inline Box minbox() { - //return bgeo::make_inverse>(); + return Box(); } // _____________________________________________________________________________ // template // inline RotatedBox shrink(const RotatedBox& b, double d) { - // double xd = - // b.b.max_corner().getX() - b.b.min_corner().getX(); - // double yd = - // b.b.max_corner().getY() - b.b.min_corner().getY(); +// double xd = +// b.b.getUpperRight().getX() - b.b.getLowerLeft().getX(); +// double yd = +// b.b.getUpperRight().getY() - b.b.getLowerLeft().getY(); - // if (xd <= 2 * d) d = xd / 2 - 1; - // if (yd <= 2 * d) d = yd / 2 - 1; +// if (xd <= 2 * d) d = xd / 2 - 1; +// if (yd <= 2 * d) d = yd / 2 - 1; - // Box r(Point(b.b.min_corner().getX() + d, - // b.b.min_corner().getY() + d), - // Point(b.b.max_corner().getX() - d, - // b.b.max_corner().getY() - d)); +// Box r(Point(b.b.getLowerLeft().getX() + d, +// b.b.getLowerLeft().getY() + d), +// Point(b.b.getUpperRight().getX() - d, +// b.b.getUpperRight().getY() - d)); - // return RotatedBox(r, b.rotateDeg, b.center); +// return RotatedBox(r, b.rotateDeg, b.center); // } // _____________________________________________________________________________ inline bool doubleEq(double a, double b) { return fabs(a - b) < 0.000001; } // _____________________________________________________________________________ -// template -// inline bool contains(const Geometry& geom, const Box& box) { - // return bgeo::within(geom, box); +template +inline bool contains(const Point& p, const Box& box) { + return p.getX() >= box.getLowerLeft().getX() && + p.getX() <= box.getUpperRight().getX() && + p.getY() >= box.getLowerLeft().getY() && + p.getY() <= box.getUpperRight().getY(); +} + +// _____________________________________________________________________________ +template +inline bool contains(const Line& l, const Box& box) { + for (const auto& p : l) + if (!contains(p, box)) return false; + return true; +} + +// _____________________________________________________________________________ +// template +// inline bool contains(const Point& p1, const Point& q1, const Point& +// p2, +// const Point& q2) { +// Line a, b; +// a.push_back(p1); +// a.push_back(q1); +// b.push_back(p2); +// b.push_back(q2); + +// return bgeo::covered_by(a, b); // } // _____________________________________________________________________________ // template -// inline bool contains(const Point& p1, const Point& q1, const Point& p2, - // const Point& q2) { - // Line a, b; - // a.push_back(p1); - // a.push_back(q1); - // b.push_back(p2); - // b.push_back(q2); +// inline bool contains(T p1x, T p1y, T q1x, T q1y, T p2x, T p2y, T q2x, T q2y) +// { +// Point p1(p1x, p1y); +// Point q1(q1x, q1y); +// Point p2(p2x, p2y); +// Point q2(q2x, q2y); - // return bgeo::covered_by(a, b); -// } - -// _____________________________________________________________________________ -// template -// inline bool contains(T p1x, T p1y, T q1x, T q1y, T p2x, T p2y, T q2x, T q2y) { - // Point p1(p1x, p1y); - // Point q1(q1x, q1y); - // Point p2(p2x, p2y); - // Point q2(q2x, q2y); - - // return contains(p1, q1, p2, q2); +// return contains(p1, q1, p2, q2); // } // _____________________________________________________________________________ // template // inline bool intersects(const Point& p1, const Point& q1, - // const Point& p2, const Point& q2) { - /* - * checks whether two line segments intersect - */ - // Line a, b; - // a.push_back(p1); - // a.push_back(q1); - // b.push_back(p2); - // b.push_back(q2); +// const Point& p2, const Point& q2) { +/* + * checks whether two line segments intersect + */ +// Line a, b; +// a.push_back(p1); +// a.push_back(q1); +// b.push_back(p2); +// b.push_back(q2); - // return !(contains(p1, q1, p2, q2) || contains(p2, q2, p1, q1)) && - // bgeo::intersects(a, b); +// return !(contains(p1, q1, p2, q2) || contains(p2, q2, p1, q1)) && +// bgeo::intersects(a, b); // } // _____________________________________________________________________________ // template -// inline bool intersects(T p1x, T p1y, T q1x, T q1y, T p2x, T p2y, T q2x, T q2y) { - /* - * checks whether two line segments intersect - */ - // Point p1(p1x, p1y); - // Point q1(q1x, q1y); - // Point p2(p2x, p2y); - // Point q2(q2x, q2y); +// inline bool intersects(T p1x, T p1y, T q1x, T q1y, T p2x, T p2y, T q2x, T +// q2y) { +/* + * checks whether two line segments intersect + */ +// Point p1(p1x, p1y); +// Point q1(q1x, q1y); +// Point p2(p2x, p2y); +// Point q2(q2x, q2y); - // return intersects(p1, q1, p2, q2); +// return intersects(p1, q1, p2, q2); // } // _____________________________________________________________________________ @@ -254,10 +271,8 @@ inline Point intersection(const Point& p1, const Point& q1, /* * calculates the intersection between two line segments */ - return intersection(p1.getX(), p1.getY(), - q1.getX(), q1.getY(), - p2.getX(), p2.getY(), - q2.getX(), q2.getY()); + return intersection(p1.getX(), p1.getY(), q1.getX(), q1.getY(), p2.getX(), + p2.getY(), q2.getX(), q2.getY()); } // _____________________________________________________________________________ @@ -280,10 +295,8 @@ inline bool lineIntersects(const Point& p1, const Point& q1, /* * checks whether two lines intersect */ - return lineIntersects(p1.getX(), p1.getY(), - q1.getX(), q1.getY(), - p2.getX(), p2.getY(), - q2.getX(), q2.getY()); + return lineIntersects(p1.getX(), p1.getY(), q1.getX(), q1.getY(), p2.getX(), + p2.getY(), q2.getX(), q2.getY()); } // _____________________________________________________________________________ @@ -296,8 +309,7 @@ inline double angBetween(double p1x, double p1y, double q1x, double q1y) { // _____________________________________________________________________________ template inline double angBetween(const Point& p1, const Point& q1) { - return angBetween(p1.getX(), p1.getY(), - q1.getX(), q1.getY()); + return angBetween(p1.getX(), p1.getY(), q1.getX(), q1.getY()); } // _____________________________________________________________________________ @@ -321,23 +333,36 @@ inline double innerProd(double x1, double y1, double x2, double y2, double x3, // _____________________________________________________________________________ template -inline double innerProd(const Point& a, const Point& b, const Point& c) { - return innerProd(a.template getX(), a.template getY(), - b.template getX(), b.template getY(), - c.template getX(), c.template getY()); +inline double innerProd(const Point& a, const Point& b, + const Point& c) { + return innerProd(a.template getX(), a.template getY(), b.template getX(), + b.template getY(), c.template getX(), c.template getY()); } // _____________________________________________________________________________ template inline double dist(const Point& p1, const Point& p2) { - return 0; // TODo + return sqrt((p1.getX() - p2.getX()) * (p1.getX() - p2.getX()) + + (p1.getY() - p2.getY()) * (p1.getY() - p2.getY())); } // _____________________________________________________________________________ template -inline std::string getWKT(const Point* p) { +inline std::string getWKT(const Point& p) { std::stringstream ss; - // TODO + ss << "POINT (" << p.getX() << " " << p.getY() << ")"; + return ss.str(); +} + +// _____________________________________________________________________________ +template +inline std::string getWKT(const Line& l) { + std::stringstream ss; + ss << "LINESTRING ("; + for (size_t i = 0; i < l.size(); i++) { + if (i) ss << ", "; + ss << l[i].getX() << " " << l[i].getY(); + } return ss.str(); } @@ -347,12 +372,26 @@ inline double len(const Point& g) { return 0; } +// _____________________________________________________________________________ +template +inline double len(const Line& g) { + double ret = 0; + for (size_t i = 1; i < g.size(); i++) ret += dist(g[i - 1], g[i]); + return ret; +} + // _____________________________________________________________________________ template inline Point simplify(const Point& g, double d) { return g; } +// _____________________________________________________________________________ +template +inline Line simplify(const Line& g, double d) { + return g; +} + // _____________________________________________________________________________ inline double distToSegment(double lax, double lay, double lbx, double lby, double px, double py) { @@ -374,24 +413,17 @@ inline double distToSegment(double lax, double lay, double lbx, double lby, template inline double distToSegment(const Point& la, const Point& lb, const Point& p) { - return distToSegment(la.getX(), la.getY(), - lb.getX(), lb.getY(), - p.getX(), p.getY()); + return distToSegment(la.getX(), la.getY(), lb.getX(), lb.getY(), p.getX(), + p.getY()); } // _____________________________________________________________________________ template inline Point projectOn(const Point& a, const Point& b, const Point& c) { - if (doubleEq(a.getX(), b.getX()) && - doubleEq(a.getY(), b.getY())) - return a; - if (doubleEq(a.getX(), c.getX()) && - doubleEq(a.getY(), c.getY())) - return a; - if (doubleEq(b.getX(), c.getX()) && - doubleEq(b.getY(), c.getY())) - return b; + if (doubleEq(a.getX(), b.getX()) && doubleEq(a.getY(), b.getY())) return a; + if (doubleEq(a.getX(), c.getX()) && doubleEq(a.getY(), c.getY())) return a; + if (doubleEq(b.getX(), c.getX()) && doubleEq(b.getY(), c.getY())) return b; double x, y; @@ -400,13 +432,11 @@ inline Point projectOn(const Point& a, const Point& b, x = a.getX(); y = b.getY(); } else { - double m = (double)(c.getY() - a.getY()) / - (c.getX() - a.getX()); + double m = (double)(c.getY() - a.getY()) / (c.getX() - a.getX()); double bb = (double)a.getY() - (m * a.getX()); x = (m * b.getY() + b.getX() - m * bb) / (m * m + 1); - y = (m * m * b.getY() + m * b.getX() + bb) / - (m * m + 1); + y = (m * m * b.getY() + m * b.getX() + bb) / (m * m + 1); } Point ret = Point(x, y); @@ -424,18 +454,18 @@ template inline double parallelity(const Box& box, const Line& line) { double ret = M_PI; - double a = angBetween(box.min_corner(), - Point(box.min_corner().getX(), - box.max_corner().getY())); - double b = angBetween(box.min_corner(), - Point(box.max_corner().getX(), - box.min_corner().getY())); - double c = angBetween(box.max_corner(), - Point(box.min_corner().getX(), - box.max_corner().getY())); - double d = angBetween(box.max_corner(), - Point(box.max_corner().getX(), - box.min_corner().getY())); + double a = angBetween( + box.getLowerLeft(), + Point(box.getLowerLeft().getX(), box.getUpperRight().getY())); + double b = angBetween( + box.getLowerLeft(), + Point(box.getUpperRight().getX(), box.getLowerLeft().getY())); + double c = angBetween( + box.getUpperRight(), + Point(box.getLowerLeft().getX(), box.getUpperRight().getY())); + double d = angBetween( + box.getUpperRight(), + Point(box.getUpperRight().getX(), box.getLowerLeft().getY())); double e = angBetween(line.front(), line.back()); @@ -454,159 +484,170 @@ inline double parallelity(const Box& box, const Line& line) { // _____________________________________________________________________________ // template // inline double parallelity(const Box& box, const MultiLine& multiline) { - // double ret = 0; - // for (const Line& l : multiline) { - // ret += parallelity(box, l); - // } +// double ret = 0; +// for (const Line& l : multiline) { +// ret += parallelity(box, l); +// } - // return ret / multiline.size(); +// return ret / multiline.size(); // } // _____________________________________________________________________________ // template // inline bool intersects(const GeomA& a, const GeomB& b) { - // return bgeo::intersects(a, b); +// return bgeo::intersects(a, b); // } // _____________________________________________________________________________ // template typename Geometry> // inline RotatedBox getOrientedEnvelope(Geometry pol) { - // // TODO: implement this nicer, works for now, but inefficient - // // see - // // https://geidav.wordpress.com/tag/gift-wrapping/#fn-1057-FreemanShapira1975 - // // for a nicer algorithm +// // TODO: implement this nicer, works for now, but inefficient +// // see +// // https://geidav.wordpress.com/tag/gift-wrapping/#fn-1057-FreemanShapira1975 +// // for a nicer algorithm - // Point center; - // bgeo::centroid(pol, center); +// Point center; +// bgeo::centroid(pol, center); - // Box tmpBox = getBoundingBox(pol); - // double rotateDeg = 0; +// Box tmpBox = getBoundingBox(pol); +// double rotateDeg = 0; - // // rotate in 5 deg steps - // for (int i = 1; i < 360; i += 1) { - // pol = rotate(pol, 1, center); - // Box e; - // bgeo::envelope(pol, e); - // if (bgeo::area(tmpBox) > bgeo::area(e)) { - // tmpBox = e; - // rotateDeg = i; - // } - // } +// // rotate in 5 deg steps +// for (int i = 1; i < 360; i += 1) { +// pol = rotate(pol, 1, center); +// Box e; +// bgeo::envelope(pol, e); +// if (bgeo::area(tmpBox) > bgeo::area(e)) { +// tmpBox = e; +// rotateDeg = i; +// } +// } - // return RotatedBox(tmpBox, -rotateDeg, center); +// return RotatedBox(tmpBox, -rotateDeg, center); // } // _____________________________________________________________________________ template -// inline Box getBoundingBox(Point pol) { - // Box tmpBox; - // bgeo::envelope(pol, tmpBox); - // return tmpBox; -// } +inline Box getBoundingBox(const Point& p) { + return Box(p, p); +} // _____________________________________________________________________________ -// template -// inline Box extendBox(const Box& a, Box b) { - // bgeo::expand(b, a); - // return b; -// } +template +inline Box getBoundingBox(const Line& l) { + Box ret; + for (const auto& p : l) extendBox(p, ret); + return ret; +} // _____________________________________________________________________________ -template -inline Box extendBox(G pol, Box b) { - Box tmp; - bgeo::envelope(pol, tmp); - bgeo::expand(b, tmp); +template +inline Box extendBox(const Box& a, Box b) { + b = extendBox(a.getLowerLeft(), b); + b = extendBox(a.getUpperRight(), b); return b; } // _____________________________________________________________________________ -// template -// inline double commonArea(const Box& ba, const Box& bb) { - // T l = std::max(ba.min_corner().getX(), - // bb.min_corner().getX()); - // T r = std::min(ba.max_corner().getX(), - // bb.max_corner().getX()); - // T b = std::max(ba.min_corner().getY(), - // bb.min_corner().getY()); - // T t = std::min(ba.max_corner().getY(), - // bb.max_corner().getY()); +template +inline Box extendBox(const Point& p, Box b) { + if (p.getX() < b.getLowerLeft().getX()) b.getLowerLeft().setX(p.getX()); + if (p.getY() < b.getLowerLeft().getY()) b.getLowerLeft().setY(p.getY()); - // if (l > r || b > t) return 0; + if (p.getX() > b.getUpperRight().getX()) b.getUpperRight().setX(p.getX()); + if (p.getY() > b.getUpperRight().getY()) b.getUpperRight().setY(p.getY()); + return b; +} - // return (r - l) * (t - b); -// } +// _____________________________________________________________________________ +template +inline Box extendBox(const Line& l, Box b) { + for (const auto& p : l) b = extendBox(p, b); + return b; +} + +// _____________________________________________________________________________ +template +inline double commonArea(const Box& ba, const Box& bb) { + T l = std::max(ba.getLowerLeft().getX(), bb.getLowerLeft().getX()); + T r = std::min(ba.getUpperRight().getX(), bb.getUpperRight().getX()); + T b = std::max(ba.getLowerLeft().getY(), bb.getLowerLeft().getY()); + T t = std::min(ba.getUpperRight().getY(), bb.getUpperRight().getY()); + + if (l > r || b > t) return 0; + return (r - l) * (t - b); +} // _____________________________________________________________________________ // template typename Geometry> // inline RotatedBox getFullEnvelope(Geometry pol) { - // Point center; - // bgeo::centroid(pol, center); +// Point center; +// bgeo::centroid(pol, center); - // Box tmpBox; - // bgeo::envelope(pol, tmpBox); - // double rotateDeg = 0; +// Box tmpBox; +// bgeo::envelope(pol, tmpBox); +// double rotateDeg = 0; - // MultiPolygon ml; +// MultiPolygon ml; - // // rotate in 5 deg steps - // for (int i = 1; i < 360; i += 1) { - // pol = rotate(pol, 1, center); - // Polygon hull; - // bgeo::convex_hull(pol, hull); - // ml.push_back(hull); - // Box e; - // bgeo::envelope(pol, e); - // if (bgeo::area(tmpBox) > bgeo::area(e)) { - // tmpBox = e; - // rotateDeg = i; - // } - // } +// // rotate in 5 deg steps +// for (int i = 1; i < 360; i += 1) { +// pol = rotate(pol, 1, center); +// Polygon hull; +// bgeo::convex_hull(pol, hull); +// ml.push_back(hull); +// Box e; +// bgeo::envelope(pol, e); +// if (bgeo::area(tmpBox) > bgeo::area(e)) { +// tmpBox = e; +// rotateDeg = i; +// } +// } - // bgeo::envelope(ml, tmpBox); +// bgeo::envelope(ml, tmpBox); - // return RotatedBox(tmpBox, rotateDeg, center); +// return RotatedBox(tmpBox, rotateDeg, center); // } // _____________________________________________________________________________ // template // inline RotatedBox getOrientedEnvelopeAvg(MultiLine ml) { - // MultiLine orig = ml; - // // get oriented envelope for hull - // RotatedBox rbox = getFullEnvelope(ml); - // Point center; - // bgeo::centroid(rbox.b, center); +// MultiLine orig = ml; +// // get oriented envelope for hull +// RotatedBox rbox = getFullEnvelope(ml); +// Point center; +// bgeo::centroid(rbox.b, center); - // ml = rotate(ml, -rbox.rotateDeg - 45, center); +// ml = rotate(ml, -rbox.rotateDeg - 45, center); - // double bestDeg = -45; - // double score = parallelity(rbox.b, ml); +// double bestDeg = -45; +// double score = parallelity(rbox.b, ml); - // for (double i = -45; i <= 45; i += .5) { - // ml = rotate(ml, -.5, center); - // double p = parallelity(rbox.b, ml); - // if (parallelity(rbox.b, ml) > score) { - // bestDeg = i; - // score = p; - // } - // } +// for (double i = -45; i <= 45; i += .5) { +// ml = rotate(ml, -.5, center); +// double p = parallelity(rbox.b, ml); +// if (parallelity(rbox.b, ml) > score) { +// bestDeg = i; +// score = p; +// } +// } - // rbox.rotateDeg += bestDeg; +// rbox.rotateDeg += bestDeg; - // // move the box along 45deg angles from its origin until it fits the ml - // // = until the intersection of its hull and the box is largest - // Polygon p = rbox.getPolygon(); - // p = rotate(p, -rbox.rotateDeg, rbox.center); +// // move the box along 45deg angles from its origin until it fits the ml +// // = until the intersection of its hull and the box is largest +// Polygon p = rbox.getPolygon(); +// p = rotate(p, -rbox.rotateDeg, rbox.center); - // Polygon hull; - // bgeo::convex_hull(orig, hull); - // hull = rotate(hull, -rbox.rotateDeg, rbox.center); +// Polygon hull; +// bgeo::convex_hull(orig, hull); +// hull = rotate(hull, -rbox.rotateDeg, rbox.center); - // Box box; - // bgeo::envelope(hull, box); - // rbox = RotatedBox(box, rbox.rotateDeg, rbox.center); +// Box box; +// bgeo::envelope(hull, box); +// rbox = RotatedBox(box, rbox.rotateDeg, rbox.center); - // return rbox; +// return rbox; // } // _____________________________________________________________________________ @@ -619,15 +660,13 @@ inline Line densify(const Line& l, double d) { ret.push_back(l.front()); for (size_t i = 1; i < l.size(); i++) { - double segd = dist(l[i-1], l[i]); - double dx = - (l[i].getX() - l[i-1].getX()) / segd; - double dy = - (l[i].getY() - l[i-1].getY()) / segd; + double segd = dist(l[i - 1], l[i]); + double dx = (l[i].getX() - l[i - 1].getX()) / segd; + double dy = (l[i].getY() - l[i - 1].getY()) / segd; double curd = d; while (curd < segd) { - ret.push_back(Point(l[i-1].getX() + dx * curd, - l[i-1].getY() + dy * curd)); + ret.push_back( + Point(l[i - 1].getX() + dx * curd, l[i - 1].getY() + dy * curd)); curd += d; } @@ -683,29 +722,29 @@ inline double frechetDist(const Line& a, const Line& b, double d) { // _____________________________________________________________________________ template inline double accFrechetDistC(const Line& a, const Line& b, double d) { - auto p = densify(a, d); auto q = densify(b, d); std::vector> ca(p.size(), - std::vector(q.size(), 0)); + std::vector(q.size(), 0)); - for (size_t i = 0; i < p.size(); i++) ca[i][0] = std::numeric_limits::infinity(); - for (size_t j = 0; j < q.size(); j++) ca[0][j] = std::numeric_limits::infinity(); + for (size_t i = 0; i < p.size(); i++) + ca[i][0] = std::numeric_limits::infinity(); + for (size_t j = 0; j < q.size(); j++) + ca[0][j] = std::numeric_limits::infinity(); ca[0][0] = 0; for (size_t i = 1; i < p.size(); i++) { for (size_t j = 1; j < q.size(); j++) { - double d = util::geo::dist(p[i], q[j]) * util::geo::dist(p[i], p[i-1]); - ca[i][j] = d + std::min(ca[i-1][j], std::min(ca[i][j-1], ca[i-1][j-1])); + double d = util::geo::dist(p[i], q[j]) * util::geo::dist(p[i], p[i - 1]); + ca[i][j] = + d + std::min(ca[i - 1][j], std::min(ca[i][j - 1], ca[i - 1][j - 1])); } } return ca[p.size() - 1][q.size() - 1]; } - - // _____________________________________________________________________________ template inline Point latLngToWebMerc(double lat, double lng) { diff --git a/src/util/geo/Line.h b/src/util/geo/Line.h new file mode 100644 index 0000000..669392e --- /dev/null +++ b/src/util/geo/Line.h @@ -0,0 +1,21 @@ +// Copyright 2016, University of Freiburg, +// Chair of Algorithms and Data Structures. +// Author: Patrick Brosi + +#ifndef UTIL_GEO_LINE_H_ +#define UTIL_GEO_LINE_H_ + +#include +#include "./Point.h" + +namespace util { +namespace geon { + +template +using Line = std::vector>; + + +} // namespace geon +} // namespace util + +#endif // UTIL_GEO_LINE_H_ diff --git a/src/util/geo/Point.h b/src/util/geo/Point.h index 2b859b9..e27ec0e 100644 --- a/src/util/geo/Point.h +++ b/src/util/geo/Point.h @@ -5,9 +5,6 @@ #ifndef UTIL_GEO_POINT_H_ #define UTIL_GEO_POINT_H_ -#include -#include - namespace util { namespace geon { @@ -21,9 +18,20 @@ class Point { void setX(T x) { _x = x; } void setY(T y) { _y = y; } + Point operator+(const Point& p) const { + return Point(_x + p.getX(), _y + p.getY()); + } + + bool operator==(const Point& p) const { + return p.getX() == _x && p.getY() == _y; + } + + bool operator!=(const Point& p) const { + return !(*this == p); + } + private: T _x, _y; - }; } // namespace geon diff --git a/src/util/tests/TestMain.cpp b/src/util/tests/TestMain.cpp index 67f2f0c..16a7555 100644 --- a/src/util/tests/TestMain.cpp +++ b/src/util/tests/TestMain.cpp @@ -846,6 +846,43 @@ CASE("nullable") { // ___________________________________________________________________________ CASE("geometry") { + geon::Point a(1, 2); + geon::Point b(2, 3); + geon::Point c(4, 5); + EXPECT(a.getX() == approx(1)); + EXPECT(a.getY() == approx(2)); + + a.setX(3); + EXPECT(a.getX() == approx(3)); + EXPECT(a.getY() == approx(2)); + + a.setY(4); + EXPECT(a.getX() == approx(3)); + EXPECT(a.getY() == approx(4)); + + auto d = a + b; + EXPECT(d.getX() == approx(5)); + EXPECT(d.getY() == approx(7)); + + a.setX(1); + a.setY(2); + + EXPECT(geon::dist(a, a) == approx(0)); + EXPECT(geon::dist(a, b) == approx(sqrt(2))); + + d = d + d; + + geon::Box box(a, c); + EXPECT(geon::contains(a, box)); + EXPECT(geon::contains(b, box)); + EXPECT(geon::contains(c, box)); + EXPECT(!geon::contains(d, box)); + + geon::Line line{a, b, c}; + + EXPECT(geon::contains(line, box)); + line.push_back(d); + EXPECT(!geon::contains(line, box)); } }; From b07110840e5974ca40938bfe5b80fe152736a015 Mon Sep 17 00:00:00 2001 From: Patrick Brosi Date: Thu, 12 Jul 2018 14:23:29 +0200 Subject: [PATCH 016/251] some work on util --- src/util/geo/Box.h | 11 +- src/util/geo/Geo.h | 778 ++++++++++++++++++----------------- src/util/geo/GeoNew.h | 780 ------------------------------------ src/util/geo/Grid.h | 1 + src/util/geo/Grid.tpp | 40 +- src/util/geo/Line.h | 7 +- src/util/geo/Point.h | 4 +- src/util/graph/Graph.h | 1 + src/util/tests/TestMain.cpp | 108 +++-- 9 files changed, 523 insertions(+), 1207 deletions(-) delete mode 100644 src/util/geo/GeoNew.h diff --git a/src/util/geo/Box.h b/src/util/geo/Box.h index 5eef056..4b0e3ff 100644 --- a/src/util/geo/Box.h +++ b/src/util/geo/Box.h @@ -8,17 +8,22 @@ #include "./Point.h" namespace util { -namespace geon { +namespace geo { template class Box { public: // maximum inverse box as default value of box - Box() : _ll(std::numeric_limits::max), _ur(std::numeric_limits::min) {} + Box() + : _ll(std::numeric_limits::max(), std::numeric_limits::max()), + _ur(std::numeric_limits::min(), std::numeric_limits::min()) {} Box(const Point& ll, const Point& ur) : _ll(ll), _ur(ur) {} const Point& getLowerLeft() const { return _ll; } const Point& getUpperRight() const { return _ur; } + Point& getLowerLeft() { return _ll; } + Point& getUpperRight() { return _ur; } + void setLowerLeft(const Point& ll) { _ll = ll; } void setUpperRight(const Point& ur) { _ur = ur; } @@ -33,7 +38,7 @@ class Box { Point _ll, _ur; }; -} // namespace geon +} // namespace geo } // namespace util #endif // UTIL_GEO_BOX_H_ diff --git a/src/util/geo/Geo.h b/src/util/geo/Geo.h index f8ca8d7..27a1391 100644 --- a/src/util/geo/Geo.h +++ b/src/util/geo/Geo.h @@ -7,43 +7,28 @@ #define _USE_MATH_DEFINES #include -#include -#include #include "util/Misc.h" +#include "util/geo/Box.h" +#include "util/geo/Line.h" +#include "util/geo/Point.h" // ------------------- // Geometry stuff // ------------------ -namespace bgeo = boost::geometry; - namespace util { namespace geo { -template -using Point = bgeo::model::point; - -template -using Line = bgeo::model::linestring>; - -template -using MultiLine = bgeo::model::multi_linestring>; - -template -using Polygon = bgeo::model::polygon>; - -template -using MultiPolygon = bgeo::model::multi_polygon>; - -template -using Box = bgeo::model::box>; - // convenience aliases typedef Point DPoint; typedef Point FPoint; typedef Point IPoint; +typedef LineSegment DLineSegment; +typedef LineSegment FLineSegment; +typedef LineSegment ILineSegment; + typedef Line DLine; typedef Line FLine; typedef Line ILine; @@ -52,197 +37,232 @@ typedef Box DBox; typedef Box FBox; typedef Box IBox; -typedef Polygon DPolygon; -typedef Polygon FPolygon; -typedef Polygon IPolygon; +const static double EPSILON = 0.0000001; + +// typedef Polygon DPolygon; +// typedef Polygon FPolygon; +// typedef Polygon IPolygon; // _____________________________________________________________________________ -template -inline Line rotate(const Line& geo, double deg, const Point& center) { - Line ret; +// template +// inline Line rotate(const Line& geo, double deg, const Point& center) +// { +// Line ret; - bgeo::strategy::transform::translate_transformer translate( - -center.template get<0>(), -center.template get<1>()); - bgeo::strategy::transform::rotate_transformer rotate( - deg); - bgeo::strategy::transform::translate_transformer translateBack( - center.template get<0>(), center.template get<1>()); +// bgeo::strategy::transform::translate_transformer translate( +// -center.getX(), -center.getY()); +// bgeo::strategy::transform::rotate_transformer rotate( +// deg); +// bgeo::strategy::transform::translate_transformer translateBack( +// center.getX(), center.getY()); - bgeo::strategy::transform::ublas_transformer translateRotate( - prod(rotate.matrix(), translate.matrix())); - bgeo::strategy::transform::ublas_transformer all( - prod(translateBack.matrix(), translateRotate.matrix())); +// bgeo::strategy::transform::ublas_transformer translateRotate( +// prod(rotate.matrix(), translate.matrix())); +// bgeo::strategy::transform::ublas_transformer all( +// prod(translateBack.matrix(), translateRotate.matrix())); - bgeo::transform(geo, ret, all); +// bgeo::transform(geo, ret, all); - return ret; -} +// return ret; +// } // _____________________________________________________________________________ -template -inline MultiLine rotate(const MultiLine& geo, double deg, - const Point& center) { - MultiLine ret; +// template +// inline MultiLine rotate(const MultiLine& geo, double deg, +// const Point& center) { +// MultiLine ret; - bgeo::strategy::transform::translate_transformer translate( - -center.template get<0>(), -center.template get<1>()); - bgeo::strategy::transform::rotate_transformer rotate( - deg); - bgeo::strategy::transform::translate_transformer translateBack( - center.template get<0>(), center.template get<1>()); +// bgeo::strategy::transform::translate_transformer translate( +// -center.getX(), -center.getY()); +// bgeo::strategy::transform::rotate_transformer rotate( +// deg); +// bgeo::strategy::transform::translate_transformer translateBack( +// center.getX(), center.getY()); - bgeo::strategy::transform::ublas_transformer translateRotate( - prod(rotate.matrix(), translate.matrix())); - bgeo::strategy::transform::ublas_transformer all( - prod(translateBack.matrix(), translateRotate.matrix())); +// bgeo::strategy::transform::ublas_transformer translateRotate( +// prod(rotate.matrix(), translate.matrix())); +// bgeo::strategy::transform::ublas_transformer all( +// prod(translateBack.matrix(), translateRotate.matrix())); - bgeo::transform(geo, ret, all); +// bgeo::transform(geo, ret, all); - return ret; -} +// return ret; +// } // _____________________________________________________________________________ template inline Box pad(const Box& box, double padding) { - return Box(Point(box.min_corner().template get<0>() - padding, - box.min_corner().template get<1>() - padding), - Point(box.max_corner().template get<0>() + padding, - box.max_corner().template get<1>() + padding)); + return Box(Point(box.getLowerLeft().getX() - padding, + box.getLowerLeft().getY() - padding), + Point(box.getUpperRight().getX() + padding, + box.getUpperRight().getY() + padding)); } // _____________________________________________________________________________ template -inline Line rotate(const Line& geo, double deg) { - Point center; - bgeo::centroid(geo, center); - return rotate(geo, deg, center); +inline Point rotate(const Point& p, double deg) { + return p; } +// _____________________________________________________________________________ +// template +// inline Line rotate(const Line& geo, double deg) { +// Point center; +// bgeo::centroid(geo, center); +// return rotate(geo, deg, center); +// } + +// _____________________________________________________________________________ +// template +// inline MultiLine rotate(const MultiLine& geo, double deg) { +// Point center; +// bgeo::centroid(geo, center); +// return rotate(geo, deg, center); +// } + // _____________________________________________________________________________ template -inline MultiLine rotate(const MultiLine& geo, double deg) { - Point center; - bgeo::centroid(geo, center); - return rotate(geo, deg, center); -} - -// _____________________________________________________________________________ -template