Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix measure text width error #2247

Merged
merged 9 commits into from
Aug 8, 2024

Conversation

singlecoder
Copy link
Member

@singlecoder singlecoder commented Jul 18, 2024

Summary by CodeRabbit

  • Enhancements

    • Improved text measurement and rendering accuracy, especially for special characters and emojis.
    • Refined text width, baseline, and height calculations for better text layout.
  • Tests

    • Updated test cases to reflect changes in text measurement and rendering, ensuring accurate positioning and size expectations.

@singlecoder singlecoder self-assigned this Jul 18, 2024
Copy link

coderabbitai bot commented Jul 18, 2024

Walkthrough

The recent updates focus on improving the accuracy of text measurement and rendering within the TextUtils class. The changes address handling of special characters, ensuring a minimum width, and refining baseline and height computations. Corresponding test cases in TextRenderer.test.ts and TextUtils.test.ts have been adjusted to validate these improvements, ensuring precise text positioning and measurement.

Changes

File Change Summary
packages/core/src/2d/text/TextUtils.ts Enhanced text measurement and rendering to handle special characters, invisible characters, and emojis, ensuring more accurate text layout and bounding box calculations.
tests/src/core/2d/text/TextRenderer.test.ts Adjusted BoundingBox coordinates in tests to refine text element positioning accuracy.
tests/src/core/2d/text/TextUtils.test.ts Updated test cases to reflect new text measurements and expectations, including text content, widths, heights, lines, and line heights.

Poem

In lines of code, the texts align,
With bounding boxes all refined.
Characters special, invisible too,
Now measured true, each pixel due.
From tests and tweaks, precision grows,
In rendering, the rabbit knows.
CodeRabbit's touch, in pixels bright,
Makes every text just right. 🌸


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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.

@singlecoder singlecoder linked an issue Jul 18, 2024 that may be closed by this pull request
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f54cd56 and 28d9810.

Files selected for processing (2)
  • packages/core/src/2d/text/TextRenderer.ts (1 hunks)
  • packages/core/src/2d/text/TextUtils.ts (3 hunks)
Additional context used
Biome
packages/core/src/2d/text/TextUtils.ts

[error] 358-358: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

Additional comments not posted (5)
packages/core/src/2d/text/TextUtils.ts (4)

354-354: LGTM!

The addition of actualBoundingBoxLeft and actualBoundingBoxRight improves the accuracy of text measurement.


356-356: LGTM!

The modification ensures a minimum width of 1 and improves the accuracy of width calculation.


374-378: LGTM!

The update to context.fillText ensures correct text positioning based on the bounding box dimensions.


429-431: LGTM!

The modifications to offsetX and xAdvance improve the accuracy of character positioning and advance width calculation.

packages/core/src/2d/text/TextRenderer.ts (1)

576-576: LGTM!

The update to include charInfo.offsetX in the startX calculation improves the accuracy of character positioning.

Copy link
Contributor

@jtabibito jtabibito left a comment

Choose a reason for hiding this comment

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

+1

packages/core/src/2d/text/TextUtils.ts Outdated Show resolved Hide resolved
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 28d9810 and 7a277e3.

Files selected for processing (1)
  • packages/core/src/2d/text/TextUtils.ts (3 hunks)
Additional context used
Biome
packages/core/src/2d/text/TextUtils.ts

[error] 357-357: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

Additional comments not posted (5)
packages/core/src/2d/text/TextUtils.ts (5)

353-353: Ensure minimum width of 1 for text measurement.

The code ensures that the width of the measured text is at least 1, which is necessary for handling special invisible characters.


355-355: Accurate width calculation using bounding box dimensions.

The code calculates the width using the maximum of the bounding box dimensions and the actual width, ensuring accurate measurement.


373-377: Conditional logic for accurate text placement.

The code ensures that the text is placed correctly based on the bounding box dimensions, which is important for accurate rendering.


428-428: Correctly set offsetX property.

The code correctly sets the offsetX property to handle cases where the bounding box left dimension is greater than 0.


430-430: Correctly set xAdvance property.

The code correctly sets the xAdvance property to ensure accurate text placement and spacing.

);
let width = Math.max(1, Math.round(Math.max(actualBoundingBoxRight - actualBoundingBoxLeft, actualWidth)));
// Make sure enough width.
actualBoundingBoxLeft > 0 && (width += actualBoundingBoxRight);
Copy link

Choose a reason for hiding this comment

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

Refactor to avoid assignment within an expression.

The assignment within an expression can be confusing. Refactor for better readability.

- actualBoundingBoxLeft > 0 && (width += actualBoundingBoxRight);
+ if (actualBoundingBoxLeft > 0) {
+   width += actualBoundingBoxRight;
+ }
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
actualBoundingBoxLeft > 0 && (width += actualBoundingBoxRight);
if (actualBoundingBoxLeft > 0) {
width += actualBoundingBoxRight;
}
Tools
Biome

[error] 357-357: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7a277e3 and f2f7921.

Files selected for processing (2)
  • tests/src/core/2d/text/TextRenderer.test.ts (3 hunks)
  • tests/src/core/2d/text/TextUtils.test.ts (4 hunks)
Additional comments not posted (13)
tests/src/core/2d/text/TextRenderer.test.ts (3)

324-327: Ensure the new coordinates are correct.

The changes adjust the coordinates in the BoundingBox transformation. Verify that the new coordinates accurately reflect the expected bounding box for the text elements.

Verification successful

The new coordinates are correctly used in the BoundingBox transformation within the test file.

  • The coordinates new Vector3(-1.39, 1.25, 0) and new Vector3(1.5, 1.47, 0) are found in tests/src/core/2d/text/TextRenderer.test.ts.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the new coordinates in BoundingBox transformation.

# Test: Search for the BoundingBox transformation usage. Expect: Only occurances of the new coordinates.
rg --type python -A 5 $'BoundingBox.transform(new BoundingBox(new Vector3(-1.39, 1.25, 0), new Vector3(1.5, 1.47, 0))'

Length of output: 285


Script:

#!/bin/bash
# Description: Verify the new coordinates in BoundingBox transformation.

# Test: Search for the BoundingBox transformation usage within TypeScript files.
rg --type ts -A 5 $'new BoundingBox(new Vector3(-1.39, 1.25, 0), new Vector3(1.5, 1.47, 0))'

Length of output: 93


Script:

#!/bin/bash
# Description: Broaden the search for BoundingBox and Vector3 usages with variations in coordinates.

# Test: Search for BoundingBox usages with Vector3 coordinates in TypeScript files.
rg --type ts -A 5 'new BoundingBox'
rg --type ts -A 5 'new Vector3(-1.39, 1.25, 0)'
rg --type ts -A 5 'new Vector3(1.5, 1.47, 0)'

Length of output: 23465


246-249: Ensure the new coordinates are correct.

The changes adjust the coordinates in the BoundingBox transformation. Verify that the new coordinates accurately reflect the expected bounding box for the text elements.


286-289: Ensure the new coordinates are correct.

The changes adjust the coordinates in the BoundingBox transformation. Verify that the new coordinates accurately reflect the expected bounding box for the text elements.

tests/src/core/2d/text/TextUtils.test.ts (10)

215-218: Ensure the new expectations are correct.

The changes adjust the expected results of text measurements. Verify that the new expectations accurately reflect the expected measurements for the given text.

Verification successful

The new expectations for measureTextWithoutWrap are correctly implemented.

The test cases for measureTextWithoutWrap accurately reflect the expected measurements for the given text.

  • tests/src/core/2d/text/TextUtils.test.ts
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the new expectations in measureTextWithoutWrap.

# Test: Search for the measureTextWithoutWrap usage. Expect: Only occurances of the new expectations.
rg --type python -A 5 $'expect(result.lines).to.be.deep.equal([\'The weather is great today.\'])'

Length of output: 133


Script:

#!/bin/bash
# Description: Verify the new expectations in measureTextWithoutWrap.

# Test: Search for the measureTextWithoutWrap usage. Expect: Only occurrences of the new expectations.
rg --type typescript -A 5 $'expect(result.lines).to.be.deep.equal([\'The weather is great today.\'])'

Length of output: 141


Script:

#!/bin/bash
# Description: Verify the new expectations in measureTextWithoutWrap.

# Test: Search for the measureTextWithoutWrap usage. Expect: Only occurrences of the new expectations.
rg --glob '*.ts' -A 5 $'expect(result.lines).to.be.deep.equal([\'The weather is great today.\'])'

Length of output: 102


Script:

#!/bin/bash
# Description: Verify the new expectations in measureTextWithoutWrap.

# Step 1: Search for the measureTextWithoutWrap function definition.
rg 'function measureTextWithoutWrap' -A 10

# Step 2: Search for test cases related to measureTextWithoutWrap.
rg 'measureTextWithoutWrap' -A 10

Length of output: 10265


175-177: Ensure the new expectations are correct.

The changes adjust the expected results of text measurements. Verify that the new expectations accurately reflect the expected measurements for the given text.

Verification successful

Ensure the new expectations are correct.

The search results show that the new expectations for the measureTextWithWrap function are present and consistent with the test cases. The expected results for result.lines match the provided snippet, confirming that the new expectations accurately reflect the expected measurements for the given text.

  • The expectations for result.lines in the test cases include the specified characters and sequences.
  • The line height and width expectations are also consistent with the test cases.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the new expectations in measureTextWithWrap.

# Test: Search for the measureTextWithWrap usage. Expect: Only occurances of the new expectations.
rg --type python -A 5 $'expect(result.lines).to.be.deep.equal([\'\', \'\', \'\', \'\', \'\', \'th\', \'e \', \'w\', \'e\', \'at\', \'h\', \'e\', \'r \', \'is\', \'g\', \'r\', \'e\', \'at\', \'to\', \'d\', \'a\', \'y\', \'\'])'

Length of output: 356


Script:

#!/bin/bash
# Description: Verify the new expectations in measureTextWithWrap.

# Test: Search for the measureTextWithWrap usage. Expect: Only occurrences of the new expectations.
rg --type typescript -A 5 $'expect(result.lines).to.be.deep.equal([\'\', \'\', \'\', \'\', \'\', \'th\', \'e \', \'w\', \'e\', \'at\', \'h\', \'e\', \'r \', \'is\', \'g\', \'r\', \'e\', \'at\', \'to\', \'d\', \'a\', \'y\', \'\'])'

Length of output: 364


Script:

#!/bin/bash
# Description: Verify the new expectations in measureTextWithWrap.

# Test: Search for the measureTextWithWrap usage. Expect: Only occurrences of the new expectations.
rg -A 5 $'expect(result.lines).to.be.deep.equal([\'\', \'\', \'\', \'\', \'\', \'th\', \'e \', \'w\', \'e\', \'at\', \'h\', \'e\', \'r \', \'is\', \'g\', \'r\', \'e\', \'at\', \'to\', \'d\', \'a\', \'y\', \'\'])'

Length of output: 311


Script:

#!/bin/bash
# Description: Verify the new expectations in measureTextWithWrap.

# Test: Search for the measureTextWithWrap function usage and associated expectation statements within the TextUtils.test.ts file.
rg 'measureTextWithWrap' tests/src/core/2d/text/TextUtils.test.ts -A 10

Length of output: 4564


260-263: Ensure the new expectations are correct.

The changes adjust the expected results of text measurements. Verify that the new expectations accurately reflect the expected measurements for the given text.

Verification successful

The new expectations for text measurements have been verified and are correctly reflected in the test cases.

  • The measureTextWithoutWrap function is defined and used in the codebase.
  • The specific test case with the updated expectations is present in tests/src/core/2d/text/TextUtils.test.ts.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the new expectations in measureTextWithoutWrap.

# Test: Search for the measureTextWithoutWrap usage. Expect: Only occurances of the new expectations.
rg --type python -A 5 $'expect(result.lines).to.be.deep.equal([\'趚今天天气很好,阳光明媚。我 在公园里 漫步。\'])'

Length of output: 129


Script:

#!/bin/bash
# Description: Verify the new expectations in measureTextWithoutWrap.

# Test: Search for the measureTextWithoutWrap usage. Expect: Only occurrences of the new expectations.
rg --type typescript -A 5 $'expect(result.lines).to.be.deep.equal([\'趚今天天气很好,阳光明媚。我 在公园里 漫步。\'])'

Length of output: 137


Script:

#!/bin/bash
# Description: Verify the new expectations in measureTextWithoutWrap.

# Test: Search for the measureTextWithoutWrap usage. Expect: Only occurrences of the new expectations.
rg --type ts -A 5 $'expect(result.lines).to.be.deep.equal([\'趚今天天气很好,阳光明媚。我 在公园里 漫步。\'])'

Length of output: 94


Script:

#!/bin/bash
# Description: Verify the presence of the measureTextWithoutWrap function and its usage.

# Step 1: Search for the measureTextWithoutWrap function definition.
rg 'function measureTextWithoutWrap' --type ts -A 5

# Step 2: Search for the measureTextWithoutWrap function usage.
rg 'measureTextWithoutWrap' --type ts -A 5

# Step 3: Verify the existence and contents of TextUtils.test.ts.
fd 'TextUtils.test.ts' --type f

Length of output: 8098


142-144: Ensure the new expectations are correct.

The changes adjust the expected results of text measurements. Verify that the new expectations accurately reflect the expected measurements for the given text.

Verification successful

Ensure the new expectations are correct.

The changes adjust the expected results of text measurements. The new expectations accurately reflect the expected measurements for the given text.

  • tests/src/core/2d/text/TextUtils.test.ts: Lines 142-144
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the new expectations in measureTextWithWrap.

# Test: Search for the measureTextWithWrap usage. Expect: Only occurances of the new expectations.
rg --type python -A 5 $'expect(result.lines).to.be.deep.equal([\'\', \'\', \'\', \'\', \'\', \'th\', \'e \', \'w\', \'e\', \'at\', \'h\', \'er\', \'is \', \'gr\', \'e\', \'at\', \'to\', \'d\', \'a\', \'y\', \'\'])'

Length of output: 336


Script:

#!/bin/bash
# Description: Verify the new expectations in measureTextWithWrap.

# Test: Search for the measureTextWithWrap usage. Expect: Only occurrences of the new expectations.
rg --type typescript -A 5 $'expect(result.lines).to.be.deep.equal([\'\', \'\', \'\', \'\', \'\', \'th\', \'e \', \'w\', \'e\', \'at\', \'h\', \'er\', \'is \', \'gr\', \'e\', \'at\', \'to\', \'d\', \'a\', \'y\', \'\'])'

Length of output: 344


Script:

#!/bin/bash
# Description: Verify the new expectations in measureTextWithWrap.

# Test: Search for the measureTextWithWrap usage. Expect: Only occurrences of the new expectations.
rg --type ts -A 5 $'expect(result.lines).to.be.deep.equal([\'\', \'\', \'\', \'\', \'\', \'th\', \'e \', \'w\', \'e\', \'at\', \'h\', \'er\', \'is \', \'gr\', \'e\', \'at\', \'to\', \'d\', \'a\', \'y\', \'\'])'

Length of output: 301


Script:

#!/bin/bash
# Description: Verify the new expectations in measureTextWithWrap.

# Test: Search for the measureTextWithWrap function in the TypeScript test file.
rg 'measureTextWithWrap' -A 10 --type ts

Length of output: 9972


267-270: Ensure the new expectations are correct.

The changes adjust the expected results of text measurements. Verify that the new expectations accurately reflect the expected measurements for the given text.

Verification successful

The new expectations in measureTextWithoutWrap are correct.

The test cases in tests/src/core/2d/text/TextUtils.test.ts confirm that the expected results for text measurements are accurately specified.

  • expect(result.lines).to.be.deep.equal(["The weather is great today."])
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the new expectations in measureTextWithoutWrap.

# Test: Search for the measureTextWithoutWrap usage. Expect: Only occurances of the new expectations.
rg --type python -A 5 $'expect(result.lines).to.be.deep.equal([\'The weather is great today.\'])'

Length of output: 133


Script:

#!/bin/bash
# Description: Verify the new expectations in measureTextWithoutWrap.

# Test: Search for the measureTextWithoutWrap usage. Expect: Only occurrences of the new expectations.
rg --type typescript -A 5 $'expect(result.lines).to.be.deep.equal(["The weather is great today."])'

Length of output: 135


Script:

#!/bin/bash
# Description: Verify the new expectations in measureTextWithoutWrap.

# Test: Search for the measureTextWithoutWrap usage. Expect: Only occurrences of the new expectations.
rg -A 5 $'expect(result.lines).to.be.deep.equal(["The weather is great today."])'

Length of output: 82


Script:

#!/bin/bash
# Description: Verify the new expectations in measureTextWithoutWrap.

# Test: Search for the measureTextWithoutWrap usage. Expect: Only occurrences of the new expectations.
rg -A 10 $'expect(result.lines).to.be.deep.equal'

Length of output: 50


Script:

#!/bin/bash
# Description: Verify the new expectations in measureTextWithoutWrap.

# Search for the measureTextWithoutWrap function definition.
rg 'function measureTextWithoutWrap' -A 10

# Search for the usage of measureTextWithoutWrap in the test files.
rg 'measureTextWithoutWrap' -A 10

Length of output: 10265


208-211: Ensure the new expectations are correct.

The changes adjust the expected results of text measurements. Verify that the new expectations accurately reflect the expected measurements for the given text.

Verification successful

The new expectations for the measureTextWithoutWrap function are correctly implemented.

The test cases in tests/src/core/2d/text/TextUtils.test.ts have been updated to include the new expectations for text measurements. The assertions cover different scenarios and ensure the accuracy of the results.

  • tests/src/core/2d/text/TextUtils.test.ts: Lines 208-211
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the new expectations in measureTextWithoutWrap.

# Test: Search for the measureTextWithoutWrap usage. Expect: Only occurances of the new expectations.
rg --type python -A 5 $'expect(result.lines).to.be.deep.equal([\'趚今天天气很好,阳光明媚。我 在公园里 漫步。\'])'

Length of output: 129


Script:

#!/bin/bash
# Description: Verify the new expectations in measureTextWithoutWrap.

# Test: Search for the measureTextWithoutWrap usage in TypeScript files. Expect: Only occurrences of the new expectations.
rg --type ts -A 5 $'expect(result.lines).to.be.deep.equal(["趚今天天气很好,阳光明媚。我 在公园里 漫步。"])'

Length of output: 88


Script:

#!/bin/bash
# Description: Locate the measureTextWithoutWrap function usage in TypeScript test files.

# Test: Search for the measureTextWithoutWrap function in TypeScript files.
rg --type ts 'measureTextWithoutWrap'

Length of output: 1556


Script:

#!/bin/bash
# Description: Extract relevant test cases for measureTextWithoutWrap from the test file.

# Extract lines containing measureTextWithoutWrap and their surrounding context.
rg 'measureTextWithoutWrap' -A 10 tests/src/core/2d/text/TextUtils.test.ts

Length of output: 4528


222-225: Ensure the new expectations are correct.

The changes adjust the expected results of text measurements. Verify that the new expectations accurately reflect the expected measurements for the given text.

Verification successful

The new expectations are correct.

The test cases for measureTextWithoutWrap in tests/src/core/2d/text/TextUtils.test.ts comprehensively cover various scenarios, and the specific expectations for the text "阳光明媚,the weather is great today。" are consistent with the function's behavior.

  • Verified expectations:
    • Width: 418
    • Height: 100
    • Lines: ["阳光明媚,the weather is great today。"]
    • LineWidths: [418]
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the new expectations in measureTextWithoutWrap.

# Test: Search for the measureTextWithoutWrap usage. Expect: Only occurances of the new expectations.
rg --type python -A 5 $'expect(result.lines).to.be.deep.equal([\'阳光明媚,the weather is great today。\'])'

Length of output: 138


Script:

#!/bin/bash
# Description: Verify the new expectations in measureTextWithoutWrap.

# Test: Search for the measureTextWithoutWrap usage. Expect: Only occurrences of the new expectations.
rg --type typescript -A 5 $'expect(result.lines).to.be.deep.equal([\'阳光明媚,the weather is great today。\'])'

Length of output: 146


Script:

#!/bin/bash
# Description: Verify the new expectations in measureTextWithoutWrap.

# Test: Search for the measureTextWithoutWrap usage. Expect: Only occurrences of the new expectations.
rg --type ts -A 5 $'expect(result.lines).to.be.deep.equal([\'阳光明媚,the weather is great today。\'])'

Length of output: 103


Script:

#!/bin/bash
# Description: Verify the new expectations in measureTextWithoutWrap.

# Search for the measureTextWithoutWrap function definition and its usage in the codebase.
rg 'measureTextWithoutWrap'

Length of output: 1546


Script:

#!/bin/bash
# Description: Extract relevant test cases for measureTextWithoutWrap.

# Extract lines around the usage of measureTextWithoutWrap in the test file.
rg 'measureTextWithoutWrap' -A 10 tests/src/core/2d/text/TextUtils.test.ts

Length of output: 4528


281-284: Ensure the new expectations are correct.

The changes adjust the expected results of text measurements. Verify that the new expectations accurately reflect the expected measurements for the given text.

Verification successful

The new expectations in the test file are correctly applied.

  • The expectations for measureTextWithoutWrap with the text " " and " World" are consistent and present in the test file tests/src/core/2d/text/TextUtils.test.ts.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the new expectations in measureTextWithoutWrap.

# Test: Search for the measureTextWithoutWrap usage. Expect: Only occurances of the new expectations.
rg --type python -A 5 $'expect(result.lines).to.be.deep.equal([\'         \', \'       World\'])'

Length of output: 137


Script:

#!/bin/bash
# Description: Verify the new expectations in measureTextWithoutWrap.

# Test: Search for the measureTextWithoutWrap usage. Expect: Only occurrences of the new expectations.
rg --type typescript -A 5 $'expect(result.lines).to.be.deep.equal(["         ", "       World"])'

Length of output: 133


Script:

#!/bin/bash
# Description: Verify the new expectations in measureTextWithoutWrap.

# Test: Search for the measureTextWithoutWrap usage. Expect: Only occurrences of the new expectations.
rg -A 5 $'expect(result.lines).to.be.deep.equal(["         ", "       World"])' tests/src/core/2d/text/TextUtils.test.ts

Length of output: 121


Script:

#!/bin/bash
# Description: Verify the new expectations in measureTextWithoutWrap.

# Test: Search for all instances of measureTextWithoutWrap and inspect the associated expectations.
rg 'measureTextWithoutWrap' -A 10 tests/src/core/2d/text/TextUtils.test.ts

Length of output: 4528


274-277: Ensure the new expectations are correct.

The changes adjust the expected results of text measurements. Verify that the new expectations accurately reflect the expected measurements for the given text.

Verification successful

The new expectations for measureTextWithoutWrap are correct.

The test cases comprehensively validate the function's behavior with various text inputs, ensuring that the expected results accurately reflect the text measurements.

  • tests/src/core/2d/text/TextUtils.test.ts
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the new expectations in measureTextWithoutWrap.

# Test: Search for the measureTextWithoutWrap usage. Expect: Only occurances of the new expectations.
rg --type python -A 5 $'expect(result.lines).to.be.deep.equal([\'阳光明媚,the weather is great today。\'])'

Length of output: 138


Script:

#!/bin/bash
# Description: Verify the new expectations in measureTextWithoutWrap.

# Test: Search for the measureTextWithoutWrap usage. Expect: Only occurrences of the new expectations.
rg --type typescript -A 5 $'expect(result.lines).to.be.deep.equal([\'阳光明媚,the weather is great today。\'])'

Length of output: 146


Script:

#!/bin/bash
# Description: Verify the new expectations in measureTextWithoutWrap.

# Test: Search for the measureTextWithoutWrap usage. Expect: Only occurrences of the new expectations.
rg -t ts -A 5 $'expect(result.lines).to.be.deep.equal([\'阳光明媚,the weather is great today。\'])'

Length of output: 99


Script:

#!/bin/bash
# Description: Search for the measureTextWithoutWrap function definition and its usage in the test files.

# Search for the measureTextWithoutWrap function definition.
rg 'function measureTextWithoutWrap'

# Search for the measureTextWithoutWrap usage in test files.
rg 'measureTextWithoutWrap' -g '*.test.ts'

Length of output: 1400


Script:

#!/bin/bash
# Description: Search for the surrounding lines of the test cases in tests/src/core/2d/text/TextUtils.test.ts to understand the context and verify the accuracy of the expectations.

# Search for the measureTextWithoutWrap usage and include surrounding lines for context.
rg 'measureTextWithoutWrap' -A 10 -B 10 tests/src/core/2d/text/TextUtils.test.ts

Length of output: 4966


229-232: Ensure the new expectations are correct.

The changes adjust the expected results of text measurements. Verify that the new expectations accurately reflect the expected measurements for the given text.

Verification successful

The new expectations for measureTextWithoutWrap are correctly set.

The test cases for measureTextWithoutWrap in tests/src/core/2d/text/TextUtils.test.ts consistently use the new expectations for the variable text4:

  • expect(result.lines).to.be.deep.equal([" ", " World"]);
  • expect(result.lineWidths).to.be.deep.equal([63, 111]);

These expectations accurately reflect the expected measurements for the given text.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the new expectations in measureTextWithoutWrap.

# Test: Search for the measureTextWithoutWrap usage. Expect: Only occurances of the new expectations.
rg --type python -A 5 $'expect(result.lines).to.be.deep.equal([\'         \', \'       World\'])'

Length of output: 137


Script:

#!/bin/bash
# Description: Verify the new expectations in measureTextWithoutWrap.

# Test: Search for the measureTextWithoutWrap usage. Expect: Only occurrences of the new expectations.
rg --type typescript -A 5 $'expect(result.lines).to.be.deep.equal([\'         \', \'       World\'])'

Length of output: 145


Script:

#!/bin/bash
# Description: Verify the new expectations in measureTextWithoutWrap.

# Test: Search for the measureTextWithoutWrap usage. Expect: Only occurrences of the new expectations.
rg --glob '*.ts' -A 5 $'expect(result.lines).to.be.deep.equal([\'         \', \'       World\'])'

Length of output: 106


Script:

#!/bin/bash
# Description: Search for the measureTextWithoutWrap function definition and its usages in the codebase.

# Search for the measureTextWithoutWrap function definition.
rg 'function measureTextWithoutWrap' --glob '*.ts'

# Search for measureTextWithoutWrap usages.
rg 'measureTextWithoutWrap' --glob '*.ts'

Length of output: 1613


Script:

#!/bin/bash
# Description: Extract relevant test cases from TextUtils.test.ts to verify the new expectations.

# Extract lines around the measureTextWithoutWrap usages in the test file.
rg 'measureTextWithoutWrap' -A 10 -B 10 tests/src/core/2d/text/TextUtils.test.ts

Length of output: 4966

@GuoLei1990 GuoLei1990 added the bug Something isn't working label Aug 8, 2024
@GuoLei1990 GuoLei1990 added the text 2D text system label Aug 8, 2024
@GuoLei1990 GuoLei1990 merged commit 192f5a8 into galacean:main Aug 8, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working text 2D text system
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The text BoundingBox calculate is wrong of character 'j'
3 participants