Skip to content

Commit

Permalink
Fix Arc.transform
Browse files Browse the repository at this point in the history
  • Loading branch information
baku89 committed Feb 26, 2024
1 parent 7449258 commit f1df6e9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
21 changes: 21 additions & 0 deletions src/Arc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {mat2d, vec2} from 'linearly'
import {describe, expect, it, test} from 'vitest'

import {Arc} from './Arc'
import {SegmentA} from './Segment'

describe('toCenterParameterization', () => {
it('should work in right angle case', () => {
Expand Down Expand Up @@ -300,3 +301,23 @@ describe('ellipticArcLength', () => {
expect(ret).toEqual(1.01218)
})
})

describe('transform', () => {
const arc: SegmentA = {
command: 'A',
start: [50, 0],
point: [0, 25],
args: [[50, 25], 0, false, true],
}

it('should rotate 90°', () => {
const ret = Arc.transform(arc, mat2d.rotation(90))

expect(ret).toEqual({
command: 'A',
start: [0, 50],
point: [-25, 0],
args: [[50, 25], 90, false, true],
})
})
})
6 changes: 3 additions & 3 deletions src/Arc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ export namespace Arc {

A2 = 0.5 * (A + C + K * ac)
C2 = 0.5 * (A + C - K * ac)
offsetRot = 0.5 * scalar.atan(B, ac)
offsetRot = scalar.deg(0.5 * Math.atan2(B, ac))
}
}

Expand All @@ -286,8 +286,8 @@ export namespace Arc {

// now A2 and C2 are half-axis:
if (ac <= 0) {
rv = C2
rh = A2
rv = A2
rh = C2
} else {
rv = C2
rh = A2
Expand Down

0 comments on commit f1df6e9

Please sign in to comment.