1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
|
//// [tests/cases/conformance/jsdoc/declarations/jsDeclarationsFunctionLikeClasses2.ts] ////
//// [source.js]
/**
* @param {number} len
*/
export function Vec(len) {
/**
* @type {number[]}
*/
this.storage = new Array(len);
}
Vec.prototype = {
/**
* @param {Vec} other
*/
dot(other) {
if (other.storage.length !== this.storage.length) {
throw new Error(`Dot product only applicable for vectors of equal length`);
}
let sum = 0;
for (let i = 0; i < this.storage.length; i++) {
sum += (this.storage[i] * other.storage[i]);
}
return sum;
},
magnitude() {
let sum = 0;
for (let i = 0; i < this.storage.length; i++) {
sum += (this.storage[i] ** 2);
}
return Math.sqrt(sum);
}
}
/**
* @param {number} x
* @param {number} y
*/
export function Point2D(x, y) {
if (!(this instanceof Point2D)) {
return new Point2D(x, y);
}
Vec.call(this, 2);
this.x = x;
this.y = y;
}
Point2D.prototype = {
__proto__: Vec,
get x() {
return this.storage[0];
},
/**
* @param {number} x
*/
set x(x) {
this.storage[0] = x;
},
get y() {
return this.storage[1];
},
/**
* @param {number} y
*/
set y(y) {
this.storage[1] = y;
}
};
//// [referencer.js]
import {Point2D} from "./source";
export const origin = new Point2D(0, 0);
// export const res = Point2D(2, 3).dot(origin); // TODO: when __proto__ works, validate this
//// [source.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Point2D = exports.Vec = void 0;
/**
* @param {number} len
*/
function Vec(len) {
/**
* @type {number[]}
*/
this.storage = new Array(len);
}
exports.Vec = Vec;
Vec.prototype = {
/**
* @param {Vec} other
*/
dot: function (other) {
if (other.storage.length !== this.storage.length) {
throw new Error("Dot product only applicable for vectors of equal length");
}
var sum = 0;
for (var i = 0; i < this.storage.length; i++) {
sum += (this.storage[i] * other.storage[i]);
}
return sum;
},
magnitude: function () {
var sum = 0;
for (var i = 0; i < this.storage.length; i++) {
sum += (Math.pow(this.storage[i], 2));
}
return Math.sqrt(sum);
}
};
/**
* @param {number} x
* @param {number} y
*/
function Point2D(x, y) {
if (!(this instanceof Point2D)) {
return new Point2D(x, y);
}
Vec.call(this, 2);
this.x = x;
this.y = y;
}
exports.Point2D = Point2D;
Point2D.prototype = {
__proto__: Vec,
get x() {
return this.storage[0];
},
/**
* @param {number} x
*/
set x(x) {
this.storage[0] = x;
},
get y() {
return this.storage[1];
},
/**
* @param {number} y
*/
set y(y) {
this.storage[1] = y;
}
};
//// [referencer.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.origin = void 0;
var source_1 = require("./source");
exports.origin = new source_1.Point2D(0, 0);
// export const res = Point2D(2, 3).dot(origin); // TODO: when __proto__ works, validate this
//// [source.d.ts]
/**
* @param {number} len
*/
export function Vec(len: number): void;
export class Vec {
/**
* @param {number} len
*/
constructor(len: number);
/**
* @type {number[]}
*/
storage: number[];
/**
* @param {Vec} other
*/
dot(other: Vec): number;
magnitude(): number;
}
/**
* @param {number} x
* @param {number} y
*/
export function Point2D(x: number, y: number): Point2D;
export class Point2D {
/**
* @param {number} x
* @param {number} y
*/
constructor(x: number, y: number);
/**
* @param {number} x
*/
set x(arg: number);
get x(): number;
/**
* @param {number} y
*/
set y(arg: number);
get y(): number;
__proto__: typeof Vec;
}
//// [referencer.d.ts]
export const origin: Point2D;
import { Point2D } from "./source";
|