Skip to content

Conversation

singlecoder
Copy link
Member

@singlecoder singlecoder commented Nov 7, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a copyTo method in the Vector2, Vector3, Vector4, Color, and Quaternion classes, allowing users to copy values to target objects.
  • Tests

    • Added test cases for the copyTo method in Vector2, Vector3, Vector4, Color, and Quaternion to ensure functionality and accuracy.

@singlecoder singlecoder added the math Math library label Nov 7, 2024
@singlecoder singlecoder added this to the 1.3 milestone Nov 7, 2024
@singlecoder singlecoder self-assigned this Nov 7, 2024
Copy link

coderabbitai bot commented Nov 7, 2024

Walkthrough

The changes introduced in this pull request involve the addition of a new method named copyTo across several classes including Vector2, Vector3, Vector4, Color, and Quaternion. This method facilitates the copying of values from an instance of each class to a target object that adheres to the respective interfaces (Vector2Like, Vector3Like, Vector4Like, ColorLike, QuaternionLike). Corresponding test cases have also been added for each class to validate the functionality of the new copyTo method, ensuring its correct operation without altering existing methods or properties.

Changes

File Change Summary
packages/math/src/Vector2.ts Added method copyTo(target: Vector2Like): Vector2Like in class Vector2.
packages/math/src/Vector3.ts Added method copyTo(target: Vector3Like): Vector3Like in class Vector3.
packages/math/src/Vector4.ts Added method copyTo(target: Vector4Like): Vector4Like in class Vector4.
packages/math/src/Color.ts Added method copyTo(target: ColorLike): ColorLike in class Color.
packages/math/src/Quaternion.ts Added method copyTo(target: QuaternionLike): QuaternionLike in class Quaternion.
packages/math/src/ICopy.ts Added optional method copyTo?(target: S): S in interface ICopy<S, T>.
tests/src/math/Vector2.test.ts Added test case for copyTo method in Vector2 class.
tests/src/math/Vector3.test.ts Added test case for copyTo method in Vector3 class.
tests/src/math/Vector4.test.ts Added test case for copyTo method in Vector4 class.
tests/src/math/Color.test.ts Added test case for copyTo method in Color class.
tests/src/math/Quaternion.test.ts Added test case for copyTo method in Quaternion class.

Poem

In the land of vectors, so bold and bright,
A new copyTo method takes flight.
From Vector2, 3, and 4, they share,
Their values with targets, with utmost care.
Hopping with joy, we test and we play,
For vectors unite in a magical way! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

codecov bot commented Nov 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 69.42%. Comparing base (4c0cfd0) to head (a021a4b).
Report is 7 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2428      +/-   ##
==========================================
+ Coverage   69.11%   69.42%   +0.30%     
==========================================
  Files         524      524              
  Lines       27411    27439      +28     
  Branches     4108     4109       +1     
==========================================
+ Hits        18946    19049     +103     
+ Misses       6968     6884      -84     
- Partials     1497     1506       +9     
Flag Coverage Δ
unittests 69.42% <100.00%> (+0.30%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (7)
tests/src/math/Vector2.test.ts (1)

151-156: LGTM! Consider adding more test cases for comprehensive coverage.

The basic test case looks good and follows the established patterns. However, consider adding the following test cases for better coverage:

it("copyTo - should handle existing values in target", () => {
  const a = new Vector2(3, 4);
  const out = new Vector2(1, 2);
  a.copyTo(out);
  expect(toString(out)).to.eq("vec2(3, 4)");
  expect(toString(a)).to.eq("vec2(3, 4)"); // verify source unchanged
});

it("copyTo - should handle edge cases", () => {
  const a = new Vector2(Number.MAX_VALUE, Number.MIN_VALUE);
  const out = new Vector2();
  a.copyTo(out);
  expect(toString(out)).to.eq(toString(a));
});
tests/src/math/Vector4.test.ts (1)

161-166: Enhance test coverage for the copyTo method.

While the basic test case is good, consider adding more test cases to ensure robust functionality:

  1. Test copying to a Vector4Like object (not just Vector4)
  2. Verify the source vector remains unchanged after copy
  3. Add edge cases (e.g., copying to self)
  4. Use direct value comparisons instead of toString

Here's a suggested expansion of the test cases:

 it("copyTo", () => {
   const a = new Vector4(3, 4, 5, 0);
   const out = new Vector4();
   a.copyTo(out);
   expect(toString(a)).to.eq(toString(out));
+
+  // Test copying to Vector4Like object
+  const vector4Like = { x: 0, y: 0, z: 0, w: 0 };
+  a.copyTo(vector4Like);
+  expect(vector4Like.x).to.eq(3);
+  expect(vector4Like.y).to.eq(4);
+  expect(vector4Like.z).to.eq(5);
+  expect(vector4Like.w).to.eq(0);
+
+  // Verify source remains unchanged
+  expect(a.x).to.eq(3);
+  expect(a.y).to.eq(4);
+  expect(a.z).to.eq(5);
+  expect(a.w).to.eq(0);
+
+  // Test copying to self
+  a.copyTo(a);
+  expect(a.x).to.eq(3);
+  expect(a.y).to.eq(4);
+  expect(a.z).to.eq(5);
+  expect(a.w).to.eq(0);
 });
tests/src/math/Vector3.test.ts (1)

179-184: Enhance test coverage for the copyTo method.

While the basic test case looks good, consider adding the following test scenarios for better coverage:

  1. Verify source vector remains unchanged after copy
  2. Test edge cases (e.g., null/undefined target)
  3. Verify that modifying the target doesn't affect the source

Example enhancement:

 it("copyTo", () => {
   const a = new Vector3(3, 4, 5);
   const out = new Vector3();
+  const originalToString = toString(a);
   
   a.copyTo(out);
   expect(toString(a)).to.eq(toString(out));
+  // Verify source remains unchanged
+  expect(toString(a)).to.eq(originalToString);
+  
+  // Verify independent copies
+  out.x = 10;
+  expect(a.x).to.eq(3);
+  
+  // Test edge cases
+  expect(() => a.copyTo(null)).to.throw();
+  expect(() => a.copyTo(undefined)).to.throw();
 });
packages/math/src/Vector2.ts (1)

360-364: Consider adding parameter validation.

The method could benefit from defensive programming by validating the target parameter.

 copyTo(target: Vector2Like): Vector2Like {
+  if (!target) {
+    throw new Error("The target vector cannot be null or undefined");
+  }
   target.x = this._x;
   target.y = this._y;
   return target;
 }
packages/math/src/Vector4.ts (1)

480-491: LGTM! The implementation is correct and well-integrated.

The new copyTo method:

  • Correctly implements value copying to target Vector4Like object
  • Maintains symmetry with existing copyFrom method
  • Properly documented following the codebase style
  • Correctly returns the modified target object

Minor suggestion for documentation completeness

Consider adding an example in the documentation to show usage:

   /**
    * Copy to vector4 like object.
    * @param target - Vector4 like object
    * @returns This Vector4 like object
+   * @example
+   * ```typescript
+   * const source = new Vector4(1, 2, 3, 4);
+   * const target = { x: 0, y: 0, z: 0, w: 0 };
+   * source.copyTo(target); // target is now { x: 1, y: 2, z: 3, w: 4 }
+   * ```
    */
packages/math/src/Vector3.ts (2)

569-574: Consider adding parameter validation.

The implementation looks good, but consider adding a null check for the target parameter to prevent runtime errors.

 copyTo(target: Vector3Like): Vector3Like {
+  if (!target) {
+    throw new Error("Target cannot be null or undefined");
+  }
   target.x = this._x;
   target.y = this._y;
   target.z = this._z;
   return target;
 }

564-568: Enhance method documentation.

The JSDoc could be more descriptive about the method's purpose and behavior.

 /**
  * Copy to vector3 like object.
+ * Copies the values of this vector to a target object that implements the Vector3Like interface.
  * @param target - Vector3 like object
+ * @throws {Error} If target is null or undefined
  * @returns This Vector3 like object
  */
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between bfebffd and a10b11f.

📒 Files selected for processing (6)
  • packages/math/src/Vector2.ts (1 hunks)
  • packages/math/src/Vector3.ts (1 hunks)
  • packages/math/src/Vector4.ts (1 hunks)
  • tests/src/math/Vector2.test.ts (1 hunks)
  • tests/src/math/Vector3.test.ts (1 hunks)
  • tests/src/math/Vector4.test.ts (1 hunks)
🔇 Additional comments (5)
tests/src/math/Vector2.test.ts (1)

151-156: Verify consistent test coverage across vector classes.

Since this is part of adding copyTo to all vector classes, let's ensure consistent test coverage exists in Vector3 and Vector4 test files.

✅ Verification successful

Test coverage for copyTo is consistent across vector classes

The verification shows that all vector classes (Vector2, Vector3, Vector4) have identical test coverage for the copyTo method, following the same pattern:

  • Creating a source vector with test values
  • Creating an empty destination vector
  • Calling copyTo
  • Verifying equality using toString
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if similar test coverage exists for Vector3 and Vector4

echo "Checking for copyTo tests in Vector3 and Vector4 test files..."
rg -A 5 'it\("copyTo"' tests/src/math/Vector3.test.ts tests/src/math/Vector4.test.ts

echo "Checking test patterns used across vector test files..."
rg -A 2 'toString\(' tests/src/math/Vector{2,3,4}.test.ts

Length of output: 14718

tests/src/math/Vector4.test.ts (1)

161-166: Verify consistent test coverage across vector classes.

Since similar copyTo methods were added to Vector2 and Vector3 classes, let's verify that they have equivalent test coverage.

✅ Verification successful

Test coverage for copyTo is consistent across vector classes

The verification shows that:

  • All vector classes (Vector2, Vector3, Vector4) have identical test coverage for the copyTo method
  • The implementation of copyTo is present in all vector classes with appropriate type signatures
  • The test structure and assertions are consistent across all test files
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if Vector2 and Vector3 test files have similar copyTo test coverage

echo "Checking Vector2 and Vector3 test files for copyTo tests..."

# Search for copyTo test cases in Vector2 and Vector3 test files
rg -A 5 'it\("copyTo"' tests/src/math/Vector[23].test.ts

# Also check the actual implementation files to ensure copyTo is implemented
echo -e "\nVerifying copyTo implementation in Vector classes..."
rg -A 3 'copyTo\(' 'packages/math/src/Vector[234].ts'

Length of output: 1159


Script:

#!/bin/bash
# Let's try with the correct path pattern for implementation files
echo "Verifying copyTo implementation in Vector classes..."
rg -A 3 'copyTo\(' packages/core/src/math/Vector[234].ts

# Double check the test coverage with correct paths
echo -e "\nChecking test coverage..."
rg -A 5 'it\("copyTo"' tests/src/math/Vector[234].test.ts

Length of output: 1485


Script:

#!/bin/bash
# Let's try finding the correct path for Vector implementation files
echo "Finding Vector implementation files..."
fd Vector[234].ts

# Then verify copyTo implementation in the found files
echo -e "\nVerifying copyTo implementation..."
fd Vector[234].ts --exec rg -A 3 'copyTo\('

Length of output: 674

packages/math/src/Vector2.ts (2)

355-364: LGTM! The implementation is clean and consistent.

The new copyTo method follows the established patterns in the codebase and provides a symmetrical operation to the existing copyFrom method.


355-364: Verify consistency with Vector3 and Vector4 implementations.

Let's ensure the implementation is consistent across all vector classes.

packages/math/src/Vector4.ts (1)

Line range hint 9-9: Verify ICopy interface implementation

The new copyTo method completes the ICopy interface implementation, working in tandem with the existing copyFrom method. This provides a symmetric API for copying vector values between objects.

✅ Verification successful

Let me verify the implementation of ICopy interface across these Vector classes.


Let me try a different approach using ripgrep to check the implementations.


ICopy interface implementation is consistent and complete

The implementation of ICopy interface is verified across Vector2, Vector3, and Vector4 classes. All classes:

  • Properly implement both copyFrom and copyTo methods
  • Handle their respective dimensional data (2D, 3D, 4D)
  • Maintain consistent return types and parameter types
  • Follow the same pattern of implementation
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify ICopy interface implementation completeness
# Search for other Vector classes to ensure consistent implementation

# Look for Vector2 and Vector3 implementations
rg "implements.*ICopy.*Vector\dLike" --type ts

Length of output: 372


Script:

#!/bin/bash
# Check implementation of copyFrom and copyTo methods in all Vector classes
ast-grep --pattern 'copyFrom($_: $_) {
  $$$
}'

ast-grep --pattern 'copyTo($_: $_) {
  $$$
}'

Length of output: 97


Script:

#!/bin/bash
# Check copyFrom and copyTo methods in Vector classes with context
rg "copyFrom|copyTo" packages/math/src/Vector*.ts -A 5 -B 1

Length of output: 4880

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (4)
packages/math/src/ICopy.ts (1)

11-15: Enhance documentation for optional copyTo method.

The JSDoc could be more descriptive about the optional nature of the method and its relationship with copyFrom.

 /**
  * Copy to target object.
+ * This optional method provides symmetrical functionality to copyFrom,
+ * allowing objects to copy their values to a target object.
  * @param target - The target object to copy values to
  * @returns This target object
  */
tests/src/math/Color.test.ts (1)

61-67: LGTM! Consider adding more test cases for comprehensive coverage.

The test case correctly verifies the basic functionality of the copyTo method. However, to ensure robust implementation, consider adding tests for:

  1. Edge cases with extreme values (0,0,0,0) and (1,1,1,1)
  2. Invalid inputs (null/undefined target)
  3. Chaining behavior (if supported)

Here's a suggested expansion of the test cases:

it("copyTo", () => {
  // Basic functionality
  const a = new Color(1, 0, 0, 1);
  const out = new Color();
  a.copyTo(out);
  expect(Color.equals(a, out)).to.eq(true);

  // Edge cases
  const black = new Color(0, 0, 0, 0);
  const white = new Color(1, 1, 1, 1);
  const target = new Color();
  
  black.copyTo(target);
  expect(Color.equals(black, target)).to.eq(true);
  
  white.copyTo(target);
  expect(Color.equals(white, target)).to.eq(true);

  // Invalid input
  expect(() => a.copyTo(null)).to.throw();
  expect(() => a.copyTo(undefined)).to.throw();
});
tests/src/math/Quaternion.test.ts (1)

264-269: Consider expanding test coverage for copyTo method.

While the current test provides a good baseline verification, consider adding the following test cases to ensure comprehensive coverage:

  1. Test with a QuaternionLike object as target
  2. Verify source remains unchanged after copy
  3. Test edge cases (e.g., identity quaternion)
  4. Verify individual components directly instead of string comparison

Example expansion:

it("copyTo", () => {
  const a = new Quaternion(3, 4, 5, 0);
  
  // Test 1: Basic quaternion copy
  const out = new Quaternion();
  a.copyTo(out);
  expect(toString(a)).to.eq(toString(out));
  
  // Test 2: Copy to QuaternionLike object
  const outLike = { x: 0, y: 0, z: 0, w: 0 };
  a.copyTo(outLike);
  expect(outLike.x).to.eq(3);
  expect(outLike.y).to.eq(4);
  expect(outLike.z).to.eq(5);
  expect(outLike.w).to.eq(0);
  
  // Test 3: Verify source unchanged
  expect(a.x).to.eq(3);
  expect(a.y).to.eq(4);
  expect(a.z).to.eq(5);
  expect(a.w).to.eq(0);
  
  // Test 4: Identity quaternion
  const identity = new Quaternion(0, 0, 0, 1);
  const outIdentity = new Quaternion();
  identity.copyTo(outIdentity);
  expect(outIdentity.x).to.eq(0);
  expect(outIdentity.y).to.eq(0);
  expect(outIdentity.z).to.eq(0);
  expect(outIdentity.w).to.eq(1);
});
packages/math/src/Color.ts (1)

261-272: Consider adding parameter validation.

The implementation looks good and follows the established patterns. Consider adding parameter validation to handle null/undefined targets.

 copyTo(target: ColorLike): ColorLike {
+  if (!target) {
+    throw new Error("The target cannot be null or undefined.");
+  }
   target.r = this._r;
   target.g = this._g;
   target.b = this._b;
   target.a = this._a;
   return target;
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between a10b11f and a021a4b.

📒 Files selected for processing (5)
  • packages/math/src/Color.ts (1 hunks)
  • packages/math/src/ICopy.ts (1 hunks)
  • packages/math/src/Quaternion.ts (1 hunks)
  • tests/src/math/Color.test.ts (1 hunks)
  • tests/src/math/Quaternion.test.ts (1 hunks)
🔇 Additional comments (3)
packages/math/src/ICopy.ts (1)

10-15: LGTM! Well-designed interface extension.

The optional copyTo method is a good addition that:

  • Maintains backward compatibility by being optional
  • Provides symmetrical functionality to copyFrom
  • Uses proper TypeScript generic types
packages/math/src/Color.ts (1)

261-272: Verify consistency across vector-like classes.

Let's verify that this implementation pattern is consistent across other classes mentioned in the PR summary (Vector2, Vector3, Vector4, Quaternion).

✅ Verification successful

Implementation pattern is consistent across all vector-like classes

The copyTo implementation in Color follows the same pattern as all other vector-like classes (Vector2, Vector3, Vector4, Quaternion):

  • All methods accept a *Like interface as parameter and return type
  • All implementations directly copy internal fields to target object properties
  • All return the target object
  • None of them include any additional processing or callbacks
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check implementation consistency of copyTo method across vector-like classes
# Expected: All implementations should follow similar pattern without _onValueChanged calls

# Search for copyTo implementations in vector-like classes
echo "Searching for copyTo implementations:"
rg -A 6 'copyTo.*:.*Like.*{' packages/math/src/

Length of output: 234


Script:

#!/bin/bash
# Let's fix the regex and search for copyTo implementations
echo "Searching for copyTo implementations in Vector2:"
rg -A 6 "copyTo.*\(.*\).*\{" packages/math/src/Vector2.ts

echo -e "\nSearching for copyTo implementations in Vector3:"
rg -A 6 "copyTo.*\(.*\).*\{" packages/math/src/Vector3.ts

echo -e "\nSearching for copyTo implementations in Vector4:"
rg -A 6 "copyTo.*\(.*\).*\{" packages/math/src/Vector4.ts

echo -e "\nSearching for copyTo implementations in Quaternion:"
rg -A 6 "copyTo.*\(.*\).*\{" packages/math/src/Quaternion.ts

Length of output: 2151

packages/math/src/Quaternion.ts (1)

733-744: Verify usage of the new copyTo method.

Let's verify if there are any existing usages of this new method to ensure backward compatibility.

✅ Verification successful

The copyTo method follows a consistent pattern across math types and has test coverage

The copyTo method implementation in Quaternion follows the same pattern as other math types (Vector2, Vector3, Vector4, Color) in the codebase. Each implementation copies component values to a target object of the corresponding type. The method is also properly tested in tests/src/math/Quaternion.test.ts, ensuring it works as expected.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any existing usage of the copyTo method
rg -A 2 "copyTo\(" .

Length of output: 1837

Comment on lines +733 to +744
/**
* Copy this quaternion to the specified quaternion.
* @param target - The specified quaternion
* @returns This specified quaternion
*/
copyTo(target: QuaternionLike): QuaternionLike {
target.x = this._x;
target.y = this._y;
target.z = this._z;
target.w = this._w;
return target;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add parameter validation and maintain consistency with other methods.

The implementation could be improved in the following areas:

  1. Add parameter validation to handle null/undefined target.
  2. Consider calling _onValueChanged on the target if it has the callback, maintaining consistency with other methods.
  3. Improve documentation by mentioning that the target must implement the QuaternionLike interface.

Consider applying these improvements:

  /**
   * Copy this quaternion to the specified quaternion.
   * @param target - The specified quaternion
+  * @throws {Error} If target is null or undefined
   * @returns This specified quaternion
   */
  copyTo(target: QuaternionLike): QuaternionLike {
+    if (!target) {
+      throw new Error("Target cannot be null or undefined");
+    }
    target.x = this._x;
    target.y = this._y;
    target.z = this._z;
    target.w = this._w;
+    if (target instanceof Quaternion && target._onValueChanged) {
+      target._onValueChanged();
+    }
    return target;
  }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
/**
* Copy this quaternion to the specified quaternion.
* @param target - The specified quaternion
* @returns This specified quaternion
*/
copyTo(target: QuaternionLike): QuaternionLike {
target.x = this._x;
target.y = this._y;
target.z = this._z;
target.w = this._w;
return target;
}
/**
* Copy this quaternion to the specified quaternion.
* @param target - The specified quaternion
* @throws {Error} If target is null or undefined
* @returns This specified quaternion
*/
copyTo(target: QuaternionLike): QuaternionLike {
if (!target) {
throw new Error("Target cannot be null or undefined");
}
target.x = this._x;
target.y = this._y;
target.z = this._z;
target.w = this._w;
if (target instanceof Quaternion && target._onValueChanged) {
target._onValueChanged();
}
return target;
}

@GuoLei1990 GuoLei1990 changed the title Feat: add function copy to vector link object for vector Add function copy to vector link object for vector Nov 7, 2024
@GuoLei1990 GuoLei1990 merged commit fc35b02 into galacean:main Nov 7, 2024
9 checks passed
@GuoLei1990 GuoLei1990 changed the title Add function copy to vector link object for vector Add function copy to vector/color/quaternion link object for vector Nov 7, 2024
@GuoLei1990 GuoLei1990 changed the title Add function copy to vector/color/quaternion link object for vector Add function support copy vector/color/quaternion to like object Nov 7, 2024
@GuoLei1990 GuoLei1990 added the enhancement New feature or request label Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request math Math library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants