How to use checkLinePos method in wpt

Best JavaScript code snippet using wpt

sketch.js

Source:sketch.js Github

copy

Full Screen

1var fontPrintChar21;2var uiDefinition = { //in pixels, not in ratio. Change this object if necessary3 fontSize: 13,4 topSpacing: 73,5 leftSpacing: 60,6 columnPosition: [0, 130, 310, 495, 865],7 titleSpaceing: 32,8 rowSize: 23,9 expandSize: 400,10 fftBlackSpace: 45,11 animationFrame: 5,12 fftGraphicLength: 920,13 fftPointsLength: 30 * 5,14 lineWeight: 1,15};16var uiDefinitionInit = null;17var useWebUSB = false;18var webUSBPressed = false;19var webUSBPort = null;20textEncoder = new TextEncoder();21var motorHeartbeatBeginned = false;22var motorCurrentStatus = false;23var motorStatusChangeTime = 0;24var tableContent = {25 title: ['IDX', 'LOC', 'NAME', 'TIME', 'DRTN'],26 content: [{27 text: ['001', 'BKLYN', 'CHANNEL', '08.31.2017.13:50', '52:30'],28 sound: 'assets/Channel_Design_06_01.mp3'29 }, {30 text: ['002', 'MTN', 'INSTAGRAM', '09.11.2017.17:44', '48:10'],31 sound: 'assets/Instagram_770_broadway_09_05_2017.mp3'32 }, {33 text: ['003', 'BKLYN', 'TOPOS', '09.15.2017.18:01', '32:50'],34 sound: 'assets/Topos_195_plymouth_Street_Brooklyn_Dumbo_09_11_2017_01.mp3'35 }, {36 text: ['004', 'BKLYN', 'MY OFFICE', '01.17.2018.15:59', '35:38'],37 sound: 'assets/My_Office_200_Morgan_Ave_Brooklyn_NY_01.mp3'38 }, {39 text: ['005', 'MTN', 'GOOGLE', '01.20.2018.12:35', '38:00'],40 sound: 'assets/Google_111_8th_Ave _New_York_NY_10011_01.mp3'41 }, {42 text: ['006', 'MTN', 'NEW YORK TIMES', '04.17.2018.13:34', '26:51'],43 sound: 'assets/New_York_Times_242_W_41st_St_New_York_NY_10036_01.mp3'44 }, {45 text: ['007', 'MTN', 'R/GA', '02.14.2018.15:20', '10:56'],46 sound: 'assets/Rga_01.mp3'47 }, {48 text: ['008', 'MTN', 'Spotify', '02.14.2018.15:20', '10:56'],49 sound: 'assets/Spotify_01.mp3'50 }, {51 text: ['009', 'MTN', 'TOPOS', '09.11.2017.12:35', '18:00']52 }, {53 text: ['010', 'BKLYN', 'MY OFFICE', '09.11.2017.12:35', '17:44']54 }, ]55};56var tableExpandSize = [];57var selectedRow = -1;58var tableRowAnimationPhase = [];59var soundFilesObj = [];60var fftObj;61var fftResult = [];62var framePlaying = [];63var wavePhase = [];64var fftAverage = [];65var fftAvgLength = 64;66var phaseShift = 0;67function preload() {68 fontPrintChar21 = loadFont('assets/PrintChar21.otf');69 var i;70 for (i = 0; i < tableContent.content.length; i++) tableExpandSize[i] = 0;71 for (i = 0; i < tableContent.content.length; i++) tableRowAnimationPhase[i] = 0;72 for (i = 0; i < tableContent.content.length; i++) soundFilesObj[i] = null;73 for (i = 0; i < tableContent.content.length; i++) {74 fftResult[i] = [];75 for (j = 0; j < uiDefinition.fftPointsLength; j++) {76 fftResult[i][j] = 0;77 }78 }79 for (i = 0; i < tableContent.content.length; i++) framePlaying[i] = 0;80 for (i = 0; i < tableContent.content.length; i++) wavePhase[i] = 0;81}82function recalulateUI() {83 if (uiDefinitionInit == null) {84 uiDefinitionInit = JSON.parse(JSON.stringify(uiDefinition)); //do a deep clone85 uiDefinitionInit.initWindowWidth = uiDefinition.leftSpacing + uiDefinition.fftGraphicLength + uiDefinition.leftSpacing;86 uiDefinitionInit.initWindowHeight = 800;87 }88 var zoomScale = windowWidth / uiDefinitionInit.initWindowWidth;89 uiDefinition.fontSize = uiDefinitionInit.fontSize * zoomScale;90 uiDefinition.topSpacing = uiDefinitionInit.topSpacing * zoomScale;91 uiDefinition.leftSpacing = uiDefinitionInit.leftSpacing * zoomScale;92 for (i = 0; i < uiDefinitionInit.columnPosition.length; i++) {93 uiDefinition.columnPosition[i] = uiDefinitionInit.columnPosition[i] * zoomScale;94 }95 uiDefinition.titleSpaceing = uiDefinitionInit.titleSpaceing * zoomScale;96 uiDefinition.rowSize = uiDefinitionInit.rowSize * zoomScale;97 uiDefinition.expandSize = uiDefinitionInit.expandSize * zoomScale;98 uiDefinition.fftBlackSpace = uiDefinitionInit.fftBlackSpace * zoomScale;99 uiDefinition.fftGraphicLength = uiDefinitionInit.fftGraphicLength * zoomScale;100 uiDefinition.lineWeight = uiDefinitionInit.lineWeight * zoomScale;101}102function setup() {103 createCanvas(windowWidth, windowHeight);104 frameRate(30);105 fftObj = new p5.FFT(0, 32);106 windowResized();107 useWebUSB = (window.location.search.substr(1)).includes('usb=1');108 if (useWebUSB) {109 serial.getPorts().then(ports => { //auto connect110 if (ports.length == 0) {111 console.log('No device found.');112 } else {113 console.log('Connecting...');114 webUSBPort = ports[0];115 webUSBConnect();116 }117 });118 }119}120function draw() {121 background(0);122 noStroke();123 //fill(0);124 //rect(0, 0, uiDefinition.leftSpacing + uiDefinition.fftGraphicLength + uiDefinition.leftSpacing, 800);125 //calculate animation of table126 for (j = 0; j < tableContent.content.length; j++) {127 if (tableRowAnimationPhase[j] > 0) {128 if (j == selectedRow) {129 if (tableRowAnimationPhase[j] < uiDefinition.animationFrame) tableRowAnimationPhase[j]++;130 } else {131 if (tableRowAnimationPhase[j] == uiDefinition.animationFrame) tableRowAnimationPhase[j]--;132 if (tableRowAnimationPhase[j] > 0) tableRowAnimationPhase[j]--;133 }134 tableExpandSize[j] = map(tableRowAnimationPhase[j], 0, uiDefinition.animationFrame, 0, uiDefinition.expandSize);135 } else {136 tableExpandSize[j] = 0;137 }138 }139 //draw table140 {141 fill(255);142 textFont(fontPrintChar21, uiDefinition.fontSize);143 for (i = 0; i < 5; i++) {144 var leftPosTitle = uiDefinition.leftSpacing + uiDefinition.columnPosition[i];145 text(tableContent.title[i], leftPosTitle, uiDefinition.topSpacing);146 }147 var topPos = uiDefinition.topSpacing + uiDefinition.titleSpaceing + uiDefinition.rowSize;148 for (j = 0; j < tableContent.content.length; j++) {149 fill(j == selectedRow ? 0x6D : 0xFF);150 for (i = 0; i < 5; i++) {151 var leftPosCell = uiDefinition.leftSpacing + uiDefinition.columnPosition[i];152 text(tableContent.content[j].text[i], leftPosCell, topPos);153 }154 topPos += uiDefinition.rowSize + tableExpandSize[j];155 }156 }157 //process FFT158 if (selectedRow >= 0) {159 if ((frameCount & 1) !== 0) {160 var spectrum = fftObj.analyze();161 var debugFFT = 0;162 if (debugFFT) {163 push();164 noStroke();165 fill(0, 255, 0); // spectrum is green166 for (var i = 0; i < spectrum.length; i++) {167 var x = map(i, 0, spectrum.length, 0, width);168 var h = -height + map(spectrum[i], 0, 255, height, 0);169 rect(x, height, width / spectrum.length, h)170 }171 pop();172 }173 var sumFFT = 0;174 for (i = 0; i < spectrum.length / 32; i++) {175 sumFFT += spectrum[i];176 }177 fftAverage.push(sumFFT);178 if (fftAverage.length > fftAvgLength) {179 fftAverage.shift();180 }181 var total = 0;182 fftAverage.forEach(function(element) {183 total += element;184 })185 var average = total / fftAverage.length;186 phaseShift = sumFFT / 2048 + ((fftAverage.length == fftAvgLength) ? ((average - sumFFT) / 256) : 0);187 }188 if (soundFilesObj[selectedRow] && soundFilesObj[selectedRow].isPlaying()) {189 wavePhase[selectedRow] += phaseShift;190 }191 var fftSelected = fftResult[selectedRow];192 var totalLenfth = uiDefinition.fftPointsLength;193 for (i = 0; i < (totalLenfth - 1); i++) {194 fftSelected[i] = fftSelected[i + 1];195 }196 fftSelected[totalLenfth - 1] = sin(wavePhase[selectedRow]);197 framePlaying[selectedRow]++;198 if (useWebUSB && webUSBPort) {199 var sendValue = -fftSelected[totalLenfth - 1]; //Y axis down200 var LEDbrightness;201 var motorValue, motorStrength;202 var duration = 100; //let every command run for 100ms or be overwritten203 var LEDvariation = sin(millis() / 500);204 if (sendValue <= 0) { //LEDmap205 LEDbrightness = Math.floor(64 + 10 * LEDvariation);206 } else {207 var squareSendValue = sendValue * sendValue * sendValue;208 LEDbrightness = map(squareSendValue, 0, 1, 64, 175) + map(squareSendValue, 0, 1, 10, 0) * LEDvariation;209 LEDbrightness = Math.floor(LEDbrightness);210 if (LEDbrightness > 255) LEDbrightness = 255;211 }212 motorStrength = 150;213 var beatDuration = 80; //the number defines beat duration (motor on time)214 if (sendValue <= 0) { //if signal is below 0, shut down motor215 motorHeartbeatBeginned = false;216 if (motorCurrentStatus && (millis() < motorStatusChangeTime)) {217 //do nothing, let this beat finish218 } else {219 motorCurrentStatus = false;220 motorStatusChangeTime = 0;221 }222 } else {223 if (!motorHeartbeatBeginned) { //just begins224 motorStatusChangeTime = millis() + 750; //rest before 1st beat.225 motorHeartbeatBeginned = true;226 }227 if (millis() >= motorStatusChangeTime) {228 if (!motorCurrentStatus) {229 motorCurrentStatus = true;230 motorStatusChangeTime = millis() + beatDuration;231 } else {232 motorCurrentStatus = false;233 motorStatusChangeTime = millis() + Math.floor(random(600, 800)); //rest between each beat234 }235 }236 }237 if (motorCurrentStatus) { //give motor a value according to on and off status238 motorValue = motorStrength;239 } else {240 motorValue = 0;241 }242 var ledHighValue = [255, 36, 0, 0, 255, 129, 0, 0, 8, 8, 38, 0, 16, 0, 38, 0, 0, 20, 0, 0, 255, 0, 0, 0];243 var ledLowValue = [10, 1, 0, 0, 11, 12, 0, 0, 3, 3, 8, 0, 3, 0, 8, 0, 0, 6, 0, 0, 25, 0, 0, 0];244 var cmdBuf = ""245 for (i = 0; i < 4 * 6; i++) {246 var interpolatedValue = int(map(LEDbrightness, 54, 185, ledLowValue[i], ledHighValue[i]))247 if (interpolatedValue > 255) interpolatedValue = 255;248 if (interpolatedValue < 0) interpolatedValue = 255;249 cmdBuf = cmdBuf + ("00" + (interpolatedValue).toString(16)).slice(-2);250 }251 var ledCmd = "L" + cmdBuf + "\n";252 var motorStr = ("00" + (motorValue).toString(16)).slice(-2);253 var durationStr = ("0000" + (duration).toString(16)).slice(-4);254 var commandStr = "M" + motorStr + durationStr + "\n" + ledCmd;255 //console.log(commandStr);256 webUSBPort.send(textEncoder.encode(commandStr)).catch(error => {257 console.log('Send error: ' + error);258 });259 }260 }261 //drawgraph262 {263 push();264 topPos = uiDefinition.topSpacing + uiDefinition.titleSpaceing;265 for (j = 0; j < tableContent.content.length; j++) {266 if (tableRowAnimationPhase[j] > 0) {267 var spaceTop = topPos + uiDefinition.rowSize + uiDefinition.fftBlackSpace;268 var spaceBottom = topPos + tableExpandSize[j] + uiDefinition.rowSize + uiDefinition.rowSize - uiDefinition.fontSize - uiDefinition.fftBlackSpace;269 var spaceMiddle = (spaceTop + spaceBottom) / 2;270 var totalLength = uiDefinition.fftPointsLength;271 var waveScale = uiDefinition.fftGraphicLength / totalLength;272 textFont(fontPrintChar21, uiDefinition.fontSize * 0.8);273 fill(0x6D);274 text('200 HZ', uiDefinition.leftSpacing, spaceTop - uiDefinition.fontSize * 1);275 text('005 HZ', uiDefinition.leftSpacing, spaceBottom + uiDefinition.fontSize * 1.8);276 stroke(0x33);277 strokeWeight(uiDefinition.lineWeight);278 line(0, spaceMiddle, uiDefinition.leftSpacing + uiDefinition.fftGraphicLength + uiDefinition.leftSpacing, spaceMiddle);279 var frameMod = framePlaying[selectedRow] % 30;280 frameMod = 0;281 noFill();282 beginShape(LINES);283 for (i = totalLength - frameMod; i >= 0; i -= 30) {284 vertex(uiDefinition.leftSpacing + i * waveScale, spaceTop);285 vertex(uiDefinition.leftSpacing + i * waveScale, spaceBottom);286 }287 endShape();288 var fftData = fftResult[j];289 stroke(0xc7);290 var xPos = uiDefinition.leftSpacing;291 var verticalScale = (spaceBottom - spaceTop) * 0.4;292 waveScale = (uiDefinition.fftGraphicLength + 2 * uiDefinition.leftSpacing) / (totalLength - 1);293 noFill();294 beginShape();295 for (i = 0; i < (totalLength); i++) {296 vertex(0 + i * waveScale, spaceMiddle + verticalScale * fftData[i]);297 }298 endShape();299 }300 if (selectedRow == j) {301 //playsound302 if (soundFilesObj[j]) {303 if (soundFilesObj[j].isLoaded()) {304 if (!soundFilesObj[j].isPlaying()) {305 soundFilesObj[j].play();306 wavePhase[j] = 0;307 }308 }309 }310 }311 topPos += uiDefinition.rowSize + tableExpandSize[j];312 }313 pop();314 }315}316function mouseClicked() {317 //console.log(mouseY);318 //check which row is clicked;319 var checkLinePos = uiDefinition.topSpacing + uiDefinition.titleSpaceing;320 var lineClicked = -1;321 if (mouseY > checkLinePos) {322 for (j = 0; j < tableContent.content.length; j++) {323 if ((mouseY <= checkLinePos + uiDefinition.rowSize + tableExpandSize[j])) {324 lineClicked = j;325 break;326 }327 checkLinePos += uiDefinition.rowSize + tableExpandSize[j];328 }329 }330 for (i = 0; i < tableContent.content.length; i++) tableExpandSize[i] = 0;331 if (lineClicked >= 0) {332 if (tableRowAnimationPhase[lineClicked] === 0) tableRowAnimationPhase[lineClicked] = 1;333 if (soundFilesObj[lineClicked] === null) {334 var soundFileLocation = tableContent.content[lineClicked].sound;335 if (soundFileLocation) {336 soundFilesObj[lineClicked] = loadSound(soundFileLocation);337 console.log('load sound: ' + soundFileLocation);338 }339 } else {340 }341 }342 //pause and rewind the rest343 for (i = 0; i < tableContent.content.length; i++) {344 if (soundFilesObj[i] && (i != lineClicked)) {345 if (soundFilesObj[i].isLoaded()) {346 soundFilesObj[i].stop();347 }348 }349 }350 if (selectedRow != lineClicked) {351 fftAverage.length = 0; //clear average array352 if (selectedRow >= 0) {353 framePlaying[selectedRow] = 0;354 for (j = 0; j < uiDefinition.fftPointsLength; j++) {355 fftResult[selectedRow][j] = 0;356 }357 }358 }359 selectedRow = lineClicked;360 if (useWebUSB && !webUSBPressed) {361 webUSBPressed = true;362 if (!webUSBPort) {363 serial.requestPort().then(selectedPort => {364 webUSBPort = selectedPort;365 webUSBConnect();366 }).catch(error => {367 console.log(error);368 });369 }370 }371}372function windowResized() {373 //adaptive374 recalulateUI();375 var contentHeight = uiDefinition.topSpacing + uiDefinition.titleSpaceing + uiDefinition.rowSize;376 contentHeight = contentHeight + (tableContent.content.length) * uiDefinition.rowSize + uiDefinition.expandSize;377 var canvasHeight = max(contentHeight, windowHeight);378 resizeCanvas(windowWidth, canvasHeight);379}380function webUSBConnect() {381 webUSBPort.connect().then(() => {382 console.log('WebUSB connected')383 webUSBPort.onReceive = data => {384 let textDecoder = new TextDecoder();385 console.log(textDecoder.decode(data));386 }387 webUSBPort.onReceiveError = error => {388 console.error(error);389 };390 }, error => {391 console.log(error);392 });...

Full Screen

Full Screen

PolygonData.js

Source:PolygonData.js Github

copy

Full Screen

1function PolygonData()2{3 // 平面多边形4 this.mLineArray = new Array(); // 2D平面上构成形状的线条 5 this.m_pCurLine = null;6 this.mMouseX = 0;7 this.mMouseY = 0;8 9 this.m_floor = null; // 地面数据指针,不需要保存10 this.m_WallArray= null; // 包围地面的类似墙面数据,不需要保存11 this.OnInit = function( )12 {13 };14 15 // 生成3D16 this.OnUpdate3D =function()17 {18 if( this.mLineArray.length == 0 )19 return;20 21 var tLineArray = [];22 for( var i = 0; i<this.mLineArray.length; i++)23 tLineArray.push(this.mLineArray[i].m_vStart);24 25 // 地面使用的材质26 var str ="ASDSD1204,c75AB6AAC376BC72D0723CC4096976E1F/c9D9A6E6DEA8974A7DDF4F2F3FCBF90BC/ASDSD1204/ASDSD1204.jpg,900A900,地毯,化纤,3,,,,2,,";27 var ab =str.split(',');28 mHouseClass.mFloorClass.CreatePlatformPoly(tLineArray,0);29 mHouseClass.mFloorClass.m_pCurFloor.OnUpdateTex3D(ab);30 mHouseClass.mFloorClass.m_pCurFloor = null;31 };32 33 this.OnMouseDown = function(mouseX,mouseY)34 {35 if( this.m_pCurLine == null ){36 this.OnBuildNewLine(mouseX,mouseY);37 }38 else39 { 40 this.CheckLinePos();41 var d = this.m_pCurLine.m_vStart.distanceTo(this.m_pCurLine.m_vEnd); // 两个点距离太近 ,不创建墙体42 if( d < 3 ) 43 return;44 45 this.mLineArray.push(this.m_pCurLine); 46 this.OnBuildNewLine(this.m_pCurLine.m_vEnd.x,this.m_pCurLine.m_vEnd.y); // 新墙 47 } 48 };49 50 this.OnMouseMove= function(mouseX,mouseY,buttonDown)51 {52 mHelpClass.mHelpCoss.position.x = -999999;53 mHelpClass.mHelpCoss.position.y = -999999; 54 if( this.m_pCurLine )55 { 56 this.m_pCurLine.m_vEnd.x = mouseX; 57 this.m_pCurLine.m_vEnd.y = mouseY; 58 59 this.CheckXYPos(this.m_pCurLine.m_vEnd); //XY轴对齐60 this.CheckLinePos();61 62 this.m_pCurLine.OnRender(); 63 64 this.mMouseX = this.m_pCurLine.m_vEnd.x;65 this.mMouseY = this.m_pCurLine.m_vEnd.y;66 mHelpClass.mHelpCoss.position.x = this.mMouseX;67 mHelpClass.mHelpCoss.position.y = this.mMouseY; 68 }69 else 70 {71 this.mMouseX = mouseX;72 this.mMouseY = mouseY; 73 var ab1 = this.CheckPosOnLine(mouseX,mouseY); 74 if( ab1[0] !=0 )75 {76 this.mMouseX = ab1[1];77 this.mMouseY = ab1[2]; 78 mHelpClass.mHelpCoss.position.x = this.mMouseX;79 mHelpClass.mHelpCoss.position.y = this.mMouseY;80 } 81 }82 };83 84 // 创建新墙体开始点85 this.OnBuildNewLine = function(mouseX,mouseY)86 {87 var ab = this.CheckPosOnLine(mouseX,mouseY); // 顶点 88 if( ab[0] ==1 || ab[0] == 2 ){89 this.mMouseX = ab[1];90 this.mMouseY = ab[2];91 }92 else{93 this.mMouseX = mouseX;94 this.mMouseY = mouseY; 95 }96 this.m_pCurLine = new GroundData(); 97 this.m_pCurLine.OnInit(this.mMouseX,this.mMouseY,0); 98 };99 100 // 点到直线的距离<10101 this.CheckPosOnLine= function ( posX, posY )102 {103 var ab1 =new Array();104 ab1.push(0);105 var pos = new THREE.Vector3(posX,posY,0);106 for( var i = 0; i< this.mLineArray.length; i++ )107 { 108 var ab = mMathClass.ClosestPointOnLine(this.mLineArray[i], posX, posY, 0, 5);109 if( ab[0] != 0 )110 {111 ab.push(i);112 return ab;113 }114 }115 return ab1;116 };117 118 // 判断附近是否已存在墙体点119 this.CheckXYPos = function(pos)120 {121 for( i = 0; i< this.mLineArray.length; i++ )122 {123 if(Math.abs(pos.x - this.mLineArray[i].m_vStart.x )< 15 )124 {125 pos.x = this.mLineArray[i].m_vStart.x;126 return true;127 }128 else if ( Math.abs(pos.y - this.mLineArray[i].m_vStart.y )< 15 )129 {130 pos.y = this.mLineArray[i].m_vStart.y;131 return true;132 }133 else if ( Math.abs(pos.x - this.mLineArray[i].m_vEnd.x )< 15 ) 134 {135 pos.x = this.mLineArray[i].m_vEnd.x; 136 return true;137 }138 else if ( Math.abs(pos.y - this.mLineArray[i].m_vEnd.y )< 15 ) 139 {140 pos.y = this.mLineArray[i].m_vEnd.y;141 return true;142 }143 }144 return false;145 };146 147 this.CheckLinePos=function()148 { 149 // 旋转5度150 mMathClass.RotateVecFromAxis( this.m_pCurLine.m_vEnd, this.m_pCurLine.m_vStart, 5);151 this.m_pCurLine.m_vEnd.x = mMathClass.mRetVec.x; 152 this.m_pCurLine.m_vEnd.y = mMathClass.mRetVec.y; 153 154 var ab = this.CheckPosOnLine(this.m_pCurLine.m_vEnd.x,this.m_pCurLine.m_vEnd.y); 155 if( ab[0] ==1 || ab[0] == 2 ) // 顶点156 {157 this.m_pCurLine.m_vEnd.x = ab[1];158 this.m_pCurLine.m_vEnd.y = ab[2];159 } 160 };161 162 // 清空墙体 163 this.OnClear= function()164 {165 for( var i = 0; i< this.mLineArray.length; i++ ){166 this.mLineArray[i].OnClear();167 }168 this.mLineArray.length = 0;169 this.m_pCurLine = null;170 };171 172 // 拾取墙体173 this.OnPick2D = function(mouseX, mouseY)174 {175 var ab = this.CheckPosOnLine(mouseX,mouseY); 176 if( ab[0] !=0 )177 { 178 return this.mLineArray[ab[4]];179 }180 return null;181 };182 183 this.OnMouseRightUp2D = function()184 {185 if( this.m_pCurLine )186 this.OnDelete(this.m_pCurLine); 187 this.m_pCurLine = null;188 mHelpClass.mHelpCoss.position.x = -999999;189 mHelpClass.mHelpCoss.position.y = -999999;190 191 this.OnUpdate3D();192 };193 194 195 this.OnDelete = function(tCurLine)196 { 197 tCurLine.OnClear();198 var iIndex = this.mLineArray.indexOf(tCurLine);199 if( iIndex == -1 )200 return;201 this.mLineArray.splice(iIndex,1);202 };203 204/* this.OnShow = function(tLine)205 {206 $('#mWallLineBar').show();207 var div1=document.getElementById("mWallLineBar");208 div1.style.left= mouseScreen.x+10+'px';209 div1.style.top= mouseScreen.y-100+'px'; 210 }211 212 this.AddLine = function(x1,y1,x2,y2)213 {214 this.m_pCurLine = new GroundData(); 215 this.m_pCurLine.OnInit(x1,y1,0);216 this.m_pCurLine.m_vEnd.x = x2; 217 this.m_pCurLine.m_vEnd.y = y2; 218 this.m_pCurLine.OnRender(); 219 this.mLineArray.push(this.m_pCurLine);220 this.m_pCurLine = null;221 }*/222 ...

Full Screen

Full Screen

helper.js

Source:helper.js Github

copy

Full Screen

1function checkLinePos(spanID,expectedPos,coordToCheck) {2 if(coordToCheck == "top")3 var spanToCheck = document.getElementById(spanID).getBoundingClientRect().top;4 else if(coordToCheck == "right")5 var spanToCheck = document.getElementById(spanID).getBoundingClientRect().right;6 else if(coordToCheck == "left")7 var spanToCheck = document.getElementById(spanID).getBoundingClientRect().left;8 else9 var spanToCheck = document.getElementById(spanID).getBoundingClientRect().bottom;10 /* Verify that the span appears where expected. It should be at expectedPos11 Test will allow 1/4 line height (3px) of leeway for minor spacing differences */12 return( (spanToCheck >= expectedPos) && (spanToCheck <= (expectedPos+3)) )...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.checkLinePos('www.webpagetest.org', function(err, data) {4 if (err) return console.error(err);5 console.log(data);6});7var wpt = require('webpagetest');8var wpt = new WebPageTest('www.webpagetest.org');9wpt.checkStatus('www.webpagetest.org', function(err, data) {10 if (err) return console.error(err);11 console.log(data);12});13var wpt = require('webpagetest');14var wpt = new WebPageTest('www.webpagetest.org');15wpt.checkTest('www.webpagetest.org', function(err, data) {16 if (err) return console.error(err);17 console.log(data);18});19var wpt = require('webpagetest');20var wpt = new WebPageTest('www.webpagetest.org');21wpt.deleteTest('www.webpagetest.org', function(err, data) {22 if (err) return console.error(err);23 console.log(data);24});25var wpt = require('webpagetest');26var wpt = new WebPageTest('www.webpagetest.org');27wpt.getLocations('www.webpagetest.org', function(err, data) {28 if (err) return console.error(err);29 console.log(data);30});31var wpt = require('webpagetest');32var wpt = new WebPageTest('www.webpagetest.org');33wpt.getTesters('www.webpagetest.org', function(err, data) {34 if (err) return console.error(err);35 console.log(data);36});37var wpt = require('webpagetest');38var wpt = new WebPageTest('www.webpagetest.org');39wpt.getTesters('www.webpagetest.org',

Full Screen

Using AI Code Generation

copy

Full Screen

1CKEDITOR.replace( 'editor1', {2} );3CKEDITOR.replace( 'editor1', {4 on: {5 instanceReady: function( evt ) {6 var editor = evt.editor;7 editor.on( 'key', function( evt ) {8 var key = evt.data.keyCode;9 var range = editor.getSelection().getRanges()[0];10 var text = range.startContainer.$.textContent;11 var pos = range.startOffset;12 var linePos = editor.plugins.wptextpattern.checkLinePos( text, pos );13 console.log( 'Key: ' + key + ', Position: ' + pos + ', Line Position: ' + linePos );14 } );15 }16 }17} );18CKEDITOR.replace( 'editor1', {19 on: {20 instanceReady: function( evt ) {21 var editor = evt.editor;22 editor.on( 'key', function( evt ) {23 var key = evt.data.keyCode;24 var range = editor.getSelection().getRanges()[0];25 var text = range.startContainer.$.textContent;26 var pos = range.startOffset;27 var linePos = editor.plugins.wptextpattern.checkLinePos( text, pos );28 console.log( 'Key: ' + key + ', Position: ' + pos + ', Line Position: ' + linePos );29 } );30 }31 }32} );33CKEDITOR.replace( 'editor1', {34 on: {35 instanceReady: function( evt ) {36 var editor = evt.editor;37 editor.on( 'key', function( evt ) {38 var key = evt.data.keyCode;39 var range = editor.getSelection().getRanges()[0];40 var text = range.startContainer.$.textContent;41 var pos = range.startOffset;42 var linePos = editor.plugins.wptextpattern.checkLinePos( text, pos );43 console.log( 'Key: ' + key + ', Position: ' + pos + ', Line Position: ' + linePos );44 } );45 }

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptc = require('wptc.js');2var checkLinePos = wptc.checkLinePos;3var line1 = {x1: 0, y1: 0, x2: 0, y2: 10};4var line2 = {x1: 0, y1: 5, x2: 10, y2: 5};5var line3 = {x1: 0, y1: 5, x2: 10, y2: 5};6var line4 = {x1: 0, y1: 5, x2: 10, y2: 5};7var lines = [line1, line2, line3, line4];8var linePos = checkLinePos(line1, lines);9console.log(linePos);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./wpt.js');2wpt.checkLinePos(0,0,1,1,0,0,function(err,data){3 if (err) {4 console.log("error");5 } else {6 console.log(data);7 }8});9var http = require('http');10var querystring = require('querystring');11var wpt = {12 checkLinePos: function (x1,y1,x2,y2,x,y,callback) {13 var post_data = querystring.stringify({14 });15 var post_options = {16 headers: {17 'Content-Length': Buffer.byteLength(post_data)18 }19 };20 var wpt_req = http.request(post_options, function(res) {21 res.setEncoding('utf8');22 res.on('data', function (chunk) {23 callback(null,chunk);24 });25 });26 wpt_req.on('error', function(e) {27 callback(e,null);28 });29 wpt_req.write(post_data);30 wpt_req.end();31 }32};33module.exports = wpt;

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./wpt.js');2var result = wpt.checkLinePos(line, 1, 1);3console.log(result);4result = wpt.checkLinePos(line, 1, 3);5console.log(result);6result = wpt.checkLinePos(line, 1, 10);7console.log(result);8exports.checkLinePos = function (line, lineNum, pos) {9 var result = {line: lineNum, pos: pos, type: ""};10 var lineLen = line.length;11 var code = true;12 for (var i = 0; i < lineLen; i++) {13 if (line[i] == '/' && line[i + 1] == '/') {14 code = false;15 }16 if (i == pos) {17 if (code) {18 result.type = "code";19 } else {20 result.type = "comment";21 }22 break;23 }24 }25 return result;26};27{ line: 1, pos: 1, type: 'code' }28{ line: 1, pos: 3, type: 'comment' }29{ line: 1, pos: 10, type: 'code' }

Full Screen

Using AI Code Generation

copy

Full Screen

1console.log(wpt.checkLinePos(3, 3, 3, 3));2console.log(wpt.checkLinePos(3, 3, 3, 4));3console.log(wpt.checkLinePos(3, 3, 2, 4));4console.log(wpt.checkLinePos(3, 3, 2, 3));5console.log(wpt.checkLinePos(3, 3, 2, 2));6console.log(wpt.checkLinePos(3, 3, 3, 2));7console.log(wpt.checkLinePos(3, 3, 4, 2));8console.log(wpt.checkLinePos(3, 3, 4, 3));9console.log(wpt.checkLinePos(3, 3, 4, 4));10console.log(wpt.checkLinePos(3, 3, 3, 3));11console.log(wpt.checkLinePos(3, 3, 3, 4));12console.log(wpt.checkLinePos(3, 3, 2, 4));13console.log(wpt.checkLinePos(3, 3, 2, 3));14console.log(wpt.checkLinePos(3, 3, 2, 2));15console.log(wpt.checkLinePos(3, 3, 3, 2));16console.log(wpt.checkLinePos(3, 3, 4, 2));17console.log(wpt.checkLinePos(3, 3, 4, 3));18console.log(wpt.checkLinePos(3, 3, 4, 4));19console.log(wpt.checkLinePos(3, 3, 3, 3));20console.log(wpt.checkLinePos(3, 3,

Full Screen

Using AI Code Generation

copy

Full Screen

1function checkLinePos(e) {2 var keynum;3 var keychar;4 var numcheck;5 {6 keynum = e.keyCode;7 }8 {9 keynum = e.which;10 }11 keychar = String.fromCharCode(keynum);12 numcheck = /\d/;13 if (keychar == "\t") {14 var ta = document.getElementById("textarea");15 var start = ta.selectionStart;16 var end = ta.selectionEnd;17 var text = ta.value;18 var before = text.substring(0, start);19 var after = text.substring(end, text.length);20 if (start == end) {21 if (start == 0) {22 ta.value = "\t" + text;23 ta.selectionStart = start + 1;24 ta.selectionEnd = start + 1;25 }26 else {27 if (text.substring(start - 1, start) == "\n") {28 ta.value = before + "\t" + after;29 ta.selectionStart = start + 1;30 ta.selectionEnd = start + 1;31 }32 else {33 ta.value = before + "\t" + after;34 ta.selectionStart = start + 1;35 ta.selectionEnd = start + 1;36 }37 }38 }39 else {40 var lines = text.substring(start, end).split("\n");41 var newlines = "";42 for (var i = 0; i < lines.length; i++) {43 newlines += "\t" + lines[i] + "\n";44 }45 ta.value = before + newlines + after;46 ta.selectionStart = start;47 ta.selectionEnd = end + lines.length;48 }49 if (e.preventDefault) {50 e.preventDefault();51 }52 return false;53 }54}

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful