diff --git a/lib/attributes.ts b/lib/attributes.ts index 88c5b584c6e..ba9ba0c49c5 100644 --- a/lib/attributes.ts +++ b/lib/attributes.ts @@ -1,18 +1,28 @@ export class Attributes { - list: {name: string, value: string}[] = []; + list: any = {}; /** Adds an attribute */ add(name: string, value: string): Attributes { - this.list.push({name, value}); + if(typeof this.list[name] === 'undefined') { + this.list[name] = []; + } + + this.list[name].push(value); return this; } + /** Retrieves an attribute */ + get(name: string): string { + return this.list[name].join(' '); + } + /** Returns SVG code for attributes */ render(): string { let svg = ''; - for (let a of this.list) { - svg += ` ${a.name}="${a.value}"`; + for (let key in this.list) { + let attrs = this.list + svg += ` ${key}="${this.list[key].join(' ')}"`; } return svg; diff --git a/tests/point.test.js b/tests/point.test.js index 5bddf92e850..2a145cb277b 100644 --- a/tests/point.test.js +++ b/tests/point.test.js @@ -148,4 +148,21 @@ it('should shift a point beyond another', () => { expect(ss.shiftOutwards(se, 200).y).to.equal(-141.42); }); - +it('should rotate a point around another', () => { + let sun = new Point(0,0); + let moon = new Point(10,0); + let a = moon.rotate(90, sun); + expect(a.x).to.equal(0); + expect(a.y).to.equal(-10); + let b = moon.rotate(-90, sun); + expect(b.x).to.equal(0); + expect(b.y).to.equal(10); + let c = moon.rotate(180, sun); + expect(c.x).to.equal(-10); + expect(c.y).to.equal(0); + let sun2 = new Point(222,44); + let moon2 = new Point(212,41); + let d = moon2.rotate(90, sun2); + expect(d.x).to.equal(219); + expect(d.y).to.equal(54); +}); diff --git a/tests/utils.test.js b/tests/utils.test.js index 75a98c59020..3ade5b4efa5 100644 --- a/tests/utils.test.js +++ b/tests/utils.test.js @@ -56,7 +56,5 @@ it('should return a line segment intersection', () => { let g = new Point(0,49); let h = new Point(-20,40); let i = new Point(20,40); - console.log(utils.beamsCross(g,f,h,i)); - });