Skip to content

Commit

Permalink
関数の戻り値を明記した
Browse files Browse the repository at this point in the history
  • Loading branch information
CaseyNelson314 committed Feb 1, 2024
1 parent cb352c3 commit fb19e16
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 70 deletions.
13 changes: 0 additions & 13 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,12 @@
<img class="control_img" src="./static/point_charge.png" alt="">
</button>
</div>
<!-- <div class="control_button">
<p class="title">有限線</p>
<button type="button" id="add_finite_line_charge_button">
<img class="control_img" src="./static/finite_line_charge.png" alt="有限線">
</button>
</div> -->
<div class="control_button">
<p class="title">無限線</p>
<button type="button" id="add_infinity_line_charge_button">
<img class="control_img" src="./static/infinity_line_charge.png" alt="無限線">
</button>
</div>
<!-- <div class="control_button">
<p class="title">有限面</p>
<button type="button" id="add_finite_surface_charge_button">
<img class="control_img" src="./static/finite_surface_charge.png" alt="有限面">
</button>
</div> -->

<div class="control_button">
<p class="title">無限柱表面</p>
<button type="button" id="add_infinity_cylinder_surface_charge_button">
Expand Down
16 changes: 8 additions & 8 deletions app/script/infinityCylinderSurfaceCharge.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as THREE from 'three';
import { Charge, ChargeToChargeType } from './charge';
import { Charge, ChargeType, ChargeToChargeType } from './charge';
import { permittivity } from './constants';
import { Editor, PositionEditor, NumberEditor, RotationEditor } from './editor';
import { Store } from './store';
Expand Down Expand Up @@ -39,7 +39,7 @@ export class InfinityCylinderSurfaceCharge extends Charge {
* 電荷の正負を取得する
* @returns 電荷の正負
*/
override getChargeType = () => {
override getChargeType = (): ChargeType => {

return ChargeToChargeType(this.surfaceDensity);

Expand All @@ -51,7 +51,7 @@ export class InfinityCylinderSurfaceCharge extends Charge {
* @param position 任意の座標
* @returns 電荷との距離ベクトル
*/
private distanceFrom = (position: THREE.Vector3) => {
private distanceFrom = (position: THREE.Vector3): THREE.Vector3 => {

// 計算を行いやすいよう、線電荷がx=z=0に位置するように観測点の座標を変換する
const positionTransformed = position.clone().sub(this.position); // 線電荷の中心を原点に移動
Expand All @@ -69,7 +69,7 @@ export class InfinityCylinderSurfaceCharge extends Charge {
* @param threshold 閾値
* @returns 接触しているかどうか
*/
override isContact = (position: THREE.Vector3, threshold: number) => {
override isContact = (position: THREE.Vector3, threshold: number): boolean => {

const lengthSq = this.distanceFrom(position).lengthSq();

Expand All @@ -90,7 +90,7 @@ export class InfinityCylinderSurfaceCharge extends Charge {
* @param position 任意の座標
* @returns 電界ベクトル
*/
override electricFieldVector = (position: THREE.Vector3) => {
override electricFieldVector = (position: THREE.Vector3): THREE.Vector3 => {

const distance = this.distanceFrom(position);

Expand All @@ -116,7 +116,7 @@ export class InfinityCylinderSurfaceCharge extends Charge {
* 電気力線の始点、方向ベクトルの配列を返す
* @returns 電気力線の始点、方向ベクトルの配列
*/
override electricForceLinesDirection = () => {
override electricForceLinesDirection = (): { begin: THREE.Vector3, direction: THREE.Vector3 }[] => {

const heightCount = 6;
const thetaCount = 10;
Expand Down Expand Up @@ -162,7 +162,7 @@ export class InfinityCylinderSurfaceCharge extends Charge {
/**
* JSONから電荷を生成する
*/
static override fromJSON = (json: any) => {
static override fromJSON = (json: any): Charge => {

return new InfinityCylinderSurfaceCharge(
new THREE.Vector3(json.position.x, json.position.y, json.position.z),
Expand Down Expand Up @@ -200,7 +200,7 @@ export class InfinityCylinderSurfaceCharge extends Charge {
/**
* パラメーター設定用エディタを生成する
*/
override createEditor = () => {
override createEditor = (): Editor => {

const positionEditor = new PositionEditor({
position: this.position,
Expand Down
16 changes: 8 additions & 8 deletions app/script/infinityCylinderVolumeCharge.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as THREE from 'three';
import { Charge, ChargeToChargeType } from './charge';
import { Charge, ChargeType, ChargeToChargeType } from './charge';
import { permittivity } from './constants';
import { Editor, PositionEditor, NumberEditor, RotationEditor } from './editor';
import { Store } from './store';
Expand Down Expand Up @@ -40,7 +40,7 @@ export class InfinityCylinderVolumeCharge extends Charge {
* 電荷の正負を取得する
* @returns 電荷の正負
*/
override getChargeType = () => {
override getChargeType = (): ChargeType => {

return ChargeToChargeType(this.volumeDensity);

Expand All @@ -52,7 +52,7 @@ export class InfinityCylinderVolumeCharge extends Charge {
* @param position 任意の座標
* @returns 電荷との距離ベクトル
*/
private distanceFrom = (position: THREE.Vector3) => {
private distanceFrom = (position: THREE.Vector3): THREE.Vector3 => {

// 計算を行いやすいよう、線電荷がx=z=0に位置するように観測点の座標を変換する
const positionTransformed = position.clone().sub(this.position); // 線電荷の中心を原点に移動
Expand All @@ -70,7 +70,7 @@ export class InfinityCylinderVolumeCharge extends Charge {
* @param threshold 閾値
* @returns 接触しているかどうか
*/
override isContact = (position: THREE.Vector3, threshold: number) => {
override isContact = (position: THREE.Vector3, threshold: number): boolean => {

return this.distanceFrom(position).lengthSq() < threshold ** 2;

Expand All @@ -82,7 +82,7 @@ export class InfinityCylinderVolumeCharge extends Charge {
* @param position 任意の座標
* @returns 電界ベクトル
*/
override electricFieldVector = (position: THREE.Vector3) => {
override electricFieldVector = (position: THREE.Vector3): THREE.Vector3 => {

const distance = this.distanceFrom(position);

Expand All @@ -108,7 +108,7 @@ export class InfinityCylinderVolumeCharge extends Charge {
* 電気力線の始点、方向ベクトルの配列を返す
* @returns 電気力線の始点、方向ベクトルの配列
*/
override electricForceLinesDirection = () => {
override electricForceLinesDirection = (): { begin: THREE.Vector3, direction: THREE.Vector3 }[] => {

const heightCount = 6;
const thetaCount = 10;
Expand Down Expand Up @@ -154,7 +154,7 @@ export class InfinityCylinderVolumeCharge extends Charge {
/**
* JSONから電荷を生成する
*/
static override fromJSON = (json: any) => {
static override fromJSON = (json: any): Charge => {

return new InfinityCylinderVolumeCharge(
new THREE.Vector3(json.position.x, json.position.y, json.position.z),
Expand Down Expand Up @@ -191,7 +191,7 @@ export class InfinityCylinderVolumeCharge extends Charge {
/**
* パラメーター設定用エディタを生成する
*/
override createEditor = () => {
override createEditor = (): Editor => {

const positionEditor = new PositionEditor({
position: this.position,
Expand Down
16 changes: 8 additions & 8 deletions app/script/infinityLineCharge.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as THREE from 'three';
import { Charge, ChargeToChargeType } from './charge';
import { Charge, ChargeType, ChargeToChargeType } from './charge';
import { permittivity } from './constants';
import { Editor, PositionEditor, NumberEditor, RotationEditor } from './editor';
import { Store } from './store';
Expand Down Expand Up @@ -38,7 +38,7 @@ export class InfinityLineCharge extends Charge {
* 電荷の正負を取得する
* @returns 電荷の正負
*/
override getChargeType = () => {
override getChargeType = (): ChargeType => {

return ChargeToChargeType(this.lineDensity);

Expand All @@ -50,7 +50,7 @@ export class InfinityLineCharge extends Charge {
* @param position 任意の座標
* @returns 電荷との距離ベクトル
*/
private distanceFrom = (position: THREE.Vector3) => {
private distanceFrom = (position: THREE.Vector3): THREE.Vector3 => {

// 計算を行いやすいよう、線電荷がx=z=0に位置するように観測点の座標を変換する
const positionTransformed = position.clone().sub(this.position); // 線電荷の中心を原点に移動
Expand All @@ -68,7 +68,7 @@ export class InfinityLineCharge extends Charge {
* @param threshold 閾値
* @returns 接触しているかどうか
*/
override isContact = (position: THREE.Vector3, threshold: number) => {
override isContact = (position: THREE.Vector3, threshold: number): boolean => {

return this.distanceFrom(position).lengthSq() < threshold ** 2;

Expand All @@ -80,7 +80,7 @@ export class InfinityLineCharge extends Charge {
* @param position 任意の座標
* @returns 電界ベクトル
*/
override electricFieldVector = (position: THREE.Vector3) => {
override electricFieldVector = (position: THREE.Vector3): THREE.Vector3 => {

const distance = this.distanceFrom(position);

Expand All @@ -97,7 +97,7 @@ export class InfinityLineCharge extends Charge {
* 電気力線の始点、方向ベクトルの配列を返す
* @returns 電気力線の始点、方向ベクトルの配列
*/
override electricForceLinesDirection = () => {
override electricForceLinesDirection = (): { begin: THREE.Vector3, direction: THREE.Vector3 }[] => {

const heightCount = 6;
const thetaCount = 10;
Expand Down Expand Up @@ -142,7 +142,7 @@ export class InfinityLineCharge extends Charge {
/**
* JSONから電荷を生成する
*/
static override fromJSON = (json: any) => {
static override fromJSON = (json: any): Charge => {

return new InfinityLineCharge(
new THREE.Vector3(json.position.x, json.position.y, json.position.z),
Expand Down Expand Up @@ -178,7 +178,7 @@ export class InfinityLineCharge extends Charge {
/**
* パラメーター設定用エディタを生成する
*/
override createEditor = () => {
override createEditor = (): Editor => {

const positionEditor = new PositionEditor({
position: this.position,
Expand Down
16 changes: 8 additions & 8 deletions app/script/infinitySurfaceCharge.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as THREE from 'three';
import { Charge, ChargeToChargeType } from './charge';
import { Charge, ChargeType, ChargeToChargeType } from './charge';
import { permittivity } from './constants';
import { Editor, PositionEditor, NumberEditor, RotationEditor } from './editor';
import { Store } from './store';
Expand Down Expand Up @@ -38,7 +38,7 @@ export class InfinitySurfaceCharge extends Charge {
* 電荷の正負を取得する
* @returns 電荷の正負
*/
override getChargeType = () => {
override getChargeType = (): ChargeType => {

return ChargeToChargeType(this.surfaceDensity);

Expand All @@ -50,7 +50,7 @@ export class InfinitySurfaceCharge extends Charge {
* @param position 任意の座標
* @returns 電荷との距離ベクトル
*/
private distanceFrom = (position: THREE.Vector3) => {
private distanceFrom = (position: THREE.Vector3): THREE.Vector3 => {

// 計算を行いやすいよう、面電荷がz=0に位置するように観測点の座標を変換する
const positionTransformed = position.clone().sub(this.position); // 面電荷の中心を原点に移動
Expand All @@ -69,7 +69,7 @@ export class InfinitySurfaceCharge extends Charge {
* @param threshold 閾値
* @returns 接触しているかどうか
*/
override isContact = (position: THREE.Vector3, threshold: number) => {
override isContact = (position: THREE.Vector3, threshold: number): boolean => {

return this.distanceFrom(position).lengthSq() < threshold ** 2;

Expand All @@ -81,7 +81,7 @@ export class InfinitySurfaceCharge extends Charge {
* @param position 任意の座標
* @returns 電界ベクトル
*/
override electricFieldVector = (position: THREE.Vector3) => {
override electricFieldVector = (position: THREE.Vector3): THREE.Vector3 => {

const distance = this.distanceFrom(position);

Expand All @@ -98,7 +98,7 @@ export class InfinitySurfaceCharge extends Charge {
* 電気力線の始点、方向ベクトルの配列を返す
* @returns 電気力線の始点、方向ベクトルの配列
*/
override electricForceLinesDirection = () => {
override electricForceLinesDirection = (): { begin: THREE.Vector3, direction: THREE.Vector3 }[] => {

const widthCount = 6;
const heightCount = 6;
Expand Down Expand Up @@ -143,7 +143,7 @@ export class InfinitySurfaceCharge extends Charge {
/**
* JSONから電荷を生成する
*/
static override fromJSON = (json: any) => {
static override fromJSON = (json: any): Charge => {

return new InfinitySurfaceCharge(
new THREE.Vector3(json.position.x, json.position.y, json.position.z),
Expand Down Expand Up @@ -179,7 +179,7 @@ export class InfinitySurfaceCharge extends Charge {
/**
* パラメーター設定用エディタを生成する
*/
override createEditor = () => {
override createEditor = (): Editor => {

const positionEditor = new PositionEditor({
position: this.position,
Expand Down
18 changes: 9 additions & 9 deletions app/script/pointCharge.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as THREE from 'three';
import { Charge, ChargeToChargeType } from './charge';
import { Charge, ChargeType, ChargeToChargeType } from './charge';
import { kCoulomb } from './constants';
import { GSS } from './gss';
import { Editor, PositionEditor, NumberEditor } from './editor';
Expand Down Expand Up @@ -38,7 +38,7 @@ export class PointCharge extends Charge {
* 電荷の正負を取得する
* @returns 電荷の正負
*/
override getChargeType = () => {
override getChargeType = (): ChargeType => {

return ChargeToChargeType(this.charge);

Expand All @@ -50,7 +50,7 @@ export class PointCharge extends Charge {
* @param position 任意の座標
* @returns 電荷との距離ベクトル
*/
private distanceFrom = (position: THREE.Vector3) => {
private distanceFrom = (position: THREE.Vector3): THREE.Vector3 => {

return position.clone().sub(this.position);

Expand All @@ -63,7 +63,7 @@ export class PointCharge extends Charge {
* @param threshold 閾値
* @returns 接触しているかどうか
*/
override isContact = (position: THREE.Vector3, threshold: number) => {
override isContact = (position: THREE.Vector3, threshold: number): boolean => {

return this.position.distanceToSquared(position) < threshold ** 2;

Expand All @@ -75,7 +75,7 @@ export class PointCharge extends Charge {
* @param position 任意の座標
* @returns 電界ベクトル
*/
override electricFieldVector = (position: THREE.Vector3) => {
override electricFieldVector = (position: THREE.Vector3): THREE.Vector3 => {

const diffVector = this.distanceFrom(position);

Expand All @@ -93,7 +93,7 @@ export class PointCharge extends Charge {
* 電気力線の始点、方向ベクトルの配列を返す
* @returns 電気力線の始点、方向ベクトルの配列
*/
override electricForceLinesDirection = () => {
override electricForceLinesDirection = (): { begin: THREE.Vector3, direction: THREE.Vector3 }[] => {

return GSS(25).map((vector) => { return { begin: this.position, direction: vector } });

Expand All @@ -119,7 +119,7 @@ export class PointCharge extends Charge {
/**
* JSONから電荷を生成する
*/
static override fromJSON = (json: any) => {
static override fromJSON = (json: any): Charge => {

return new PointCharge(
new THREE.Vector3(json.position.x, json.position.y, json.position.z),
Expand All @@ -132,7 +132,7 @@ export class PointCharge extends Charge {
/**
* 電荷をJSONに変換する
*/
override toJSON = () => {
override toJSON = (): any => {

return {
position: {
Expand All @@ -149,7 +149,7 @@ export class PointCharge extends Charge {
/**
* パラメーター設定用エディタを生成する
*/
override createEditor = () => {
override createEditor = (): Editor => {

const positionEditor = new PositionEditor({
position: this.position,
Expand Down
Loading

0 comments on commit fb19e16

Please sign in to comment.