Merge branch 'processing:main' into store-installs

This commit is contained in:
Stef Tervelde
2025-04-21 14:17:06 +02:00
committed by GitHub
38 changed files with 552 additions and 43 deletions
+10
View File
@@ -1493,6 +1493,16 @@
"code",
"a11y"
]
},
{
"login": "SushantBansal-tech",
"name": "SushantBansal-tech",
"avatar_url": "https://avatars.githubusercontent.com/u/189839531?v=4",
"profile": "https://github.com/SushantBansal-tech",
"contributions": [
"ideas",
"code"
]
}
],
"repoType": "github",
+2
View File
@@ -8,6 +8,8 @@ First, [download the IntelliJ IDEA Community Edition](https://www.jetbrains.com/
1. Clone the Processing4 repository to your machine locally
1. Open the cloned repository in IntelliJ IDEA CE
1. When prompted, select **Trust Project**. You can preview the project in Safe Mode but you won't be able to build Processing.
1. IntelliJ may start loading Gradle dependencies automatically. Wait for this process to complete.
1. In the main menu, go to File > Project Structure > Project Settings > Project.
1. In the SDK Dropdown option, select a JDK version 17 or Download the jdk
1. Click the green Run Icon in the top right of the window. This is also where you can find the option to debug Processing.
+20 -5
View File
@@ -69,22 +69,37 @@ If there hasnt been any activity after two weeks, feel free to gently follow
Before opening a pull request, please make sure to discuss the related issue and get assigned to it first. This helps us stay aligned and avoid unnecessary work. Thank you!
## New Features
## Adding New Features to Processing
In most cases, the best way to contribute a new feature is to create a library. The [Processing Library Template](https://github.com/processing/processing-library-template) is a great way to get started. For more instructions, see the [library template documenation](https://processing.github.io/processing-library-template/).
If you have an idea for something Processing doesnt yet support, **creating a library** is often the best way to contribute. The [Processing Library Template](https://github.com/processing/processing-library-template) provides a starting point for developing, packaging, and distributing Processing libraries. For more instructions, see the [library template documentation](https://processing.github.io/processing-library-template/).
Once your library is complete, you can submit it to the official [Processing Contributions](https://github.com/processing/processing-contributions) repository. This makes it discoverable through the PDEs Contribution Manager. Follow the guidelines in the [Processing Library Guidelines](https://github.com/processing/processing4/wiki/Library-Guidelines).
### Libraries as the Starting Point for Features
Nearly all new features are first introduced as a Library or a Mode, or even as an example. The current [OpenGL renderer](http://glgraphics.sourceforge.net/) and Video library began as separate projects by Andrés Colubri, who needed a more performant, more sophisticated version of what we had in Processing for work that he was creating. The original `loadShape()` implementation came from the “Candy” library by Michael Chang (“mflux“). Similarly, Tweak Mode began as a [separate project](http://galsasson.com/tweakmode/) by Gal Sasson before being incorporated. PDE X was a Google Summer of code [project](https://github.com/processing/processing-experimental) by Manindra Moharana that updated the PDE to include basic refactoring and better error checking.
Developing features separately from the main software has several benefits:
### Why Develop Outside the Core?
Working outside the main Processing codebase has several advantages:
* Its easier for the contributor to develop the software without it needing to work for tens or hundreds of thousands of Processing users.
* It provides a way to get feedback on that code independently of everything else, and the ability to iterate on it rapidly.
* This feedback process also helps gauge the level of interest for the community, and how it should be prioritized for the software.
* We can delay the process of “normalizing” the features so that theyre consistent with the rest of Processing (function naming, structure, etc).
A major consideration for any new feature is the level of maintenance that it might require in the future. If the original maintainer loses interest over time (which is normal) and the feature breaks (which happens more often than we'd like), it sits on the issues list unfixed, which isnt good for anyone.
### What Guides the Inclusion of New Features?
We take maintenance seriously. A feature added to the core becomes a long-term responsibility. If it breaks, it needs fixing. Sometimes the original developer is no longer active (which is normal), and the burden falls on others.
Processing is a massive project that has existed for more than 20 years. Part of its longevity comes from the effort thats gone into keeping things as simple as we can, and in particular, making a lot of difficult decisions about *what to leave out*. Adding a new feature always has to be weighed against the potential confusion of one more thing—whether its a menu item, a dialog box, a function that needs to be added to the reference, etc. Adding a new graphics function means making it work across all the renderers that we ship (Java2D, OpenGL, JavaFX, PDF, etc) and across platforms (macOS, Windows, Linux). Does the feature help enough people that it's worth making the reference longer? Or the additional burden of maintaining that feature? It's no fun to say “no,” especially to people volunteering their time, but we often have to.
Processing is a massive project that has existed for more than 20 years. Part of its longevity comes from the effort thats gone into keeping things as simple as we can, and in particular, making a lot of difficult decisions about *what to leave out*.
Adding a new feature always has to be weighed against the potential confusion of one more thing—whether its a menu item, a dialog box, a function that needs to be added to the reference, etc. Adding a new graphics function means making it work across all the renderers that we ship (Java2D, OpenGL, JavaFX, PDF, etc) and across platforms (macOS, Windows, Linux).
It may also mean new interface elements, updates to the reference, and more documentation.
So when we consider a new feature, we ask ourselves:
> Does this solve a problem for many users? Is it worth the added complexity and extra maintenance work?
These are not easy decisions, especially when volunteers are offering their time and ideas. But we have to make them carefully to keep Processing sustainable.
## Editor
+8 -6
View File
@@ -7,14 +7,14 @@ Processing is a flexible software sketchbook and a programming language designed
This repository contains the source code for the [Processing](https://processing.org/) project for people who want to help improve the code.
## Announcing Processing 4.3.1
## Welcome to Processing 4.4!
Were excited to announce the release of Processing 4.3.1! This update brings tooling improvements and a friendlier experience for contributors. To learn more, read the [Processing 4.3.1 announcement](https://github.com/processing/processing4-carbon-aug-19/wiki/Announcing-Processing-4.3.1).
Were excited to announce the release of Processing 4.4! This update modernizes Processing under the hood to make future development easier. Key changes include switching the build system from Ant to Gradle, starting the transition from Swing to Jetpack Compose Multiplatform for the UI, and adding Kotlin support to the codebase. To learn more, check out [Changes in 4.4.0](https://github.com/processing/processing4/wiki/Changes-in-4.4).
Processing was initiated in 2001 by Ben Fry and Casey Reas, who lead the development and maintenance of the project until 2023. We are grateful for their vision and dedication to the project. Processing is also indebted to over two decades of contributions from the broader Processing community.
We hope these updates will make it easier for more people to contribute to Processing. If you'd like to get involved, have a look at our [Contributor Guide](CONTRIBUTING.md).
> [!NOTE]
> Due to platform limitations, the GitHub Contributors page for this repository does not show the complete list of contributors. However, the [git commit history](https://github.com/processing/processing4/commits/main/) provides a full record of the project's contributions. For contributor graphs before November 13th, refer to [this page](https://github.com/benfry/processing4/graphs/contributors). A comprehensive [list of all contributors](#contributors) is also included below. To see all commits by a contributor, click on the [💻](https://github.com/processing/processing4/commits?author=benfry) emoji below their name.
## Acknowledgement
Processing was initiated in 2001 by Ben Fry and Casey Reas, who led the development and maintenance of the project until 2023. We are grateful for their vision and dedication to the project. Processing is also indebted to over two decades of contributions from the broader Processing community.
## Using Processing
@@ -66,8 +66,9 @@ For licensing information about the Processing website see the [processing-websi
Copyright (c) 2015-now The Processing Foundation
## Contributors
The Processing project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification, recognizing all forms of contributions (not just code!). A list of all contributors is included below. You can add yourself to the contributors list [here](https://github.com/processing/processing4-carbon-aug-19/issues/839)!
Add yourself to the contributors list [here](https://github.com/processing/processing4-carbon-aug-19/issues/839)!
_Note: due to GitHub's limitations, this repository's [Contributors](https://github.com/processing/processing4/graphs/contributors) page only shows accurate contribution data starting from late 2024. Contributor graphs from before November 13th 2024 can be found on [this page](https://github.com/benfry/processing4/graphs/contributors). The [git commit history](https://github.com/processing/processing4/commits/main/) provides a full record of the project's contributions. To see all commits by a contributor, click on the [💻](https://github.com/processing/processing4/commits?author=benfry) emoji below their name._
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore-start -->
@@ -292,6 +293,7 @@ Add yourself to the contributors list [here](https://github.com/processing/proce
</tr>
<tr>
<td align="center" valign="top" width="16.66%"><a href="https://github.com/babaissarkar"><img src="https://avatars.githubusercontent.com/u/8469888?v=4?s=120" width="120px;" alt="Subhraman Sarkar"/><br /><sub><b>Subhraman Sarkar</b></sub></a><br /><a href="https://github.com/processing/processing4/commits?author=babaissarkar" title="Code">💻</a> <a href="#a11y-babaissarkar" title="Accessibility">️♿️</a></td>
<td align="center" valign="top" width="16.66%"><a href="https://github.com/SushantBansal-tech"><img src="https://avatars.githubusercontent.com/u/189839531?v=4?s=120" width="120px;" alt="SushantBansal-tech"/><br /><sub><b>SushantBansal-tech</b></sub></a><br /><a href="#ideas-SushantBansal-tech" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/processing/processing4/commits?author=SushantBansal-tech" title="Code">💻</a></td>
</tr>
</tbody>
</table>
+1 -1
View File
@@ -161,7 +161,7 @@ editor.scrollbar.color = #0066C5
## PdeTextAreaPainter - extras added to the editor ##
editor.gutter.text.font = processing.mono,bold,16
editor.gutter.text.font = processing.mono,bold,12
editor.gutter.text.color = #C0FFFF
# transparency (0..100) for line numbers in gutter
+1 -1
View File
@@ -161,7 +161,7 @@ editor.scrollbar.color = #834548
## PdeTextAreaPainter - extras added to the editor ##
editor.gutter.text.font = processing.mono,bold,16
editor.gutter.text.font = processing.mono,bold,12
editor.gutter.text.color = #FFEBEC
# transparency (0..100) for line numbers in gutter
+1 -1
View File
@@ -161,7 +161,7 @@ editor.scrollbar.color = #49D0A7
## PdeTextAreaPainter - extras added to the editor ##
editor.gutter.text.font = processing.mono,bold,16
editor.gutter.text.font = processing.mono,bold,12
editor.gutter.text.color = #1A0300
# transparency (0..100) for line numbers in gutter
+1 -1
View File
@@ -161,7 +161,7 @@ editor.scrollbar.color = #431D29
## PdeTextAreaPainter - extras added to the editor ##
editor.gutter.text.font = processing.mono,bold,16
editor.gutter.text.font = processing.mono,bold,12
editor.gutter.text.color = #FFF2FF
# transparency (0..100) for line numbers in gutter
+1 -1
View File
@@ -161,7 +161,7 @@ editor.scrollbar.color = #47502C
## PdeTextAreaPainter - extras added to the editor ##
editor.gutter.text.font = processing.mono,bold,16
editor.gutter.text.font = processing.mono,bold,12
editor.gutter.text.color = #FBFFD7
# transparency (0..100) for line numbers in gutter
+1 -1
View File
@@ -161,7 +161,7 @@ editor.scrollbar.color = #978FAC
## PdeTextAreaPainter - extras added to the editor ##
editor.gutter.text.font = processing.mono,bold,16
editor.gutter.text.font = processing.mono,bold,12
editor.gutter.text.color = #540000
# transparency (0..100) for line numbers in gutter
+1 -1
View File
@@ -161,7 +161,7 @@ editor.scrollbar.color = #9D0038
## PdeTextAreaPainter - extras added to the editor ##
editor.gutter.text.font = processing.mono,bold,16
editor.gutter.text.font = processing.mono,bold,12
editor.gutter.text.color = #FFE8FF
# transparency (0..100) for line numbers in gutter
+1 -1
View File
@@ -161,7 +161,7 @@ editor.scrollbar.color = #F07D44
## PdeTextAreaPainter - extras added to the editor ##
editor.gutter.text.font = processing.mono,bold,16
editor.gutter.text.font = processing.mono,bold,12
editor.gutter.text.color = #3E0000
# transparency (0..100) for line numbers in gutter
+1 -1
View File
@@ -161,7 +161,7 @@ editor.scrollbar.color = #E9E9E9
## PdeTextAreaPainter - extras added to the editor ##
editor.gutter.text.font = processing.mono,bold,16
editor.gutter.text.font = processing.mono,bold,12
editor.gutter.text.color = #00003B
# transparency (0..100) for line numbers in gutter
+1 -1
View File
@@ -161,7 +161,7 @@ editor.scrollbar.color = #FF6E38
## PdeTextAreaPainter - extras added to the editor ##
editor.gutter.text.font = processing.mono,bold,16
editor.gutter.text.font = processing.mono,bold,12
editor.gutter.text.color = #000049
# transparency (0..100) for line numbers in gutter
+1 -1
View File
@@ -161,7 +161,7 @@ editor.scrollbar.color = #FF8F2F
## PdeTextAreaPainter - extras added to the editor ##
editor.gutter.text.font = processing.mono,bold,16
editor.gutter.text.font = processing.mono,bold,12
editor.gutter.text.color = #470000
# transparency (0..100) for line numbers in gutter
+1 -1
View File
@@ -161,7 +161,7 @@ editor.scrollbar.color = #697982
## PdeTextAreaPainter - extras added to the editor ##
editor.gutter.text.font = processing.mono,bold,16
editor.gutter.text.font = processing.mono,bold,12
editor.gutter.text.color = #EFFFFF
# transparency (0..100) for line numbers in gutter
+1 -1
View File
@@ -161,7 +161,7 @@ editor.scrollbar.color = #4E535A
## PdeTextAreaPainter - extras added to the editor ##
editor.gutter.text.font = processing.mono,bold,16
editor.gutter.text.font = processing.mono,bold,12
editor.gutter.text.color = #FAFFFF
# transparency (0..100) for line numbers in gutter
+1 -1
View File
@@ -161,7 +161,7 @@ editor.scrollbar.color = #00593B
## PdeTextAreaPainter - extras added to the editor ##
editor.gutter.text.font = processing.mono,bold,16
editor.gutter.text.font = processing.mono,bold,12
editor.gutter.text.color = #B7FFEA
# transparency (0..100) for line numbers in gutter
+1 -1
View File
@@ -161,7 +161,7 @@ editor.scrollbar.color = #A55134
## PdeTextAreaPainter - extras added to the editor ##
editor.gutter.text.font = processing.mono,bold,16
editor.gutter.text.font = processing.mono,bold,12
editor.gutter.text.color = #FFFDFB
# transparency (0..100) for line numbers in gutter
+1 -1
View File
@@ -161,7 +161,7 @@ editor.scrollbar.color = #008A50
## PdeTextAreaPainter - extras added to the editor ##
editor.gutter.text.font = processing.mono,bold,16
editor.gutter.text.font = processing.mono,bold,12
editor.gutter.text.color = #CBFFEF
# transparency (0..100) for line numbers in gutter
+1 -1
View File
@@ -161,7 +161,7 @@ editor.scrollbar.color = #092D38
## PdeTextAreaPainter - extras added to the editor ##
editor.gutter.text.font = processing.mono,bold,16
editor.gutter.text.font = processing.mono,bold,12
editor.gutter.text.color = #E1FFFF
# transparency (0..100) for line numbers in gutter
+1 -1
View File
@@ -161,7 +161,7 @@ editor.scrollbar.color = #4A4E59
## PdeTextAreaPainter - extras added to the editor ##
editor.gutter.text.font = processing.mono,bold,16
editor.gutter.text.font = processing.mono,bold,12
editor.gutter.text.color = #FAFEFF
# transparency (0..100) for line numbers in gutter
+1 -1
View File
@@ -161,7 +161,7 @@ editor.scrollbar.color = #00926F
## PdeTextAreaPainter - extras added to the editor ##
editor.gutter.text.font = processing.mono,bold,16
editor.gutter.text.font = processing.mono,bold,12
editor.gutter.text.color = #001E00
# transparency (0..100) for line numbers in gutter
+1 -1
View File
@@ -161,7 +161,7 @@ editor.scrollbar.color = #B9BDC4
## PdeTextAreaPainter - extras added to the editor ##
editor.gutter.text.font = processing.mono,bold,16
editor.gutter.text.font = processing.mono,bold,12
editor.gutter.text.color = #000009
# transparency (0..100) for line numbers in gutter
+1 -1
View File
@@ -161,7 +161,7 @@ editor.scrollbar.color = #BD8A68
## PdeTextAreaPainter - extras added to the editor ##
editor.gutter.text.font = processing.mono,bold,16
editor.gutter.text.font = processing.mono,bold,12
editor.gutter.text.color = #270000
# transparency (0..100) for line numbers in gutter
+1 -1
View File
@@ -161,7 +161,7 @@ editor.scrollbar.color = #402563
## PdeTextAreaPainter - extras added to the editor ##
editor.gutter.text.font = processing.mono,bold,16
editor.gutter.text.font = processing.mono,bold,12
editor.gutter.text.color = #FFEFFF
# transparency (0..100) for line numbers in gutter
+1 -1
View File
@@ -161,7 +161,7 @@ editor.scrollbar.color = #7A896D
## PdeTextAreaPainter - extras added to the editor ##
editor.gutter.text.font = processing.mono,bold,16
editor.gutter.text.font = processing.mono,bold,12
editor.gutter.text.color = #000700
# transparency (0..100) for line numbers in gutter
+1 -1
View File
@@ -161,7 +161,7 @@ editor.scrollbar.color = #6C7076
## PdeTextAreaPainter - extras added to the editor ##
editor.gutter.text.font = processing.mono,bold,16
editor.gutter.text.font = processing.mono,bold,12
editor.gutter.text.color = #000009
# transparency (0..100) for line numbers in gutter
+1 -1
View File
@@ -161,7 +161,7 @@ editor.scrollbar.color = #973542
## PdeTextAreaPainter - extras added to the editor ##
editor.gutter.text.font = processing.mono,bold,16
editor.gutter.text.font = processing.mono,bold,12
editor.gutter.text.color = #FFEFF2
# transparency (0..100) for line numbers in gutter
+1 -1
View File
@@ -161,7 +161,7 @@ editor.scrollbar.color = #CC383C
## PdeTextAreaPainter - extras added to the editor ##
editor.gutter.text.font = processing.mono,bold,16
editor.gutter.text.font = processing.mono,bold,12
editor.gutter.text.color = #fbb5b5
# transparency (0..100) for line numbers in gutter
+1 -1
View File
@@ -161,7 +161,7 @@ editor.scrollbar.color = #5E93BF
## PdeTextAreaPainter - extras added to the editor ##
editor.gutter.text.font = processing.mono,bold,16
editor.gutter.text.font = processing.mono,bold,12
editor.gutter.text.color = #000833
# transparency (0..100) for line numbers in gutter
@@ -161,7 +161,7 @@ editor.scrollbar.color = #313E38
## PdeTextAreaPainter - extras added to the editor ##
editor.gutter.text.font = processing.mono,bold,16
editor.gutter.text.font = processing.mono,bold,12
editor.gutter.text.color = #F2FFFA
# transparency (0..100) for line numbers in gutter
+1 -1
View File
@@ -161,7 +161,7 @@ editor.scrollbar.color = #869F36
## PdeTextAreaPainter - extras added to the editor ##
editor.gutter.text.font = processing.mono,bold,16
editor.gutter.text.font = processing.mono,bold,12
editor.gutter.text.color = #000D00
# transparency (0..100) for line numbers in gutter
+1 -1
View File
@@ -161,7 +161,7 @@ editor.scrollbar.color = #EFBA4E
## PdeTextAreaPainter - extras added to the editor ##
editor.gutter.text.font = processing.mono,bold,16
editor.gutter.text.font = processing.mono,bold,12
editor.gutter.text.color = #2D0000
# transparency (0..100) for line numbers in gutter
+1 -1
View File
@@ -161,7 +161,7 @@ editor.scrollbar.color = #06545D
## PdeTextAreaPainter - extras added to the editor ##
editor.gutter.text.font = processing.mono,bold,16
editor.gutter.text.font = processing.mono,bold,12
editor.gutter.text.color = #C9FFFF
# transparency (0..100) for line numbers in gutter
@@ -161,7 +161,7 @@ editor.scrollbar.color = #DE5C25
## PdeTextAreaPainter - extras added to the editor ##
editor.gutter.text.font = processing.mono,bold,16
editor.gutter.text.font = processing.mono,bold,12
editor.gutter.text.color = #440000
# transparency (0..100) for line numbers in gutter
@@ -0,0 +1,186 @@
package processing.core;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
public class PMatrix2DTest {
private PMatrix2D m;
@Before
public void setUp() {
m = new PMatrix2D();
}
@Test
public void testIdentity() {
assertTrue("New matrix should be identity", m.isIdentity());
float[] arr = m.get(null);
assertEquals(1, arr[0], 0.0001f); // m00
assertEquals(0, arr[1], 0.0001f); // m01
assertEquals(0, arr[2], 0.0001f); // m02
assertEquals(0, arr[3], 0.0001f); // m10
assertEquals(1, arr[4], 0.0001f); // m11
assertEquals(0, arr[5], 0.0001f); // m12
}
@Test
public void testTranslate() {
m.translate(10, 20);
assertEquals(10, m.m02, 0.0001f);
assertEquals(20, m.m12, 0.0001f);
}
@Test
public void testRotate() {
m.rotate(PConstants.HALF_PI);
assertEquals(0, m.m00, 0.0001f);
assertEquals(-1, m.m01, 0.0001f);
assertEquals(1, m.m10, 0.0001f);
assertEquals(0, m.m11, 0.0001f);
}
@Test
public void testScale() {
m.scale(2, 3);
assertEquals(2, m.m00, 0.0001f);
assertEquals(3, m.m11, 0.0001f);
assertEquals(0, m.m02, 0.0001f);
assertEquals(0, m.m12, 0.0001f);
}
@Test
public void testShear() {
float shearAngle = 0.2f;
m.shearX(shearAngle);
assertEquals(0, m.m01, 0.0001f);
assertEquals((float)Math.tan(shearAngle), m.m10, 0.0001f);
assertEquals(1, m.m02, 0.0001f);
m.reset();
m.shearY(shearAngle);
assertEquals(0, m.m01, 0.0001f);
assertEquals(0, m.m10, 0.0001f);
assertEquals((float)Math.tan(shearAngle), m.m11, 0.0001f);
assertEquals(1, m.m02, 0.0001f);
}
@Test
public void testApply() {
PMatrix2D m2 = new PMatrix2D(1, 2, 3, 4, 5, 6);
m.apply(m2);
assertEquals(m2.m00, m.m00, 0.0001f);
assertEquals(m2.m01, m.m01, 0.0001f);
assertEquals(m2.m02, m.m02, 0.0001f);
assertEquals(m2.m10, m.m10, 0.0001f);
assertEquals(m2.m11, m.m11, 0.0001f);
assertEquals(m2.m12, m.m12, 0.0001f);
}
@Test
public void testPreApply() {
PMatrix2D m1 = new PMatrix2D(1, 2, 3, 4, 5, 6);
m.reset(); // identity matrix
m.preApply(m1);
assertEquals(m1.m00, m.m00, 0.0001f);
assertEquals(m1.m01, m.m01, 0.0001f);
assertEquals(m1.m02, m.m02, 0.0001f);
assertEquals(m1.m10, m.m10, 0.0001f);
assertEquals(m1.m11, m.m11, 0.0001f);
assertEquals(m1.m12, m.m12, 0.0001f);
}
@Test
public void testMultPVector() {
PVector src = new PVector(1, 2, 0);
PVector result = m.mult(src, null);
assertEquals(src.x, result.x, 0.0001f);
assertEquals(src.y, result.y, 0.0001f);
}
@Test
public void testMultArray() {
float[] vec = { 1, 2 };
float[] out = m.mult(vec, null);
assertEquals(1, out[0], 0.0001f);
assertEquals(2, out[1], 0.0001f);
}
@Test
public void testMultXandY() {
float x = 10, y = 20;
float xOut = m.multX(x, y);
float yOut = m.multY(x, y);
assertEquals(x, xOut, 0.0001f);
assertEquals(y, yOut, 0.0001f);
}
@Test
public void testInvertAndDeterminant() {
m.set(2, 0, 5, 1, 3, 7);
float det = m.determinant();
assertEquals(6, det, 0.0001f);
boolean invertible = m.invert();
assertTrue("Matrix should be invertible", invertible);
PMatrix2D identity = new PMatrix2D(2, 0, 5, 1, 3, 7);
identity.apply(m);
assertEquals(1, identity.m00, 0.001f);
assertEquals(0, identity.m01, 0.001f);
assertEquals(0, identity.m10, 0.001f);
assertEquals(1, identity.m11, 0.001f);
}
@Test
public void testIdentityWarped() {
assertTrue(m.isIdentity());
assertFalse(m.isWarped());
m.translate(10, 20);
assertFalse(m.isIdentity());
}
@Test(expected = IllegalArgumentException.class)
public void testTranslate3DThrows() {
m.translate(1, 2, 3);
}
@Test(expected = IllegalArgumentException.class)
public void testRotateXThrows() {
m.rotateX(1);
}
@Test(expected = IllegalArgumentException.class)
public void testRotateYThrows() {
m.rotateY(1);
}
@Test(expected = IllegalArgumentException.class)
public void testScale3DThrows() {
m.scale(1, 2, 3);
}
@Test(expected = IllegalArgumentException.class)
public void testApplyPMatrix3DThrows() {
PMatrix3D m3d = new PMatrix3D(1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1);
m.apply(m3d);
}
@Test
public void testGetArray() {
m.set(new float[]{1, 2, 0, 0, 1, 0});
float[] arr = m.get(null);
assertEquals(1, arr[0], 0.0001f);
assertEquals(2, arr[1], 0.0001f);
assertEquals(0, arr[2], 0.0001f);
}
}
+294
View File
@@ -0,0 +1,294 @@
package processing.core;
import org.junit.Assert;
import org.junit.Test;
public class PVectorTest {
@Test
public void testConstructors() {
PVector v0 = new PVector();
Assert.assertEquals(0, v0.x, 0.0001f);
Assert.assertEquals(0, v0.y, 0.0001f);
Assert.assertEquals(0, v0.z, 0.0001f);
PVector v2 = new PVector(3, 4);
Assert.assertEquals(3, v2.x, 0.0001f);
Assert.assertEquals(4, v2.y, 0.0001f);
Assert.assertEquals(0, v2.z, 0.0001f);
PVector v3 = new PVector(1, 2, 3);
Assert.assertEquals(1, v3.x, 0.0001f);
Assert.assertEquals(2, v3.y, 0.0001f);
Assert.assertEquals(3, v3.z, 0.0001f);
}
@Test
public void testSetAndCopy() {
PVector v = new PVector(1, 2, 3);
PVector copy = v.copy();
Assert.assertEquals(v.x, copy.x, 0.0001f);
Assert.assertEquals(v.y, copy.y, 0.0001f);
Assert.assertEquals(v.z, copy.z, 0.0001f);
v.set(4, 5, 6);
Assert.assertEquals(4, v.x, 0.0001f);
Assert.assertEquals(5, v.y, 0.0001f);
Assert.assertEquals(6, v.z, 0.0001f);
}
@Test
public void testAdd() {
PVector v1 = new PVector(1, 1, 1);
PVector v2 = new PVector(2, 3, 4);
v1.add(v2);
Assert.assertEquals(3, v1.x, 0.0001f);
Assert.assertEquals(4, v1.y, 0.0001f);
Assert.assertEquals(5, v1.z, 0.0001f);
PVector v3 = new PVector(1, 2, 3);
PVector result = PVector.add(v3, new PVector(4, 5, 6));
Assert.assertEquals(5, result.x, 0.0001f);
Assert.assertEquals(7, result.y, 0.0001f);
Assert.assertEquals(9, result.z, 0.0001f);
}
@Test
public void testSub() {
PVector v1 = new PVector(5, 7, 9);
PVector v2 = new PVector(1, 2, 3);
v1.sub(v2);
Assert.assertEquals(4, v1.x, 0.0001f);
Assert.assertEquals(5, v1.y, 0.0001f);
Assert.assertEquals(6, v1.z, 0.0001f);
PVector v3 = new PVector(10, 10, 10);
PVector result = PVector.sub(v3, new PVector(3, 3, 3));
Assert.assertEquals(7, result.x, 0.0001f);
Assert.assertEquals(7, result.y, 0.0001f);
Assert.assertEquals(7, result.z, 0.0001f);
}
@Test
public void testMult() {
PVector v = new PVector(1, 2, 3);
v.mult(2);
Assert.assertEquals(2, v.x, 0.0001f);
Assert.assertEquals(4, v.y, 0.0001f);
Assert.assertEquals(6, v.z, 0.0001f);
PVector result = PVector.mult(new PVector(1, 1, 1), 5);
Assert.assertEquals(5, result.x, 0.0001f);
Assert.assertEquals(5, result.y, 0.0001f);
Assert.assertEquals(5, result.z, 0.0001f);
}
@Test
public void testDiv() {
PVector v1 = new PVector(10, 20, 30);
v1.div(2);
Assert.assertEquals(5, v1.x, 0.0001f);
Assert.assertEquals(10, v1.y, 0.0001f);
Assert.assertEquals(15, v1.z, 0.0001f);
PVector result = PVector.div(new PVector(10, 20, 30), 2);
Assert.assertEquals(5, result.x, 0.0001f);
Assert.assertEquals(10, result.y, 0.0001f);
Assert.assertEquals(15, result.z, 0.0001f);
// Division by zero
PVector v2 = new PVector(1, 2, 3);
v2.div(0);
Assert.assertTrue(Float.isInfinite(v2.x));
Assert.assertTrue(Float.isInfinite(v2.y));
Assert.assertTrue(Float.isInfinite(v2.z));
}
@Test
public void testMagnitude() {
PVector v = new PVector(3, 4, 0);
Assert.assertEquals(5, v.mag(), 0.0001f);
Assert.assertEquals(25, v.magSq(), 0.0001f);
}
@Test
public void testDot() {
PVector v1 = new PVector(1, 2, 3);
PVector v2 = new PVector(4, -5, 6);
float dot = v1.dot(v2);
Assert.assertEquals(12, dot, 0.0001f);
float dotStatic = PVector.dot(v1, v2);
Assert.assertEquals(12, dotStatic, 0.0001f);
}
@Test
public void testCross() {
PVector v1 = new PVector(1, 0, 0);
PVector v2 = new PVector(0, 1, 0);
PVector cross = v1.cross(v2);
Assert.assertEquals(0, cross.x, 0.0001f);
Assert.assertEquals(0, cross.y, 0.0001f);
Assert.assertEquals(1, cross.z, 0.0001f);
}
@Test
public void testNormalize() {
PVector v1 = new PVector(3, 4, 0);
v1.normalize();
Assert.assertEquals(1, v1.mag(), 0.0001f);
//with target
PVector v2 = new PVector(3, 4, 0);
PVector target = new PVector();
PVector result = v2.normalize(target);
Assert.assertSame(target, result);
Assert.assertEquals(0.6f, result.x, 0.0001f);
Assert.assertEquals(0.8f, result.y, 0.0001f);
Assert.assertEquals(0, result.z, 0.0001f);
// Normalize zero vector
PVector zero = new PVector(0, 0, 0);
zero.normalize();
Assert.assertEquals(0, zero.x, 0.0001f);
Assert.assertEquals(0, zero.y, 0.0001f);
Assert.assertEquals(0, zero.z, 0.0001f);
}
@Test
public void testLimit() {
PVector v = new PVector(10, 0, 0);
v.limit(5);
Assert.assertEquals(5, v.mag(), 0.0001f);
}
@Test
public void testSetMag() {
PVector v = new PVector(3, 4, 0);
v.setMag(10);
Assert.assertEquals(10, v.mag(), 0.0001f);
}
@Test
public void testHeading() {
PVector v = new PVector(0, 1);
float heading = v.heading();
Assert.assertEquals(PConstants.HALF_PI, heading, 0.0001f);
}
@Test
public void testRotate() {
PVector v = new PVector(1, 0);
v.rotate(PConstants.HALF_PI);
Assert.assertEquals(0, v.x, 0.0001f);
Assert.assertEquals(1, v.y, 0.0001f);
}
@Test
public void testLerp() {
PVector v1 = new PVector(0, 0, 0);
PVector v2 = new PVector(10, 10, 10);
v1.lerp(v2, 0.5f);
Assert.assertEquals(5, v1.x, 0.0001f);
Assert.assertEquals(5, v1.y, 0.0001f);
Assert.assertEquals(5, v1.z, 0.0001f);
PVector result = PVector.lerp(new PVector(0, 0, 0), new PVector(10, 10, 10), 0.5f);
Assert.assertEquals(5, result.x, 0.0001f);
Assert.assertEquals(5, result.y, 0.0001f);
Assert.assertEquals(5, result.z, 0.0001f);
}
@Test
public void testAngleBetween() {
PVector v1 = new PVector(1, 0, 0);
PVector v2 = new PVector(0, 1, 0);
float a1 = PVector.angleBetween(v1, v2);
Assert.assertEquals(PConstants.HALF_PI, a1, 0.0001f);
// angleBetween with zero vectors
float a2 = PVector.angleBetween(new PVector(0, 0, 0), new PVector(1, 0, 0));
Assert.assertEquals(0, a2, 0.0001f);
// angleBetween with parallel vectors
float a3 = PVector.angleBetween(new PVector(1, 0, 0), new PVector(2, 0, 0));
Assert.assertEquals(0, a3, 0.0001f);
// angleBetween with opposite vectors
float a4 = PVector.angleBetween(new PVector(1, 0, 0), new PVector(-1, 0, 0));
Assert.assertEquals(PConstants.PI, a4, 0.0001f);
}
@Test
public void testFromAngle() {
PVector v = PVector.fromAngle(0);
Assert.assertEquals(1, v.x, 0.0001f);
Assert.assertEquals(0, v.y, 0.0001f);
Assert.assertEquals(0, v.z, 0.0001f);
v = PVector.fromAngle(PConstants.HALF_PI);
Assert.assertEquals(0, v.x, 0.0001f);
Assert.assertEquals(1, v.y, 0.0001f);
Assert.assertEquals(0, v.z, 0.0001f);
PVector target = new PVector();
PVector result = PVector.fromAngle(PConstants.PI, target);
Assert.assertSame(target, result);
Assert.assertEquals(-1, result.x, 0.0001f);
Assert.assertEquals(0, result.y, 0.0001f);
}
@Test
public void testArray() {
PVector v = new PVector(3, 4, 5);
float[] arr = v.array();
Assert.assertEquals(3, arr[0], 0.0001f);
Assert.assertEquals(4, arr[1], 0.0001f);
Assert.assertEquals(5, arr[2], 0.0001f);
}
@Test
public void testRandom2D() {
PVector v = PVector.random2D();
Assert.assertEquals(1, v.mag(), 0.0001f);
Assert.assertEquals(0, v.z, 0.0001f);
PVector target = new PVector();
PVector result = PVector.random2D(target);
Assert.assertSame(target, result);
Assert.assertEquals(1, result.mag(), 0.0001f);
}
@Test
public void testRandom3D() {
PVector v = PVector.random3D();
Assert.assertEquals(1, v.mag(), 0.0001f);
PVector target = new PVector();
PVector result = PVector.random3D(target);
Assert.assertSame(target, result);
Assert.assertEquals(1, result.mag(), 0.0001f);
}
@Test
public void testEqualsAndHashCode() {
PVector v1 = new PVector(1, 2, 3);
PVector v2 = new PVector(1, 2, 3);
PVector v3 = new PVector(3, 2, 1);
Assert.assertTrue(v1.equals(v2));
Assert.assertFalse(v1.equals(v3));
Assert.assertEquals(v1.hashCode(), v2.hashCode());
}
@Test
public void testToString() {
PVector v = new PVector(1, 2, 3);
String expected = "[ 1.0, 2.0, 3.0 ]";
Assert.assertEquals(expected, v.toString());
}
}