🚧 Made attributes retrievable
This commit is contained in:
parent
ef84eb9468
commit
39f177dc26
3 changed files with 32 additions and 7 deletions
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
|
|
@ -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));
|
||||
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue