1/** 2 * src/core/utils.js 3 * å ±éã¦ã¼ãã£ãªã㣠4 */ 5 6/** 7 * ð ç¨ç´ãµã¤ãº â ãã¯ã»ã«è¨ç® 8 * @param {string} paperSize - 'A4', 'A3', 'A5' 9 * @param {'portrait'|'landscape'} orientation 10 * @param {number} dpi - default 96 11 * @returns {{width:number,height:number}} 12 */ 13export function getPixelSizeFromPaper(paperSize, orientation='portrait', dpi=96){ 14 const mmPerInch = 25.4; 15 const sizeTable = { 16 A4:{width:210,height:297}, 17 A3:{width:297,height:420}, 18 A5:{width:148,height:210} 19 }; 20 const mm = sizeTable[paperSize]; 21 if(!mm){ 22 console.warn('æªå¯¾å¿ã®ç¨ç´ãµã¤ãº:',paperSize); 23 return {width:800,height:600}; 24 } 25 const wmm = orientation==='landscape'?mm.height:mm.width; 26 const hmm = orientation==='landscape'?mm.width:mm.height; 27 return { 28 width: Math.round((wmm/mmPerInch)*dpi), 29 height: Math.round((hmm/mmPerInch)*dpi) 30 }; 31} 32 33/** 34 * ð Haversineå ¬å¼ã«ãã2ç¹éè·é¢è¨ç® 35 * @param {number} lat1 - å°ç¹1ã®ç·¯åº¦ 36 * @param {number} lng1 - å°ç¹1ã®çµåº¦ 37 * @param {number} lat2 - å°ç¹2ã®ç·¯åº¦ 38 * @param {number} lng2 - å°ç¹2ã®çµåº¦ 39 * @returns {number} è·é¢ï¼ã¡ã¼ãã«ï¼ 40 */ 41export function calculateHaversineDistance(lat1, lng1, lat2, lng2) { 42 const R = 6371000; // å°çã®åå¾ï¼ã¡ã¼ãã«ï¼ 43 const toRad = (deg) => deg * Math.PI / 180; 44 45 const dLat = toRad(lat2 - lat1); 46 const dLng = toRad(lng2 - lng1); 47 48 const a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + 49 Math.cos(toRad(lat1)) * Math.cos(toRad(lat2)) * 50 Math.sin(dLng / 2) * Math.sin(dLng / 2); 51 52 const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); 53 54 return R * c; 55} 56 57/** 58 * ð 座æ¨ãªã¹ãã®åè¨è·é¢ãè¨ç® 59 * @param {Array<{lat: number, lng: number}>} coords - 座æ¨ãªã¹ã 60 * @returns {number} åè¨è·é¢ï¼ã¡ã¼ãã«ï¼ 61 */ 62export function calculateTotalDistance(coords) { 63 if (coords.length < 2) return 0; 64 65 let total = 0; 66 for (let i = 0; i < coords.length - 1; i++) { 67 total += calculateHaversineDistance( 68 coords[i].lat, coords[i].lng, 69 coords[i + 1].lat, coords[i + 1].lng 70 ); 71 } 72 return total; 73} 74 75/** 76 * ð è·é¢ã®è¡¨ç¤ºãã©ã¼ããã 77 * @param {number} meters - è·é¢ï¼ã¡ã¼ãã«ï¼ 78 * @returns {string} ãã©ã¼ããããããè·é¢æåå 79 */ 80export function formatDistance(meters) { 81 if (meters < 1000) { 82 return `${Math.round(meters)} m`; 83 } 84 return `${(meters / 1000).toFixed(2)} km`; 85}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.