Skip to content

Implement acute angle detection for orthogonal link labels with AutoRight/AutoLeft#271

Merged
ugwis merged 12 commits intoawslabs:mainfrom
ugwis:fix-link-lr-acute
Jan 14, 2026
Merged

Implement acute angle detection for orthogonal link labels with AutoRight/AutoLeft#271
ugwis merged 12 commits intoawslabs:mainfrom
ugwis:fix-link-lr-acute

Conversation

@ugwis
Copy link
Member

@ugwis ugwis commented Jan 13, 2026

Summary

This PR implements acute angle detection for orthogonal link labels to improve visual clarity by positioning labels on the acute angle side of the longest horizontal segment.

Changes

Core Implementation

  • Vector.Cross(): Add 2D cross product calculation method for angle detection
  • findPerpendicularSegments(): Detect 90-degree angles using normalized cross product
  • getAcuteAngleSide(): Independent Left/Right acute angle detection for each label

Label Positioning Logic

  • Acute angle detection: Use cross product sign to determine rotation direction
    • crossProduct > 0: Right side acute (90° counterclockwise)
    • crossProduct < 0: Left side acute (90° clockwise, 270° counterclockwise)
  • Parameter reversal: When acute angles detected, reverse all placement parameters:
    • source/target, autoPt1/autoPt2, Left/Right positioning, autoPos direction
    • Use (autoPos + 8) mod 16 for 180-degree autoPos rotation

New Label Types

  • AutoRight/AutoLeft: Replace Right/Left with more explicit auto-positioning labels
  • Backward compatibility: Maintains existing SourceRight/SourceLeft/TargetRight/TargetLeft

Testing

  • Comprehensive tests: Added tests for autoPos reversal and acute angle detection
  • Integration tests: YAML-based tests with various orthogonal link configurations
  • Fixed existing tests: Updated expectations for correct cross product calculations

Visual Impact

Labels are now positioned on the acute angle side of orthogonal links, providing:

  • Better visual clarity by avoiding overlap with link paths
  • Consistent label placement near acute angle control points
  • Improved readability for complex orthogonal diagrams

Example Usage

Diagram:

  Links:
    # Test case 1: Source to Target1 - should create L-shaped path
    - Source: SourceResource
      Target: TargetResource1
      Type: orthogonal
      Labels:
        AutoRight:
          Title: "R1"
        AutoLeft:
          Title: "L1"

    # Test case 2: Source to Target2 - should create different L-shaped path
    - Source: SourceResource
      Target: TargetResource2
      Type: orthogonal
      Labels:
        AutoRight:
          Title: "R2"
        AutoLeft:
          Title: "L2"
image

Labels will automatically position themselves on the appropriate side based on acute angle detection.

ugwis added 12 commits January 13, 2026 03:15
- Add Right/Left auto-positioning labels documentation
- Add explanation for longest horizontal segment detection in orthogonal links
- Update Link Labels section with complete label positioning options
- Add Cross product method to Vector for 2D cross product calculation
- Implement findPerpendicularSegments to detect 90-degree angles using cross product
- Add getAcuteAngleSide to determine Left/Right acute angle sides independently
- Update label placement logic to reverse parameters when acute angles detected:
  - Reverse source/target, autoPt1/autoPt2, Left/Right, and autoPos direction
  - Use (autoPos + 8) % 16 for 180-degree autoPos rotation
- Add comprehensive tests for autoPos reversal and acute angle detection
- Fix existing test expectations for correct cross product calculations

This improves label placement on orthogonal links by positioning labels
on the acute angle side of the longest horizontal segment for better
visual clarity.
- Update LinkLabels struct to use AutoRight/AutoLeft instead of Right/Left
- Modify label processing logic to use new field names
- Update YAML parsing and conversion to support AutoRight/AutoLeft
- Update test YAML file to use new label names

This change makes the auto-positioning nature of these labels more explicit
and distinguishes them from fixed-position labels.
- Run go fmt to fix code formatting
- Remove trailing whitespace and align comments properly
- Update TestAcuteAngleLabelPlacement to use AutoRight/AutoLeft instead of deprecated Right/Left fields
- This fixes the compilation error in CI tests
- Improve segment selection to check angles both before and after horizontal segments
- This allows detection of acute angles at the end of paths (before horizontal segment)
- Maintains preference for segments with detectable acute angles when lengths are equal
- Enables better label placement by considering all possible acute angle positions
…sition

- Remove label reversal logic (no more source/target/side swapping)
- Implement findBestSegmentForSideWithPosition() to detect acute angle position
- Select segment based on acute angle position:
  * before (n-1 to n acute): use segment n
  * after (n to n+1 acute): use segment n+1
- Support vertical segments for label placement
- Add autoPos calculation for vertical segments (North/South)
- AutoLeft and AutoRight independently select optimal segments
- Labels naturally avoid acute angles without reversal
- Add TestSegmentSelectionBasedOnAcutePosition test case
- Update auto-positioning label names in links.md
- Add description of acute angle avoidance behavior
@ugwis ugwis merged commit 9ab65ea into awslabs:main Jan 14, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant