Merge pull request #2 from XDrake99/tree-structure-with-root
Merge Tree structure with root
This commit is contained in:
commit
bce8865662
20
.classpath
20
.classpath
@ -3,29 +3,29 @@
|
||||
<classpathentry excluding="org/warp/picalculator/deprecatedmath/" kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="src" path="res"/>
|
||||
<classpathentry kind="lib" path="D:/Users/Andrea/Downloads/objenesis-2.4-bin/objenesis-2.4/objenesis-2.4.jar" sourcepath="D:/Users/Andrea/Downloads/objenesis-2.4-bin/objenesis-2.4/objenesis-2.4-sources.jar">
|
||||
<classpathentry kind="lib" path="libs/pi4j-1.1/pi4j-core.jar" sourcepath="libs/pi4j-1.1/pi4j-core-sources.jar">
|
||||
<attributes>
|
||||
<attribute name="javadoc_location" value="jar:file:/D:/Users/Andrea/Downloads/objenesis-2.4-bin/objenesis-2.4/objenesis-2.4-javadoc.jar!/"/>
|
||||
<attribute name="javadoc_location" value="jar:platform:/resource/PICalculator/libs/pi4j-1.1/pi4j-core-javadoc.jar!/"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="lib" path="G:/Users/Andrea/Downloads/pi4j-1.1/pi4j-1.1/lib/pi4j-core.jar" sourcepath="G:/Users/Andrea/Downloads/pi4j-1.1/pi4j-1.1/lib/pi4j-core-sources.jar">
|
||||
<classpathentry kind="lib" path="libs/pi4j-1.1/pi4j-device.jar" sourcepath="libs/pi4j-1.1/pi4j-device-sources.jar">
|
||||
<attributes>
|
||||
<attribute name="javadoc_location" value="jar:file:/G:/Users/Andrea/Downloads/pi4j-1.1/pi4j-1.1/lib/pi4j-core-javadoc.jar!/"/>
|
||||
<attribute name="javadoc_location" value="jar:platform:/resource/PICalculator/libs/pi4j-1.1/pi4j-device-javadoc.jar!/"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="lib" path="G:/Users/Andrea/Downloads/pi4j-1.1/pi4j-1.1/lib/pi4j-device.jar" sourcepath="G:/Users/Andrea/Downloads/pi4j-1.1/pi4j-1.1/lib/pi4j-device-sources.jar">
|
||||
<classpathentry kind="lib" path="libs/pi4j-1.1/pi4j-gpio-extension.jar" sourcepath="libs/pi4j-1.1/pi4j-gpio-extension-sources.jar">
|
||||
<attributes>
|
||||
<attribute name="javadoc_location" value="jar:file:/G:/Users/Andrea/Downloads/pi4j-1.1/pi4j-1.1/lib/pi4j-device-javadoc.jar!/"/>
|
||||
<attribute name="javadoc_location" value="jar:platform:/resource/PICalculator/libs/pi4j-1.1/pi4j-gpio-extension-javadoc.jar!/"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="lib" path="G:/Users/Andrea/Downloads/pi4j-1.1/pi4j-1.1/lib/pi4j-gpio-extension.jar" sourcepath="G:/Users/Andrea/Downloads/pi4j-1.1/pi4j-1.1/lib/pi4j-gpio-extension-sources.jar">
|
||||
<classpathentry kind="lib" path="libs/pi4j-1.1/pi4j-service.jar" sourcepath="libs/pi4j-1.1/pi4j-service-sources.jar">
|
||||
<attributes>
|
||||
<attribute name="javadoc_location" value="jar:file:/G:/Users/Andrea/Downloads/pi4j-1.1/pi4j-1.1/lib/pi4j-gpio-extension-javadoc.jar!/"/>
|
||||
<attribute name="javadoc_location" value="jar:platform:/resource/PICalculator/libs/pi4j-1.1/pi4j-service-javadoc.jar!/"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="lib" path="G:/Users/Andrea/Downloads/pi4j-1.1/pi4j-1.1/lib/pi4j-service.jar" sourcepath="G:/Users/Andrea/Downloads/pi4j-1.1/pi4j-1.1/lib/pi4j-service-sources.jar">
|
||||
<classpathentry kind="lib" path="libs/objenesis-2.4/objenesis-2.4.jar" sourcepath="libs/objenesis-2.4/objenesis-2.4-sources.jar">
|
||||
<attributes>
|
||||
<attribute name="javadoc_location" value="jar:file:/G:/Users/Andrea/Downloads/pi4j-1.1/pi4j-1.1/lib/pi4j-service-javadoc.jar!/"/>
|
||||
<attribute name="javadoc_location" value="jar:platform:/resource/PICalculator/libs/objenesis-2.4/objenesis-2.4-javadoc.jar!/"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
|
Binary file not shown.
29
libs/lwjgl/LICENSE
Normal file
29
libs/lwjgl/LICENSE
Normal file
@ -0,0 +1,29 @@
|
||||
Copyright (c) 2012-present Lightweight Java Game Library
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
- Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
- Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
- Neither the name Lightweight Java Game Library nor the names of
|
||||
its contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
1
libs/lwjgl/build.txt
Normal file
1
libs/lwjgl/build.txt
Normal file
@ -0,0 +1 @@
|
||||
LWJGL 3.1.1 build 16
|
14
libs/lwjgl/dyncall_license.txt
Normal file
14
libs/lwjgl/dyncall_license.txt
Normal file
@ -0,0 +1,14 @@
|
||||
Copyright (c) 2007-2015 Daniel Adler <dadler AT uni-goettingen DOT de>,
|
||||
Tassilo Philipp <tphilipp AT potion-studios DOT com>
|
||||
|
||||
Permission to use, copy, modify, and distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
21
libs/lwjgl/glfw_license.txt
Normal file
21
libs/lwjgl/glfw_license.txt
Normal file
@ -0,0 +1,21 @@
|
||||
Copyright (c) 2002-2006 Marcus Geelnard
|
||||
Copyright (c) 2006-2010 Camilla Berglund <elmindreda@elmindreda.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would
|
||||
be appreciated but is not required.
|
||||
|
||||
2. Altered source versions must be plainly marked as such, and must not
|
||||
be misrepresented as being the original software.
|
||||
|
||||
3. This notice may not be removed or altered from any source
|
||||
distribution.
|
23
libs/lwjgl/jemalloc_license.txt
Normal file
23
libs/lwjgl/jemalloc_license.txt
Normal file
@ -0,0 +1,23 @@
|
||||
Copyright (C) 2002-2014 Jason Evans <jasone@canonware.com>.
|
||||
All rights reserved.
|
||||
Copyright (C) 2007-2012 Mozilla Foundation. All rights reserved.
|
||||
Copyright (C) 2009-2014 Facebook, Inc. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
1. Redistributions of source code must retain the above copyright notice(s),
|
||||
this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice(s),
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY EXPRESS
|
||||
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
22
libs/lwjgl/khronos_license.txt
Normal file
22
libs/lwjgl/khronos_license.txt
Normal file
@ -0,0 +1,22 @@
|
||||
/*
|
||||
** Copyright (c) 2013-2014 The Khronos Group Inc.
|
||||
**
|
||||
** Permission is hereby granted, free of charge, to any person obtaining a
|
||||
** copy of this software and/or associated documentation files (the
|
||||
** "Materials"), to deal in the Materials without restriction, including
|
||||
** without limitation the rights to use, copy, modify, merge, publish,
|
||||
** distribute, sublicense, and/or sell copies of the Materials, and to
|
||||
** permit persons to whom the Materials are furnished to do so, subject to
|
||||
** the following conditions:
|
||||
**
|
||||
** The above copyright notice and this permission notice shall be included
|
||||
** in all copies or substantial portions of the Materials.
|
||||
**
|
||||
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
|
||||
*/
|
202
libs/objenesis-2.4/LICENSE
Normal file
202
libs/objenesis-2.4/LICENSE
Normal file
@ -0,0 +1,202 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
9
libs/objenesis-2.4/NOTICE
Normal file
9
libs/objenesis-2.4/NOTICE
Normal file
@ -0,0 +1,9 @@
|
||||
// ------------------------------------------------------------------
|
||||
// NOTICE file corresponding to the section 4d of The Apache License,
|
||||
// Version 2.0, in this case for Objenesis
|
||||
// ------------------------------------------------------------------
|
||||
|
||||
Objenesis
|
||||
Copyright 2006-2016 Joe Walnes, Henri Tremblay, Leonardo Mesquita
|
||||
|
||||
|
165
libs/pi4j-1.1/LICENSE.txt
Normal file
165
libs/pi4j-1.1/LICENSE.txt
Normal file
@ -0,0 +1,165 @@
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
|
||||
This version of the GNU Lesser General Public License incorporates
|
||||
the terms and conditions of version 3 of the GNU General Public
|
||||
License, supplemented by the additional permissions listed below.
|
||||
|
||||
0. Additional Definitions.
|
||||
|
||||
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||
General Public License.
|
||||
|
||||
"The Library" refers to a covered work governed by this License,
|
||||
other than an Application or a Combined Work as defined below.
|
||||
|
||||
An "Application" is any work that makes use of an interface provided
|
||||
by the Library, but which is not otherwise based on the Library.
|
||||
Defining a subclass of a class defined by the Library is deemed a mode
|
||||
of using an interface provided by the Library.
|
||||
|
||||
A "Combined Work" is a work produced by combining or linking an
|
||||
Application with the Library. The particular version of the Library
|
||||
with which the Combined Work was made is also called the "Linked
|
||||
Version".
|
||||
|
||||
The "Minimal Corresponding Source" for a Combined Work means the
|
||||
Corresponding Source for the Combined Work, excluding any source code
|
||||
for portions of the Combined Work that, considered in isolation, are
|
||||
based on the Application, and not on the Linked Version.
|
||||
|
||||
The "Corresponding Application Code" for a Combined Work means the
|
||||
object code and/or source code for the Application, including any data
|
||||
and utility programs needed for reproducing the Combined Work from the
|
||||
Application, but excluding the System Libraries of the Combined Work.
|
||||
|
||||
1. Exception to Section 3 of the GNU GPL.
|
||||
|
||||
You may convey a covered work under sections 3 and 4 of this License
|
||||
without being bound by section 3 of the GNU GPL.
|
||||
|
||||
2. Conveying Modified Versions.
|
||||
|
||||
If you modify a copy of the Library, and, in your modifications, a
|
||||
facility refers to a function or data to be supplied by an Application
|
||||
that uses the facility (other than as an argument passed when the
|
||||
facility is invoked), then you may convey a copy of the modified
|
||||
version:
|
||||
|
||||
a) under this License, provided that you make a good faith effort to
|
||||
ensure that, in the event an Application does not supply the
|
||||
function or data, the facility still operates, and performs
|
||||
whatever part of its purpose remains meaningful, or
|
||||
|
||||
b) under the GNU GPL, with none of the additional permissions of
|
||||
this License applicable to that copy.
|
||||
|
||||
3. Object Code Incorporating Material from Library Header Files.
|
||||
|
||||
The object code form of an Application may incorporate material from
|
||||
a header file that is part of the Library. You may convey such object
|
||||
code under terms of your choice, provided that, if the incorporated
|
||||
material is not limited to numerical parameters, data structure
|
||||
layouts and accessors, or small macros, inline functions and templates
|
||||
(ten or fewer lines in length), you do both of the following:
|
||||
|
||||
a) Give prominent notice with each copy of the object code that the
|
||||
Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the object code with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
4. Combined Works.
|
||||
|
||||
You may convey a Combined Work under terms of your choice that,
|
||||
taken together, effectively do not restrict modification of the
|
||||
portions of the Library contained in the Combined Work and reverse
|
||||
engineering for debugging such modifications, if you also do each of
|
||||
the following:
|
||||
|
||||
a) Give prominent notice with each copy of the Combined Work that
|
||||
the Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
c) For a Combined Work that displays copyright notices during
|
||||
execution, include the copyright notice for the Library among
|
||||
these notices, as well as a reference directing the user to the
|
||||
copies of the GNU GPL and this license document.
|
||||
|
||||
d) Do one of the following:
|
||||
|
||||
0) Convey the Minimal Corresponding Source under the terms of this
|
||||
License, and the Corresponding Application Code in a form
|
||||
suitable for, and under terms that permit, the user to
|
||||
recombine or relink the Application with a modified version of
|
||||
the Linked Version to produce a modified Combined Work, in the
|
||||
manner specified by section 6 of the GNU GPL for conveying
|
||||
Corresponding Source.
|
||||
|
||||
1) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (a) uses at run time
|
||||
a copy of the Library already present on the user's computer
|
||||
system, and (b) will operate properly with a modified version
|
||||
of the Library that is interface-compatible with the Linked
|
||||
Version.
|
||||
|
||||
e) Provide Installation Information, but only if you would otherwise
|
||||
be required to provide such information under section 6 of the
|
||||
GNU GPL, and only to the extent that such information is
|
||||
necessary to install and execute a modified version of the
|
||||
Combined Work produced by recombining or relinking the
|
||||
Application with a modified version of the Linked Version. (If
|
||||
you use option 4d0, the Installation Information must accompany
|
||||
the Minimal Corresponding Source and Corresponding Application
|
||||
Code. If you use option 4d1, you must provide the Installation
|
||||
Information in the manner specified by section 6 of the GNU GPL
|
||||
for conveying Corresponding Source.)
|
||||
|
||||
5. Combined Libraries.
|
||||
|
||||
You may place library facilities that are a work based on the
|
||||
Library side by side in a single library together with other library
|
||||
facilities that are not Applications and are not covered by this
|
||||
License, and convey such a combined library under terms of your
|
||||
choice, if you do both of the following:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work based
|
||||
on the Library, uncombined with any other library facilities,
|
||||
conveyed under the terms of this License.
|
||||
|
||||
b) Give prominent notice with the combined library that part of it
|
||||
is a work based on the Library, and explaining where to find the
|
||||
accompanying uncombined form of the same work.
|
||||
|
||||
6. Revised Versions of the GNU Lesser General Public License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions
|
||||
of the GNU Lesser 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
|
||||
Library as you received it specifies that a certain numbered version
|
||||
of the GNU Lesser General Public License "or any later version"
|
||||
applies to it, you have the option of following the terms and
|
||||
conditions either of that published version or of any later version
|
||||
published by the Free Software Foundation. If the Library as you
|
||||
received it does not specify a version number of the GNU Lesser
|
||||
General Public License, you may choose any version of the GNU Lesser
|
||||
General Public License ever published by the Free Software Foundation.
|
||||
|
||||
If the Library as you received it specifies that a proxy can decide
|
||||
whether future versions of the GNU Lesser General Public License shall
|
||||
apply, that proxy's public statement of acceptance of any version is
|
||||
permanent authorization for you to choose that version for the
|
||||
Library.
|
33
libs/pi4j-1.1/NOTICE.txt
Normal file
33
libs/pi4j-1.1/NOTICE.txt
Normal file
@ -0,0 +1,33 @@
|
||||
=========================================================================
|
||||
Pi4J :: Java library for Raspberry Pi
|
||||
=========================================================================
|
||||
|
||||
Pi4J Library
|
||||
Copyright (C) 2012-2016 Pi4J.com
|
||||
|
||||
This product includes software developed at:
|
||||
The Pi4J Project (http://www.pi4j.com/).
|
||||
|
||||
This product was originally authored by: Robert Savage
|
||||
|
||||
This software is licensed under the GNU LGPLv3 license.
|
||||
More information about licensing terms can be found at:
|
||||
http://pi4j.com/license.html
|
||||
|
||||
Additional information about this project and its authors can be found at:
|
||||
- http://www.pi4j.com/
|
||||
- http://www.raspicentral.com
|
||||
- http://www.savagehomeautomation.com
|
||||
|
||||
This software compiles against libraries from the WiringPi project.
|
||||
The Wiring Pi project is provided by Gordon Henderson and is available
|
||||
from
|
||||
http://wiringpi.com/
|
||||
|
||||
The WiringPi project is licensed under the GNU LGPLv3 license
|
||||
http://www.gnu.org/licenses/lgpl.html
|
||||
|
||||
=========================================================================
|
||||
Subject to the terms of the software license, this NOTICE file must be
|
||||
included in any Derivative Works that You distribute as a readable copy.
|
||||
(Section 4d)
|
BIN
res/font_ex.rft
BIN
res/font_ex.rft
Binary file not shown.
@ -34,12 +34,12 @@ import java.util.regex.Pattern;
|
||||
*/
|
||||
public class Cloner {
|
||||
private final IInstantiationStrategy instantiationStrategy;
|
||||
private final Set<Class<?>> ignored = new HashSet<Class<?>>();
|
||||
private final Set<Class<?>> ignoredInstanceOf = new HashSet<Class<?>>();
|
||||
private final Set<Class<?>> nullInstead = new HashSet<Class<?>>();
|
||||
private final Map<Class<?>, IFastCloner> fastCloners = new HashMap<Class<?>, IFastCloner>();
|
||||
private final Map<Object, Boolean> ignoredInstances = new IdentityHashMap<Object, Boolean>();
|
||||
private final ConcurrentHashMap<Class<?>, List<Field>> fieldsCache = new ConcurrentHashMap<Class<?>, List<Field>>();
|
||||
private final Set<Class<?>> ignored = new HashSet<>();
|
||||
private final Set<Class<?>> ignoredInstanceOf = new HashSet<>();
|
||||
private final Set<Class<?>> nullInstead = new HashSet<>();
|
||||
private final Map<Class<?>, IFastCloner> fastCloners = new HashMap<>();
|
||||
private final Map<Object, Boolean> ignoredInstances = new IdentityHashMap<>();
|
||||
private final ConcurrentHashMap<Class<?>, List<Field>> fieldsCache = new ConcurrentHashMap<>();
|
||||
|
||||
public IDumpCloned getDumpCloned() {
|
||||
return dumpCloned;
|
||||
@ -333,7 +333,7 @@ public class Cloner {
|
||||
if (dumpCloned != null) {
|
||||
dumpCloned.startCloning(o.getClass());
|
||||
}
|
||||
final Map<Object, Object> clones = new IdentityHashMap<Object, Object>(16);
|
||||
final Map<Object, Object> clones = new IdentityHashMap<>(16);
|
||||
try {
|
||||
return cloneInternal(o, clones);
|
||||
} catch (final IllegalAccessException e) {
|
||||
@ -349,7 +349,7 @@ public class Cloner {
|
||||
if (dumpCloned != null) {
|
||||
dumpCloned.startCloning(o.getClass());
|
||||
}
|
||||
final Map<Object, Object> clones = new IdentityHashMap<Object, Object>(16);
|
||||
final Map<Object, Object> clones = new IdentityHashMap<>(16);
|
||||
for (final Object dc : dontCloneThese) {
|
||||
clones.put(dc, dc);
|
||||
}
|
||||
@ -383,7 +383,7 @@ public class Cloner {
|
||||
}
|
||||
|
||||
// caches immutables for quick reference
|
||||
private final ConcurrentHashMap<Class<?>, Boolean> immutables = new ConcurrentHashMap<Class<?>, Boolean>();
|
||||
private final ConcurrentHashMap<Class<?>, Boolean> immutables = new ConcurrentHashMap<>();
|
||||
private boolean cloneAnonymousParent = true;
|
||||
|
||||
/**
|
||||
@ -602,7 +602,7 @@ public class Cloner {
|
||||
protected List<Field> allFields(final Class<?> c) {
|
||||
List<Field> l = fieldsCache.get(c);
|
||||
if (l == null) {
|
||||
l = new LinkedList<Field>();
|
||||
l = new LinkedList<>();
|
||||
final Field[] fields = c.getDeclaredFields();
|
||||
addAll(l, fields);
|
||||
Class<?> sc = c;
|
||||
|
@ -15,7 +15,7 @@ public class Bernoulli {
|
||||
/*
|
||||
* The list of all Bernoulli numbers as a vector, n=0,2,4,....
|
||||
*/
|
||||
static Vector<Rational> a = new Vector<Rational>();
|
||||
static Vector<Rational> a = new Vector<>();
|
||||
|
||||
public Bernoulli() {
|
||||
if (a.size() == 0) {
|
||||
|
@ -28,7 +28,7 @@ public class BigIntegerPoly implements Cloneable {
|
||||
* Creates the polynomial p(x)=0.
|
||||
*/
|
||||
public BigIntegerPoly() {
|
||||
a = new Vector<BigInteger>();
|
||||
a = new Vector<>();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -38,7 +38,7 @@ public class BigIntegerPoly implements Cloneable {
|
||||
* the string of the form a0,a1,a2,a3 with the coefficients
|
||||
*/
|
||||
public BigIntegerPoly(final String L) throws NumberFormatException {
|
||||
a = new Vector<BigInteger>();
|
||||
a = new Vector<>();
|
||||
Scanner sc = new Scanner(L);
|
||||
sc.useDelimiter(",");
|
||||
while (sc.hasNextBigInteger())
|
||||
@ -537,7 +537,7 @@ public class BigIntegerPoly implements Cloneable {
|
||||
*/
|
||||
public Vector<BigInteger> iroots() {
|
||||
/* The vector of the roots */
|
||||
Vector<BigInteger> res = new Vector<BigInteger>();
|
||||
Vector<BigInteger> res = new Vector<>();
|
||||
|
||||
/*
|
||||
* collect the zero
|
||||
@ -581,7 +581,7 @@ public class BigIntegerPoly implements Cloneable {
|
||||
/*
|
||||
* The vector of the factors to be returned
|
||||
*/
|
||||
Vector<BigIntegerPoly> res = new Vector<BigIntegerPoly>();
|
||||
Vector<BigIntegerPoly> res = new Vector<>();
|
||||
|
||||
if (degree() < 2)
|
||||
return res;
|
||||
@ -679,7 +679,7 @@ public class BigIntegerPoly implements Cloneable {
|
||||
/*
|
||||
* this ought be entirely rewritten in terms of the LLL algorithm
|
||||
*/
|
||||
Vector<BigIntegerPoly> fac = new Vector<BigIntegerPoly>();
|
||||
Vector<BigIntegerPoly> fac = new Vector<>();
|
||||
|
||||
/* collect integer roots (polynomial factors of degree 1) */
|
||||
Vector<BigInteger> r = iroots();
|
||||
|
@ -39,7 +39,7 @@ public class BigSurdVec implements Comparable<BigSurdVec> {
|
||||
* @since 2012-02-15
|
||||
*/
|
||||
public BigSurdVec() {
|
||||
terms = new Vector<BigSurd>();
|
||||
terms = new Vector<>();
|
||||
} /* ctor */
|
||||
|
||||
/**
|
||||
@ -50,7 +50,7 @@ public class BigSurdVec implements Comparable<BigSurdVec> {
|
||||
* @since 2012-02-15
|
||||
*/
|
||||
public BigSurdVec(BigSurd a) {
|
||||
terms = new Vector<BigSurd>(1);
|
||||
terms = new Vector<>(1);
|
||||
terms.add(a);
|
||||
} /* ctor */
|
||||
|
||||
@ -64,7 +64,7 @@ public class BigSurdVec implements Comparable<BigSurdVec> {
|
||||
* @since 2012-02-15
|
||||
*/
|
||||
public BigSurdVec(BigSurd a, BigSurd b) {
|
||||
terms = new Vector<BigSurd>(2);
|
||||
terms = new Vector<>(2);
|
||||
terms.add(a);
|
||||
terms.add(b);
|
||||
try {
|
||||
@ -90,7 +90,7 @@ public class BigSurdVec implements Comparable<BigSurdVec> {
|
||||
if (terms.size() <= 1)
|
||||
return;
|
||||
|
||||
Vector<BigSurd> newter = new Vector<BigSurd>();
|
||||
Vector<BigSurd> newter = new Vector<>();
|
||||
newter.add(terms.firstElement());
|
||||
/*
|
||||
* add j-th element to the existing vector and combine were possible
|
||||
|
@ -14,7 +14,7 @@ public class Euler {
|
||||
/*
|
||||
* The list of all Euler numbers as a vector, n=0,2,4,....
|
||||
*/
|
||||
static protected Vector<BigInteger> a = new Vector<BigInteger>();
|
||||
static protected Vector<BigInteger> a = new Vector<>();
|
||||
|
||||
/**
|
||||
* Ctor(). Fill the hash list initially with E_0 to E_3.
|
||||
|
@ -14,7 +14,7 @@ public class Factorial {
|
||||
/**
|
||||
* The list of all factorials as a vector.
|
||||
*/
|
||||
static Vector<Ifactor> a = new Vector<Ifactor>();
|
||||
static Vector<Ifactor> a = new Vector<>();
|
||||
|
||||
/**
|
||||
* ctor().
|
||||
|
@ -45,7 +45,7 @@ public class Ifactor implements Cloneable, Comparable<Ifactor> {
|
||||
*/
|
||||
public Ifactor(int number) {
|
||||
n = new BigInteger("" + number);
|
||||
primeexp = new Vector<Integer>();
|
||||
primeexp = new Vector<>();
|
||||
if (number > 1) {
|
||||
int primindx = 0;
|
||||
Prime primes = new Prime();
|
||||
@ -86,7 +86,7 @@ public class Ifactor implements Cloneable, Comparable<Ifactor> {
|
||||
*/
|
||||
public Ifactor(BigInteger number) {
|
||||
n = number;
|
||||
primeexp = new Vector<Integer>();
|
||||
primeexp = new Vector<>();
|
||||
if (number.compareTo(BigInteger.ONE) == 0) {
|
||||
primeexp.add(new Integer(1));
|
||||
primeexp.add(new Integer(0));
|
||||
@ -125,7 +125,7 @@ public class Ifactor implements Cloneable, Comparable<Ifactor> {
|
||||
* continuous prime-smooth basis.
|
||||
*/
|
||||
public Ifactor(Vector<Integer> pows) {
|
||||
primeexp = new Vector<Integer>(2 * pows.size());
|
||||
primeexp = new Vector<>(2 * pows.size());
|
||||
if (pows.size() > 0) {
|
||||
n = BigInteger.ONE;
|
||||
Prime primes = new Prime();
|
||||
@ -512,7 +512,7 @@ public class Ifactor implements Cloneable, Comparable<Ifactor> {
|
||||
* multiplied
|
||||
* by 1 or by a product that contains the factors p1..py.
|
||||
*/
|
||||
Vector<BigInteger> d = new Vector<BigInteger>();
|
||||
Vector<BigInteger> d = new Vector<>();
|
||||
if (n.compareTo(BigInteger.ZERO) == 0)
|
||||
return d;
|
||||
d.add(BigInteger.ONE);
|
||||
|
@ -13,7 +13,7 @@ public class PartitionsP {
|
||||
/**
|
||||
* The list of all partitions as a vector.
|
||||
*/
|
||||
static protected Vector<BigInteger> a = new Vector<BigInteger>();
|
||||
static protected Vector<BigInteger> a = new Vector<>();
|
||||
|
||||
/**
|
||||
* The maximum integer covered by the high end of the list.
|
||||
|
@ -21,7 +21,7 @@ public class Prime {
|
||||
/**
|
||||
* The list of all numbers as a vector.
|
||||
*/
|
||||
static Vector<BigInteger> a = new Vector<BigInteger>();
|
||||
static Vector<BigInteger> a = new Vector<>();
|
||||
|
||||
/**
|
||||
* The maximum integer covered by the high end of the list.
|
||||
|
@ -31,7 +31,7 @@ class RatPoly {
|
||||
* Initializes the zero-valued polynomial x=0.
|
||||
*/
|
||||
public RatPoly() {
|
||||
a = new Vector<Rational>();
|
||||
a = new Vector<>();
|
||||
} /* ctor */
|
||||
|
||||
/**
|
||||
@ -42,7 +42,7 @@ class RatPoly {
|
||||
* is created.
|
||||
*/
|
||||
public RatPoly(final Vector<Rational> L) {
|
||||
a = new Vector<Rational>();
|
||||
a = new Vector<>();
|
||||
for (int i = 0; i < L.size(); i++)
|
||||
a.add(L.elementAt(i).clone());
|
||||
simplify();
|
||||
@ -55,7 +55,7 @@ class RatPoly {
|
||||
* the string of the form a0,a1,a2,a3 with the coefficients
|
||||
*/
|
||||
public RatPoly(final String L) throws NumberFormatException {
|
||||
a = new Vector<Rational>();
|
||||
a = new Vector<>();
|
||||
Scanner sc = new Scanner(L);
|
||||
sc.useDelimiter(",");
|
||||
while (sc.hasNext()) {
|
||||
@ -129,7 +129,7 @@ class RatPoly {
|
||||
* @since 2008-11-13
|
||||
*/
|
||||
protected void init(final Vector<BigInteger> A, final Vector<BigInteger> B, int nmax) throws Error {
|
||||
a = new Vector<Rational>();
|
||||
a = new Vector<>();
|
||||
Factorial f = new Factorial();
|
||||
for (int n = 0; n <= nmax; n++) {
|
||||
Rational c = new Rational(1, 1);
|
||||
@ -888,7 +888,7 @@ class RatPoly {
|
||||
Random rand = new Random();
|
||||
MathContext mc = new MathContext(digits + 3, RoundingMode.DOWN);
|
||||
|
||||
Vector<BigComplex> res = new Vector<BigComplex>();
|
||||
Vector<BigComplex> res = new Vector<>();
|
||||
|
||||
final int d = mon.degree();
|
||||
double randRad = 0.;
|
||||
@ -918,7 +918,7 @@ class RatPoly {
|
||||
for (; !convr;)// ORIGINAL LINE: for(int itr =0 ; ! convr ; itr++)
|
||||
{
|
||||
convr = true;
|
||||
Vector<BigComplex> resPlus = new Vector<BigComplex>();
|
||||
Vector<BigComplex> resPlus = new Vector<>();
|
||||
for (int v = 0; v < d; v++) {
|
||||
/*
|
||||
* evaluate f(x)/(x-root1)/(x-root2)/... (x-rootdegr), Newton
|
||||
@ -959,7 +959,7 @@ class RatPoly {
|
||||
*/
|
||||
public Vector<BigInteger> iroots() {
|
||||
/* The vector of the roots */
|
||||
Vector<BigInteger> res = new Vector<BigInteger>();
|
||||
Vector<BigInteger> res = new Vector<>();
|
||||
|
||||
int lowd = ldegree();
|
||||
if (lowd == 0 && a.elementAt(0).compareTo(BigInteger.ZERO) == 0) {
|
||||
@ -984,7 +984,7 @@ class RatPoly {
|
||||
* and eventually get the integer polynomial by ignoring the
|
||||
* denominators
|
||||
*/
|
||||
Vector<BigInteger> ipo = new Vector<BigInteger>();
|
||||
Vector<BigInteger> ipo = new Vector<>();
|
||||
for (int i = 0; i < a.size(); i++) {
|
||||
BigInteger d = a.elementAt(i).a.multiply(lcmDeno).divide(a.elementAt(i).b);
|
||||
ipo.add(d);
|
||||
|
@ -7,15 +7,17 @@ import org.warp.picalculator.screens.LoadingScreen;
|
||||
import com.pi4j.wiringpi.Gpio;
|
||||
|
||||
public class Main {
|
||||
public static int[] screenPos = new int[] { 55, 0 };
|
||||
public static int[] screenPos = new int[] { 0, 0 };
|
||||
public static final int[] screenSize = new int[] { 480, 320 };
|
||||
public static final int screenScale = 1;
|
||||
public static final boolean zoomed = true;
|
||||
public static Main instance;
|
||||
public static boolean haxMode = true;
|
||||
|
||||
public Main() throws InterruptedException {
|
||||
instance = this;
|
||||
Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
|
||||
Thread.currentThread().setName("Main thread");
|
||||
beforeStart();
|
||||
new PIDisplay(new LoadingScreen());
|
||||
Utils.debug.println("Shutdown...");
|
||||
@ -33,6 +35,7 @@ public class Main {
|
||||
screenPos = new int[]{0,0};
|
||||
Utils.debugOn = true;
|
||||
}
|
||||
Utils.debugThirdScreen = Utils.debugOn & false;
|
||||
PIDisplay.setBrightness(0.5f);
|
||||
}
|
||||
|
||||
|
@ -44,6 +44,7 @@ public class Utils {
|
||||
public static DebugStream debug = new DebugStream();
|
||||
|
||||
public static boolean debugOn;
|
||||
public static boolean debugThirdScreen;
|
||||
|
||||
public static Cloner cloner = new Cloner();
|
||||
|
||||
@ -486,4 +487,20 @@ public class Utils {
|
||||
public static boolean isIntegerValue(BigDecimal bd) {
|
||||
return bd.signum() == 0 || bd.scale() <= 0 || bd.stripTrailingZeros().scale() <= 0;
|
||||
}
|
||||
|
||||
public static <T> String arrayToString(T... data) {
|
||||
String sdata = "";
|
||||
for (T o : data) {
|
||||
sdata += ","+o.toString();
|
||||
}
|
||||
return sdata.substring(1);
|
||||
}
|
||||
|
||||
public static String arrayToString(boolean... data) {
|
||||
String sdata = "";
|
||||
for (boolean o : data) {
|
||||
sdata += (o)?1:0;
|
||||
}
|
||||
return sdata;
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,12 @@
|
||||
package org.warp.picalculator.device;
|
||||
|
||||
import java.awt.event.KeyEvent;
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.device.chip.ParallelToSerial;
|
||||
import org.warp.picalculator.device.chip.SerialToParallel;
|
||||
import org.warp.picalculator.device.graphicengine.Display;
|
||||
import org.warp.picalculator.device.graphicengine.Screen;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.screens.KeyboardDebugScreen;
|
||||
import org.warp.picalculator.screens.MarioScreen;
|
||||
|
||||
import com.pi4j.wiringpi.Gpio;
|
||||
@ -26,25 +27,40 @@ public class Keyboard {
|
||||
|
||||
private static volatile boolean[][] precedentStates = new boolean[8][8];
|
||||
public static volatile boolean[][] debugKeysDown = new boolean[8][8];
|
||||
public static volatile KeyEvent debugKeyEvent;
|
||||
|
||||
public static void startKeyboard() {
|
||||
if (Utils.debugOn == false) {
|
||||
Gpio.pinMode(CLK_INH_pin, Gpio.OUTPUT);
|
||||
Gpio.pinMode(RCK_pin, Gpio.OUTPUT);
|
||||
Gpio.pinMode(SER_pin, Gpio.OUTPUT);
|
||||
Gpio.pinMode(SH_LD_pin, Gpio.OUTPUT);
|
||||
Gpio.pinMode(SCK_and_CLK_pin, Gpio.OUTPUT);
|
||||
Gpio.pinMode(QH_pin, Gpio.INPUT);
|
||||
|
||||
Gpio.digitalWrite(CLK_INH_pin, false);
|
||||
Gpio.digitalWrite(RCK_pin, false);
|
||||
Gpio.digitalWrite(SER_pin, false);
|
||||
Gpio.digitalWrite(SH_LD_pin, false);
|
||||
Gpio.digitalWrite(SCK_and_CLK_pin, false);
|
||||
Gpio.digitalWrite(QH_pin, false);
|
||||
Thread kt = new Thread(()->{
|
||||
Thread kt = new Thread(()->{
|
||||
if (Utils.debugOn) {
|
||||
try {
|
||||
while(true) {
|
||||
if (debugKeyEvent != null) {
|
||||
debugKeyPressed(debugKeyEvent);
|
||||
debugKeyEvent = null;
|
||||
}
|
||||
Thread.sleep(50);
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
} else {
|
||||
Gpio.pinMode(CLK_INH_pin, Gpio.OUTPUT);
|
||||
Gpio.pinMode(RCK_pin, Gpio.OUTPUT);
|
||||
Gpio.pinMode(SER_pin, Gpio.OUTPUT);
|
||||
Gpio.pinMode(SH_LD_pin, Gpio.OUTPUT);
|
||||
Gpio.pinMode(SCK_and_CLK_pin, Gpio.OUTPUT);
|
||||
Gpio.pinMode(QH_pin, Gpio.INPUT);
|
||||
|
||||
Gpio.digitalWrite(CLK_INH_pin, false);
|
||||
Gpio.digitalWrite(RCK_pin, false);
|
||||
Gpio.digitalWrite(SER_pin, false);
|
||||
Gpio.digitalWrite(SH_LD_pin, false);
|
||||
Gpio.digitalWrite(SCK_and_CLK_pin, false);
|
||||
Gpio.digitalWrite(QH_pin, false);
|
||||
SerialToParallel chip1 = new SerialToParallel(RCK_pin, SCK_and_CLK_pin /*SCK*/, SER_pin);
|
||||
ParallelToSerial chip2 = new ParallelToSerial(SH_LD_pin, CLK_INH_pin, QH_pin, SCK_and_CLK_pin/*CLK*/);
|
||||
|
||||
KeyboardDebugScreen.log("Started keyboard system");
|
||||
|
||||
while(true) {
|
||||
boolean[] data;
|
||||
for (int col = 0; col < 8; col++) {
|
||||
@ -52,25 +68,306 @@ public class Keyboard {
|
||||
data[col] = true;
|
||||
chip1.write(data);
|
||||
|
||||
data = new boolean[8];
|
||||
data = chip2.read();
|
||||
KeyboardDebugScreen.ks[col] = data;
|
||||
|
||||
for (int row = 0; row < 8; row++) {
|
||||
if (data[row] == true && precedentStates[row][col] == false) {
|
||||
System.out.println("Pressed button at "+(row+1) +", "+(col+1));
|
||||
KeyboardDebugScreen.log("Pressed button at "+(row+1) +", "+(col+1));
|
||||
keyPressedRaw(row+1, col+1);
|
||||
} else if (data[row] == false && precedentStates[row][col] == true) {
|
||||
keyReleasedRaw(row+1, col+1);
|
||||
KeyboardDebugScreen.log("Released button at "+(row+1) +", "+(col+1));
|
||||
}
|
||||
precedentStates[row][col] = data[row];
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
kt.setName("Keyboard thread");
|
||||
kt.setPriority(Thread.MIN_PRIORITY);
|
||||
kt.setDaemon(true);
|
||||
kt.start();
|
||||
}
|
||||
});
|
||||
kt.setName("Keyboard thread");
|
||||
kt.setPriority(Thread.MIN_PRIORITY);
|
||||
kt.setDaemon(true);
|
||||
kt.start();
|
||||
}
|
||||
|
||||
private static void debugKeyPressed(KeyEvent arg0) {
|
||||
switch (arg0.getKeyCode()) {
|
||||
case KeyEvent.VK_ESCAPE:
|
||||
Keyboard.keyPressed(Key.POWER);
|
||||
break;
|
||||
case KeyEvent.VK_S:
|
||||
if (Keyboard.shift) {
|
||||
Keyboard.keyPressed(Key.ARCSINE);
|
||||
} else if (Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.SINE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_C:
|
||||
if (Keyboard.shift) {
|
||||
Keyboard.keyPressed(Key.ARCCOSINE);
|
||||
} else if (Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.COSINE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_T:
|
||||
if (Keyboard.shift) {
|
||||
Keyboard.keyPressed(Key.ARCTANGENT);
|
||||
} else if (Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.TANGENT);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_D:
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.debug_DEG);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_R:
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.debug_RAD);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_G:
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.debug_GRA);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_X:
|
||||
if (Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.LETTER_X);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_P:
|
||||
if (Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.PI);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_Y:
|
||||
if (Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.LETTER_Y);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_B:
|
||||
if (Keyboard.shift) {
|
||||
Keyboard.keyPressed(Key.BRIGHTNESS_CYCLE_REVERSE);
|
||||
} else if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.BRIGHTNESS_CYCLE);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_ENTER:
|
||||
if (Keyboard.shift) {
|
||||
Keyboard.keyPressed(Key.SIMPLIFY);
|
||||
} else if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.SOLVE);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
}
|
||||
int row = 2;
|
||||
int col = 1;
|
||||
Keyboard.debugKeysDown[row-1][col-1] = true;
|
||||
break;
|
||||
case KeyEvent.VK_1:
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.NUM1);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_2:
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.NUM2);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_3:
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.NUM3);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_4:
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.NUM4);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_5:
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.NUM5);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_6:
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.NUM6);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_7:
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.NUM7);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_8:
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.NUM8);
|
||||
} else if (Keyboard.shift) {
|
||||
Keyboard.keyPressed(Key.PARENTHESIS_OPEN);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_9:
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.NUM9);
|
||||
} else if (Keyboard.shift) {
|
||||
Keyboard.keyPressed(Key.PARENTHESIS_CLOSE);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_0:
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.NUM0);
|
||||
} else if (Keyboard.shift) {
|
||||
Keyboard.keyPressed(Key.EQUAL);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_ADD:
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.PLUS);
|
||||
} else if (Keyboard.shift) {
|
||||
Keyboard.keyPressed(Key.PLUS_MINUS);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_SUBTRACT:
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.MINUS);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_MULTIPLY:
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.MULTIPLY);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_DIVIDE:
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.DIVIDE);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_BACK_SPACE:
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.DELETE);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_DELETE:
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.RESET);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_LEFT:
|
||||
//LEFT
|
||||
row = 2;
|
||||
col = 3;
|
||||
Keyboard.debugKeysDown[row-1][col-1] = true;
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.LEFT);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_RIGHT:
|
||||
//RIGHT
|
||||
row = 2;
|
||||
col = 5;
|
||||
Keyboard.debugKeysDown[row-1][col-1] = true;
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.RIGHT);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_NUMPAD4:
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.HISTORY_BACK);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_NUMPAD6:
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.HISTORY_FORWARD);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_PERIOD:
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.DOT);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_SHIFT:
|
||||
Keyboard.keyPressed(Key.SHIFT);
|
||||
break;
|
||||
case KeyEvent.VK_A:
|
||||
Keyboard.keyPressed(Key.ALPHA);
|
||||
break;
|
||||
case KeyEvent.VK_NUMPAD1:
|
||||
Keyboard.keyPressed(Key.SQRT);
|
||||
break;
|
||||
case KeyEvent.VK_NUMPAD2:
|
||||
Keyboard.keyPressed(Key.ROOT);
|
||||
break;
|
||||
case KeyEvent.VK_NUMPAD3:
|
||||
Keyboard.keyPressed(Key.POWER_OF_2);
|
||||
break;
|
||||
case KeyEvent.VK_NUMPAD5:
|
||||
Keyboard.keyPressed(Key.POWER_OF_x);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -83,12 +380,16 @@ public class Keyboard {
|
||||
}
|
||||
|
||||
private static void keyReleasedRaw(int row, int col) {
|
||||
KeyboardDebugScreen.keyX = row;
|
||||
KeyboardDebugScreen.keyY = col;
|
||||
if (row == 1 && col == 1) {
|
||||
keyReleased(Key.BRIGHTNESS_CYCLE);
|
||||
//keyReleased(Key.BRIGHTNESS_CYCLE);
|
||||
}
|
||||
}
|
||||
|
||||
static void keyPressedRaw(int row, int col) {
|
||||
KeyboardDebugScreen.keyX = row;
|
||||
KeyboardDebugScreen.keyY = col;
|
||||
if (row == 1 && col == 1) {
|
||||
keyPressed(Key.SHIFT);
|
||||
} else if (row == 1 && col == 2) {
|
||||
@ -111,7 +412,7 @@ public class Keyboard {
|
||||
}
|
||||
} else if (row == 2 && col == 8) {
|
||||
if (shift) {
|
||||
keyPressed(Key.NONE);
|
||||
keyPressed(Key.PI);
|
||||
} else if (alpha) {
|
||||
keyPressed(Key.DRG_CYCLE);
|
||||
} else {
|
||||
@ -389,34 +690,6 @@ public class Keyboard {
|
||||
break;
|
||||
case NONE:
|
||||
break;
|
||||
case debug_DEG:
|
||||
if (Calculator.angleMode.equals("deg") == false) {
|
||||
refresh = true;
|
||||
}
|
||||
Calculator.angleMode = "deg";
|
||||
break;
|
||||
case debug_RAD:
|
||||
if (Calculator.angleMode.equals("rad") == false) {
|
||||
refresh = true;
|
||||
}
|
||||
Calculator.angleMode = "rad";
|
||||
break;
|
||||
case debug_GRA:
|
||||
if (Calculator.angleMode.equals("gra") == false) {
|
||||
refresh = true;
|
||||
}
|
||||
Calculator.angleMode = "gra";
|
||||
break;
|
||||
case DRG_CYCLE:
|
||||
if (Calculator.angleMode.equals("deg") == true) {
|
||||
Calculator.angleMode = "rad";
|
||||
} else if (Calculator.angleMode.equals("rad") == true) {
|
||||
Calculator.angleMode = "gra";
|
||||
} else {
|
||||
Calculator.angleMode = "deg";
|
||||
}
|
||||
refresh = true;
|
||||
break;
|
||||
case LETTER_X:
|
||||
letterPressed('X');
|
||||
break;
|
||||
@ -498,14 +771,22 @@ public class Keyboard {
|
||||
PARENTHESIS_OPEN, PARENTHESIS_CLOSE, PLUS, MINUS, PLUS_MINUS, MULTIPLY, DIVIDE, EQUAL,
|
||||
DELETE, RESET, LEFT, RIGHT, UP, DOWN, OK, debug1, debug2, debug3, debug4, debug5,
|
||||
SQRT, ROOT, POWER_OF_2, POWER_OF_x,
|
||||
SINE, COSINE, TANGENT, ARCSINE, ARCCOSINE, ARCTANGENT
|
||||
SINE, COSINE, TANGENT, ARCSINE, ARCCOSINE, ARCTANGENT, PI
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
||||
|
||||
-coord-
|
||||
NORMAL
|
||||
SHIFT
|
||||
ALPHA
|
||||
-------
|
||||
|
||||
|1,1---|1,2---|------|1,4---|------|------|1,7---|
|
||||
|SHIFT |ALPHA |------| ^ |------|------|+BRIGH|
|
||||
|SHIFT |ALPHA |------| |------|------|-BRIGH|
|
||||
@ -540,7 +821,7 @@ public class Keyboard {
|
||||
| | | | | |
|
||||
|5,8---|4,8---|3,8---|2,8---|1,8-----------------|
|
||||
| 0 | . | | | SOLVE |
|
||||
| | | | | SIMPLIFY |
|
||||
| | | |PI | SIMPLIFY |
|
||||
| X | Y | Z |DRGCYCL| |
|
||||
|------|------|------|------|--------------------|
|
||||
|
||||
|
@ -23,8 +23,6 @@ import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.device.graphicengine.Display;
|
||||
import org.warp.picalculator.device.graphicengine.RAWFont;
|
||||
import org.warp.picalculator.device.graphicengine.Screen;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
|
||||
import com.pi4j.wiringpi.Gpio;
|
||||
|
||||
/**
|
||||
@ -89,13 +87,13 @@ public final class PIDisplay {
|
||||
public void setScreen(Screen screen) {
|
||||
if (screen.initialized == false) {
|
||||
if (screen.canBeInHistory) {
|
||||
Calculator.currentSession = 0;
|
||||
for (int i = Calculator.sessions.length - 1; i >= 1; i--) {
|
||||
Calculator.sessions[i] = Calculator.sessions[i - 1];
|
||||
PIDisplay.currentSession = 0;
|
||||
for (int i = PIDisplay.sessions.length - 1; i >= 1; i--) {
|
||||
PIDisplay.sessions[i] = PIDisplay.sessions[i - 1];
|
||||
}
|
||||
Calculator.sessions[0] = screen;
|
||||
PIDisplay.sessions[0] = screen;
|
||||
} else {
|
||||
Calculator.currentSession = -1;
|
||||
PIDisplay.currentSession = -1;
|
||||
}
|
||||
}
|
||||
screen.d = this;
|
||||
@ -114,11 +112,11 @@ public final class PIDisplay {
|
||||
public void replaceScreen(Screen screen) {
|
||||
if (screen.initialized == false) {
|
||||
if (screen.canBeInHistory) {
|
||||
Calculator.sessions[Calculator.currentSession] = screen;
|
||||
PIDisplay.sessions[PIDisplay.currentSession] = screen;
|
||||
} else {
|
||||
Calculator.currentSession = -1;
|
||||
for (int i = 0; i < Calculator.sessions.length - 2; i++) {
|
||||
Calculator.sessions[i] = Calculator.sessions[i + 1];
|
||||
PIDisplay.currentSession = -1;
|
||||
for (int i = 0; i < PIDisplay.sessions.length - 2; i++) {
|
||||
PIDisplay.sessions[i] = PIDisplay.sessions[i + 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -136,13 +134,13 @@ public final class PIDisplay {
|
||||
}
|
||||
|
||||
public boolean canGoBack() {
|
||||
if (Calculator.currentSession == -1) {
|
||||
return Calculator.sessions[0] != null;
|
||||
if (PIDisplay.currentSession == -1) {
|
||||
return PIDisplay.sessions[0] != null;
|
||||
}
|
||||
if (PIDisplay.screen != Calculator.sessions[Calculator.currentSession]) {
|
||||
if (PIDisplay.screen != PIDisplay.sessions[PIDisplay.currentSession]) {
|
||||
|
||||
} else if (Calculator.currentSession + 1 < Calculator.sessions.length) {
|
||||
if (Calculator.sessions[Calculator.currentSession + 1] != null) {
|
||||
} else if (PIDisplay.currentSession + 1 < PIDisplay.sessions.length) {
|
||||
if (PIDisplay.sessions[PIDisplay.currentSession + 1] != null) {
|
||||
|
||||
} else {
|
||||
return false;
|
||||
@ -150,7 +148,7 @@ public final class PIDisplay {
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
if (Calculator.sessions[Calculator.currentSession] != null) {
|
||||
if (PIDisplay.sessions[PIDisplay.currentSession] != null) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -158,22 +156,22 @@ public final class PIDisplay {
|
||||
|
||||
public void goBack() {
|
||||
if (canGoBack()) {
|
||||
if (Calculator.currentSession >= 0 && PIDisplay.screen != Calculator.sessions[Calculator.currentSession]) {
|
||||
if (PIDisplay.currentSession >= 0 && PIDisplay.screen != PIDisplay.sessions[PIDisplay.currentSession]) {
|
||||
} else {
|
||||
Calculator.currentSession += 1;
|
||||
PIDisplay.currentSession += 1;
|
||||
}
|
||||
PIDisplay.screen = Calculator.sessions[Calculator.currentSession];
|
||||
PIDisplay.screen = PIDisplay.sessions[PIDisplay.currentSession];
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canGoForward() {
|
||||
if (Calculator.currentSession <= 0) { // -1 e 0
|
||||
if (PIDisplay.currentSession <= 0) { // -1 e 0
|
||||
return false;
|
||||
}
|
||||
if (PIDisplay.screen != Calculator.sessions[Calculator.currentSession]) {
|
||||
if (PIDisplay.screen != PIDisplay.sessions[PIDisplay.currentSession]) {
|
||||
|
||||
} else if (Calculator.currentSession > 0) {
|
||||
if (Calculator.sessions[Calculator.currentSession - 1] != null) {
|
||||
} else if (PIDisplay.currentSession > 0) {
|
||||
if (PIDisplay.sessions[PIDisplay.currentSession - 1] != null) {
|
||||
|
||||
} else {
|
||||
return false;
|
||||
@ -181,7 +179,7 @@ public final class PIDisplay {
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
if (Calculator.sessions[Calculator.currentSession] != null) {
|
||||
if (PIDisplay.sessions[PIDisplay.currentSession] != null) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -189,12 +187,12 @@ public final class PIDisplay {
|
||||
|
||||
public void goForward() {
|
||||
if (canGoForward()) {
|
||||
if (PIDisplay.screen != Calculator.sessions[Calculator.currentSession]) {
|
||||
if (PIDisplay.screen != PIDisplay.sessions[PIDisplay.currentSession]) {
|
||||
|
||||
} else {
|
||||
Calculator.currentSession -= 1;
|
||||
PIDisplay.currentSession -= 1;
|
||||
}
|
||||
PIDisplay.screen = Calculator.sessions[Calculator.currentSession];
|
||||
PIDisplay.screen = PIDisplay.sessions[PIDisplay.currentSession];
|
||||
}
|
||||
}
|
||||
|
||||
@ -249,15 +247,16 @@ public final class PIDisplay {
|
||||
} else {
|
||||
drawSkinPart(2 + 18 * 1, 2, 16 * 1, 16 * 0, 16 + 16 * 1, 16 + 16 * 0);
|
||||
}
|
||||
if (Calculator.angleMode == "deg") {
|
||||
/*
|
||||
if (Calculator.angleMode == AngleMode.DEG) {
|
||||
drawSkinPart(8 + 18 * 2, 2, 16 * 4, 16 * 0, 16 + 16 * 4, 16 + 16 * 0);
|
||||
drawSkinPart(8 + 18 * 3, 2, 16 * 7, 16 * 0, 16 + 16 * 7, 16 + 16 * 0);
|
||||
drawSkinPart(8 + 18 * 4, 2, 16 * 9, 16 * 0, 16 + 16 * 9, 16 + 16 * 0);
|
||||
} else if (Calculator.angleMode == "rad") {
|
||||
} else if (Calculator.angleMode == AngleMode.RAD) {
|
||||
drawSkinPart(8 + 18 * 2, 2, 16 * 5, 16 * 0, 16 + 16 * 5, 16 + 16 * 0);
|
||||
drawSkinPart(8 + 18 * 3, 2, 16 * 6, 16 * 0, 16 + 16 * 6, 16 + 16 * 0);
|
||||
drawSkinPart(8 + 18 * 4, 2, 16 * 9, 16 * 0, 16 + 16 * 9, 16 + 16 * 0);
|
||||
} else if (Calculator.angleMode == "gra") {
|
||||
} else if (Calculator.angleMode == AngleMode.GRA) {
|
||||
drawSkinPart(8 + 18 * 2, 2, 16 * 5, 16 * 0, 16 + 16 * 5, 16 + 16 * 0);
|
||||
drawSkinPart(8 + 18 * 3, 2, 16 * 7, 16 * 0, 16 + 16 * 7, 16 + 16 * 0);
|
||||
drawSkinPart(8 + 18 * 4, 2, 16 * 8, 16 * 0, 16 + 16 * 8, 16 + 16 * 0);
|
||||
@ -265,7 +264,7 @@ public final class PIDisplay {
|
||||
drawSkinPart(8 + 18 * 2, 2, 16 * 5, 16 * 0, 16 + 16 * 5, 16 + 16 * 0);
|
||||
drawSkinPart(8 + 18 * 3, 2, 16 * 7, 16 * 0, 16 + 16 * 7, 16 + 16 * 0);
|
||||
drawSkinPart(8 + 18 * 4, 2, 16 * 9, 16 * 0, 16 + 16 * 9, 16 + 16 * 0);
|
||||
}
|
||||
}*/
|
||||
|
||||
int padding = 2;
|
||||
|
||||
@ -287,7 +286,7 @@ public final class PIDisplay {
|
||||
boolean canGoBack = canGoBack();
|
||||
boolean canGoForward = canGoForward();
|
||||
|
||||
if (Calculator.haxMode) {
|
||||
if (Main.haxMode) {
|
||||
drawSkinPart(Main.screenSize[0] - (padding + 16), 2, 16 * 18, 16 * 0, 16 + 16 * 18, 16 + 16 * 0);
|
||||
padding += 18 + 6;
|
||||
}
|
||||
@ -320,7 +319,7 @@ public final class PIDisplay {
|
||||
if (error != null) {
|
||||
glSetFont(Utils.getFont(false, false));
|
||||
glColor3i(129, 28, 22);
|
||||
glDrawStringRight(Main.screenSize[0] - 2, Main.screenSize[1]- this.glyphsHeight[1] - 2, "ANDREA CAVALLI'S CALCULATOR");
|
||||
glDrawStringRight(Main.screenSize[0] - 2, Main.screenSize[1]- PIDisplay.glyphsHeight[1] - 2, "ANDREA CAVALLI'S CALCULATOR");
|
||||
glColor3i(149, 32, 26);
|
||||
glDrawStringCenter((Main.screenSize[0] / 2), 22, error);
|
||||
glColor3i(164, 34, 28);
|
||||
@ -443,6 +442,8 @@ public final class PIDisplay {
|
||||
}
|
||||
|
||||
public float[] colore = new float[] { 0.0f, 0.0f, 0.0f, 1.0f };
|
||||
public static int currentSession = 0;
|
||||
public static Screen[] sessions = new Screen[5];
|
||||
|
||||
public static void colore(float f1, float f2, float f3, float f4) {
|
||||
PIDisplay.INSTANCE.colore = new float[] { f1, f2, f3, f4 };
|
||||
|
@ -9,7 +9,7 @@ import org.warp.picalculator.device.PIDisplay;
|
||||
|
||||
public class Display {
|
||||
|
||||
private static Frame INSTANCE = new Frame();
|
||||
private static SwingWindow INSTANCE = new SwingWindow();
|
||||
public static int[] size = new int[] { 1, 1 };
|
||||
public static BufferedImage g = new BufferedImage(size[0], size[1], BufferedImage.TYPE_INT_RGB);
|
||||
static int[] canvas2d = new int[1];
|
||||
@ -35,7 +35,7 @@ public class Display {
|
||||
}
|
||||
|
||||
public static void create() {
|
||||
Display.setResizable(Utils.debugOn);
|
||||
Display.setResizable(Utils.debugOn&!Utils.debugThirdScreen);
|
||||
Display.setDisplayMode(Main.screenSize[0], Main.screenSize[1]);
|
||||
INSTANCE.setVisible(true);
|
||||
initialized = true;
|
||||
@ -179,7 +179,7 @@ public class Display {
|
||||
newColor = skin[(s0 + texx) + (t0 + texy) * skinwidth];
|
||||
if (transparent) {
|
||||
oldColor = canvas2d[(x0 + texx*onex + width) + (y0 + texy*oney + height) * size[0]];
|
||||
float a2 = ((float)(newColor >> 24 & 0xFF)) / 255f;
|
||||
float a2 = (newColor >> 24 & 0xFF) / 255f;
|
||||
float a1 = 1f-a2;
|
||||
int r = (int) ((oldColor >> 16 & 0xFF) * a1 + (newColor >> 16 & 0xFF) * a2);
|
||||
int g = (int) ((oldColor >> 8 & 0xFF) * a1 + (newColor >> 8 & 0xFF) * a2);
|
||||
|
@ -1,494 +0,0 @@
|
||||
package org.warp.picalculator.device.graphicengine;
|
||||
|
||||
import java.awt.Cursor;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Point;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.awt.event.ComponentListener;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.KeyListener;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.DataBufferInt;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.device.Keyboard;
|
||||
import org.warp.picalculator.device.Keyboard.Key;
|
||||
import org.warp.picalculator.device.PIDisplay;
|
||||
|
||||
public class Frame extends JFrame {
|
||||
private static final long serialVersionUID = 2945898937634075491L;
|
||||
public CustomCanvas c;
|
||||
public boolean wasResized = false;
|
||||
|
||||
public Frame() {
|
||||
c = new CustomCanvas();
|
||||
c.setDoubleBuffered(false);
|
||||
this.add(c);
|
||||
// this.setExtendedState(Frame.MAXIMIZED_BOTH);
|
||||
Toolkit.getDefaultToolkit().setDynamicLayout(false);
|
||||
// Transparent 16 x 16 pixel cursor image.
|
||||
BufferedImage cursorImg = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
|
||||
|
||||
if (!Utils.debugOn) {
|
||||
// Create a new blank cursor.
|
||||
Cursor blankCursor = Toolkit.getDefaultToolkit().createCustomCursor(cursorImg, new Point(0, 0), "blank cursor");
|
||||
|
||||
// Set the blank cursor to the JFrame.
|
||||
getContentPane().setCursor(blankCursor);
|
||||
}
|
||||
|
||||
this.setTitle("Raspberry PI Calculator by XDrake99 (Andrea Cavalli)");
|
||||
this.setResizable(Utils.debugOn);
|
||||
|
||||
this.addComponentListener(new ComponentListener() {
|
||||
@Override
|
||||
public void componentHidden(ComponentEvent e) {
|
||||
Display.destroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void componentMoved(ComponentEvent e) {}
|
||||
|
||||
@Override
|
||||
public void componentResized(ComponentEvent e) {
|
||||
wasResized = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void componentShown(ComponentEvent e) {}
|
||||
});
|
||||
this.addKeyListener(new KeyListener() {
|
||||
@Override
|
||||
public void keyPressed(KeyEvent arg0) {
|
||||
switch (arg0.getKeyCode()) {
|
||||
case KeyEvent.VK_ESCAPE:
|
||||
Keyboard.keyPressed(Key.POWER);
|
||||
break;
|
||||
case KeyEvent.VK_S:
|
||||
if (Keyboard.shift) {
|
||||
Keyboard.keyPressed(Key.ARCSINE);
|
||||
} else if (Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.SINE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_C:
|
||||
if (Keyboard.shift) {
|
||||
Keyboard.keyPressed(Key.ARCCOSINE);
|
||||
} else if (Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.COSINE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_T:
|
||||
if (Keyboard.shift) {
|
||||
Keyboard.keyPressed(Key.ARCTANGENT);
|
||||
} else if (Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.TANGENT);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_D:
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.debug_DEG);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_R:
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.debug_RAD);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_G:
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.debug_GRA);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_X:
|
||||
if (Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.LETTER_X);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_Y:
|
||||
if (Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.LETTER_Y);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_B:
|
||||
if (Keyboard.shift) {
|
||||
Keyboard.keyPressed(Key.BRIGHTNESS_CYCLE_REVERSE);
|
||||
} else if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.BRIGHTNESS_CYCLE);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_ENTER:
|
||||
if (Keyboard.shift) {
|
||||
Keyboard.keyPressed(Key.SIMPLIFY);
|
||||
} else if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.SOLVE);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
}
|
||||
int row = 2;
|
||||
int col = 1;
|
||||
Keyboard.debugKeysDown[row-1][col-1] = true;
|
||||
break;
|
||||
case KeyEvent.VK_1:
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.NUM1);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_2:
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.NUM2);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_3:
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.NUM3);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_4:
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.NUM4);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_5:
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.NUM5);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_6:
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.NUM6);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_7:
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.NUM7);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_8:
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.NUM8);
|
||||
} else if (Keyboard.shift) {
|
||||
Keyboard.keyPressed(Key.PARENTHESIS_OPEN);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_9:
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.NUM9);
|
||||
} else if (Keyboard.shift) {
|
||||
Keyboard.keyPressed(Key.PARENTHESIS_CLOSE);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_0:
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.NUM0);
|
||||
} else if (Keyboard.shift) {
|
||||
Keyboard.keyPressed(Key.EQUAL);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_ADD:
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.PLUS);
|
||||
} else if (Keyboard.shift) {
|
||||
Keyboard.keyPressed(Key.PLUS_MINUS);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_SUBTRACT:
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.MINUS);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_MULTIPLY:
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.MULTIPLY);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_DIVIDE:
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.DIVIDE);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_BACK_SPACE:
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.DELETE);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_DELETE:
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.RESET);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_LEFT:
|
||||
//LEFT
|
||||
row = 2;
|
||||
col = 3;
|
||||
Keyboard.debugKeysDown[row-1][col-1] = true;
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.LEFT);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_RIGHT:
|
||||
//RIGHT
|
||||
row = 2;
|
||||
col = 5;
|
||||
Keyboard.debugKeysDown[row-1][col-1] = true;
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.RIGHT);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_NUMPAD4:
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.HISTORY_BACK);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_NUMPAD6:
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.HISTORY_FORWARD);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_PERIOD:
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.DOT);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_SHIFT:
|
||||
Keyboard.keyPressed(Key.SHIFT);
|
||||
break;
|
||||
case KeyEvent.VK_A:
|
||||
Keyboard.keyPressed(Key.ALPHA);
|
||||
break;
|
||||
case KeyEvent.VK_NUMPAD1:
|
||||
Keyboard.keyPressed(Key.SQRT);
|
||||
break;
|
||||
case KeyEvent.VK_NUMPAD2:
|
||||
Keyboard.keyPressed(Key.ROOT);
|
||||
break;
|
||||
case KeyEvent.VK_NUMPAD3:
|
||||
Keyboard.keyPressed(Key.POWER_OF_2);
|
||||
break;
|
||||
case KeyEvent.VK_NUMPAD5:
|
||||
Keyboard.keyPressed(Key.POWER_OF_x);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent arg0) {
|
||||
switch (arg0.getKeyCode()) {
|
||||
case KeyEvent.VK_ESCAPE:
|
||||
Keyboard.keyReleased(Key.POWER);
|
||||
break;
|
||||
case KeyEvent.VK_D:
|
||||
Keyboard.keyReleased(Key.debug_DEG);
|
||||
break;
|
||||
case KeyEvent.VK_R:
|
||||
Keyboard.keyReleased(Key.debug_RAD);
|
||||
break;
|
||||
case KeyEvent.VK_G:
|
||||
Keyboard.keyReleased(Key.debug_GRA);
|
||||
break;
|
||||
case KeyEvent.VK_X:
|
||||
if (Keyboard.alpha) {
|
||||
Keyboard.keyReleased(Key.LETTER_X);
|
||||
} else {
|
||||
Keyboard.keyReleased(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_B:
|
||||
if (Keyboard.shift) {
|
||||
Keyboard.keyReleased(Key.BRIGHTNESS_CYCLE_REVERSE);
|
||||
} else if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyReleased(Key.BRIGHTNESS_CYCLE);
|
||||
} else {
|
||||
Keyboard.keyReleased(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_ENTER:
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyReleased(Key.SOLVE);
|
||||
} else {
|
||||
Keyboard.keyReleased(Key.NONE);
|
||||
}
|
||||
int row = 2;
|
||||
int col = 1;
|
||||
Keyboard.debugKeysDown[row-1][col-1] = false;
|
||||
break;
|
||||
case KeyEvent.VK_1:
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyReleased(Key.debug1);
|
||||
} else {
|
||||
Keyboard.keyReleased(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_2:
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyReleased(Key.debug2);
|
||||
} else {
|
||||
Keyboard.keyReleased(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_3:
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyReleased(Key.debug3);
|
||||
} else {
|
||||
Keyboard.keyReleased(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_4:
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyReleased(Key.debug4);
|
||||
} else {
|
||||
Keyboard.keyReleased(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_5:
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyReleased(Key.debug5);
|
||||
} else {
|
||||
Keyboard.keyReleased(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_SHIFT:
|
||||
Keyboard.keyReleased(Key.SHIFT);
|
||||
break;
|
||||
case KeyEvent.VK_A:
|
||||
Keyboard.keyReleased(Key.ALPHA);
|
||||
break;
|
||||
case KeyEvent.VK_LEFT:
|
||||
//LEFT
|
||||
row = 2;
|
||||
col = 3;
|
||||
Keyboard.debugKeysDown[row-1][col-1] = false;
|
||||
case KeyEvent.VK_RIGHT:
|
||||
//RIGHT
|
||||
row = 2;
|
||||
col = 5;
|
||||
Keyboard.debugKeysDown[row-1][col-1] = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(KeyEvent arg0) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSize(int width, int height) {
|
||||
c.setSize(width, height);
|
||||
super.getContentPane().setPreferredSize(new Dimension(width, height));
|
||||
super.pack();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension getSize() {
|
||||
return c.getSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return c.getWidth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return c.getHeight();
|
||||
}
|
||||
|
||||
// private static ArrayList<Double> mediaValori = new ArrayList<Double>();
|
||||
|
||||
public static class CustomCanvas extends JPanel {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 605243927485370885L;
|
||||
|
||||
@Override
|
||||
public void paintComponent(Graphics g) {
|
||||
// long time1 = System.nanoTime();
|
||||
PIDisplay.INSTANCE.refresh();
|
||||
|
||||
final int[] a = ((DataBufferInt) Display.g.getRaster().getDataBuffer()).getData();
|
||||
// System.arraycopy(canvas2d, 0, a, 0, canvas2d.length);
|
||||
Display.canvas2d = a;
|
||||
g.clearRect(0, 0, Display.size[0], Display.size[1]);
|
||||
g.drawImage(Display.g, 0, 0, null);
|
||||
// long time2 = System.nanoTime();
|
||||
// double timeDelta = ((double)(time2-time1))/1000000000d;
|
||||
// double mediaAttuale = timeDelta;
|
||||
// mediaValori.add(mediaAttuale);
|
||||
// double somma = 0;
|
||||
// for (Double val : mediaValori) {
|
||||
// somma+=val;
|
||||
// }
|
||||
// System.out.println(somma/((double)mediaValori.size()));
|
||||
}
|
||||
}
|
||||
}
|
@ -166,7 +166,7 @@ public class RAWFont {
|
||||
j = x + cpos + dx;
|
||||
if (j > 0 & j < screenSize[0]) {
|
||||
int bit = dx + dy * charW;
|
||||
currentInt = (int) (Math.floor((double)bit)/((double)intBits));
|
||||
currentInt = (int) (Math.floor(bit)/(intBits));
|
||||
currentIntBitPosition = bit-(currentInt*intBits);
|
||||
bitData = (chars32[charIndex*charIntCount+currentInt] >> currentIntBitPosition) & 1;
|
||||
screenPos = x + cpos + dx + (y + dy) * screenSize[0];
|
||||
|
241
src/org/warp/picalculator/device/graphicengine/SwingWindow.java
Normal file
241
src/org/warp/picalculator/device/graphicengine/SwingWindow.java
Normal file
@ -0,0 +1,241 @@
|
||||
package org.warp.picalculator.device.graphicengine;
|
||||
|
||||
import java.awt.Cursor;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Point;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.awt.event.ComponentListener;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.KeyListener;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.DataBufferInt;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.device.Keyboard;
|
||||
import org.warp.picalculator.device.Keyboard.Key;
|
||||
import org.warp.picalculator.device.PIDisplay;
|
||||
|
||||
public class SwingWindow extends JFrame {
|
||||
private static final long serialVersionUID = 2945898937634075491L;
|
||||
public CustomCanvas c;
|
||||
public boolean wasResized = false;
|
||||
|
||||
public SwingWindow() {
|
||||
c = new CustomCanvas();
|
||||
c.setDoubleBuffered(false);
|
||||
this.add(c);
|
||||
// this.setExtendedState(Frame.MAXIMIZED_BOTH);
|
||||
Toolkit.getDefaultToolkit().setDynamicLayout(false);
|
||||
// Transparent 16 x 16 pixel cursor image.
|
||||
BufferedImage cursorImg = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
|
||||
|
||||
if (Utils.debugOn) {
|
||||
if (Utils.debugThirdScreen) {
|
||||
this.setLocation(2880, 900);
|
||||
this.setResizable(false);
|
||||
this.setAlwaysOnTop(true);
|
||||
}
|
||||
} else {
|
||||
// Create a new blank cursor.
|
||||
Cursor blankCursor = Toolkit.getDefaultToolkit().createCustomCursor(cursorImg, new Point(0, 0), "blank cursor");
|
||||
|
||||
// Set the blank cursor to the JFrame.
|
||||
getContentPane().setCursor(blankCursor);
|
||||
|
||||
this.setResizable(false);
|
||||
}
|
||||
|
||||
this.setTitle("Raspberry PI Calculator by XDrake99 (Andrea Cavalli)");
|
||||
|
||||
|
||||
this.addComponentListener(new ComponentListener() {
|
||||
@Override
|
||||
public void componentHidden(ComponentEvent e) {
|
||||
Display.destroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void componentMoved(ComponentEvent e) {}
|
||||
|
||||
@Override
|
||||
public void componentResized(ComponentEvent e) {
|
||||
wasResized = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void componentShown(ComponentEvent e) {}
|
||||
});
|
||||
this.addKeyListener(new KeyListener() {
|
||||
@Override
|
||||
public void keyPressed(KeyEvent arg0) {
|
||||
Keyboard.debugKeyEvent = arg0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent arg0) {
|
||||
switch (arg0.getKeyCode()) {
|
||||
case KeyEvent.VK_ESCAPE:
|
||||
Keyboard.keyReleased(Key.POWER);
|
||||
break;
|
||||
case KeyEvent.VK_D:
|
||||
Keyboard.keyReleased(Key.debug_DEG);
|
||||
break;
|
||||
case KeyEvent.VK_R:
|
||||
Keyboard.keyReleased(Key.debug_RAD);
|
||||
break;
|
||||
case KeyEvent.VK_G:
|
||||
Keyboard.keyReleased(Key.debug_GRA);
|
||||
break;
|
||||
case KeyEvent.VK_X:
|
||||
if (Keyboard.alpha) {
|
||||
Keyboard.keyReleased(Key.LETTER_X);
|
||||
} else {
|
||||
Keyboard.keyReleased(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_P:
|
||||
if (Keyboard.alpha) {
|
||||
Keyboard.keyReleased(Key.PI);
|
||||
} else {
|
||||
Keyboard.keyReleased(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_B:
|
||||
if (Keyboard.shift) {
|
||||
Keyboard.keyReleased(Key.BRIGHTNESS_CYCLE_REVERSE);
|
||||
} else if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyReleased(Key.BRIGHTNESS_CYCLE);
|
||||
} else {
|
||||
Keyboard.keyReleased(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_ENTER:
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyReleased(Key.SOLVE);
|
||||
} else {
|
||||
Keyboard.keyReleased(Key.NONE);
|
||||
}
|
||||
int row = 2;
|
||||
int col = 1;
|
||||
Keyboard.debugKeysDown[row-1][col-1] = false;
|
||||
break;
|
||||
case KeyEvent.VK_1:
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyReleased(Key.debug1);
|
||||
} else {
|
||||
Keyboard.keyReleased(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_2:
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyReleased(Key.debug2);
|
||||
} else {
|
||||
Keyboard.keyReleased(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_3:
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyReleased(Key.debug3);
|
||||
} else {
|
||||
Keyboard.keyReleased(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_4:
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyReleased(Key.debug4);
|
||||
} else {
|
||||
Keyboard.keyReleased(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_5:
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyReleased(Key.debug5);
|
||||
} else {
|
||||
Keyboard.keyReleased(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_SHIFT:
|
||||
Keyboard.keyReleased(Key.SHIFT);
|
||||
break;
|
||||
case KeyEvent.VK_A:
|
||||
Keyboard.keyReleased(Key.ALPHA);
|
||||
break;
|
||||
case KeyEvent.VK_LEFT:
|
||||
//LEFT
|
||||
row = 2;
|
||||
col = 3;
|
||||
Keyboard.debugKeysDown[row-1][col-1] = false;
|
||||
case KeyEvent.VK_RIGHT:
|
||||
//RIGHT
|
||||
row = 2;
|
||||
col = 5;
|
||||
Keyboard.debugKeysDown[row-1][col-1] = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(KeyEvent arg0) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSize(int width, int height) {
|
||||
c.setSize(width, height);
|
||||
super.getContentPane().setPreferredSize(new Dimension(width, height));
|
||||
super.pack();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension getSize() {
|
||||
return c.getSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return c.getWidth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return c.getHeight();
|
||||
}
|
||||
|
||||
// private static ArrayList<Double> mediaValori = new ArrayList<Double>();
|
||||
|
||||
public static class CustomCanvas extends JPanel {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 605243927485370885L;
|
||||
|
||||
@Override
|
||||
public void paintComponent(Graphics g) {
|
||||
// long time1 = System.nanoTime();
|
||||
PIDisplay.INSTANCE.refresh();
|
||||
|
||||
final int[] a = ((DataBufferInt) Display.g.getRaster().getDataBuffer()).getData();
|
||||
// System.arraycopy(canvas2d, 0, a, 0, canvas2d.length);
|
||||
Display.canvas2d = a;
|
||||
g.clearRect(0, 0, Display.size[0], Display.size[1]);
|
||||
g.drawImage(Display.g, 0, 0, null);
|
||||
// long time2 = System.nanoTime();
|
||||
// double timeDelta = ((double)(time2-time1))/1000000000d;
|
||||
// double mediaAttuale = timeDelta;
|
||||
// mediaValori.add(mediaAttuale);
|
||||
// double somma = 0;
|
||||
// for (Double val : mediaValori) {
|
||||
// somma+=val;
|
||||
// }
|
||||
// System.out.println(somma/((double)mediaValori.size()));
|
||||
}
|
||||
}
|
||||
}
|
7
src/org/warp/picalculator/math/AngleMode.java
Normal file
7
src/org/warp/picalculator/math/AngleMode.java
Normal file
@ -0,0 +1,7 @@
|
||||
package org.warp.picalculator.math;
|
||||
|
||||
public enum AngleMode {
|
||||
DEG,
|
||||
RAD,
|
||||
GRA
|
||||
}
|
@ -2,38 +2,40 @@ package org.warp.picalculator.math;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.Errors;
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.device.PIDisplay;
|
||||
import org.warp.picalculator.device.graphicengine.Screen;
|
||||
import org.warp.picalculator.math.functions.Expression;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.Number;
|
||||
import org.warp.picalculator.math.functions.Variable.VariableValue;
|
||||
import org.warp.picalculator.math.functions.equations.Equation;
|
||||
import org.warp.picalculator.math.functions.equations.EquationsSystem;
|
||||
import org.warp.picalculator.screens.MathInputScreen;
|
||||
import org.warp.picalculator.screens.SolveEquationScreen;
|
||||
|
||||
public class Calculator {
|
||||
|
||||
public static String angleMode = "deg";
|
||||
public static Screen[] sessions = new Screen[5];
|
||||
public static int currentSession = 0;
|
||||
public static boolean haxMode = true;
|
||||
public static boolean exactMode = false;
|
||||
public static Function parseString(String string) throws Error {
|
||||
public AngleMode angleMode = AngleMode.DEG;
|
||||
public boolean exactMode = false;
|
||||
public ArrayList<Function> f;
|
||||
public ArrayList<Function> f2;
|
||||
public ArrayList<VariableValue> variablesValues;
|
||||
public int resultsCount;
|
||||
|
||||
public Calculator() {
|
||||
f = new ArrayList<>();
|
||||
f2 = new ArrayList<>();
|
||||
variablesValues = new ArrayList<>();
|
||||
resultsCount = 0;
|
||||
}
|
||||
|
||||
public Function parseString(String string) throws Error {
|
||||
if (string.contains("{")) {
|
||||
if (!string.startsWith("{")) {
|
||||
throw new Error(Errors.SYNTAX_ERROR);
|
||||
}
|
||||
String[] parts = string.substring(1).split("\\{");
|
||||
EquationsSystem s = new EquationsSystem(null);
|
||||
EquationsSystem s = new EquationsSystem(this);
|
||||
for (String part : parts) {
|
||||
s.addFunctionToEnd(parseEquationString(part));
|
||||
}
|
||||
@ -41,28 +43,28 @@ public class Calculator {
|
||||
} else if (string.contains("=")) {
|
||||
return parseEquationString(string);
|
||||
} else {
|
||||
return new Expression(null, string);
|
||||
return new Expression(this, string);
|
||||
}
|
||||
}
|
||||
|
||||
public static Function parseEquationString(String string) throws Error {
|
||||
public Function parseEquationString(String string) throws Error {
|
||||
String[] parts = string.split("=");
|
||||
if (parts.length == 1) {
|
||||
Equation e = new Equation(null, null, null);
|
||||
e.setVariable1(new Expression(e, parts[0]));
|
||||
e.setVariable2(new Number(e, BigInteger.ZERO));
|
||||
Equation e = new Equation(this, null, null);
|
||||
e.setVariable1(new Expression(this, parts[0]));
|
||||
e.setVariable2(new Number(this, BigInteger.ZERO));
|
||||
return e;
|
||||
} else if (parts.length == 2) {
|
||||
Equation e = new Equation(null, null, null);
|
||||
e.setVariable1(new Expression(e, parts[0]));
|
||||
e.setVariable2(new Expression(e, parts[1]));
|
||||
Equation e = new Equation(this, null, null);
|
||||
e.setVariable1(new Expression(this, parts[0]));
|
||||
e.setVariable2(new Expression(this, parts[1]));
|
||||
return e;
|
||||
} else {
|
||||
throw new Error(Errors.SYNTAX_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
public static ArrayList<Function> solveExpression(ArrayList<Function> input) throws Error {
|
||||
public ArrayList<Function> solveExpression(ArrayList<Function> input) throws Error {
|
||||
ArrayList<Function> results = new ArrayList<>();
|
||||
ArrayList<Function> partialResults = new ArrayList<>();
|
||||
for (Function f : input) {
|
||||
@ -84,41 +86,47 @@ public class Calculator {
|
||||
partialResults.add(itm);
|
||||
}
|
||||
}
|
||||
results = new ArrayList<Function>(partialResults);
|
||||
results = new ArrayList<>(partialResults);
|
||||
partialResults.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
public static void solve(MathInputScreen es) throws Error {
|
||||
for (Function f : es.f) {
|
||||
if (f instanceof Equation) {
|
||||
PIDisplay.INSTANCE.setScreen(new SolveEquationScreen(es));
|
||||
return;
|
||||
|
||||
public Function getChild() {
|
||||
return f.get(0);
|
||||
}
|
||||
|
||||
public void init() {
|
||||
if (f == null & f2 == null) {
|
||||
f = new ArrayList<>();
|
||||
f2 = new ArrayList<>();
|
||||
variablesValues = new ArrayList<>();
|
||||
resultsCount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void parseInputString(String eqn) throws Error {
|
||||
ArrayList<Function> fncs = new ArrayList<>();
|
||||
if (eqn.length() > 0) {
|
||||
try {
|
||||
fncs.add(parseString(eqn.replace("sqrt", "Ⓐ").replace("^", "Ⓑ")));
|
||||
} catch (Exception ex) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
ArrayList<Function> results = solveExpression(es.f);
|
||||
if (results.size() == 0) {
|
||||
es.resultsCount = 0;
|
||||
} else {
|
||||
es.resultsCount = results.size();
|
||||
Collections.reverse(results);
|
||||
// add elements to al, including duplicates
|
||||
Set<Function> hs = new LinkedHashSet<>();
|
||||
hs.addAll(results);
|
||||
results.clear();
|
||||
results.addAll(hs);
|
||||
es.f2 = results;
|
||||
for (Function rf : es.f2) {
|
||||
rf.generateGraphics();
|
||||
f = fncs;
|
||||
for (Function f : f) {
|
||||
try {
|
||||
f.generateGraphics();
|
||||
} catch (NullPointerException ex) {
|
||||
throw new Error(Errors.SYNTAX_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*public static void solve(EquationScreen equationScreen, char letter) throws Error {
|
||||
/*public void solve(EquationScreen equationScreen, char letter) throws Error {
|
||||
if (Calculator.currentSession == 0 && Calculator.sessions[0] instanceof EquationScreen) {
|
||||
EquationScreen es = (EquationScreen) Calculator.sessions[0];
|
||||
ArrayList<Function> f = es.f;
|
||||
@ -138,41 +146,4 @@ public class Calculator {
|
||||
}
|
||||
}*/
|
||||
|
||||
public static void simplify(MathInputScreen es) throws Error {
|
||||
ArrayList<Function> results = new ArrayList<>();
|
||||
ArrayList<Function> partialResults = new ArrayList<>();
|
||||
for (Function f : es.f2) {
|
||||
if (f instanceof Equation) {
|
||||
PIDisplay.INSTANCE.setScreen(new SolveEquationScreen(es));
|
||||
} else {
|
||||
results.add(f);
|
||||
for (Function itm : results) {
|
||||
if (itm.isSolved() == false) {
|
||||
List<Function> dt = itm.solveOneStep();
|
||||
partialResults.addAll(dt);
|
||||
} else {
|
||||
partialResults.add(itm);
|
||||
}
|
||||
}
|
||||
results = new ArrayList<Function>(partialResults);
|
||||
partialResults.clear();
|
||||
}
|
||||
}
|
||||
if (results.size() == 0) {
|
||||
es.resultsCount = 0;
|
||||
} else {
|
||||
es.resultsCount = results.size();
|
||||
Collections.reverse(results);
|
||||
// add elements to al, including duplicates
|
||||
Set<Function> hs = new LinkedHashSet<>();
|
||||
hs.addAll(results);
|
||||
results.clear();
|
||||
results.addAll(hs);
|
||||
es.f2 = results;
|
||||
for (Function rf : es.f2) {
|
||||
rf.generateGraphics();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ public class MathematicalSymbols {
|
||||
public static final String ARC_SINE = "Ⓕ";
|
||||
public static final String ARC_COSINE = "Ⓖ";
|
||||
public static final String ARC_TANGENT = "Ⓗ";
|
||||
public static final String PI = "π";
|
||||
|
||||
public static final String[] functions() {
|
||||
return concat(functionsNSN(), functionsSN());
|
||||
@ -50,7 +51,7 @@ public class MathematicalSymbols {
|
||||
}
|
||||
|
||||
public static String[] variables() {
|
||||
return new String[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "ⓧ", "Ⓨ", "Z"};
|
||||
return new String[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "ⓧ", "Ⓨ", "Z", PI};
|
||||
}
|
||||
|
||||
public static String[] genericSyntax() {
|
||||
|
@ -3,25 +3,30 @@ package org.warp.picalculator.math.functions;
|
||||
import static org.warp.picalculator.device.graphicengine.Display.Render.glDrawStringLeft;
|
||||
import static org.warp.picalculator.device.graphicengine.Display.Render.glGetStringWidth;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.device.graphicengine.Display;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
|
||||
import com.rits.cloning.Cloner;
|
||||
|
||||
public abstract class AnteriorFunction implements Function {
|
||||
public AnteriorFunction(Function parent, Function value) {
|
||||
setParent(parent);
|
||||
setVariable(value);
|
||||
public AnteriorFunction(Function value) {
|
||||
this.root = value.getRoot();
|
||||
variable = value;
|
||||
}
|
||||
|
||||
protected abstract Function NewInstance(Function parent2, Function f);
|
||||
|
||||
protected Function parent;
|
||||
protected Function variable = new Number(null, BigInteger.ZERO);
|
||||
public AnteriorFunction(Calculator root, Function value) {
|
||||
this.root = root;
|
||||
variable = value;
|
||||
}
|
||||
|
||||
protected abstract Function NewInstance(Calculator root, Function value);
|
||||
|
||||
protected final Calculator root;
|
||||
protected Function variable;
|
||||
protected int width;
|
||||
protected int height;
|
||||
protected int line;
|
||||
@ -35,13 +40,9 @@ public abstract class AnteriorFunction implements Function {
|
||||
variable = value;
|
||||
}
|
||||
|
||||
public Function getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public Function setParent(Function value) {
|
||||
parent = value;
|
||||
return this;
|
||||
@Override
|
||||
public Calculator getRoot() {
|
||||
return root;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -55,7 +56,7 @@ public abstract class AnteriorFunction implements Function {
|
||||
if (result == null || result.isEmpty()) {
|
||||
result = new ArrayList<>();
|
||||
|
||||
ArrayList<Function> l1 = new ArrayList<Function>();
|
||||
ArrayList<Function> l1 = new ArrayList<>();
|
||||
if (variable.isSolved()) {
|
||||
l1.add(variable);
|
||||
} else {
|
||||
@ -63,7 +64,7 @@ public abstract class AnteriorFunction implements Function {
|
||||
}
|
||||
|
||||
for (Function f : l1) {
|
||||
result.add(NewInstance(this.parent, (Function)f));
|
||||
result.add(NewInstance(this.root, f));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -18,13 +18,13 @@ import org.warp.picalculator.math.rules.UndefinedRule2;
|
||||
|
||||
public class Division extends FunctionTwoValues {
|
||||
|
||||
public Division(Function parent, Function value1, Function value2) {
|
||||
super(parent, value1, value2);
|
||||
public Division(Calculator root, Function value1, Function value2) {
|
||||
super(root, value1, value2);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Function NewInstance(Function parent2, Function value1, Function value2) {
|
||||
return new Division(parent, value1, value2);
|
||||
protected Function NewInstance(Calculator root, Function value1, Function value2) {
|
||||
return new Division(root, value1, value2);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -39,7 +39,7 @@ public class Division extends FunctionTwoValues {
|
||||
if (FractionsRule2.compare(this)) return true;
|
||||
if (FractionsRule3.compare(this)) return true;
|
||||
if (UndefinedRule2.compare(this)) return true;
|
||||
if (variable1 instanceof Number && variable2 instanceof Number && Calculator.exactMode == false) {
|
||||
if (variable1 instanceof Number && variable2 instanceof Number && root.exactMode == false) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -56,8 +56,8 @@ public class Division extends FunctionTwoValues {
|
||||
result = FractionsRule3.execute(this);
|
||||
} else if (UndefinedRule2.compare(this)) {
|
||||
result = UndefinedRule2.execute(this);
|
||||
} else if (variable1 instanceof Number && variable2 instanceof Number && Calculator.exactMode == false) {
|
||||
result.add(((Number)variable1).divide((Number)variable2).setParent(parent));
|
||||
} else if (variable1 instanceof Number && variable2 instanceof Number && root.exactMode == false) {
|
||||
result.add(((Number)variable1).divide((Number)variable2));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -5,10 +5,15 @@ import java.util.List;
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.device.graphicengine.Display;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
|
||||
public class EmptyNumber implements Function {
|
||||
|
||||
public static EmptyNumber emptyNumber = new EmptyNumber();
|
||||
public EmptyNumber(Calculator root) {
|
||||
this.root = root;
|
||||
}
|
||||
|
||||
private final Calculator root;
|
||||
|
||||
@Override
|
||||
public String getSymbol() {
|
||||
@ -52,13 +57,8 @@ public class EmptyNumber implements Function {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Function setParent(Function parent) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Function getParent() {
|
||||
return null;
|
||||
public Calculator getRoot() {
|
||||
return root;
|
||||
}
|
||||
|
||||
private boolean small = false;
|
||||
|
@ -13,6 +13,7 @@ import java.util.regex.Pattern;
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.Errors;
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
import org.warp.picalculator.math.functions.trigonometry.ArcCosine;
|
||||
import org.warp.picalculator.math.functions.trigonometry.ArcSine;
|
||||
@ -23,30 +24,29 @@ import org.warp.picalculator.math.functions.trigonometry.Tangent;
|
||||
|
||||
public class Expression extends FunctionMultipleValues {
|
||||
|
||||
public Expression(Function parent) {
|
||||
super(parent);
|
||||
public Expression(Calculator root) {
|
||||
super(root);
|
||||
}
|
||||
|
||||
public Expression(Function parent, Function[] values) {
|
||||
super(parent, values);
|
||||
public Expression(Calculator root, Function[] values) {
|
||||
super(root, values);
|
||||
}
|
||||
|
||||
private boolean initialParenthesis = false;
|
||||
|
||||
public Expression(Function parent, String string) throws Error {
|
||||
this(parent, string, "", true);
|
||||
public Expression(Calculator root, String string) throws Error {
|
||||
this(root, string, "", true);
|
||||
}
|
||||
|
||||
public Expression(Function parent, String string, String debugSpaces, boolean initialParenthesis) throws Error {
|
||||
super(parent);
|
||||
this.parent = parent;
|
||||
public Expression(Calculator root, String string, String debugSpaces, boolean initialParenthesis) throws Error {
|
||||
super(root);
|
||||
this.initialParenthesis = initialParenthesis;
|
||||
boolean isNumber = false;
|
||||
|
||||
// Determine if the expression is already a number:
|
||||
// Determina se l'espressione è già un numero:
|
||||
try {
|
||||
new Number(this, string);
|
||||
new Number(root, string);
|
||||
isNumber = true;
|
||||
} catch (NumberFormatException ex) {
|
||||
isNumber = false;
|
||||
@ -60,7 +60,7 @@ public class Expression extends FunctionMultipleValues {
|
||||
if (isNumber){
|
||||
// If the expression is already a number:
|
||||
// Se l'espressione è già un numero:
|
||||
Number t = new Number(this, string);
|
||||
Number t = new Number(root, string);
|
||||
setVariables(new Function[] { t });
|
||||
Utils.debug.println(debugSpaces + "•Result:" + t.toString());
|
||||
} else {
|
||||
@ -211,7 +211,7 @@ public class Expression extends FunctionMultipleValues {
|
||||
debugSpaces += " ";
|
||||
|
||||
// Convert the expression to a list of objects
|
||||
Expression imputRawParenthesis = new Expression(this);
|
||||
Expression imputRawParenthesis = new Expression(root);
|
||||
imputRawParenthesis.setVariables(new Function[] {});
|
||||
String tmp = "";
|
||||
final String[] functions = concat(concat(concat(concat(MathematicalSymbols.functions(), MathematicalSymbols.parentheses()), MathematicalSymbols.signums(true)), MathematicalSymbols.variables()), MathematicalSymbols.genericSyntax());
|
||||
@ -225,49 +225,49 @@ public class Expression extends FunctionMultipleValues {
|
||||
Function f = null;
|
||||
switch (charI) {
|
||||
case MathematicalSymbols.SUM:
|
||||
f = new Sum(this, null, null);
|
||||
f = new Sum(root, null, null);
|
||||
break;
|
||||
case MathematicalSymbols.SUM_SUBTRACTION:
|
||||
f = new SumSubtraction(this, null, null);
|
||||
f = new SumSubtraction(root, null, null);
|
||||
break;
|
||||
case MathematicalSymbols.SUBTRACTION:
|
||||
f = new Subtraction(this, null, null);
|
||||
f = new Subtraction(root, null, null);
|
||||
break;
|
||||
case MathematicalSymbols.MINUS:
|
||||
f = new Negative(this, null);
|
||||
f = new Negative(root, null);
|
||||
break;
|
||||
case MathematicalSymbols.MULTIPLICATION:
|
||||
f = new Multiplication(this, null, null);
|
||||
f = new Multiplication(root, null, null);
|
||||
break;
|
||||
case MathematicalSymbols.DIVISION:
|
||||
f = new Division(this, null, null);
|
||||
f = new Division(root, null, null);
|
||||
break;
|
||||
case MathematicalSymbols.NTH_ROOT:
|
||||
f = new Root(this, null, null);
|
||||
f = new Root(root, null, null);
|
||||
break;
|
||||
case MathematicalSymbols.SQUARE_ROOT:
|
||||
f = new RootSquare(this, null);
|
||||
f = new RootSquare(root, null);
|
||||
break;
|
||||
case MathematicalSymbols.POWER:
|
||||
f = new Power(this, null, null);
|
||||
f = new Power(root, null, null);
|
||||
break;
|
||||
case MathematicalSymbols.SINE:
|
||||
f = new Sine(this, null);
|
||||
f = new Sine(root, null);
|
||||
break;
|
||||
case MathematicalSymbols.COSINE:
|
||||
f = new Cosine(this, null);
|
||||
f = new Cosine(root, null);
|
||||
break;
|
||||
case MathematicalSymbols.TANGENT:
|
||||
f = new Tangent(this, null);
|
||||
f = new Tangent(root, null);
|
||||
break;
|
||||
case MathematicalSymbols.ARC_SINE:
|
||||
f = new ArcSine(this, null);
|
||||
f = new ArcSine(root, null);
|
||||
break;
|
||||
case MathematicalSymbols.ARC_COSINE:
|
||||
f = new ArcCosine(this, null);
|
||||
f = new ArcCosine(root, null);
|
||||
break;
|
||||
case MathematicalSymbols.ARC_TANGENT:
|
||||
f = new ArcTangent(this, null);
|
||||
f = new ArcTangent(root, null);
|
||||
break;
|
||||
case MathematicalSymbols.PARENTHESIS_OPEN:
|
||||
// Find the last closed parenthesis
|
||||
@ -300,15 +300,16 @@ public class Expression extends FunctionMultipleValues {
|
||||
tmpExpr += processExpression.charAt(i);
|
||||
i++;
|
||||
}
|
||||
f = new Expression(this, tmpExpr, debugSpaces, false);
|
||||
f = new Expression(root, tmpExpr, debugSpaces, false);
|
||||
break;
|
||||
default:
|
||||
if (Utils.isInArray(charI, MathematicalSymbols.variables())) {
|
||||
f = new Variable(this, charI);
|
||||
f = new Variable(root, charI);
|
||||
} else {
|
||||
if (charI == "(" || charI == ")") {
|
||||
throw new Error(Errors.UNBALANCED_BRACKETS);
|
||||
} else {
|
||||
System.err.println("Unexpected character while parsing expression: " + charI);
|
||||
throw new Error(Errors.SYNTAX_ERROR);
|
||||
}
|
||||
// throw new java.lang.RuntimeException("Il carattere " + charI + " non è tra le funzioni designate!\nAggiungerlo ad esse o rimuovere il carattere dall'espressione!");
|
||||
@ -319,28 +320,28 @@ public class Expression extends FunctionMultipleValues {
|
||||
} else if (f instanceof Variable) {
|
||||
if (imputRawParenthesis.getVariablesLength() == 0) {
|
||||
if (tmp.length() > 0) {
|
||||
imputRawParenthesis.addFunctionToEnd(new Number(this, tmp));
|
||||
imputRawParenthesis.addFunctionToEnd(new Number(root, tmp));
|
||||
Utils.debug.println(debugSpaces + "•Added number to expression:" + tmp);
|
||||
imputRawParenthesis.addFunctionToEnd(new Multiplication(this, null, null));
|
||||
Utils.debug.println(debugSpaces + "•Added multiplication to expression:" + new Multiplication(this, null, null).getSymbol());
|
||||
imputRawParenthesis.addFunctionToEnd(new Multiplication(root, null, null));
|
||||
Utils.debug.println(debugSpaces + "•Added multiplication to expression:" + new Multiplication(root, null, null).getSymbol());
|
||||
}
|
||||
} else {
|
||||
Function precedentFunction = imputRawParenthesis.getVariable(imputRawParenthesis.getVariablesLength() - 1);
|
||||
if (tmp.length() > 0) {
|
||||
if (precedentFunction instanceof Number || precedentFunction instanceof Variable) {
|
||||
imputRawParenthesis.addFunctionToEnd(new Multiplication(this, null, null));
|
||||
Utils.debug.println(debugSpaces + "•Added multiplication to expression:" + new Multiplication(this, null, null).getSymbol());
|
||||
imputRawParenthesis.addFunctionToEnd(new Multiplication(root, null, null));
|
||||
Utils.debug.println(debugSpaces + "•Added multiplication to expression:" + new Multiplication(root, null, null).getSymbol());
|
||||
}
|
||||
if (tmp.equals("-")) {
|
||||
imputRawParenthesis.addFunctionToEnd(new Subtraction(this, null, null));
|
||||
imputRawParenthesis.addFunctionToEnd(new Subtraction(root, null, null));
|
||||
} else {
|
||||
imputRawParenthesis.addFunctionToEnd(new Number(this, tmp));
|
||||
imputRawParenthesis.addFunctionToEnd(new Number(root, tmp));
|
||||
Utils.debug.println(debugSpaces + "•Added number to expression:" + tmp);
|
||||
}
|
||||
}
|
||||
if (tmp.length() > 0 || (precedentFunction instanceof Number || precedentFunction instanceof Variable)) {
|
||||
imputRawParenthesis.addFunctionToEnd(new Multiplication(this, null, null));
|
||||
Utils.debug.println(debugSpaces + "•Added multiplication to expression:" + new Multiplication(this, null, null).getSymbol());
|
||||
imputRawParenthesis.addFunctionToEnd(new Multiplication(root, null, null));
|
||||
Utils.debug.println(debugSpaces + "•Added multiplication to expression:" + new Multiplication(root, null, null).getSymbol());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -350,7 +351,7 @@ public class Expression extends FunctionMultipleValues {
|
||||
tmp = "-1";
|
||||
}
|
||||
}
|
||||
imputRawParenthesis.addFunctionToEnd(new Number(this, tmp));
|
||||
imputRawParenthesis.addFunctionToEnd(new Number(root, tmp));
|
||||
Utils.debug.println(debugSpaces + "•Added number to expression:" + tmp);
|
||||
}
|
||||
}
|
||||
@ -373,7 +374,7 @@ public class Expression extends FunctionMultipleValues {
|
||||
if (tmp.length() > 0) {
|
||||
Utils.debug.println(debugSpaces + "•Added variable to expression:" + tmp);
|
||||
try {
|
||||
imputRawParenthesis.addFunctionToEnd(new Number(this, tmp));
|
||||
imputRawParenthesis.addFunctionToEnd(new Number(root, tmp));
|
||||
} catch (NumberFormatException ex) {
|
||||
throw new Error(Errors.SYNTAX_ERROR);
|
||||
}
|
||||
@ -406,7 +407,7 @@ public class Expression extends FunctionMultipleValues {
|
||||
Utils.debug.println(debugSpaces + "•Pushing classes...");
|
||||
|
||||
Function[] oldFunctionsArray = imputRawParenthesis.getVariables();
|
||||
ArrayList<Function> oldFunctionsList = new ArrayList<Function>();
|
||||
ArrayList<Function> oldFunctionsList = new ArrayList<>();
|
||||
for (int i = 0; i < oldFunctionsArray.length; i++) {
|
||||
Function funzione = oldFunctionsArray[i];
|
||||
if (funzione != null) {
|
||||
@ -417,7 +418,7 @@ public class Expression extends FunctionMultipleValues {
|
||||
oldFunctionsArray[i-1] = null;
|
||||
oldFunctionsList.remove(oldFunctionsList.size()-1);
|
||||
i -= 1;
|
||||
funzione = new RootSquare(this, null);
|
||||
funzione = new RootSquare(root, null);
|
||||
}
|
||||
}
|
||||
//Aggiunta della funzione alla lista grezza
|
||||
@ -448,7 +449,7 @@ public class Expression extends FunctionMultipleValues {
|
||||
System.out.println("WARN: ---> POSSIBILE ERRORE????? <---");// BOH
|
||||
// throw new Errore(Errori.SYNTAX_ERROR);
|
||||
while (oldFunctionsList.size() > 1) {
|
||||
oldFunctionsList.set(0, new Multiplication(this, oldFunctionsList.get(0), oldFunctionsList.remove(1)));
|
||||
oldFunctionsList.set(0, new Multiplication(root, oldFunctionsList.get(0), oldFunctionsList.remove(1)));
|
||||
}
|
||||
}
|
||||
Utils.debug.println(debugSpaces + " •Phase: "+step);
|
||||
@ -512,8 +513,8 @@ public class Expression extends FunctionMultipleValues {
|
||||
change = true;
|
||||
|
||||
if (i + 1 < oldFunctionsList.size() && i - 1 >= 0) {
|
||||
((FunctionTwoValues) funzioneTMP).setVariable1((Function) oldFunctionsList.get(i - 1));
|
||||
((FunctionTwoValues) funzioneTMP).setVariable2((Function) oldFunctionsList.get(i + 1));
|
||||
((FunctionTwoValues) funzioneTMP).setVariable1(oldFunctionsList.get(i - 1));
|
||||
((FunctionTwoValues) funzioneTMP).setVariable2(oldFunctionsList.get(i + 1));
|
||||
oldFunctionsList.set(i, funzioneTMP);
|
||||
|
||||
// è importante togliere prima gli elementi
|
||||
@ -546,7 +547,7 @@ public class Expression extends FunctionMultipleValues {
|
||||
|
||||
} else {
|
||||
change = true;
|
||||
((AnteriorFunction) funzioneTMP).setVariable((Function) nextFunc);
|
||||
((AnteriorFunction) funzioneTMP).setVariable(nextFunc);
|
||||
oldFunctionsList.set(i, funzioneTMP);
|
||||
|
||||
// è importante togliere prima gli elementi in
|
||||
@ -580,7 +581,7 @@ public class Expression extends FunctionMultipleValues {
|
||||
} while (((oldFunctionsList.size() != before || step != "sums") && oldFunctionsList.size() > 1));
|
||||
}
|
||||
if(oldFunctionsList.isEmpty()) {
|
||||
setVariables(new Function[]{new Number(this, 0)});
|
||||
setVariables(new Function[]{new Number(root, 0)});
|
||||
} else {
|
||||
setVariables(oldFunctionsList);
|
||||
}
|
||||
@ -630,7 +631,7 @@ public class Expression extends FunctionMultipleValues {
|
||||
if (f instanceof Number || f instanceof Variable) {
|
||||
ret.add(f);
|
||||
} else {
|
||||
ret.add(new Expression(this, new Function[]{(Function) f}));
|
||||
ret.add(new Expression(root, new Function[]{f}));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
@ -640,7 +641,7 @@ public class Expression extends FunctionMultipleValues {
|
||||
if (f.isSolved() == false) {
|
||||
List<Function> partial = f.solveOneStep();
|
||||
for (Function fnc : partial) {
|
||||
ret.add(new Expression(this, new Function[]{(Function) fnc}));
|
||||
ret.add(new Expression(root, new Function[]{fnc}));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -662,7 +663,7 @@ public class Expression extends FunctionMultipleValues {
|
||||
|
||||
public boolean parenthesisNeeded() {
|
||||
boolean parenthesisneeded = true;
|
||||
if (parent == null || initialParenthesis || parent instanceof Division) {
|
||||
if (initialParenthesis) {
|
||||
parenthesisneeded = false;
|
||||
} else {
|
||||
if (functions.length == 1) {
|
||||
|
@ -3,6 +3,7 @@ package org.warp.picalculator.math.functions;
|
||||
import java.util.List;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
|
||||
public interface Function {
|
||||
public String getSymbol();
|
||||
@ -21,9 +22,7 @@ public interface Function {
|
||||
|
||||
public int getLine();
|
||||
|
||||
public Function setParent(Function parent);
|
||||
|
||||
public Function getParent();
|
||||
public Calculator getRoot();
|
||||
|
||||
public void setSmall(boolean small);
|
||||
|
||||
|
@ -3,20 +3,31 @@ package org.warp.picalculator.math.functions;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
|
||||
import com.rits.cloning.Cloner;
|
||||
|
||||
public abstract class FunctionMultipleValues implements Function {
|
||||
public FunctionMultipleValues(Function parent) {
|
||||
setParent(parent);
|
||||
setVariables(new Function[] {});
|
||||
public FunctionMultipleValues(Calculator root) {
|
||||
this.root = root;
|
||||
functions = new Function[] {};
|
||||
}
|
||||
|
||||
public FunctionMultipleValues(Function parent, Function[] values) {
|
||||
setParent(parent);
|
||||
setVariables(values);
|
||||
public FunctionMultipleValues(Function[] values) {
|
||||
if (values.length > 0) {
|
||||
this.root = values[0].getRoot();
|
||||
} else {
|
||||
throw new NullPointerException("Nessun elemento nell'array. Impossibile ricavare il nodo root");
|
||||
}
|
||||
functions = values;
|
||||
}
|
||||
|
||||
protected Function parent;
|
||||
public FunctionMultipleValues(Calculator root, Function[] values) {
|
||||
this.root = root;
|
||||
functions = values;
|
||||
}
|
||||
|
||||
protected final Calculator root;
|
||||
protected Function[] functions;
|
||||
protected int width;
|
||||
protected int height;
|
||||
@ -27,34 +38,28 @@ public abstract class FunctionMultipleValues implements Function {
|
||||
return functions;
|
||||
}
|
||||
|
||||
public void setVariables(Function[] value) {
|
||||
for (Function f : value) {
|
||||
f.setParent(this);
|
||||
}
|
||||
functions = value;
|
||||
}
|
||||
|
||||
public void setVariables(final List<Function> value) {
|
||||
int vsize = value.size();
|
||||
Function[] tmp = new Function[vsize];
|
||||
for (int i = 0; i < vsize; i++) {
|
||||
tmp[i] = value.get(i);
|
||||
tmp[i].setParent(this);
|
||||
}
|
||||
functions = tmp;
|
||||
}
|
||||
|
||||
public void setVariables(final Function[] value) {
|
||||
functions = value;
|
||||
}
|
||||
|
||||
public Function getVariable(int index) {
|
||||
return functions[index];
|
||||
}
|
||||
|
||||
public void setVariable(int index, Function value) {
|
||||
value.setParent(this);
|
||||
functions[index] = value;
|
||||
}
|
||||
|
||||
public void addFunctionToEnd(Function value) {
|
||||
value.setParent(this);
|
||||
int index = functions.length;
|
||||
setVariablesLength(index + 1);
|
||||
functions[index] = value;
|
||||
@ -83,14 +88,9 @@ public abstract class FunctionMultipleValues implements Function {
|
||||
|
||||
protected abstract boolean isSolvable();
|
||||
|
||||
|
||||
public Function setParent(Function value) {
|
||||
parent = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Function getParent() {
|
||||
return parent;
|
||||
@Override
|
||||
public Calculator getRoot() {
|
||||
return root;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -8,19 +8,20 @@ import java.util.ArrayList;
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.device.graphicengine.Display;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
|
||||
import com.rits.cloning.Cloner;
|
||||
|
||||
public abstract class FunctionTwoValues implements Function {
|
||||
public FunctionTwoValues(Function parent, Function value1, Function value2) {
|
||||
this.parent = parent;
|
||||
public FunctionTwoValues(Calculator root, Function value1, Function value2) {
|
||||
this.root = root;
|
||||
variable1 = value1;
|
||||
variable2 = value2;
|
||||
}
|
||||
|
||||
protected abstract Function NewInstance(Function parent2, Function value1, Function value2);
|
||||
protected abstract Function NewInstance(Calculator root, Function value1, Function value2);
|
||||
|
||||
protected Function parent;
|
||||
protected final Calculator root;
|
||||
|
||||
protected Function variable1 = null;
|
||||
protected Function variable2 = null;
|
||||
@ -34,25 +35,19 @@ public abstract class FunctionTwoValues implements Function {
|
||||
}
|
||||
|
||||
public void setVariable1(Function value) {
|
||||
value.setParent(this);
|
||||
variable1 = value;
|
||||
}
|
||||
|
||||
public Function getParent() {
|
||||
return parent;
|
||||
@Override
|
||||
public Calculator getRoot() {
|
||||
return root;
|
||||
}
|
||||
|
||||
public Function setParent(Function value) {
|
||||
parent = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public Function getVariable2() {
|
||||
return variable2;
|
||||
}
|
||||
|
||||
public void setVariable2(Function value) {
|
||||
value.setParent(this);
|
||||
variable2 = value;
|
||||
}
|
||||
|
||||
@ -74,8 +69,8 @@ public abstract class FunctionTwoValues implements Function {
|
||||
if (result == null || result.isEmpty()) {
|
||||
result = new ArrayList<>();
|
||||
|
||||
ArrayList<Function> l1 = new ArrayList<Function>();
|
||||
ArrayList<Function> l2 = new ArrayList<Function>();
|
||||
ArrayList<Function> l1 = new ArrayList<>();
|
||||
ArrayList<Function> l2 = new ArrayList<>();
|
||||
if (variable1.isSolved()) {
|
||||
l1.add(variable1);
|
||||
} else {
|
||||
@ -90,7 +85,7 @@ public abstract class FunctionTwoValues implements Function {
|
||||
Function[][] results = Utils.joinFunctionsResults(l1, l2);
|
||||
|
||||
for (Function[] f : results) {
|
||||
result.add(NewInstance(this.parent, (Function)f[0], (Function)f[1]));
|
||||
result.add(NewInstance(this.root, f[0], f[1]));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@ import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.device.PIDisplay;
|
||||
import org.warp.picalculator.device.graphicengine.Display;
|
||||
import org.warp.picalculator.device.graphicengine.RAWFont;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
|
||||
public class Joke implements Function {
|
||||
|
||||
@ -16,8 +17,10 @@ public class Joke implements Function {
|
||||
private static final String[] jokes = new String[]{"♓", "TORNADO", "SHARKNADO"};
|
||||
private static final int[] jokesFont = new int[]{4, -1, -1};
|
||||
private final byte joke;
|
||||
private final Calculator root;
|
||||
|
||||
public Joke(byte joke) {
|
||||
public Joke(Calculator root, byte joke) {
|
||||
this.root = root;
|
||||
this.joke = joke;
|
||||
}
|
||||
|
||||
@ -75,15 +78,10 @@ public class Joke implements Function {
|
||||
public int getLine() {
|
||||
return getHeight()/2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Function setParent(Function value) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Function getParent() {
|
||||
return null;
|
||||
public Calculator getRoot() {
|
||||
return root;
|
||||
}
|
||||
|
||||
private boolean small = false;
|
||||
|
@ -3,6 +3,7 @@ package org.warp.picalculator.math.functions;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
import org.warp.picalculator.math.rules.ExponentRule15;
|
||||
import org.warp.picalculator.math.rules.NumberRule1;
|
||||
@ -13,8 +14,8 @@ import org.warp.picalculator.math.rules.methods.MultiplicationMethod1;
|
||||
|
||||
public class Multiplication extends FunctionTwoValues {
|
||||
|
||||
public Multiplication(Function parent, Function value1, Function value2) {
|
||||
super(parent, value1, value2);
|
||||
public Multiplication(Calculator root, Function value1, Function value2) {
|
||||
super(root, value1, value2);
|
||||
if (value1 instanceof Variable && value2 instanceof Variable == false) {
|
||||
variable1 = value2;
|
||||
variable2 = value1;
|
||||
@ -22,8 +23,8 @@ public class Multiplication extends FunctionTwoValues {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Function NewInstance(Function parent2, Function value1, Function value2) {
|
||||
return new Multiplication(parent, value1, value2);
|
||||
protected Function NewInstance(Calculator root, Function value1, Function value2) {
|
||||
return new Multiplication(root, value1, value2);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -6,19 +6,20 @@ import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.Errors;
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.device.graphicengine.Display;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
import org.warp.picalculator.math.rules.ExpandRule1;
|
||||
import org.warp.picalculator.math.rules.ExpandRule5;
|
||||
|
||||
public class Negative extends AnteriorFunction {
|
||||
|
||||
public Negative(Function parent, Function value) {
|
||||
super(parent, value);
|
||||
public Negative(Calculator root, Function value) {
|
||||
super(root, value);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Function NewInstance(Function parent, Function value) {
|
||||
return new Negative(parent, value);
|
||||
public Function NewInstance(Calculator root, Function value) {
|
||||
return new Negative(root, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -44,6 +45,7 @@ public class Negative extends AnteriorFunction {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<Function> solve() throws Error {
|
||||
if (variable == null) {
|
||||
throw new Error(Errors.SYNTAX_ERROR);
|
||||
@ -56,7 +58,7 @@ public class Negative extends AnteriorFunction {
|
||||
} else if (variable.isSolved()) {
|
||||
try {
|
||||
Number var = (Number) getVariable();
|
||||
result.add(var.multiply(new Number(null, "-1")));
|
||||
result.add(var.multiply(new Number(root, "-1")));
|
||||
} catch(NullPointerException ex) {
|
||||
throw new Error(Errors.ERROR);
|
||||
} catch(NumberFormatException ex) {
|
||||
@ -65,7 +67,7 @@ public class Negative extends AnteriorFunction {
|
||||
throw new Error(Errors.NUMBER_TOO_SMALL);
|
||||
}
|
||||
} else {
|
||||
ArrayList<Function> l1 = new ArrayList<Function>();
|
||||
ArrayList<Function> l1 = new ArrayList<>();
|
||||
if (variable.isSolved()) {
|
||||
l1.add(variable);
|
||||
} else {
|
||||
@ -73,7 +75,7 @@ public class Negative extends AnteriorFunction {
|
||||
}
|
||||
|
||||
for (Function f : l1) {
|
||||
result.add(new Negative(this.parent, (Function)f));
|
||||
result.add(new Negative(root, f));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
@ -20,37 +20,37 @@ import com.rits.cloning.Cloner;
|
||||
|
||||
public class Number implements Function {
|
||||
|
||||
private Function parent;
|
||||
private final Calculator root;
|
||||
protected BigDecimal term;
|
||||
protected int width;
|
||||
protected int height;
|
||||
protected int line;
|
||||
protected boolean small;
|
||||
|
||||
public Number(Function parent, BigInteger val) {
|
||||
this.parent = parent;
|
||||
public Number(Calculator root, BigInteger val) {
|
||||
this.root = root;
|
||||
term = new BigDecimal(val).setScale(Utils.scale, Utils.scaleMode2);
|
||||
}
|
||||
|
||||
public Number(Function parent, BigDecimal val) {
|
||||
this.parent = parent;
|
||||
public Number(Calculator root, BigDecimal val) {
|
||||
this.root = root;
|
||||
term = val.setScale(Utils.scale, Utils.scaleMode2);
|
||||
}
|
||||
|
||||
public Number(Function parent, String s) throws Error {
|
||||
this(parent, new BigInteger(s));
|
||||
public Number(Calculator root, String s) throws Error {
|
||||
this(root, new BigDecimal(s).setScale(Utils.scale, Utils.scaleMode2));
|
||||
}
|
||||
|
||||
public Number(Function parent, int s) {
|
||||
this(parent, BigDecimal.valueOf(s).setScale(Utils.scale, Utils.scaleMode2));
|
||||
public Number(Calculator root, int s) {
|
||||
this(root, BigDecimal.valueOf(s).setScale(Utils.scale, Utils.scaleMode2));
|
||||
}
|
||||
|
||||
public Number(Function parent, float s) {
|
||||
this(parent, BigDecimal.valueOf(s).setScale(Utils.scale, Utils.scaleMode2));
|
||||
public Number(Calculator root, float s) {
|
||||
this(root, BigDecimal.valueOf(s).setScale(Utils.scale, Utils.scaleMode2));
|
||||
}
|
||||
|
||||
public Number(Function parent, double s) {
|
||||
this(parent, BigDecimal.valueOf(s).setScale(Utils.scale, Utils.scaleMode2));
|
||||
public Number(Calculator root, double s) {
|
||||
this(root, BigDecimal.valueOf(s).setScale(Utils.scale, Utils.scaleMode2));
|
||||
}
|
||||
|
||||
public BigDecimal getTerm() {
|
||||
@ -74,26 +74,26 @@ public class Number implements Function {
|
||||
}
|
||||
|
||||
public Number add(Number f) {
|
||||
Number ret = new Number(this.parent, getTerm().add(f.getTerm()));
|
||||
Number ret = new Number(this.root, getTerm().add(f.getTerm()));
|
||||
return ret;
|
||||
}
|
||||
|
||||
public Number multiply(Number f) {
|
||||
Number ret = new Number(this.parent, getTerm().multiply(f.getTerm()));
|
||||
Number ret = new Number(this.root, getTerm().multiply(f.getTerm()));
|
||||
return ret;
|
||||
}
|
||||
|
||||
public Number divide(Number f) throws Error {
|
||||
Number ret = new Number(this.parent, BigDecimalMath.divideRound(getTerm(), f.getTerm()));
|
||||
Number ret = new Number(this.root, BigDecimalMath.divideRound(getTerm(), f.getTerm()));
|
||||
return ret;
|
||||
}
|
||||
|
||||
public Number pow(Number f) throws Error {
|
||||
Number ret = new Number(this.parent, BigDecimal.ONE);
|
||||
Number ret = new Number(this.root, BigDecimal.ONE);
|
||||
if (Utils.isIntegerValue(f.term)) {
|
||||
final BigInteger bi = f.term.toBigInteger();
|
||||
for (BigInteger i = BigInteger.ZERO; i.compareTo(bi) < 0; i = i.add(BigInteger.ONE)) {
|
||||
ret = ret.multiply(new Number(this.parent, getTerm()));
|
||||
ret = ret.multiply(new Number(this.root, getTerm()));
|
||||
}
|
||||
} else {
|
||||
ret.term = BigDecimalMath.pow(term, f.term);
|
||||
@ -113,7 +113,7 @@ public class Number implements Function {
|
||||
s = s+"…";
|
||||
}
|
||||
|
||||
if (Calculator.exactMode == false) {
|
||||
if (root.exactMode == false) {
|
||||
String cuttedNumber = s.split("\\.")[0];
|
||||
if (cuttedNumber.length() > 8) {
|
||||
return cuttedNumber.substring(0, 1)+","+cuttedNumber.substring(1, 8)+"ℯ℮"+(cuttedNumber.length()-1);
|
||||
@ -265,14 +265,9 @@ public class Number implements Function {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Function setParent(Function value) {
|
||||
parent = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Function getParent() {
|
||||
return parent;
|
||||
public Calculator getRoot() {
|
||||
return root;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -302,7 +297,7 @@ public class Number implements Function {
|
||||
{
|
||||
BigInteger n = getTerm().toBigIntegerExact();
|
||||
BigInteger two = BigInteger.valueOf(2);
|
||||
LinkedList<BigInteger> fs = new LinkedList<BigInteger>();
|
||||
LinkedList<BigInteger> fs = new LinkedList<>();
|
||||
|
||||
if (n.compareTo(two) < 0)
|
||||
{
|
||||
|
@ -3,6 +3,7 @@ package org.warp.picalculator.math.functions;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
import org.warp.picalculator.math.rules.ExponentRule1;
|
||||
import org.warp.picalculator.math.rules.ExponentRule2;
|
||||
@ -14,13 +15,13 @@ import org.warp.picalculator.math.rules.UndefinedRule1;
|
||||
|
||||
public class Power extends FunctionTwoValues {
|
||||
|
||||
public Power(Function parent, Function value1, Function value2) {
|
||||
super(parent, value1, value2);
|
||||
public Power(Calculator root, Function value1, Function value2) {
|
||||
super(root, value1, value2);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Function NewInstance(Function parent2, Function value1, Function value2) {
|
||||
return new Power(parent, value1, value2);
|
||||
protected Function NewInstance(Calculator root, Function value1, Function value2) {
|
||||
return new Power(root, value1, value2);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -74,7 +75,7 @@ public class Power extends FunctionTwoValues {
|
||||
} else if (FractionsRule5.compare(this)) {
|
||||
result.addAll(FractionsRule5.execute(this));
|
||||
} else if (variable1 instanceof Number & variable2 instanceof Number) {
|
||||
result.add((Function) ((Number)variable1).pow((Number)variable2));
|
||||
result.add(((Number)variable1).pow((Number)variable2));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -12,13 +12,13 @@ import org.warp.picalculator.math.MathematicalSymbols;
|
||||
|
||||
public class Root extends FunctionTwoValues {
|
||||
|
||||
public Root(Function parent, Function value1, Function value2) {
|
||||
super(parent, value1, value2);
|
||||
public Root(Calculator root, Function value1, Function value2) {
|
||||
super(root, value1, value2);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Function NewInstance(Function parent2, Function value1, Function value2) {
|
||||
return new Root(parent, value1, value2);
|
||||
protected Function NewInstance(Calculator root, Function value1, Function value2) {
|
||||
return new Root(root, value1, value2);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -41,23 +41,23 @@ public class Root extends FunctionTwoValues {
|
||||
|
||||
@Override
|
||||
protected boolean isSolvable() {
|
||||
if (variable1 instanceof Number & variable2 instanceof Number) {
|
||||
if (Calculator.exactMode == false) {
|
||||
return true;
|
||||
}
|
||||
if (variable1 instanceof Number & variable2 instanceof Number) {
|
||||
if (root.exactMode == false) {
|
||||
return true;
|
||||
}
|
||||
try {
|
||||
Number exponent = new Number(this.parent, BigDecimal.ONE);
|
||||
Number exponent = new Number(root, BigDecimal.ONE);
|
||||
exponent = exponent.divide((Number) variable1);
|
||||
Number resultVal = ((Number)variable2).pow(exponent);
|
||||
Number originalVariable = resultVal.pow(new Number(null, 2));
|
||||
Number originalVariable = resultVal.pow(new Number(root, 2));
|
||||
if (originalVariable.equals(variable2)) {
|
||||
return true;
|
||||
}
|
||||
} catch (Exception | Error ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (variable1 instanceof Number && ((Number)variable1).equals(new Number(null, 2))) {
|
||||
if (variable1 instanceof Number && ((Number)variable1).equals(new Number(root, 2))) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -65,12 +65,12 @@ public class Root extends FunctionTwoValues {
|
||||
|
||||
@Override
|
||||
public ArrayList<Function> solve() throws Error {
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
if (Calculator.exactMode) {
|
||||
if (variable1 instanceof Number && ((Number)variable1).equals(new Number(null, 2))) {
|
||||
result.add(new RootSquare(parent, variable2));
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
if (root.exactMode) {
|
||||
if (variable1 instanceof Number && ((Number)variable1).equals(new Number(root, 2))) {
|
||||
result.add(new RootSquare(root, variable2));
|
||||
} else {
|
||||
Number exponent = new Number(this.parent, BigInteger.ONE);
|
||||
Number exponent = new Number(root, BigInteger.ONE);
|
||||
exponent = exponent.divide((Number) variable1);
|
||||
result.add(((Number)variable2).pow(exponent));
|
||||
}
|
||||
@ -78,7 +78,7 @@ public class Root extends FunctionTwoValues {
|
||||
Number exp = (Number) variable1;
|
||||
Number numb = (Number) variable2;
|
||||
|
||||
result.add(numb.pow(new Number(null, 1).divide(exp)).setParent(parent));
|
||||
result.add(numb.pow(new Number(root, 1).divide(exp)));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -10,13 +10,13 @@ import org.warp.picalculator.math.MathematicalSymbols;
|
||||
|
||||
public class RootSquare extends AnteriorFunction {
|
||||
|
||||
public RootSquare(Function parent, Function value) {
|
||||
super(parent, value);
|
||||
public RootSquare(Calculator root, Function value) {
|
||||
super(root, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Function NewInstance(Function parent, Function value) {
|
||||
return new RootSquare(parent, value);
|
||||
public Function NewInstance(Calculator root, Function value) {
|
||||
return new RootSquare(root, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -36,15 +36,15 @@ public class RootSquare extends AnteriorFunction {
|
||||
|
||||
@Override
|
||||
protected boolean isSolvable() {
|
||||
if (variable instanceof Number) {
|
||||
if (Calculator.exactMode == false) {
|
||||
if (variable instanceof Number) {
|
||||
if (root.exactMode == false) {
|
||||
return true;
|
||||
}
|
||||
try {
|
||||
Number exponent = new Number(this.parent, BigInteger.ONE);
|
||||
exponent = exponent.divide(new Number(null, 2));
|
||||
Number exponent = new Number(root, BigInteger.ONE);
|
||||
exponent = exponent.divide(new Number(root, 2));
|
||||
Number resultVal = ((Number)variable).pow(exponent);
|
||||
Number originalVariable = resultVal.pow(new Number(null, 2));
|
||||
Number originalVariable = resultVal.pow(new Number(root, 2));
|
||||
if (originalVariable.equals(variable)) {
|
||||
return true;
|
||||
}
|
||||
@ -57,16 +57,16 @@ public class RootSquare extends AnteriorFunction {
|
||||
|
||||
@Override
|
||||
public ArrayList<Function> solve() throws Error {
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
if (Calculator.exactMode) {
|
||||
Number exponent = new Number(this.parent, BigInteger.ONE);
|
||||
exponent = exponent.divide(new Number(null, 2));
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
if (root.exactMode) {
|
||||
Number exponent = new Number(root, BigInteger.ONE);
|
||||
exponent = exponent.divide(new Number(root, 2));
|
||||
result.add(((Number)variable).pow(exponent));
|
||||
} else {
|
||||
Number exp = new Number(null, 2);
|
||||
Number exp = new Number(root, 2);
|
||||
Number numb = (Number) variable;
|
||||
|
||||
result.add(numb.pow(new Number(null, 1).divide(exp)).setParent(parent));
|
||||
result.add(numb.pow(new Number(root, 1).divide(exp)));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package org.warp.picalculator.math.functions;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
import org.warp.picalculator.math.rules.ExpandRule1;
|
||||
import org.warp.picalculator.math.rules.ExpandRule5;
|
||||
@ -15,13 +16,13 @@ import org.warp.picalculator.math.rules.methods.SumMethod1;
|
||||
|
||||
public class Subtraction extends FunctionTwoValues {
|
||||
|
||||
public Subtraction(Function parent, Function value1, Function value2) {
|
||||
super(parent, value1, value2);
|
||||
public Subtraction(Calculator root, Function value1, Function value2) {
|
||||
super(root, value1, value2);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Function NewInstance(Function parent2, Function value1, Function value2) {
|
||||
return new Subtraction(parent, value1, value2);
|
||||
protected Function NewInstance(Calculator root, Function value1, Function value2) {
|
||||
return new Subtraction(root, value1, value2);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -65,7 +66,7 @@ public class Subtraction extends FunctionTwoValues {
|
||||
} else if (SumMethod1.compare(this)) {
|
||||
result = SumMethod1.execute(this);
|
||||
} else if (variable1.isSolved() & variable2.isSolved()) {
|
||||
result.add(((Number)variable1).add(((Number)variable2).multiply(new Number(this.parent, "-1"))));
|
||||
result.add(((Number)variable1).add(((Number)variable2).multiply(new Number(root, "-1"))));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import java.util.ArrayList;
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.Errors;
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
import org.warp.picalculator.math.rules.NumberRule3;
|
||||
import org.warp.picalculator.math.rules.NumberRule5;
|
||||
@ -20,13 +21,13 @@ import org.warp.picalculator.math.rules.methods.SumMethod1;
|
||||
|
||||
public class Sum extends FunctionTwoValues {
|
||||
|
||||
public Sum(Function parent, Function value1, Function value2) {
|
||||
super(parent, value1, value2);
|
||||
public Sum(Calculator root, Function value1, Function value2) {
|
||||
super(root, value1, value2);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Function NewInstance(Function parent2, Function value1, Function value2) {
|
||||
return new Sum(parent, value1, value2);
|
||||
protected Function NewInstance(Calculator root, Function value1, Function value2) {
|
||||
return new Sum(root, value1, value2);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -73,15 +74,15 @@ public class Sum extends FunctionTwoValues {
|
||||
} else if (SumMethod1.compare(this)) {
|
||||
result = SumMethod1.execute(this);
|
||||
} else if (variable1.isSolved() & variable2.isSolved()) {
|
||||
if ((parent == null || parent.getParent() == null)) {
|
||||
if ((root.getChild().equals(this))) {
|
||||
if (((Number)variable1).term.compareTo(new BigDecimal(2)) == 0 && ((Number)variable2).term.compareTo(new BigDecimal(2)) == 0) {
|
||||
result.add(new Joke(Joke.FISH));
|
||||
result.add(new Joke(root, Joke.FISH));
|
||||
return result;
|
||||
} else if (((Number)variable1).term.compareTo(new BigDecimal(20)) == 0 && ((Number)variable2).term.compareTo(new BigDecimal(20)) == 0) {
|
||||
result.add(new Joke(Joke.TORNADO));
|
||||
result.add(new Joke(root, Joke.TORNADO));
|
||||
return result;
|
||||
} else if (((Number)variable1).term.compareTo(new BigDecimal(29)) == 0 && ((Number)variable2).term.compareTo(new BigDecimal(29)) == 0) {
|
||||
result.add(new Joke(Joke.SHARKNADO));
|
||||
} else if (((Number)variable1).term.compareTo(new BigDecimal(29)) == 0 && ((Number)variable2).term.compareTo(new BigDecimal(29)) == 0) {
|
||||
result.add(new Joke(root, Joke.SHARKNADO));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.Errors;
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.device.graphicengine.Display;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
import org.warp.picalculator.math.rules.ExpandRule1;
|
||||
import org.warp.picalculator.math.rules.NumberRule3;
|
||||
@ -17,13 +18,13 @@ import org.warp.picalculator.math.rules.NumberRule5;
|
||||
|
||||
public class SumSubtraction extends FunctionTwoValues {
|
||||
|
||||
public SumSubtraction(Function parent, Function value1, Function value2) {
|
||||
super(parent, value1, value2);
|
||||
public SumSubtraction(Calculator root, Function value1, Function value2) {
|
||||
super(root, value1, value2);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Function NewInstance(Function parent2, Function value1, Function value2) {
|
||||
return new SumSubtraction(parent, value1, value2);
|
||||
protected Function NewInstance(Calculator root, Function value1, Function value2) {
|
||||
return new SumSubtraction(root, value1, value2);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -59,7 +60,7 @@ public class SumSubtraction extends FunctionTwoValues {
|
||||
result = NumberRule5.execute(this);
|
||||
} else if (variable1.isSolved() & variable2.isSolved()) {
|
||||
result.add(((Number)variable1).add((Number)variable2));
|
||||
result.add(((Number)variable1).add(((Number)variable2).multiply(new Number(this.parent, "-1"))));
|
||||
result.add(((Number)variable1).add(((Number)variable2).multiply(new Number(root, "-1"))));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -5,11 +5,14 @@ import java.util.List;
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.device.graphicengine.Display;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
|
||||
public class Undefined implements Function {
|
||||
|
||||
protected final Calculator root;
|
||||
|
||||
public Undefined(Function parent) {
|
||||
setParent(parent);
|
||||
public Undefined(Calculator root) {
|
||||
this.root = root;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -28,7 +31,6 @@ public class Undefined implements Function {
|
||||
}
|
||||
|
||||
private int width, height, line;
|
||||
private Function parent;
|
||||
private boolean small;
|
||||
|
||||
@Override
|
||||
@ -60,14 +62,8 @@ public class Undefined implements Function {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Function setParent(Function parent) {
|
||||
this.parent = parent;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Function getParent() {
|
||||
return parent;
|
||||
public Calculator getRoot() {
|
||||
return root;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -9,25 +9,26 @@ import java.util.List;
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.device.graphicengine.Display;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
|
||||
import com.rits.cloning.Cloner;
|
||||
|
||||
public class Variable implements Function {
|
||||
|
||||
private Function parent;
|
||||
protected char var;
|
||||
protected int width;
|
||||
protected int height;
|
||||
protected int line;
|
||||
protected boolean small;
|
||||
protected final Calculator root;
|
||||
|
||||
public Variable(Function parent, char val) {
|
||||
this.parent = parent;
|
||||
public Variable(Calculator root, char val) {
|
||||
this.root = root;
|
||||
var = val;
|
||||
}
|
||||
|
||||
public Variable(Function parent, String s) throws Error {
|
||||
this(parent, s.charAt(0));
|
||||
public Variable(Calculator root, String s) throws Error {
|
||||
this(root, s.charAt(0));
|
||||
}
|
||||
|
||||
public char getChar() {
|
||||
@ -95,6 +96,16 @@ public class Variable implements Function {
|
||||
private int calcLine() {
|
||||
return Utils.getFontHeight(small) / 2;
|
||||
}
|
||||
|
||||
public static class VariableValue {
|
||||
public final Variable v;
|
||||
public final Number n;
|
||||
|
||||
public VariableValue(Variable v, Number n) {
|
||||
this.v = v;
|
||||
this.n = n;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Variable clone() {
|
||||
@ -132,13 +143,8 @@ public class Variable implements Function {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Function setParent(Function value) {
|
||||
parent = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Function getParent() {
|
||||
return parent;
|
||||
public Calculator getRoot() {
|
||||
return root;
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import java.util.Set;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.Errors;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
import org.warp.picalculator.math.SolveMethod;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
@ -19,8 +20,13 @@ import com.rits.cloning.Cloner;
|
||||
|
||||
public class Equation extends FunctionTwoValues {
|
||||
|
||||
public Equation(Function parent, Function value1, Function value2) {
|
||||
super(parent, value1,value2);
|
||||
public Equation(Calculator root, Function value1, Function value2) {
|
||||
super(root, value1,value2);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Function NewInstance(Calculator root, Function value1, Function value2) {
|
||||
return new Equation(root, value1, value2);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -46,9 +52,9 @@ public class Equation extends FunctionTwoValues {
|
||||
if (((Number)variable2).getTerm().compareTo(new BigDecimal(0)) == 0) {
|
||||
result.add(this);
|
||||
} else {
|
||||
Equation e = new Equation(this.parent, null, null);
|
||||
e.setVariable1(new Subtraction(e, variable1, variable2));
|
||||
e.setVariable2(new Number(e, "0"));
|
||||
Equation e = new Equation(root, null, null);
|
||||
e.setVariable1(new Subtraction(root, variable1, variable2));
|
||||
e.setVariable2(new Number(root, "0"));
|
||||
result.add(e);
|
||||
}
|
||||
}
|
||||
@ -65,10 +71,10 @@ public class Equation extends FunctionTwoValues {
|
||||
|
||||
//WORK IN PROGRESS
|
||||
public ArrayList<Equation> solveStep(char charIncognita) {
|
||||
ArrayList<Equation> result = new ArrayList<Equation>();
|
||||
ArrayList<Equation> result = new ArrayList<>();
|
||||
result.add(this.clone());
|
||||
for (SolveMethod t : SolveMethod.techniques) {
|
||||
ArrayList<Equation> newResults = new ArrayList<Equation>();
|
||||
ArrayList<Equation> newResults = new ArrayList<>();
|
||||
final int sz = result.size();
|
||||
for (int n = 0; n < sz; n++) {
|
||||
newResults.addAll(t.solve(result.get(n)));
|
||||
|
@ -1,12 +1,10 @@
|
||||
package org.warp.picalculator.math.functions.equations;
|
||||
|
||||
import java.math.BigInteger;
|
||||
|
||||
import org.warp.picalculator.math.functions.Number;
|
||||
|
||||
public class EquationResult {
|
||||
public boolean isAnEquation = false;
|
||||
public Number LR = new Number(null, new BigInteger("0"));
|
||||
public Number LR;
|
||||
|
||||
public EquationResult(Number LR, boolean isAnEquation) {
|
||||
this.LR = LR;
|
||||
|
@ -6,6 +6,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.functions.Expression;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.FunctionMultipleValues;
|
||||
@ -13,17 +14,17 @@ import org.warp.picalculator.math.functions.Number;
|
||||
|
||||
public class EquationsSystem extends FunctionMultipleValues {
|
||||
static final int spacing = 2;
|
||||
|
||||
public EquationsSystem(Function parent) {
|
||||
super(parent);
|
||||
|
||||
public EquationsSystem(Calculator root) {
|
||||
super(root);
|
||||
}
|
||||
|
||||
public EquationsSystem(Function parent, Function value) {
|
||||
super(parent, new Function[]{value});
|
||||
public EquationsSystem(Calculator root, Function value) {
|
||||
super(root, new Function[]{value});
|
||||
}
|
||||
|
||||
public EquationsSystem(Function parent, Function[] value) {
|
||||
super(parent, value);
|
||||
public EquationsSystem(Calculator root, Function[] value) {
|
||||
super(root, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -52,7 +53,7 @@ public class EquationsSystem extends FunctionMultipleValues {
|
||||
if (f instanceof Number) {
|
||||
ret.add(f);
|
||||
} else {
|
||||
ret.add(new Expression(this.parent, new Function[]{(Function) f}));
|
||||
ret.add(new Expression(this.root, new Function[]{f}));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
@ -62,7 +63,7 @@ public class EquationsSystem extends FunctionMultipleValues {
|
||||
if (f.isSolved() == false) {
|
||||
List<Function> partial = f.solveOneStep();
|
||||
for (Function fnc : partial) {
|
||||
ret.add(new Expression(this.parent, new Function[]{(Function) fnc}));
|
||||
ret.add(new Expression(this.root, new Function[]{fnc}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,37 +6,27 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
import org.warp.picalculator.math.functions.AnteriorFunction;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
|
||||
public class EquationsSystemPart extends AnteriorFunction {
|
||||
|
||||
public EquationsSystemPart(Function parent, Equation equazione) {
|
||||
super(parent, equazione);
|
||||
public EquationsSystemPart(Calculator root, Equation equazione) {
|
||||
super(root, equazione);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Function NewInstance(Calculator root, Function value) {
|
||||
return new EquationsSystemPart(root, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSymbol() {
|
||||
return MathematicalSymbols.SYSTEM;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isSolvable() throws Error {
|
||||
return variable.isSolved()==false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Function> solveOneStep() throws NumberFormatException, Error {
|
||||
// TODO implementare il calcolo dei sistemi
|
||||
if (variable.isSolved()) {
|
||||
List<Function> ret = new ArrayList<>();
|
||||
ret.add(variable);
|
||||
return ret;
|
||||
}
|
||||
return variable.solveOneStep();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateGraphics() {
|
||||
variable.setSmall(false);
|
||||
|
@ -3,19 +3,20 @@ package org.warp.picalculator.math.functions.trigonometry;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
import org.warp.picalculator.math.functions.AnteriorFunction;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
|
||||
public class ArcCosine extends AnteriorFunction {
|
||||
|
||||
public ArcCosine(Function parent, Function value) {
|
||||
super(parent, value);
|
||||
public ArcCosine(Calculator root, Function value) {
|
||||
super(root, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Function NewInstance(Function parent, Function value) {
|
||||
return new ArcCosine(parent, value);
|
||||
public Function NewInstance(Calculator root, Function value) {
|
||||
return new ArcCosine(root, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -3,19 +3,20 @@ package org.warp.picalculator.math.functions.trigonometry;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
import org.warp.picalculator.math.functions.AnteriorFunction;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
|
||||
public class ArcSine extends AnteriorFunction {
|
||||
|
||||
public ArcSine(Function parent, Function value) {
|
||||
super(parent, value);
|
||||
public ArcSine(Calculator root, Function value) {
|
||||
super(root, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Function NewInstance(Function parent, Function value) {
|
||||
return new ArcSine(parent, value);
|
||||
public Function NewInstance(Calculator root, Function value) {
|
||||
return new ArcSine(root, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -3,19 +3,20 @@ package org.warp.picalculator.math.functions.trigonometry;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
import org.warp.picalculator.math.functions.AnteriorFunction;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
|
||||
public class ArcTangent extends AnteriorFunction {
|
||||
|
||||
public ArcTangent(Function parent, Function value) {
|
||||
super(parent, value);
|
||||
public ArcTangent(Calculator root, Function value) {
|
||||
super(root, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Function NewInstance(Function parent, Function value) {
|
||||
return new ArcTangent(parent, value);
|
||||
public Function NewInstance(Calculator root, Function value) {
|
||||
return new ArcTangent(root, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -3,19 +3,20 @@ package org.warp.picalculator.math.functions.trigonometry;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
import org.warp.picalculator.math.functions.AnteriorFunction;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
|
||||
public class Cosine extends AnteriorFunction {
|
||||
|
||||
public Cosine(Function parent, Function value) {
|
||||
super(parent, value);
|
||||
public Cosine(Calculator root, Function value) {
|
||||
super(root, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Function NewInstance(Function parent, Function value) {
|
||||
return new Cosine(parent, value);
|
||||
public Function NewInstance(Calculator root, Function value) {
|
||||
return new Cosine(root, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -2,20 +2,24 @@ package org.warp.picalculator.math.functions.trigonometry;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.nevec.rjm.BigDecimalMath;
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.AngleMode;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
import org.warp.picalculator.math.functions.AnteriorFunction;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.Number;
|
||||
|
||||
public class Sine extends AnteriorFunction {
|
||||
|
||||
public Sine(Function parent, Function value) {
|
||||
super(parent, value);
|
||||
public Sine(Calculator root, Function value) {
|
||||
super(root, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Function NewInstance(Function parent, Function value) {
|
||||
return new Sine(parent, value);
|
||||
public Function NewInstance(Calculator root, Function value) {
|
||||
return new Sine(root, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -24,15 +28,27 @@ public class Sine extends AnteriorFunction {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<Function> solve() throws Error {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
protected boolean isSolvable() {
|
||||
if (variable instanceof Number) {
|
||||
if (root.exactMode == false) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (root.angleMode == AngleMode.DEG) {
|
||||
Function[] solvableValues = new Function[]{new Number(root, 0), new Number(root, 30), new Number(root, 90), };
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isSolvable() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
public ArrayList<Function> solve() throws Error {
|
||||
ArrayList<Function> results = new ArrayList<>();
|
||||
if (variable instanceof Number) {
|
||||
if (root.exactMode == false) {
|
||||
results.add(new Number(root, BigDecimalMath.sin(((Number) variable).getTerm())));
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -3,19 +3,20 @@ package org.warp.picalculator.math.functions.trigonometry;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
import org.warp.picalculator.math.functions.AnteriorFunction;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
|
||||
public class Tangent extends AnteriorFunction {
|
||||
|
||||
public Tangent(Function parent, Function value) {
|
||||
super(parent, value);
|
||||
public Tangent(Calculator root, Function value) {
|
||||
super(root, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Function NewInstance(Function parent, Function value) {
|
||||
return new Tangent(parent, value);
|
||||
public Function NewInstance(Calculator root, Function value) {
|
||||
return new Tangent(root, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -3,6 +3,7 @@ package org.warp.picalculator.math.rules;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.functions.Expression;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.FunctionTwoValues;
|
||||
@ -55,6 +56,7 @@ public class ExpandRule1 {
|
||||
|
||||
public static ArrayList<Function> execute(Function f) throws Error {
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
Calculator root = f.getRoot();
|
||||
|
||||
Expression expr = null;
|
||||
int fromSubtraction = 0;
|
||||
@ -78,10 +80,10 @@ public class ExpandRule1 {
|
||||
if (fnc instanceof Sum) {
|
||||
Function a = ((Sum) fnc).getVariable1();
|
||||
Function b = ((Sum) fnc).getVariable2();
|
||||
Subtraction fnc2 = new Subtraction(f.getParent(), null, b);
|
||||
fnc2.setVariable1(new Negative(fnc2, a));
|
||||
Subtraction fnc2 = new Subtraction(root, null, b);
|
||||
fnc2.setVariable1(new Negative(root, a));
|
||||
if (fromSubtraction > 0) {
|
||||
subtraction = new Subtraction(f.getParent(), null, null);
|
||||
subtraction = new Subtraction(root, null, null);
|
||||
subtraction.setVariable1(((FunctionTwoValues)f).getVariable1());
|
||||
subtraction.setVariable2(fnc2);
|
||||
result.add(subtraction);
|
||||
@ -91,10 +93,10 @@ public class ExpandRule1 {
|
||||
} else if (fnc instanceof Subtraction) {
|
||||
Function a = ((Subtraction) fnc).getVariable1();
|
||||
Function b = ((Subtraction) fnc).getVariable2();
|
||||
Sum fnc2 = new Sum(((Negative) f).getParent(), null, b);
|
||||
fnc2.setVariable1(new Negative(fnc2, a));
|
||||
Sum fnc2 = new Sum(root, null, b);
|
||||
fnc2.setVariable1(new Negative(root, a));
|
||||
if (fromSubtraction > 0) {
|
||||
subtraction = new Subtraction(f.getParent(), null, null);
|
||||
subtraction = new Subtraction(root, null, null);
|
||||
subtraction.setVariable1(((FunctionTwoValues)f).getVariable1());
|
||||
subtraction.setVariable2(fnc2);
|
||||
result.add(subtraction);
|
||||
@ -104,16 +106,16 @@ public class ExpandRule1 {
|
||||
} else if (fnc instanceof SumSubtraction) {
|
||||
Function a = ((SumSubtraction) fnc).getVariable1();
|
||||
Function b = ((SumSubtraction) fnc).getVariable2();
|
||||
Sum fnc2 = new Sum(f.getParent(), null, b);
|
||||
fnc2.setVariable1(new Negative(fnc2, a));
|
||||
Subtraction fnc3 = new Subtraction(f.getParent(), null, b);
|
||||
fnc3.setVariable1(new Negative(fnc2, a));
|
||||
Sum fnc2 = new Sum(root, null, b);
|
||||
fnc2.setVariable1(new Negative(root, a));
|
||||
Subtraction fnc3 = new Subtraction(root, null, b);
|
||||
fnc3.setVariable1(new Negative(root, a));
|
||||
if (fromSubtraction > 0) {
|
||||
subtraction = new SumSubtraction(f.getParent(), null, null);
|
||||
subtraction = new SumSubtraction(root, null, null);
|
||||
subtraction.setVariable1(((FunctionTwoValues)f).getVariable1());
|
||||
subtraction.setVariable2(fnc2);
|
||||
result.add(subtraction);
|
||||
subtraction = new SumSubtraction(f.getParent(), null, null);
|
||||
subtraction = new SumSubtraction(root, null, null);
|
||||
subtraction.setVariable1(((FunctionTwoValues)f).getVariable1());
|
||||
subtraction.setVariable2(fnc3);
|
||||
result.add(subtraction);
|
||||
|
@ -3,6 +3,7 @@ package org.warp.picalculator.math.rules;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.functions.Expression;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.Negative;
|
||||
@ -39,10 +40,10 @@ public class ExpandRule5 {
|
||||
|
||||
if (f instanceof Negative) {
|
||||
Negative fnc = (Negative) f;
|
||||
result.add(((Negative)((Expression)fnc.getVariable()).getVariable(0)).getVariable().setParent(f.getParent()));
|
||||
result.add(((Negative)((Expression)fnc.getVariable()).getVariable(0)).getVariable());
|
||||
} else if (f instanceof Subtraction) {
|
||||
Subtraction fnc = (Subtraction) f;
|
||||
result.add(((Negative)((Expression)fnc.getVariable2()).getVariable(0)).getVariable().setParent(f.getParent()));
|
||||
result.add(((Negative)((Expression)fnc.getVariable2()).getVariable(0)).getVariable());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package org.warp.picalculator.math.rules;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.Number;
|
||||
import org.warp.picalculator.math.functions.Power;
|
||||
@ -17,15 +18,17 @@ public class ExponentRule1 {
|
||||
|
||||
public static boolean compare(Function f) {
|
||||
Power fnc = (Power) f;
|
||||
if (fnc.getVariable1().equals(new Number(null, 1))) {
|
||||
Calculator root = f.getRoot();
|
||||
if (fnc.getVariable1().equals(new Number(root, 1))) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static ArrayList<Function> execute(Function f) throws Error {
|
||||
Calculator root = f.getRoot();
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
result.add(new Number(f.getParent(), 1));
|
||||
result.add(new Number(root, 1));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@ package org.warp.picalculator.math.rules;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.functions.Expression;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.Multiplication;
|
||||
@ -26,13 +27,14 @@ public class ExponentRule15 {
|
||||
}
|
||||
|
||||
public static ArrayList<Function> execute(Function f) throws Error {
|
||||
Calculator root = f.getRoot();
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
Multiplication fnc = (Multiplication) f;
|
||||
Power p = new Power(fnc.getParent(), null, null);
|
||||
Expression expr = new Expression(p);
|
||||
Function a = fnc.getVariable1().setParent(expr);
|
||||
Power p = new Power(root, null, null);
|
||||
Expression expr = new Expression(root);
|
||||
Function a = fnc.getVariable1();
|
||||
expr.addFunctionToEnd(a);
|
||||
Number two = new Number(p, 2);
|
||||
Number two = new Number(root, 2);
|
||||
p.setVariable1(expr);
|
||||
p.setVariable2(two);
|
||||
result.add(p);
|
||||
|
@ -3,6 +3,7 @@ package org.warp.picalculator.math.rules;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.functions.Expression;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.Multiplication;
|
||||
@ -29,13 +30,14 @@ public class ExponentRule16 {
|
||||
}
|
||||
|
||||
public static ArrayList<Function> execute(Function f) throws Error {
|
||||
Calculator root = f.getRoot();
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
Multiplication fnc = (Multiplication) f;
|
||||
Power p = new Power(fnc.getParent(), null, null);
|
||||
Expression expr = new Expression(p);
|
||||
Function a = fnc.getVariable1().setParent(expr);
|
||||
Power p = new Power(fnc.getRoot(), null, null);
|
||||
Expression expr = new Expression(root);
|
||||
Function a = fnc.getVariable1();
|
||||
expr.addFunctionToEnd(a);
|
||||
Number two = new Number(p, 2);
|
||||
Number two = new Number(root, 2);
|
||||
p.setVariable1(expr);
|
||||
p.setVariable2(two);
|
||||
result.add(p);
|
||||
|
@ -17,7 +17,7 @@ public class ExponentRule2 {
|
||||
|
||||
public static boolean compare(Function f) {
|
||||
Power fnc = (Power) f;
|
||||
if (fnc.getVariable2().equals(new Number(null, 1))) {
|
||||
if (fnc.getVariable2().equals(new Number(f.getRoot(), 1))) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -25,7 +25,7 @@ public class ExponentRule2 {
|
||||
|
||||
public static ArrayList<Function> execute(Function f) throws Error {
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
result.add(((Power)f).getVariable1().setParent(f.getParent()));
|
||||
result.add(((Power)f).getVariable1());
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,7 @@ public class ExponentRule3 {
|
||||
|
||||
public static boolean compare(Function f) {
|
||||
Power fnc = (Power) f;
|
||||
if (fnc.getVariable2().equals(new Number(null, 0))) {
|
||||
if (fnc.getVariable2().equals(new Number(f.getRoot(), 0))) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -25,7 +25,7 @@ public class ExponentRule3 {
|
||||
|
||||
public static ArrayList<Function> execute(Function f) throws Error {
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
result.add(new Number(f.getParent(), 1));
|
||||
result.add(new Number(f.getRoot(), 1));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@ package org.warp.picalculator.math.rules;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.functions.Expression;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.Multiplication;
|
||||
@ -26,6 +27,7 @@ public class ExponentRule4 {
|
||||
}
|
||||
|
||||
public static ArrayList<Function> execute(Function f) throws Error {
|
||||
Calculator root = f.getRoot();
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
Power fnc = (Power) f;
|
||||
Expression expr = (Expression) fnc.getVariable1();
|
||||
@ -33,14 +35,14 @@ public class ExponentRule4 {
|
||||
Function a = mult.getVariable1();
|
||||
Function b = mult.getVariable2();
|
||||
Number n = (Number) fnc.getVariable2();
|
||||
Multiplication retMult = new Multiplication(f.getParent(), null, null);
|
||||
Power p1 = new Power(retMult, null, null);
|
||||
Expression e1 = new Expression(p1);
|
||||
Multiplication retMult = new Multiplication(root, null, null);
|
||||
Power p1 = new Power(root, null, null);
|
||||
Expression e1 = new Expression(root);
|
||||
e1.addFunctionToEnd(a);
|
||||
p1.setVariable1(e1);
|
||||
p1.setVariable2(n);
|
||||
Power p2 = new Power(retMult, null, null);
|
||||
Expression e2 = new Expression(p2);
|
||||
Power p2 = new Power(root, null, null);
|
||||
Expression e2 = new Expression(root);
|
||||
e2.addFunctionToEnd(b);
|
||||
p2.setVariable1(e2);
|
||||
p2.setVariable2(n);
|
||||
|
@ -3,6 +3,7 @@ package org.warp.picalculator.math.rules;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.functions.Division;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.Number;
|
||||
@ -16,25 +17,26 @@ import org.warp.picalculator.math.functions.Number;
|
||||
public class FractionsRule1 {
|
||||
|
||||
public static boolean compare(Function f) {
|
||||
Division fnc = (Division) f;
|
||||
if (fnc.getVariable1() instanceof Number) {
|
||||
Number numb1 = (Number) fnc.getVariable1();
|
||||
if (numb1.equals(new Number(null, 0))) {
|
||||
if (fnc.getVariable2() instanceof Number) {
|
||||
Number numb2 = (Number) fnc.getVariable2();
|
||||
if (numb2.equals(new Number(null, 0))) {
|
||||
return false;
|
||||
}
|
||||
Calculator root = f.getRoot();
|
||||
Division fnc = (Division) f;
|
||||
if (fnc.getVariable1() instanceof Number) {
|
||||
Number numb1 = (Number) fnc.getVariable1();
|
||||
if (numb1.equals(new Number(root, 0))) {
|
||||
if (fnc.getVariable2() instanceof Number) {
|
||||
Number numb2 = (Number) fnc.getVariable2();
|
||||
if (numb2.equals(new Number(root, 0))) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static ArrayList<Function> execute(Function f) throws Error {
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
result.add(new Number(f.getParent(), 0));
|
||||
result.add(new Number(f.getRoot(), 0));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@ public class FractionsRule2 {
|
||||
Division fnc = (Division) f;
|
||||
if (fnc.getVariable2() instanceof Number) {
|
||||
Number numb = (Number) fnc.getVariable2();
|
||||
if (numb.equals(new Number(null, 1))) {
|
||||
if (numb.equals(new Number(f.getRoot(), 1))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -29,7 +29,7 @@ public class FractionsRule2 {
|
||||
public static ArrayList<Function> execute(Function f) throws Error {
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
Division fnc = (Division) f;
|
||||
result.add(fnc.getVariable1().setParent(f.getParent()));
|
||||
result.add(fnc.getVariable1());
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@ public class FractionsRule3 {
|
||||
|
||||
public static ArrayList<Function> execute(Function f) throws Error {
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
result.add(new Number(f.getParent(), 1));
|
||||
result.add(new Number(f.getRoot(), 1));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ public class FractionsRule4 {
|
||||
Power fnc = (Power) f;
|
||||
if (fnc.getVariable1() instanceof Division && fnc.getVariable2() instanceof Number) {
|
||||
Number n2 = (Number) fnc.getVariable2();
|
||||
if (n2.equals(new Number(null, -1))) {
|
||||
if (n2.equals(new Number(f.getRoot(), -1))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -32,7 +32,7 @@ public class FractionsRule4 {
|
||||
Power fnc = (Power) f;
|
||||
Function a = ((Division)fnc.getVariable1()).getVariable1();
|
||||
Function b = ((Division)fnc.getVariable1()).getVariable2();
|
||||
Division res = new Division(f.getParent(), b, a);
|
||||
Division res = new Division(f.getRoot(), b, a);
|
||||
result.add(res);
|
||||
return result;
|
||||
}
|
||||
|
@ -1,11 +1,12 @@
|
||||
package org.warp.picalculator.math.rules;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.functions.Division;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.Number;
|
||||
package org.warp.picalculator.math.rules;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.functions.Division;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.Number;
|
||||
import org.warp.picalculator.math.functions.Power;
|
||||
|
||||
/**
|
||||
@ -20,7 +21,7 @@ public class FractionsRule5 {
|
||||
Power fnc = (Power) f;
|
||||
if (fnc.getVariable1() instanceof Division && fnc.getVariable2() instanceof Number) {
|
||||
Number n2 = (Number) fnc.getVariable2();
|
||||
if (n2.getTerm().compareTo(BigDecimal.ZERO) < 0) {
|
||||
if (n2.getTerm().compareTo(BigDecimal.ZERO) < 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -28,14 +29,14 @@ public class FractionsRule5 {
|
||||
}
|
||||
|
||||
public static ArrayList<Function> execute(Function f) throws Error {
|
||||
Calculator root = f.getRoot();
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
Power fnc = (Power) f;
|
||||
Function a = ((Division)fnc.getVariable1()).getVariable1();
|
||||
Function b = ((Division)fnc.getVariable1()).getVariable2();
|
||||
Function c = ((Number)fnc.getVariable2()).multiply(new Number(null, "-1"));
|
||||
Division dv = new Division(null, b, a);
|
||||
Power pow = new Power(f.getParent(), dv, c);
|
||||
dv.setParent(pow);
|
||||
Function c = ((Number)fnc.getVariable2()).multiply(new Number(root, "-1"));
|
||||
Division dv = new Division(root, b, a);
|
||||
Power pow = new Power(root, dv, c);
|
||||
result.add(pow);
|
||||
return result;
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package org.warp.picalculator.math.rules;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.Multiplication;
|
||||
import org.warp.picalculator.math.functions.Number;
|
||||
@ -16,16 +17,17 @@ import org.warp.picalculator.math.functions.Number;
|
||||
public class NumberRule1 {
|
||||
|
||||
public static boolean compare(Function f) {
|
||||
Calculator root = f.getRoot();
|
||||
Multiplication mult = (Multiplication) f;
|
||||
if (mult.getVariable1() instanceof Number) {
|
||||
Number numb = (Number) mult.getVariable1();
|
||||
if (numb.equals(new Number(null, 0))) {
|
||||
if (numb.equals(new Number(root, 0))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (mult.getVariable2() instanceof Number) {
|
||||
Number numb = (Number) mult.getVariable2();
|
||||
if (numb.equals(new Number(null, 0))) {
|
||||
if (numb.equals(new Number(root, 0))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -34,7 +36,7 @@ public class NumberRule1 {
|
||||
|
||||
public static ArrayList<Function> execute(Function f) throws Error {
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
result.add(new Number(f.getParent(), "0"));
|
||||
result.add(new Number(f.getRoot(), "0"));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@ package org.warp.picalculator.math.rules;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.Multiplication;
|
||||
import org.warp.picalculator.math.functions.Number;
|
||||
@ -16,16 +17,17 @@ import org.warp.picalculator.math.functions.Number;
|
||||
public class NumberRule2 {
|
||||
|
||||
public static boolean compare(Function f) {
|
||||
Calculator root = f.getRoot();
|
||||
Multiplication mult = (Multiplication) f;
|
||||
if (mult.getVariable1() instanceof Number) {
|
||||
Number numb = (Number) mult.getVariable1();
|
||||
if (numb.equals(new Number(null, 1))) {
|
||||
if (numb.equals(new Number(root, 1))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (mult.getVariable2() instanceof Number) {
|
||||
Number numb = (Number) mult.getVariable2();
|
||||
if (numb.equals(new Number(null, 1))) {
|
||||
if (numb.equals(new Number(root, 1))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -33,26 +35,27 @@ public class NumberRule2 {
|
||||
}
|
||||
|
||||
public static ArrayList<Function> execute(Function f) throws Error {
|
||||
Calculator root = f.getRoot();
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
Function a = null;
|
||||
boolean aFound = false;
|
||||
Multiplication mult = (Multiplication) f;
|
||||
if (aFound == false & mult.getVariable1() instanceof Number) {
|
||||
Number numb = (Number) mult.getVariable1();
|
||||
if (numb.equals(new Number(null, 1))) {
|
||||
if (numb.equals(new Number(root, 1))) {
|
||||
a = mult.getVariable2();
|
||||
aFound = true;
|
||||
}
|
||||
}
|
||||
if (aFound == false && mult.getVariable2() instanceof Number) {
|
||||
Number numb = (Number) mult.getVariable2();
|
||||
if (numb.equals(new Number(null, 1))) {
|
||||
if (numb.equals(new Number(root, 1))) {
|
||||
a = mult.getVariable1();
|
||||
aFound = true;
|
||||
}
|
||||
}
|
||||
|
||||
result.add(a.setParent(f.getParent()));
|
||||
result.add(a.setParent(root));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@ package org.warp.picalculator.math.rules;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.Multiplication;
|
||||
import org.warp.picalculator.math.functions.Negative;
|
||||
@ -45,14 +46,15 @@ public class NumberRule3 {
|
||||
}
|
||||
|
||||
public static ArrayList<Function> execute(Function f) throws Error {
|
||||
Calculator root = f.getRoot();
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
if (f instanceof SumSubtraction) {
|
||||
Multiplication mul = new Multiplication(f.getParent(), null, null);
|
||||
mul.setVariable1(new Number(null, 2));
|
||||
Multiplication mul = new Multiplication(root, null, null);
|
||||
mul.setVariable1(new Number(root, 2));
|
||||
mul.setVariable2(f);
|
||||
result.add(mul);
|
||||
}
|
||||
result.add(new Number(f.getParent(), 0));
|
||||
result.add(new Number(root, 0));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@ package org.warp.picalculator.math.rules;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.Subtraction;
|
||||
import org.warp.picalculator.math.functions.Sum;
|
||||
@ -24,10 +25,11 @@ public class NumberRule4 {
|
||||
}
|
||||
|
||||
public static ArrayList<Function> execute(Function f) throws Error {
|
||||
Calculator root = f.getRoot();
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
SumSubtraction ss = (SumSubtraction) f;
|
||||
result.add(new Sum(f.getParent(), ss.getVariable1(), ss.getVariable2()));
|
||||
result.add(new Subtraction(f.getParent(), ss.getVariable1(), ss.getVariable2()));
|
||||
result.add(new Sum(root, ss.getVariable1(), ss.getVariable2()));
|
||||
result.add(new Subtraction(root, ss.getVariable1(), ss.getVariable2()));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@ package org.warp.picalculator.math.rules;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.FunctionTwoValues;
|
||||
import org.warp.picalculator.math.functions.Number;
|
||||
@ -21,21 +22,23 @@ import org.warp.picalculator.math.functions.Number;
|
||||
public class NumberRule5 {
|
||||
|
||||
public static boolean compare(Function f) {
|
||||
Calculator root = f.getRoot();
|
||||
FunctionTwoValues fnc = (FunctionTwoValues) f;
|
||||
if (fnc.getVariable1().equals(new Number(null, 0)) || fnc.getVariable2().equals(new Number(null, 0))) {
|
||||
if (fnc.getVariable1().equals(new Number(root, 0)) || fnc.getVariable2().equals(new Number(root, 0))) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static ArrayList<Function> execute(Function f) throws Error {
|
||||
Calculator root = f.getRoot();
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
FunctionTwoValues fnc = (FunctionTwoValues) f;
|
||||
Function a = fnc.getVariable1();
|
||||
if (a.equals(new Number(null, 0))) {
|
||||
if (a.equals(new Number(root, 0))) {
|
||||
a = fnc.getVariable2();
|
||||
}
|
||||
result.add(a.setParent(f.getParent()));
|
||||
result.add(a);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@ package org.warp.picalculator.math.rules;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.Multiplication;
|
||||
import org.warp.picalculator.math.functions.Negative;
|
||||
@ -17,16 +18,17 @@ import org.warp.picalculator.math.functions.Number;
|
||||
public class NumberRule6 {
|
||||
|
||||
public static boolean compare(Function f) {
|
||||
Calculator root = f.getRoot();
|
||||
Multiplication mult = (Multiplication) f;
|
||||
if (mult.getVariable1() instanceof Number) {
|
||||
Number numb = (Number) mult.getVariable1();
|
||||
if (numb.equals(new Number(null, -1))) {
|
||||
if (numb.equals(new Number(root, -1))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (mult.getVariable2() instanceof Number) {
|
||||
Number numb = (Number) mult.getVariable2();
|
||||
if (numb.equals(new Number(null, -1))) {
|
||||
if (numb.equals(new Number(root, -1))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -34,26 +36,27 @@ public class NumberRule6 {
|
||||
}
|
||||
|
||||
public static ArrayList<Function> execute(Function f) throws Error {
|
||||
Calculator root = f.getRoot();
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
Function a = null;
|
||||
boolean aFound = false;
|
||||
Multiplication mult = (Multiplication) f;
|
||||
if (aFound == false & mult.getVariable1() instanceof Number) {
|
||||
Number numb = (Number) mult.getVariable1();
|
||||
if (numb.equals(new Number(null, -1))) {
|
||||
if (numb.equals(new Number(root, -1))) {
|
||||
a = mult.getVariable2();
|
||||
aFound = true;
|
||||
}
|
||||
}
|
||||
if (aFound == false && mult.getVariable2() instanceof Number) {
|
||||
Number numb = (Number) mult.getVariable2();
|
||||
if (numb.equals(new Number(null, -1))) {
|
||||
if (numb.equals(new Number(root, -1))) {
|
||||
a = mult.getVariable1();
|
||||
aFound = true;
|
||||
}
|
||||
}
|
||||
|
||||
Negative minus = new Negative(f.getParent(), null);
|
||||
Negative minus = new Negative(root, null);
|
||||
minus.setVariable(a);
|
||||
|
||||
result.add(minus);
|
||||
|
@ -3,6 +3,7 @@ package org.warp.picalculator.math.rules;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.Multiplication;
|
||||
import org.warp.picalculator.math.functions.Number;
|
||||
@ -21,9 +22,10 @@ public class NumberRule7 {
|
||||
}
|
||||
|
||||
public static ArrayList<Function> execute(Sum f) throws Error {
|
||||
Calculator root = f.getRoot();
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
Multiplication mult = new Multiplication(f.getParent(), null, null);
|
||||
mult.setVariable1(new Number(null, 2));
|
||||
Multiplication mult = new Multiplication(root, null, null);
|
||||
mult.setVariable1(new Number(root, 2));
|
||||
mult.setVariable2(f.getVariable1());
|
||||
result.add(mult);
|
||||
return result;
|
||||
|
@ -3,6 +3,7 @@ package org.warp.picalculator.math.rules;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.FunctionTwoValues;
|
||||
import org.warp.picalculator.math.functions.Multiplication;
|
||||
@ -27,6 +28,7 @@ public class SyntaxRule1 {
|
||||
}
|
||||
|
||||
public static ArrayList<Function> execute(Function f) throws Error {
|
||||
Calculator root = f.getRoot();
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
FunctionTwoValues mOut = (FunctionTwoValues) f;
|
||||
Function a = ((FunctionTwoValues)mOut.getVariable1()).getVariable1();
|
||||
@ -34,9 +36,9 @@ public class SyntaxRule1 {
|
||||
Function c = mOut.getVariable2();
|
||||
FunctionTwoValues mIn;
|
||||
if (f instanceof Multiplication) {
|
||||
mIn = new Multiplication(mOut, null, null);
|
||||
mIn = new Multiplication(root, null, null);
|
||||
} else {
|
||||
mIn = new Sum(mOut, null, null);
|
||||
mIn = new Sum(root, null, null);
|
||||
}
|
||||
mOut.setVariable1(a);
|
||||
mIn.setVariable1(b);
|
||||
|
@ -29,6 +29,7 @@ public class SyntaxRule2 {
|
||||
}
|
||||
|
||||
public static ArrayList<Function> execute(Sum f) throws Error {
|
||||
Calculator root = f.getRoot();
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
Function a = f.getVariable1();
|
||||
Function b, c;
|
||||
@ -39,7 +40,7 @@ public class SyntaxRule2 {
|
||||
b = ((Sum)((Expression)f.getVariable2()).getVariable(0)).getVariable1();
|
||||
c = ((Sum)((Expression)f.getVariable2()).getVariable(0)).getVariable2();
|
||||
}
|
||||
Sum mIn = new Sum(f, null, null);
|
||||
Sum mIn = new Sum(root, null, null);
|
||||
f.setVariable1(mIn);
|
||||
mIn.setVariable1(a);
|
||||
mIn.setVariable2(b);
|
||||
|
@ -3,6 +3,7 @@ package org.warp.picalculator.math.rules;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.Number;
|
||||
import org.warp.picalculator.math.functions.Power;
|
||||
@ -17,16 +18,18 @@ import org.warp.picalculator.math.functions.Undefined;
|
||||
public class UndefinedRule1 {
|
||||
|
||||
public static boolean compare(Function f) {
|
||||
Calculator root = f.getRoot();
|
||||
Power fnc = (Power) f;
|
||||
if (fnc.getVariable1().equals(new Number(null, 0)) && fnc.getVariable2().equals(new Number(null, 0))) {
|
||||
if (fnc.getVariable1().equals(new Number(root, 0)) && fnc.getVariable2().equals(new Number(root, 0))) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static ArrayList<Function> execute(Function f) throws Error {
|
||||
Calculator root = f.getRoot();
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
result.add(new Undefined(f.getParent()));
|
||||
result.add(new Undefined(root));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@ package org.warp.picalculator.math.rules;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.functions.Division;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.Number;
|
||||
@ -17,10 +18,11 @@ import org.warp.picalculator.math.functions.Undefined;
|
||||
public class UndefinedRule2 {
|
||||
|
||||
public static boolean compare(Function f) {
|
||||
Calculator root = f.getRoot();
|
||||
Division fnc = (Division) f;
|
||||
if (fnc.getVariable2() instanceof Number) {
|
||||
Number numb = (Number) fnc.getVariable2();
|
||||
if (numb.equals(new Number(null, 0))) {
|
||||
if (numb.equals(new Number(root, 0))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -28,8 +30,9 @@ public class UndefinedRule2 {
|
||||
}
|
||||
|
||||
public static ArrayList<Function> execute(Function f) throws Error {
|
||||
Calculator root = f.getRoot();
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
result.add(new Undefined(f.getParent()));
|
||||
result.add(new Undefined(root));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@ package org.warp.picalculator.math.rules;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.functions.Expression;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.FunctionTwoValues;
|
||||
@ -30,6 +31,7 @@ public class VariableRule1 {
|
||||
}
|
||||
|
||||
public static ArrayList<Function> execute(FunctionTwoValues fnc) throws Error {
|
||||
Calculator root = fnc.getRoot();
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
Multiplication m1 = (Multiplication) fnc.getVariable1();
|
||||
Multiplication m2 = (Multiplication) fnc.getVariable2();
|
||||
@ -37,13 +39,13 @@ public class VariableRule1 {
|
||||
Function b = m2.getVariable1();
|
||||
Function x = m1.getVariable2();
|
||||
|
||||
Multiplication retm = new Multiplication(fnc.getParent(), null, null);
|
||||
Expression rete = new Expression(retm);
|
||||
Multiplication retm = new Multiplication(root, null, null);
|
||||
Expression rete = new Expression(root);
|
||||
FunctionTwoValues rets;
|
||||
if (fnc instanceof Sum){
|
||||
rets = new Sum(rete, null, null);
|
||||
rets = new Sum(root, null, null);
|
||||
} else {
|
||||
rets = new Subtraction(rete, null, null);
|
||||
rets = new Subtraction(root, null, null);
|
||||
}
|
||||
rets.setVariable1(a);
|
||||
rets.setVariable2(b);
|
||||
|
@ -3,6 +3,7 @@ package org.warp.picalculator.math.rules;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.functions.Expression;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.FunctionTwoValues;
|
||||
@ -30,22 +31,23 @@ public class VariableRule2 {
|
||||
}
|
||||
|
||||
public static ArrayList<Function> execute(FunctionTwoValues fnc) throws Error {
|
||||
Calculator root = fnc.getRoot();
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
Multiplication m1 = (Multiplication) fnc.getVariable1();
|
||||
Function a = m1.getVariable1();
|
||||
Function x = fnc.getVariable2();
|
||||
|
||||
Multiplication retm = new Multiplication(fnc.getParent(), null, null);
|
||||
Expression rete = new Expression(retm);
|
||||
Multiplication retm = new Multiplication(root, null, null);
|
||||
Expression rete = new Expression(root);
|
||||
|
||||
FunctionTwoValues rets;
|
||||
if (fnc instanceof Sum) {
|
||||
rets = new Sum(rete, null, null);
|
||||
rets = new Sum(root, null, null);
|
||||
} else {
|
||||
rets = new Subtraction(rete, null, null);
|
||||
rets = new Subtraction(root, null, null);
|
||||
}
|
||||
rets.setVariable1(a);
|
||||
rets.setVariable2(new Number(rets, 1));
|
||||
rets.setVariable2(new Number(root, 1));
|
||||
rete.addFunctionToEnd(rets);
|
||||
retm.setVariable1(rete);
|
||||
retm.setVariable2(x);
|
||||
|
@ -3,6 +3,7 @@ package org.warp.picalculator.math.rules;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.functions.Expression;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.FunctionTwoValues;
|
||||
@ -30,21 +31,22 @@ public class VariableRule3 {
|
||||
}
|
||||
|
||||
public static ArrayList<Function> execute(FunctionTwoValues fnc) throws Error {
|
||||
Calculator root = fnc.getRoot();
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
Multiplication m2 = (Multiplication) fnc.getVariable2();
|
||||
Function a = m2.getVariable1();
|
||||
Function x = fnc.getVariable1();
|
||||
|
||||
Multiplication retm = new Multiplication(fnc.getParent(), null, null);
|
||||
Expression rete = new Expression(retm);
|
||||
Multiplication retm = new Multiplication(root, null, null);
|
||||
Expression rete = new Expression(root);
|
||||
FunctionTwoValues rets;
|
||||
if (fnc instanceof Sum) {
|
||||
rets = new Sum(rete, null, null);
|
||||
rets = new Sum(root, null, null);
|
||||
} else {
|
||||
rets = new Subtraction(rete, null, null);
|
||||
rets = new Subtraction(root, null, null);
|
||||
}
|
||||
|
||||
rets.setVariable1(new Number(rets, 1));
|
||||
rets.setVariable1(new Number(root, 1));
|
||||
rets.setVariable2(a);
|
||||
rete.addFunctionToEnd(rets);
|
||||
retm.setVariable1(rete);
|
||||
|
@ -0,0 +1,93 @@
|
||||
package org.warp.picalculator.math.rules.methods;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.Multiplication;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.functions.Division;
|
||||
import org.warp.picalculator.math.functions.Number;
|
||||
|
||||
/**
|
||||
* Division method<br>
|
||||
* <b>Example: (XY)/(YZ) = X/Z</b>
|
||||
* @author Andrea Cavalli
|
||||
*
|
||||
*/
|
||||
public class DivisionRule1 {
|
||||
|
||||
public static boolean compare(Division f) {
|
||||
return f.getVariable1().isSolved() && f.getVariable2().isSolved() && !(f.getVariable1() instanceof Number && f.getVariable2() instanceof Number) && getFirstWorkingDivisionCouple(getDivisionElements(f)) != null;
|
||||
}
|
||||
|
||||
public static ArrayList<Function> execute(Division f) throws Error {
|
||||
Calculator root = f.getRoot();
|
||||
Function result;
|
||||
ArrayList<Function> elements = getDivisionElements(f);
|
||||
int[] workingElementCouple = getFirstWorkingDivisionCouple(elements);
|
||||
Function elem1 = elements.get(workingElementCouple[0]);
|
||||
Function elem2 = elements.get(workingElementCouple[1]);
|
||||
|
||||
final int size = elements.size();
|
||||
Function prec = new Multiplication(root, elem1, elem2);
|
||||
for (int i = size-1; i >= 0; i--) {
|
||||
if (i != workingElementCouple[0] & i != workingElementCouple[1]) {
|
||||
Function a = prec;
|
||||
Function b = elements.get(i);
|
||||
prec = new Multiplication(root, a, b);
|
||||
}
|
||||
}
|
||||
|
||||
result = prec;
|
||||
|
||||
ArrayList<Function> results = new ArrayList<>();
|
||||
results.add(result);
|
||||
return results;
|
||||
}
|
||||
|
||||
private static ArrayList<Function> getDivisionElements(Division division) {
|
||||
ArrayList<Function> elementsNumerator = new ArrayList<>();
|
||||
Function numMult = division.getVariable1();
|
||||
while (numMult instanceof Multiplication) {
|
||||
elementsNumerator.add(((Multiplication) numMult).getVariable1());
|
||||
numMult = ((Multiplication) numMult).getVariable2();
|
||||
}
|
||||
elementsNumerator.add(numMult);
|
||||
|
||||
ArrayList<Function> elementsDenominator = new ArrayList<>();
|
||||
Function denomMult = division.getVariable1();
|
||||
while (denomMult instanceof Multiplication) {
|
||||
elementsDenominator.add(((Multiplication) denomMult).getVariable1());
|
||||
denomMult = ((Multiplication) denomMult).getVariable2();
|
||||
}
|
||||
elementsDenominator.add(denomMult);
|
||||
|
||||
|
||||
return elements;
|
||||
}
|
||||
|
||||
private static int[] getFirstWorkingDivisionCouple(ArrayList<Function> elements) {
|
||||
final int size = elements.size();
|
||||
Function a;
|
||||
Function b;
|
||||
if (elements.size() == 2) {
|
||||
return null;
|
||||
}
|
||||
for (int i = 0; i < size; i++) {
|
||||
a = elements.get(i);
|
||||
for (int j = 0; j < size; j++) {
|
||||
b = elements.get(j);
|
||||
if (i != j) {
|
||||
Function testFunc;
|
||||
testFunc = new Multiplication(root, a, b);
|
||||
if (!testFunc.isSolved()) {
|
||||
return new int[]{i, j};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -3,6 +3,7 @@ package org.warp.picalculator.math.rules.methods;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.Multiplication;
|
||||
import org.warp.picalculator.math.functions.Number;
|
||||
@ -21,25 +22,21 @@ public class MultiplicationMethod1 {
|
||||
|
||||
public static ArrayList<Function> execute(Function f) throws Error {
|
||||
Function result;
|
||||
Calculator root = f.getRoot();
|
||||
ArrayList<Function> elements = getMultiplicationElements(f);
|
||||
int[] workingElementCouple = getFirstWorkingMultiplicationCouple(elements);
|
||||
Function elem1 = elements.get(workingElementCouple[0]);
|
||||
Function elem2 = elements.get(workingElementCouple[1]);
|
||||
|
||||
final int size = elements.size();
|
||||
Function prec = new Multiplication(null, elem1, elem2);
|
||||
elem1.setParent(prec);
|
||||
elem2.setParent(prec);
|
||||
Function prec = new Multiplication(root, elem1, elem2);
|
||||
for (int i = size-1; i >= 0; i--) {
|
||||
if (i != workingElementCouple[0] & i != workingElementCouple[1]) {
|
||||
Function a = prec;
|
||||
Function b = elements.get(i);
|
||||
prec = new Multiplication(null, a, b);
|
||||
a.setParent(prec);
|
||||
b.setParent(prec);
|
||||
prec = new Multiplication(root, a, b);
|
||||
}
|
||||
}
|
||||
prec.setParent(f.getParent());
|
||||
|
||||
result = prec;
|
||||
|
||||
@ -62,16 +59,20 @@ public class MultiplicationMethod1 {
|
||||
final int size = elements.size();
|
||||
Function a;
|
||||
Function b;
|
||||
if (elements.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
if (elements.size() == 2) {
|
||||
return null;
|
||||
}
|
||||
Calculator root = elements.get(0).getRoot();
|
||||
for (int i = 0; i < size; i++) {
|
||||
a = elements.get(i);
|
||||
for (int j = 0; j < size; j++) {
|
||||
b = elements.get(j);
|
||||
if (i != j) {
|
||||
Function testFunc;
|
||||
testFunc = new Multiplication(null, a, b);
|
||||
testFunc = new Multiplication(root, a, b);
|
||||
if (!testFunc.isSolved()) {
|
||||
return new int[]{i, j};
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.FunctionTwoValues;
|
||||
import org.warp.picalculator.math.functions.Negative;
|
||||
@ -20,40 +21,35 @@ import org.warp.picalculator.math.functions.Sum;
|
||||
public class SumMethod1 {
|
||||
|
||||
public static boolean compare(Function f) {
|
||||
return (f instanceof Sum || f instanceof Subtraction) && ((FunctionTwoValues)f).getVariable1().isSolved() && ((FunctionTwoValues)f).getVariable2().isSolved() && !(((FunctionTwoValues)f).getVariable1() instanceof Number && ((FunctionTwoValues)f).getVariable2() instanceof Number) && getFirstWorkingSumCouple(getSumElements(f)) != null;
|
||||
Calculator root = f.getRoot();
|
||||
return (f instanceof Sum || f instanceof Subtraction) && ((FunctionTwoValues)f).getVariable1().isSolved() && ((FunctionTwoValues)f).getVariable2().isSolved() && !(((FunctionTwoValues)f).getVariable1() instanceof Number && ((FunctionTwoValues)f).getVariable2() instanceof Number) && getFirstWorkingSumCouple(root, getSumElements(f)) != null;
|
||||
}
|
||||
|
||||
public static ArrayList<Function> execute(Function f) throws Error {
|
||||
Function result;
|
||||
Calculator root = f.getRoot();
|
||||
ArrayList<Function> elements = getSumElements(f);
|
||||
int[] workingElementCouple = getFirstWorkingSumCouple(elements);
|
||||
int[] workingElementCouple = getFirstWorkingSumCouple(root, elements);
|
||||
Function elem1 = elements.get(workingElementCouple[0]);
|
||||
Function elem2 = elements.get(workingElementCouple[1]);
|
||||
|
||||
final int size = elements.size();
|
||||
Function prec = new Sum(null, elem1, elem2);
|
||||
elem1.setParent(prec);
|
||||
elem2.setParent(prec);
|
||||
Function prec = new Sum(root, elem1, elem2);
|
||||
for (int i = size-1; i >= 0; i--) {
|
||||
if (i != workingElementCouple[0] & i != workingElementCouple[1]) {
|
||||
Function a = prec;
|
||||
Function b = elements.get(i);
|
||||
if (b instanceof Negative) {
|
||||
prec = new Subtraction(null, a, ((Negative)b).getVariable());
|
||||
a.setParent(prec);
|
||||
((FunctionTwoValues)prec).getVariable2().setParent(prec);
|
||||
prec = new Subtraction(root, a, ((Negative)b).getVariable());
|
||||
((FunctionTwoValues)prec).getVariable2();
|
||||
} else if (b instanceof Number && ((Number) b).getTerm().compareTo(BigDecimal.ZERO) < 0) {
|
||||
prec = new Subtraction(null, a, ((Number)b).multiply(new Number(null, -1)));
|
||||
a.setParent(prec);
|
||||
((FunctionTwoValues)prec).getVariable2().setParent(prec);
|
||||
prec = new Subtraction(root, a, ((Number)b).multiply(new Number(root, -1)));
|
||||
((FunctionTwoValues)prec).getVariable2();
|
||||
} else {
|
||||
prec = new Sum(null, a, b);
|
||||
a.setParent(prec);
|
||||
b.setParent(prec);
|
||||
prec = new Sum(root, a, b);
|
||||
}
|
||||
}
|
||||
}
|
||||
prec.setParent(f.getParent());
|
||||
|
||||
result = prec;
|
||||
|
||||
@ -63,12 +59,13 @@ public class SumMethod1 {
|
||||
}
|
||||
|
||||
private static ArrayList<Function> getSumElements(Function sum) {
|
||||
Calculator root = sum.getRoot();
|
||||
ArrayList<Function> elements = new ArrayList<>();
|
||||
while (sum instanceof Sum || sum instanceof Subtraction) {
|
||||
if (sum instanceof Sum) {
|
||||
elements.add(((FunctionTwoValues) sum).getVariable2());
|
||||
} else {
|
||||
elements.add(new Negative(null, ((FunctionTwoValues) sum).getVariable2()));
|
||||
elements.add(new Negative(root, ((FunctionTwoValues) sum).getVariable2()));
|
||||
}
|
||||
sum = ((FunctionTwoValues) sum).getVariable1();
|
||||
}
|
||||
@ -76,7 +73,7 @@ public class SumMethod1 {
|
||||
return elements;
|
||||
}
|
||||
|
||||
private static int[] getFirstWorkingSumCouple(ArrayList<Function> elements) {
|
||||
private static int[] getFirstWorkingSumCouple(Calculator root, ArrayList<Function> elements) {
|
||||
final int size = elements.size();
|
||||
Function a;
|
||||
Function b;
|
||||
@ -90,15 +87,15 @@ public class SumMethod1 {
|
||||
if (i != j) {
|
||||
Function testFunc;
|
||||
if (b instanceof Negative) {
|
||||
testFunc = new Subtraction(null, a, ((Negative)b).getVariable());
|
||||
testFunc = new Subtraction(root, a, ((Negative)b).getVariable());
|
||||
} else if (b instanceof Number && ((Number) b).getTerm().compareTo(BigDecimal.ZERO) < 0) {
|
||||
testFunc = new Subtraction(null, a, ((Number)b).multiply(new Number(null, -1)));
|
||||
testFunc = new Subtraction(root, a, ((Number)b).multiply(new Number(root, -1)));
|
||||
} else if (a instanceof Negative) {
|
||||
testFunc = new Subtraction(null, b, ((Negative)a).getVariable());
|
||||
} else if (a instanceof Number && ((Number) a).getTerm().compareTo(BigDecimal.ZERO) < 0) {
|
||||
testFunc = new Subtraction(null, b, ((Number)a).multiply(new Number(null, -1)));
|
||||
testFunc = new Subtraction(root, b, ((Negative)a).getVariable());
|
||||
} else if (a instanceof Number && ((Number) a).getTerm().compareTo(BigDecimal.ZERO) < 0) {
|
||||
testFunc = new Subtraction(root, b, ((Number)a).multiply(new Number(root, -1)));
|
||||
} else {
|
||||
testFunc = new Sum(null, a, b);
|
||||
testFunc = new Sum(root, a, b);
|
||||
}
|
||||
if (!testFunc.isSolved()) {
|
||||
return new int[]{i, j};
|
||||
|
@ -0,0 +1,81 @@
|
||||
package org.warp.picalculator.screens;
|
||||
|
||||
import static org.warp.picalculator.device.graphicengine.Display.Render.glColor3i;
|
||||
import static org.warp.picalculator.device.graphicengine.Display.Render.glColor4i;
|
||||
import static org.warp.picalculator.device.graphicengine.Display.Render.glDrawStringCenter;
|
||||
|
||||
import org.warp.picalculator.Main;
|
||||
import org.warp.picalculator.device.Keyboard.Key;
|
||||
import org.warp.picalculator.device.graphicengine.Screen;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.Variable.VariableValue;
|
||||
|
||||
public class ChooseVariableValueScreen extends Screen {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private MathInputScreen es;
|
||||
public Function resultNumberValue;
|
||||
|
||||
public ChooseVariableValueScreen(MathInputScreen es, VariableValue variableValue) {
|
||||
super();
|
||||
canBeInHistory = false;
|
||||
|
||||
this.es = es;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void created() throws InterruptedException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() throws InterruptedException {}
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
glColor4i(0, 0, 0, 64);
|
||||
glDrawStringCenter(Main.screenSize[0]/2+1, Main.screenSize[1]/4, "WORK IN PROGRESS. THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE.");
|
||||
glDrawStringCenter(Main.screenSize[0]/2, Main.screenSize[1]/4+1, "WORK IN PROGRESS. THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE.");
|
||||
glDrawStringCenter(Main.screenSize[0]/2+1, Main.screenSize[1]/4+1, "WORK IN PROGRESS. THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE.");
|
||||
glColor3i(255, 0, 0);
|
||||
glDrawStringCenter(Main.screenSize[0]/2, Main.screenSize[1]/4, "WORK IN PROGRESS. THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeRender(float dt) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mustBeRefreshed() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyPressed(Key k) {
|
||||
switch (k) {
|
||||
case LETTER_X:
|
||||
// PIDisplay.INSTANCE.goBack();
|
||||
// try {
|
||||
// Calculator.solveExpression('X');
|
||||
// } catch (Error e) {
|
||||
// Screen scr = PIDisplay.INSTANCE.getScreen();
|
||||
// if (scr instanceof MathInputScreen) {
|
||||
// MathInputScreen escr = (MathInputScreen) scr;
|
||||
// escr.errorLevel = 1;
|
||||
// escr.err2 = e;
|
||||
// } else {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyReleased(Key k) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
229
src/org/warp/picalculator/screens/KeyboardDebugScreen.java
Normal file
229
src/org/warp/picalculator/screens/KeyboardDebugScreen.java
Normal file
@ -0,0 +1,229 @@
|
||||
package org.warp.picalculator.screens;
|
||||
|
||||
import static org.warp.picalculator.device.PIDisplay.colore;
|
||||
import static org.warp.picalculator.device.PIDisplay.fonts;
|
||||
import static org.warp.picalculator.device.graphicengine.Display.Render.*;
|
||||
|
||||
import org.warp.picalculator.Main;
|
||||
import org.warp.picalculator.device.Keyboard.Key;
|
||||
import org.warp.picalculator.device.graphicengine.Screen;
|
||||
|
||||
public class KeyboardDebugScreen extends Screen {
|
||||
|
||||
public String key;
|
||||
public String keyevent;
|
||||
public static int keyX;
|
||||
public static int keyY;
|
||||
public static String[] log = new String[]{"POWER ON","LOADING","LOADED","DONE","---"};
|
||||
public long beforetime;
|
||||
|
||||
public KeyboardDebugScreen() {
|
||||
super();
|
||||
canBeInHistory = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void created() throws InterruptedException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() throws InterruptedException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
glSetFont(fonts[2]);
|
||||
colore(0.75f, 0.0f, 0.0f, 1.0f);
|
||||
glDrawStringRight(Main.screenSize[0] - 10, 30, "-" + keyevent.toUpperCase() + "-");
|
||||
if (keyevent != "NONE") {
|
||||
glSetFont(fonts[2]);
|
||||
colore(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
glDrawStringLeft(10, 30, "Key position");
|
||||
glDrawStringLeft(10, 45, "X: " + keyX + ", Y:" + keyY);
|
||||
glDrawStringLeft(10, 65, "Key value");
|
||||
glDrawStringLeft(10, 80, key);
|
||||
}
|
||||
glSetFont(fonts[3]);
|
||||
colore(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
for (int i = 0; i < 5; i++) {
|
||||
if (log[i] != null) {
|
||||
glDrawStringLeft(10, 230 + 15*(i+1), log[i].toUpperCase());
|
||||
}
|
||||
}
|
||||
|
||||
//FROM SERIAL
|
||||
colore(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
glFillRect(-80+100+200, 90, 5, 5);
|
||||
glFillRect(-80+100, 100, 200, 70);
|
||||
glSetFont(fonts[2]);
|
||||
colore(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
glDrawStringCenter(-80+100+200/2, 100+70/2-(currentFont.charH/2), "FROM SERIAL");
|
||||
glSetFont(fonts[3]);
|
||||
colore(0.0f, 0.0f, 1.0f, 1.0f);
|
||||
for (int i = 0; i < 8; i++) {
|
||||
if (pinsA[i] == 1) {
|
||||
colore(0.0f, 1.0f, 0.0f, 1.0f);
|
||||
} else if (pinsA[i] == 2) {
|
||||
colore(0.5f, 0.5f, 1.0f, 1.0f);
|
||||
} else if (pinsA[i] == -1) {
|
||||
colore(0.7f, 0.7f, 0.7f, 1.0f);
|
||||
} else if (pinsA[i] == 0) {
|
||||
colore(1.0f, 0.0f, 0.0f, 1.0f);
|
||||
}
|
||||
glFillRect(-80+103+25*(7-i), 80, 20, 20);
|
||||
colore(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
glDrawStringCenter(-80+113+25*(7-i), 90-(currentFont.charH/2), ""+(i+1));
|
||||
}
|
||||
for (int i = 15; i >= 8; i--) {
|
||||
if (pinsA[i] == 1) {
|
||||
colore(0.0f, 1.0f, 0.0f, 1.0f);
|
||||
} else if (pinsA[i] == 2) {
|
||||
colore(0.5f, 0.5f, 1.0f, 1.0f);
|
||||
} else if (pinsA[i] == -1) {
|
||||
colore(0.7f, 0.7f, 0.7f, 1.0f);
|
||||
} else if (pinsA[i] == 0) {
|
||||
colore(1.0f, 0.0f, 0.0f, 1.0f);
|
||||
}
|
||||
glFillRect(-80+103+25*(i-8), 170, 20, 20);
|
||||
colore(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
glDrawStringCenter(-80+113+25*(i-8), 180-(currentFont.charH/2), ""+(i+1));
|
||||
}
|
||||
for (int i = 0; i < 8; i++) {
|
||||
if (dataA[i]) {
|
||||
colore(0.0f, 1.0f, 0.0f, 1.0f);
|
||||
} else {
|
||||
colore(1.0f, 0.0f, 0.0f, 1.0f);
|
||||
}
|
||||
glFillRect(-80+160+10*(i), 150, 8, 8);
|
||||
}
|
||||
|
||||
//TO SERIAL
|
||||
colore(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
glFillRect(150+90, 200, 5, 5);
|
||||
glFillRect(150+100, 100, 200, 70);
|
||||
glSetFont(fonts[2]);
|
||||
colore(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
glDrawStringCenter(150+100+200/2, 100+70/2-(currentFont.charH/2), "TO SERIAL");
|
||||
glSetFont(fonts[3]);
|
||||
colore(0.0f, 0.0f, 1.0f, 1.0f);
|
||||
for (int i = 15; i >= 8; i--) {
|
||||
if (pinsB[i] == 1) {
|
||||
colore(0.0f, 1.0f, 0.0f, 1.0f);
|
||||
} else if (pinsB[i] == 2) {
|
||||
colore(0.5f, 0.5f, 1.0f, 1.0f);
|
||||
} else if (pinsB[i] == -1) {
|
||||
colore(0.7f, 0.7f, 0.7f, 1.0f);
|
||||
} else if (pinsB[i] == 0) {
|
||||
colore(1.0f, 0.0f, 0.0f, 1.0f);
|
||||
}
|
||||
glFillRect(150+103+25*(15-i), 80, 20, 20);
|
||||
colore(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
glDrawStringCenter(150+113+25*(15-i), 90-(currentFont.charH/2), ""+(i+1));
|
||||
}
|
||||
for (int i = 7; i >= 0; i--) {
|
||||
if (pinsB[i] == 1) {
|
||||
colore(0.0f, 1.0f, 0.0f, 1.0f);
|
||||
} else if (pinsB[i] == 2) {
|
||||
colore(0.5f, 0.5f, 1.0f, 1.0f);
|
||||
} else if (pinsB[i] == -1) {
|
||||
colore(0.7f, 0.7f, 0.7f, 1.0f);
|
||||
} else if (pinsB[i] == 0) {
|
||||
colore(1.0f, 0.0f, 0.0f, 1.0f);
|
||||
}
|
||||
glFillRect(150+103+25*(i), 170, 20, 20);
|
||||
colore(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
glDrawStringCenter(150+113+25*(i), 180-(currentFont.charH/2), ""+(i+1));
|
||||
}
|
||||
for (int i = 0; i < 8; i++) {
|
||||
if (dataB[i]) {
|
||||
colore(0.0f, 1.0f, 0.0f, 1.0f);
|
||||
} else {
|
||||
colore(1.0f, 0.0f, 0.0f, 1.0f);
|
||||
}
|
||||
glFillRect(150+160+10*(i), 150, 8, 8);
|
||||
}
|
||||
|
||||
//GPIO
|
||||
for (int i = 0; i < 40; i++) {
|
||||
if (gpio[i] == true) {
|
||||
colore(0.0f, 1.0f, 0.0f, 1.0f);
|
||||
} else {
|
||||
colore(1.0f, 0.0f, 0.0f, 1.0f);
|
||||
}
|
||||
if (i % 2 == 0) {
|
||||
glFillRect(53+15*((i)/2), 50, 5, 5);
|
||||
colore(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
glDrawStringCenter(55+15*((i)/2), 60, ""+(i+1));
|
||||
} else {
|
||||
glFillRect(53+15*((i-1)/2), 40, 5, 5);
|
||||
colore(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
glDrawStringCenter(55+15*((i-1)/2), 35-currentFont.charH, ""+(i+1));
|
||||
}
|
||||
}
|
||||
|
||||
//KEYS
|
||||
for (int c = 0; c < 8; c++) {
|
||||
for (int r = 0; r < 8; r++) {
|
||||
if (ks[c][r]) {
|
||||
colore(0.0f, 1.0f, 0.0f, 1.0f);
|
||||
} else {
|
||||
colore(1.0f, 0.0f, 0.0f, 1.0f);
|
||||
}
|
||||
glFillRect(250+6*c, 250+6*r, 5, 5);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeRender(float dt) {
|
||||
if (System.currentTimeMillis()-beforetime >= 1000) {
|
||||
keyevent = "NONE";
|
||||
keyX = 0;
|
||||
keyY = 0;
|
||||
key = "";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mustBeRefreshed() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyPressed(Key k) {
|
||||
beforetime = System.currentTimeMillis();
|
||||
keyevent = "PRESSED";
|
||||
keyX = 0;
|
||||
keyY = 0;
|
||||
key = k.toString();
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyReleased(Key k) {
|
||||
beforetime = System.currentTimeMillis();
|
||||
keyevent = "RELEASED";
|
||||
keyX = 0;
|
||||
keyY = 0;
|
||||
key = k.toString();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public static int[] pinsA = new int[]{2, 2, 2, 2, 2, 2, 2, 1, -1, -1, 0, 0, 0, 0, 2, -1};
|
||||
public static int[] pinsB = new int[]{0, 0, 2, 2, 2, 2, -1, 1, 0, -1, 2, 2, 2, 2, 0, -1};
|
||||
public static boolean[] dataA = new boolean[8];
|
||||
public static boolean[] dataB = new boolean[8];
|
||||
public static boolean[][] ks = new boolean[8][8];
|
||||
public static boolean[] gpio = new boolean[40];
|
||||
|
||||
public static void log(String str) {
|
||||
String[] newlog = log;
|
||||
for (int i = 1; i < 5; i++) {
|
||||
newlog[i-1] = newlog[i];
|
||||
}
|
||||
newlog[4] = "[" + System.currentTimeMillis() + "]" + str;
|
||||
log = newlog;
|
||||
}
|
||||
|
||||
}
|
@ -12,7 +12,11 @@ import static org.warp.picalculator.device.graphicengine.Display.Render.glSetFon
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.Errors;
|
||||
@ -24,9 +28,17 @@ import org.warp.picalculator.device.PIDisplay;
|
||||
import org.warp.picalculator.device.graphicengine.Display;
|
||||
import org.warp.picalculator.device.graphicengine.RAWFont;
|
||||
import org.warp.picalculator.device.graphicengine.Screen;
|
||||
import org.warp.picalculator.math.AngleMode;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
import org.warp.picalculator.math.functions.AnteriorFunction;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.FunctionMultipleValues;
|
||||
import org.warp.picalculator.math.functions.FunctionTwoValues;
|
||||
import org.warp.picalculator.math.functions.Variable;
|
||||
import org.warp.picalculator.math.functions.Variable.VariableValue;
|
||||
import org.warp.picalculator.math.functions.equations.Equation;
|
||||
import org.warp.picalculator.math.functions.Number;
|
||||
|
||||
public class MathInputScreen extends Screen {
|
||||
|
||||
@ -35,18 +47,18 @@ public class MathInputScreen extends Screen {
|
||||
public volatile int caretPos = 0;
|
||||
public volatile boolean showCaret = true;
|
||||
public volatile float showCaretDelta = 0f;
|
||||
public ArrayList<Function> f;
|
||||
public ArrayList<Function> f2;
|
||||
public int resultsCount;
|
||||
public Calculator calc;
|
||||
public boolean autoscroll;
|
||||
public int scrollX = 0;
|
||||
public int errorLevel = 0; // 0 = nessuno, 1 = risultato, 2 = tutto
|
||||
boolean mustRefresh = true;
|
||||
boolean afterDoNextStep = false;
|
||||
|
||||
|
||||
public MathInputScreen() {
|
||||
super();
|
||||
canBeInHistory = true;
|
||||
|
||||
calc = new Calculator();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -86,11 +98,7 @@ public class MathInputScreen extends Screen {
|
||||
// Funzione f = new Parentesi("5Y+XY=2", "")
|
||||
|
||||
// calcola("((5^2+3√(100/0.1))+Ⓐ(7)+9/15*2√(26/2))/21");
|
||||
if (f == null & f2 == null) {
|
||||
f = new ArrayList<Function>();
|
||||
f2 = new ArrayList<Function>();
|
||||
resultsCount = 0;
|
||||
}
|
||||
calc.init();
|
||||
// interpreta("{(5X*(15X/3X))+(25X/(5X*(15X/3X)))=15{X=5"); //TODO RIMUOVERE
|
||||
|
||||
// long start = System.nanoTime();
|
||||
@ -121,22 +129,8 @@ public class MathInputScreen extends Screen {
|
||||
if (!temporary) {
|
||||
equazioneCorrente = eqn;
|
||||
}
|
||||
ArrayList<Function> fncs = new ArrayList<Function>();
|
||||
if (eqn.length() > 0) {
|
||||
try {
|
||||
fncs.add(Calculator.parseString(eqn.replace("sqrt", "Ⓐ").replace("^", "Ⓑ")));
|
||||
} catch (Exception ex) {
|
||||
|
||||
}
|
||||
}
|
||||
f = fncs;
|
||||
for (Function f : f) {
|
||||
try {
|
||||
f.generateGraphics();
|
||||
} catch (NullPointerException ex) {
|
||||
throw new Error(Errors.SYNTAX_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
calc.parseInputString(eqn);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -188,9 +182,9 @@ public class MathInputScreen extends Screen {
|
||||
glColor(textColor);
|
||||
PIDisplay.drawSkinPart(Main.screenSize[0]-16, padding+20+fontBig.charH/2-16/2, 304, 0, 304+16, 16);
|
||||
}
|
||||
if (f != null) {
|
||||
if (calc.f != null) {
|
||||
int topSpacing = 0;
|
||||
Iterator<Function> iter = f.iterator();
|
||||
Iterator<Function> iter = calc.f.iterator();
|
||||
while (iter.hasNext()) {
|
||||
Function fnc = iter.next();
|
||||
try {
|
||||
@ -218,14 +212,14 @@ public class MathInputScreen extends Screen {
|
||||
topSpacing += fnc.getHeight() + 2;
|
||||
}
|
||||
}
|
||||
if (f2 != null) {
|
||||
if (calc.f2 != null) {
|
||||
int bottomSpacing = 0;
|
||||
for (Function f : f2) {
|
||||
for (Function f : calc.f2) {
|
||||
bottomSpacing += f.getHeight()+2;
|
||||
f.draw(Display.getWidth() - 2 - f.getWidth(), Display.getHeight() - bottomSpacing);
|
||||
}
|
||||
if (resultsCount > 1 && resultsCount != f2.size()) {
|
||||
String resultsCountText = resultsCount+" total results".toUpperCase();
|
||||
if (calc.resultsCount > 1 && calc.resultsCount != calc.f2.size()) {
|
||||
String resultsCountText = calc.resultsCount+" total results".toUpperCase();
|
||||
glColor(0xFF9AAEA0);
|
||||
glSetFont(Utils.getFont(true));
|
||||
bottomSpacing += fontBig.charH+2;
|
||||
@ -249,29 +243,34 @@ public class MathInputScreen extends Screen {
|
||||
switch (k) {
|
||||
case SIMPLIFY:
|
||||
if (nuovaEquazione.length() > 0) {
|
||||
try {
|
||||
if (!afterDoNextStep) {
|
||||
try {
|
||||
if (!afterDoNextStep) {
|
||||
interpreta(false);
|
||||
f2 = f;
|
||||
afterDoNextStep = true;
|
||||
Calculator.simplify(this);
|
||||
try {
|
||||
interpreta(true);
|
||||
showVariablesDialog(new Runnable(){
|
||||
@Override
|
||||
public void run() {
|
||||
equazioneCorrente = nuovaEquazione;
|
||||
calc.f2 = calc.f;
|
||||
afterDoNextStep = true;
|
||||
simplify(MathInputScreen.this);
|
||||
}
|
||||
});
|
||||
} catch (Exception ex) {
|
||||
if (Utils.debugOn)
|
||||
ex.printStackTrace();
|
||||
throw new Error(Errors.SYNTAX_ERROR);
|
||||
}
|
||||
Calculator.simplify(this);
|
||||
} catch (Exception ex) {
|
||||
if (Utils.debugOn) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
throw new Error(Errors.SYNTAX_ERROR);
|
||||
} catch (Error e) {
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
e.printStackTrace(pw);
|
||||
d.errorStackTrace = sw.toString().toUpperCase().replace("\t", " ").replace("\r", "").split("\n");
|
||||
PIDisplay.error = e.id.toString();
|
||||
System.err.println(e.id);
|
||||
}
|
||||
} catch (Error e) {
|
||||
glClearColor(0xFFDC3C32);
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
e.printStackTrace(pw);
|
||||
d.errorStackTrace = sw.toString().toUpperCase().replace("\t", " ").replace("\r", "").split("\n");
|
||||
PIDisplay.error = e.id.toString();
|
||||
System.err.println(e.id);
|
||||
} else {
|
||||
simplify(this);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@ -280,20 +279,25 @@ public class MathInputScreen extends Screen {
|
||||
Utils.debug.println("Resetting after error...");
|
||||
PIDisplay.error = null;
|
||||
this.equazioneCorrente = null;
|
||||
this.f = null;
|
||||
this.f2 = null;
|
||||
this.resultsCount = 0;
|
||||
calc.f = null;
|
||||
calc.f2 = null;
|
||||
calc.resultsCount = 0;
|
||||
return true;
|
||||
} else {
|
||||
try {
|
||||
try {
|
||||
if (afterDoNextStep) {
|
||||
Calculator.simplify(this);
|
||||
simplify(this);
|
||||
} else {
|
||||
if (nuovaEquazione != equazioneCorrente && nuovaEquazione.length() > 0) {
|
||||
changeEquationScreen();
|
||||
interpreta(false);
|
||||
Calculator.solve(this);
|
||||
interpreta(true);
|
||||
showVariablesDialog(new Runnable(){
|
||||
@Override
|
||||
public void run() {
|
||||
equazioneCorrente = nuovaEquazione;
|
||||
solve();
|
||||
}});
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
@ -381,6 +385,9 @@ public class MathInputScreen extends Screen {
|
||||
case POWER_OF_x:
|
||||
typeChar(MathematicalSymbols.POWER);
|
||||
return true;
|
||||
case PI:
|
||||
typeChar(MathematicalSymbols.PI);
|
||||
return true;
|
||||
case LETTER_X:
|
||||
typeChar(MathematicalSymbols.variables()[23]);
|
||||
return true;
|
||||
@ -446,33 +453,18 @@ public class MathInputScreen extends Screen {
|
||||
caretPos = 0;
|
||||
nuovaEquazione="";
|
||||
afterDoNextStep = false;
|
||||
if (f != null) {
|
||||
f.clear();
|
||||
if (calc.f != null) {
|
||||
calc.f.clear();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case SURD_MODE:
|
||||
Calculator.exactMode = !Calculator.exactMode;
|
||||
try {
|
||||
try {
|
||||
if (Calculator.exactMode == false) {
|
||||
f2 = Calculator.solveExpression(f2);
|
||||
} else {
|
||||
equazioneCorrente = "";
|
||||
Keyboard.keyPressed(Key.SOLVE);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
if (Utils.debugOn)
|
||||
ex.printStackTrace();
|
||||
throw new Error(Errors.SYNTAX_ERROR);
|
||||
}
|
||||
} catch (Error e) {
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
e.printStackTrace(pw);
|
||||
d.errorStackTrace = sw.toString().toUpperCase().replace("\t", " ").replace("\r", "").split("\n");
|
||||
PIDisplay.error = e.id.toString();
|
||||
System.err.println(e.id);
|
||||
calc.exactMode = !calc.exactMode;
|
||||
if (calc.exactMode == false) {
|
||||
calc.f2 = solveExpression(calc.f2);
|
||||
} else {
|
||||
equazioneCorrente = "";
|
||||
Keyboard.keyPressed(Key.SOLVE);
|
||||
}
|
||||
return true;
|
||||
case debug1:
|
||||
@ -480,7 +472,7 @@ public class MathInputScreen extends Screen {
|
||||
return true;
|
||||
case HISTORY_BACK:
|
||||
if (PIDisplay.INSTANCE.canGoBack()) {
|
||||
if (equazioneCorrente != null && equazioneCorrente.length() > 0 & Calculator.sessions[Calculator.currentSession+1] instanceof MathInputScreen) {
|
||||
if (equazioneCorrente != null && equazioneCorrente.length() > 0 & PIDisplay.sessions[PIDisplay.currentSession+1] instanceof MathInputScreen) {
|
||||
nuovaEquazione = equazioneCorrente;
|
||||
try {
|
||||
interpreta(true);
|
||||
@ -491,7 +483,7 @@ public class MathInputScreen extends Screen {
|
||||
return false;
|
||||
case HISTORY_FORWARD:
|
||||
if (PIDisplay.INSTANCE.canGoForward()) {
|
||||
if (equazioneCorrente != null && equazioneCorrente.length() > 0 & Calculator.sessions[Calculator.currentSession-1] instanceof MathInputScreen) {
|
||||
if (equazioneCorrente != null && equazioneCorrente.length() > 0 & PIDisplay.sessions[PIDisplay.currentSession-1] instanceof MathInputScreen) {
|
||||
nuovaEquazione = equazioneCorrente;
|
||||
try {
|
||||
interpreta(true);
|
||||
@ -500,11 +492,156 @@ public class MathInputScreen extends Screen {
|
||||
}
|
||||
}
|
||||
return false;
|
||||
case debug_DEG:
|
||||
if (calc.angleMode.equals(AngleMode.DEG) == false) {
|
||||
calc.angleMode = AngleMode.DEG;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
case debug_RAD:
|
||||
if (calc.angleMode.equals(AngleMode.RAD) == false) {
|
||||
calc.angleMode = AngleMode.RAD;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
case debug_GRA:
|
||||
if (calc.angleMode.equals(AngleMode.GRA) == false) {
|
||||
calc.angleMode = AngleMode.GRA;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
case DRG_CYCLE:
|
||||
if (calc.angleMode.equals(AngleMode.DEG) == true) {
|
||||
calc.angleMode = AngleMode.RAD;
|
||||
} else if (calc.angleMode.equals(AngleMode.RAD) == true) {
|
||||
calc.angleMode = AngleMode.GRA;
|
||||
} else {
|
||||
calc.angleMode = AngleMode.DEG;
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private ArrayList<Function> solveExpression(ArrayList<Function> f22) {
|
||||
try {
|
||||
try {
|
||||
return calc.solveExpression(f22);
|
||||
} catch (Exception ex) {
|
||||
if (Utils.debugOn) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
throw new Error(Errors.SYNTAX_ERROR);
|
||||
}
|
||||
} catch (Error e) {
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
e.printStackTrace(pw);
|
||||
d.errorStackTrace = sw.toString().toUpperCase().replace("\t", " ").replace("\r", "").split("\n");
|
||||
PIDisplay.error = e.id.toString();
|
||||
System.err.println(e.id);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void simplify(MathInputScreen mathInputScreen) {
|
||||
try {
|
||||
try {
|
||||
showVariablesDialog();
|
||||
ArrayList<Function> results = new ArrayList<>();
|
||||
ArrayList<Function> partialResults = new ArrayList<>();
|
||||
for (Function f : calc.f2) {
|
||||
if (f instanceof Equation) {
|
||||
PIDisplay.INSTANCE.setScreen(new SolveEquationScreen(this));
|
||||
} else {
|
||||
results.add(f);
|
||||
for (Function itm : results) {
|
||||
if (itm.isSolved() == false) {
|
||||
List<Function> dt = itm.solveOneStep();
|
||||
partialResults.addAll(dt);
|
||||
} else {
|
||||
partialResults.add(itm);
|
||||
}
|
||||
}
|
||||
results = new ArrayList<>(partialResults);
|
||||
partialResults.clear();
|
||||
}
|
||||
}
|
||||
|
||||
if (results.size() == 0) {
|
||||
calc.resultsCount = 0;
|
||||
} else {
|
||||
calc.resultsCount = results.size();
|
||||
Collections.reverse(results);
|
||||
// add elements to al, including duplicates
|
||||
Set<Function> hs = new LinkedHashSet<>();
|
||||
hs.addAll(results);
|
||||
results.clear();
|
||||
results.addAll(hs);
|
||||
calc.f2 = results;
|
||||
for (Function rf : calc.f2) {
|
||||
rf.generateGraphics();
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
if (Utils.debugOn) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
throw new Error(Errors.SYNTAX_ERROR);
|
||||
}
|
||||
} catch (Error e) {
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
e.printStackTrace(pw);
|
||||
d.errorStackTrace = sw.toString().toUpperCase().replace("\t", " ").replace("\r", "").split("\n");
|
||||
PIDisplay.error = e.id.toString();
|
||||
System.err.println(e.id);
|
||||
}
|
||||
}
|
||||
|
||||
protected void solve() {
|
||||
try {
|
||||
try {
|
||||
for (Function f : calc.f) {
|
||||
if (f instanceof Equation) {
|
||||
PIDisplay.INSTANCE.setScreen(new SolveEquationScreen(this));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ArrayList<Function> results = solveExpression(calc.f);
|
||||
if (results.size() == 0) {
|
||||
calc.resultsCount = 0;
|
||||
} else {
|
||||
calc.resultsCount = results.size();
|
||||
Collections.reverse(results);
|
||||
// add elements to al, including duplicates
|
||||
Set<Function> hs = new LinkedHashSet<>();
|
||||
hs.addAll(results);
|
||||
results.clear();
|
||||
results.addAll(hs);
|
||||
calc.f2 = results;
|
||||
for (Function rf : calc.f2) {
|
||||
rf.generateGraphics();
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
if (Utils.debugOn) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
throw new Error(Errors.SYNTAX_ERROR);
|
||||
}
|
||||
} catch (Error e) {
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
e.printStackTrace(pw);
|
||||
d.errorStackTrace = sw.toString().toUpperCase().replace("\t", " ").replace("\r", "").split("\n");
|
||||
PIDisplay.error = e.id.toString();
|
||||
System.err.println(e.id);
|
||||
}
|
||||
}
|
||||
|
||||
private void changeEquationScreen() {
|
||||
if (equazioneCorrente != null && equazioneCorrente.length() > 0) {
|
||||
MathInputScreen cloned = clone();
|
||||
@ -536,10 +673,76 @@ public class MathInputScreen extends Screen {
|
||||
|
||||
@Override
|
||||
public boolean keyReleased(Key k) {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void showVariablesDialog() {
|
||||
showVariablesDialog(null);
|
||||
}
|
||||
|
||||
public void showVariablesDialog(final Runnable runnable) {
|
||||
Thread ct = new Thread(()->{
|
||||
ArrayList<Function> variablesInFunctions = getVariables(calc.f.toArray(new Function[calc.f.size()]));
|
||||
for (VariableValue f : calc.variablesValues) {
|
||||
if (variablesInFunctions.contains(f.v)) {
|
||||
variablesInFunctions.remove(f.v);
|
||||
}
|
||||
}
|
||||
|
||||
boolean cancelled = false;
|
||||
for (Function f : variablesInFunctions) {
|
||||
ChooseVariableValueScreen cvs = new ChooseVariableValueScreen(this, new VariableValue((Variable) f, new Number(calc, 0)));
|
||||
PIDisplay.INSTANCE.setScreen(cvs);
|
||||
try {
|
||||
while (PIDisplay.screen == cvs) {
|
||||
Utils.debug.println(Thread.currentThread().getName());
|
||||
Thread.sleep(200);
|
||||
}
|
||||
} catch (InterruptedException e) {}
|
||||
if (cvs.resultNumberValue == null) {
|
||||
cancelled = true;
|
||||
break;
|
||||
} else {
|
||||
final int is = calc.variablesValues.size();
|
||||
for (int i = 0; i < is; i++) {
|
||||
if (calc.variablesValues.get(i).v == f) {
|
||||
calc.variablesValues.remove(i);
|
||||
}
|
||||
}
|
||||
calc.variablesValues.add(new VariableValue((Variable) f, (Number) cvs.resultNumberValue));
|
||||
}
|
||||
}
|
||||
if (!cancelled) {
|
||||
if (runnable != null) {
|
||||
runnable.run();
|
||||
}
|
||||
Utils.debug.println(calc.f.toString());
|
||||
}
|
||||
});
|
||||
ct.setName("Variables user-input queue thread");
|
||||
ct.setPriority(Thread.MIN_PRIORITY);
|
||||
ct.setDaemon(true);
|
||||
ct.start();
|
||||
}
|
||||
|
||||
private ArrayList<Function> getVariables(Function[] fncs) {
|
||||
ArrayList<Function> res = new ArrayList<>();
|
||||
for (Function f : fncs) {
|
||||
if (f instanceof FunctionTwoValues) {
|
||||
res.addAll(getVariables(new Function[]{((FunctionTwoValues)f).getVariable1(), ((FunctionTwoValues)f).getVariable2()}));
|
||||
} else if (f instanceof FunctionMultipleValues) {
|
||||
res.addAll(getVariables(((FunctionMultipleValues)f).getVariables()));
|
||||
} else if (f instanceof AnteriorFunction) {
|
||||
res.addAll(getVariables(new Function[]{((AnteriorFunction)f).getVariable()}));
|
||||
} else if (f instanceof Variable) {
|
||||
if (!res.contains(f)) {
|
||||
res.add(f);
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MathInputScreen clone() {
|
||||
MathInputScreen es = this;
|
||||
@ -550,13 +753,15 @@ public class MathInputScreen extends Screen {
|
||||
es2.showCaret = es.showCaret;
|
||||
es2.showCaretDelta = es.showCaretDelta;
|
||||
es2.caretPos = es.caretPos;
|
||||
es2.f = Utils.cloner.deepClone(es.f);
|
||||
es2.f2 = Utils.cloner.deepClone(es.f2);
|
||||
es2.resultsCount = es.resultsCount;
|
||||
// es2.calc.f = Utils.cloner.deepClone(es.calc.f);
|
||||
// es2.calc.f2 = Utils.cloner.deepClone(es.calc.f2);
|
||||
// es2.calc.resultsCount = es.calc.resultsCount;
|
||||
es2.autoscroll = es.autoscroll;
|
||||
es2.errorLevel = es.errorLevel;
|
||||
es2.mustRefresh = es.mustRefresh;
|
||||
es2.afterDoNextStep = es.afterDoNextStep;
|
||||
// es2.calc.variablesValues = Utils.cloner.deepClone(es.calc.variablesValues);
|
||||
es2.calc = Utils.cloner.deepClone(es.calc);
|
||||
return es2;
|
||||
}
|
||||
|
||||
|
@ -56,13 +56,13 @@ public class SolveEquationScreen extends Screen {
|
||||
case LETTER_X:
|
||||
PIDisplay.INSTANCE.goBack();
|
||||
try {
|
||||
Calculator.solveExpression('X');
|
||||
es.calc.solveExpression('X');
|
||||
} catch (Error e) {
|
||||
Screen scr = PIDisplay.INSTANCE.getScreen();
|
||||
if (scr instanceof MathInputScreen) {
|
||||
MathInputScreen escr = (MathInputScreen) scr;
|
||||
escr.errorLevel = 1;
|
||||
escr.err2 = e;
|
||||
//escr.err2 = e; //TODO: What is this variable, and why it doesn't exists?
|
||||
} else {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user