Skip to content

Commit

Permalink
Clean up comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ricktu288 committed Jan 2, 2024
1 parent c8e8ee2 commit 844e1e9
Show file tree
Hide file tree
Showing 34 changed files with 631 additions and 641 deletions.
144 changes: 72 additions & 72 deletions simulator/js/editor.js

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions simulator/js/graphs.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var graphs = {
/**
* 基本圖型 Basic geometric figures
* Basic geometric figures
**/
point: function(x, y) {return {type: 1, x: x, y: y, exist: true}},

Expand Down Expand Up @@ -43,7 +43,7 @@ var graphs = {
},

/**
* 求交點 Find intersection
* Find intersection
* @method intersection
* @param {graph} obj1
* @param {graph} obj2
Expand All @@ -65,7 +65,7 @@ var graphs = {
},

/**
* 兩直線交點 Intersection of two lines
* Intersection of two lines
* @method intersection_2line
* @param {graph.line} l1
* @param {graph.line} l2
Expand All @@ -82,7 +82,7 @@ var graphs = {
},

/**
* 直線與圓的交點 Intersection of a line and a circle
* Intersection of a line and a circle
* @method intersection_line_circle
* @param {graph.line} l1
* @param {graph.circle} c2
Expand Down Expand Up @@ -138,7 +138,7 @@ var graphs = {
},

/**
* 線段長度 Length of a segment
* Length of a segment
* @method length_segment
* @param {graph.segment} seg
* @return {Number}
Expand All @@ -148,7 +148,7 @@ var graphs = {
},

/**
* 線段長度平方 Square of the length of a segment
* Square of the length of a segment
* @method length_segment_squared
* @param {graph.segment} seg
* @return {Number}
Expand All @@ -158,7 +158,7 @@ var graphs = {
},

/**
* 兩點距離 Distance between two points
* Distance between two points
* @method length
* @param {graph.point} p1
* @param {graph.point} p2
Expand All @@ -169,7 +169,7 @@ var graphs = {
},

/**
* 兩點距離平方 Square of the distance between two points
* Square of the distance between two points
* @method length_squared
* @param {graph.point} p1
* @param {graph.point} p2
Expand All @@ -183,11 +183,11 @@ var graphs = {


/*
* 基本作圖函數 Basic geometric constructions
* Basic geometric constructions
*/

/**
* 線段中點 Midpoint of a line segment
* Midpoint of a line segment
* @method midpoint
* @param {graph.line} l1
* @return {graph.point}
Expand All @@ -212,7 +212,7 @@ var graphs = {
},

/**
* 線段中垂線 Perpendicular bisector of a line segment
* Perpendicular bisector of a line segment
* @method perpendicular_bisector
* @param {graph.segment} l1
* @return {graph.line}
Expand Down
20 changes: 10 additions & 10 deletions simulator/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ var ctx0;
var ctxLight;
var ctxGrid;
var dpr = 1;
var objs = []; //物件 The objects
var objCount = 0; //物件數量 Number of the objects
var objs = []; // The objects
var objCount = 0; // Number of the objects
var observer;
var xyBox_cancelContextMenu = false;
var scale = 1;
Expand Down Expand Up @@ -366,7 +366,7 @@ window.onload = function (e) {
document.getElementById('rayDensity_mobile').oninput = document.getElementById('rayDensity').oninput;

document.getElementById('rayDensity').onmouseup = function () {
setRayDensity(Math.exp(this.value)); //為了讓不支援oninput的瀏覽器可使用 For browsers not supporting oninput
setRayDensity(Math.exp(this.value)); // For browsers not supporting oninput
document.getElementById('rayDensity').value = this.value;
document.getElementById('rayDensity_more').value = this.value;
document.getElementById('rayDensity_mobile').value = this.value;
Expand All @@ -378,7 +378,7 @@ window.onload = function (e) {
document.getElementById('rayDensity_mobile').onmouseup = document.getElementById('rayDensity').onmouseup;

document.getElementById('rayDensity').ontouchend = function () {
setRayDensity(Math.exp(this.value)); //為了讓不支援oninput的瀏覽器可使用 For browsers not supporting oninput
setRayDensity(Math.exp(this.value)); // For browsers not supporting oninput
document.getElementById('rayDensity').value = this.value;
document.getElementById('rayDensity_more').value = this.value;
document.getElementById('rayDensity_mobile').value = this.value;
Expand Down Expand Up @@ -632,8 +632,8 @@ function initParameters() {
objs.length = 0;
selectObj(-1);

rayDensity_light = 0.1; //光線密度(光線相關模式) The Ray Density when View is Rays or Extended rays
rayDensity_images = 1; //光線密度(像相關模式) The Ray Density when View is All Images or Seen by Observer
rayDensity_light = 0.1; // The Ray Density when View is Rays or Extended rays
rayDensity_images = 1; // The Ray Density when View is All Images or Seen by Observer
document.getElementById("rayDensity").value = rayDensity_light;
document.getElementById("rayDensity_more").value = rayDensity_light;
document.getElementById("rayDensity_mobile").value = rayDensity_light;
Expand Down Expand Up @@ -872,7 +872,7 @@ function JSONInput() {
var jsonData = JSON.parse(document.getElementById('textarea1').value);
if (typeof jsonData != 'object') return;
if (!jsonData.version) {
//為"線光學模擬1.0"或之前的格式 Earlier than "Ray Optics Simulation 1.0"
// Earlier than "Ray Optics Simulation 1.0"
var str1 = document.getElementById('textarea1').value.replace(/"point"|"xxa"|"aH"/g, '1').replace(/"circle"|"xxf"/g, '5').replace(/"k"/g, '"objs"').replace(/"L"/g, '"p1"').replace(/"G"/g, '"p2"').replace(/"F"/g, '"p3"').replace(/"bA"/g, '"exist"').replace(/"aa"/g, '"parallel"').replace(/"ba"/g, '"mirror"').replace(/"bv"/g, '"lens"').replace(/"av"/g, '"notDone"').replace(/"bP"/g, '"lightAlpha"').replace(/"ab"|"observed_light"|"observed_images"/g, '"observer"');
jsonData = JSON.parse(str1);
if (!jsonData.objs) {
Expand All @@ -893,11 +893,11 @@ function JSONInput() {
jsonData.version = 1;
}
if (jsonData.version == 1) {
//"線光學模擬1.1"至"線光學模擬1.2" "Ray Optics Simulation 1.1" to "Ray Optics Simulation 1.2"
// "Ray Optics Simulation 1.1" to "Ray Optics Simulation 1.2"
jsonData.origin = { x: 0, y: 0 };
}
if (jsonData.version > 2) {
//為比此版本新的檔案版本 Newer than the current version
// Newer than the current version
return;
}
//TODO: Create new version.
Expand Down Expand Up @@ -1015,7 +1015,7 @@ function modebtn_clicked(mode1) {
document.getElementById("rayDensity_mobile").value = Math.log(rayDensity_light);
}
if (mode == 'observer' && !observer) {
//初始化觀察者 Initialize the observer
// Initialize the observer
observer = graphs.circle(graphs.point((canvas.width * 0.5 / dpr - origin.x) / scale, (canvas.height * 0.5 / dpr - origin.y) / scale), parseFloat(document.getElementById('observer_size').value) * 0.5);
}

Expand Down
46 changes: 23 additions & 23 deletions simulator/js/objs/aperture.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Blocker
objTypes['aperture'] = {

//建立物件 Create the obj
// Create the obj
create: function(mouse) {
return {type: 'aperture', p1: mouse, p2: mouse, p3: mouse, p4: mouse};
},

//建立物件過程滑鼠按下 Mousedown when the obj is being constructed by the user
// Mousedown when the obj is being constructed by the user
c_mousedown: function(obj, mouse, ctrl, shift)
{
if (shift)
Expand All @@ -23,7 +23,7 @@ objTypes['aperture'] = {

},

//建立物件過程滑鼠移動 Mousemove when the obj is being constructed by the user
// Mousemove when the obj is being constructed by the user
c_mousemove: function(obj, mouse, ctrl, shift)
{
if (shift)
Expand All @@ -41,7 +41,7 @@ objTypes['aperture'] = {
obj.p4 = graphs.point(obj.p1.x * 0.4 + obj.p2.x * 0.6, obj.p1.y * 0.4 + obj.p2.y * 0.6);

},
//建立物件過程滑鼠放開 Mouseup when the obj is being constructed by the user
// Mouseup when the obj is being constructed by the user
c_mouseup: function(obj, mouse, ctrl, shift)
{
if (!mouseOnPoint_construct(mouse, obj.p1))
Expand All @@ -51,12 +51,12 @@ objTypes['aperture'] = {
}
},

//平移物件 Move the object
// Move the object
move: function(obj, diffX, diffY) {
//移動線段的第一點 Move the first point
// Move the first point
obj.p1.x = obj.p1.x + diffX;
obj.p1.y = obj.p1.y + diffY;
//移動線段的第二點 Move the second point
// Move the second point
obj.p2.x = obj.p2.x + diffX;
obj.p2.y = obj.p2.y + diffY;

Expand All @@ -68,7 +68,7 @@ objTypes['aperture'] = {
},


//繪圖區被按下時(判斷物件被按下的部分) When the drawing area is clicked (test which part of the obj is clicked)
// When the drawing area is clicked (test which part of the obj is clicked)
clicked: function(obj, mouse_nogrid, mouse, draggingPart) {


Expand Down Expand Up @@ -104,15 +104,15 @@ objTypes['aperture'] = {
if (mouseOnSegment(mouse_nogrid, segment1) || mouseOnSegment(mouse_nogrid, segment2))
{
draggingPart.part = 0;
draggingPart.mouse0 = mouse; //開始拖曳時的滑鼠位置 Mouse position when the user starts dragging
draggingPart.mouse1 = mouse; //拖曳時上一點的滑鼠位置 Mouse position at the last moment during dragging
draggingPart.mouse0 = mouse; // Mouse position when the user starts dragging
draggingPart.mouse1 = mouse; // Mouse position at the last moment during dragging
draggingPart.snapData = {};
return true;
}
return false;
},

//拖曳物件時 When the user is dragging the obj
// When the user is dragging the obj
dragging: function(obj, mouse, draggingPart, ctrl, shift) {
var basePoint;

Expand All @@ -121,15 +121,15 @@ objTypes['aperture'] = {
{
if (draggingPart.part == 1)
{
//正在拖曳第一個端點 Dragging the first endpoint Dragging the first endpoint
// Dragging the first endpoint Dragging the first endpoint
basePoint = ctrl ? graphs.midpoint(draggingPart.originalObj) : draggingPart.originalObj.p2;

obj.p1 = shift ? snapToDirection(mouse, basePoint, [{x: 1, y: 0},{x: 0, y: 1},{x: 1, y: 1},{x: 1, y: -1},{x: (draggingPart.originalObj.p2.x - draggingPart.originalObj.p1.x), y: (draggingPart.originalObj.p2.y - draggingPart.originalObj.p1.y)}]) : mouse;
obj.p2 = ctrl ? graphs.point(2 * basePoint.x - obj.p1.x, 2 * basePoint.y - obj.p1.y) : basePoint;
}
else
{
//正在拖曳第二個端點 Dragging the second endpoint Dragging the second endpoint
// Dragging the second endpoint Dragging the second endpoint
basePoint = ctrl ? graphs.midpoint(draggingPart.originalObj) : draggingPart.originalObj.p1;

obj.p2 = shift ? snapToDirection(mouse, basePoint, [{x: 1, y: 0},{x: 0, y: 1},{x: 1, y: 1},{x: 1, y: -1},{x: (draggingPart.originalObj.p2.x - draggingPart.originalObj.p1.x), y: (draggingPart.originalObj.p2.y - draggingPart.originalObj.p1.y)}]) : mouse;
Expand Down Expand Up @@ -159,7 +159,7 @@ objTypes['aperture'] = {
}
else if (draggingPart.part == 0)
{
//正在拖曳整條線 Dragging the entire line
// Dragging the entire line

if (shift)
{
Expand All @@ -168,15 +168,15 @@ objTypes['aperture'] = {
else
{
var mouse_snapped = mouse;
draggingPart.snapData = {}; //放開shift時解除原先之拖曳方向鎖定 Unlock the dragging direction when the user release the shift key
draggingPart.snapData = {}; // Unlock the dragging direction when the user release the shift key
}

var mouseDiffX = draggingPart.mouse1.x - mouse_snapped.x; //目前滑鼠位置與上一次的滑鼠位置的X軸差 The X difference between the mouse position now and at the previous moment
var mouseDiffY = draggingPart.mouse1.y - mouse_snapped.y; //目前滑鼠位置與上一次的滑鼠位置的Y軸差 The Y difference between the mouse position now and at the previous moment The Y difference between the mouse position now and at the previous moment
//移動線段的第一點 Move the first point
var mouseDiffX = draggingPart.mouse1.x - mouse_snapped.x; // The X difference between the mouse position now and at the previous moment
var mouseDiffY = draggingPart.mouse1.y - mouse_snapped.y; // The Y difference between the mouse position now and at the previous moment
// Move the first point
obj.p1.x = obj.p1.x - mouseDiffX;
obj.p1.y = obj.p1.y - mouseDiffY;
//移動線段的第二點 Move the second point
// Move the second point
obj.p2.x = obj.p2.x - mouseDiffX;
obj.p2.y = obj.p2.y - mouseDiffY;

Expand All @@ -186,12 +186,12 @@ objTypes['aperture'] = {
obj.p4.x = obj.p4.x - mouseDiffX;
obj.p4.y = obj.p4.y - mouseDiffY;

//更新滑鼠位置 Update the mouse position
// Update the mouse position
draggingPart.mouse1 = mouse_snapped;
}
},

//將物件畫到Canvas上 Draw the obj on canvas
// Draw the obj on canvas
draw: function(obj, ctx, aboveLight) {
ctx.strokeStyle = getMouseStyle(obj, (colorMode && obj.wavelength && obj.isDichroic) ? wavelengthToColor(obj.wavelength || GREEN_WAVELENGTH, 1) : 'rgb(70,35,10)');
ctx.lineWidth = 3;
Expand All @@ -212,7 +212,7 @@ objTypes['aperture'] = {
}
},

//顯示屬性方塊 Show the property box
// Show the property box
p_box: function(obj, elem) {
var originalDiameter = graphs.length(obj.p3, obj.p4);

Expand Down Expand Up @@ -243,7 +243,7 @@ objTypes['aperture'] = {
return false;
},

//當物件被光射到時 When the obj is shot by a ray
// When the obj is shot by a ray
shot: function(obj, ray, rayIndex, rp) {
ray.exist = false;
}
Expand Down
Loading

0 comments on commit 844e1e9

Please sign in to comment.