Skip to content

Commit

Permalink
Add ability to change between imperial or metric units
Browse files Browse the repository at this point in the history
Fixes #4

Add ability to change between imperial or metric units in the numpy array.

* Add a dropdown in `src/components/MicMasterFlex.tsx` to select between metric and imperial units.
* Update the `getNumpyArrayString` function to include a comment indicating the units.
* Update the `copyToClipboard` function to include the unit comment.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/nicolasperez19/mic-master-flex/issues/4?shareId=XXXX-XXXX-XXXX-XXXX).
  • Loading branch information
nkzarrabi committed Oct 31, 2024
1 parent 871197e commit f2e01e0
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/components/MicMasterFlex.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const MicMasterFlex = () => {
const [showEditDialog, setShowEditDialog] = useState(false);
const [editX, setEditX] = useState('');
const [editY, setEditY] = useState('');
const [unit, setUnit] = useState('metric'); // P44ca

const svgRef = useRef<SVGSVGElement>(null);
const gridSize = 10; // 10x10 meters grid
Expand Down Expand Up @@ -176,9 +177,10 @@ const MicMasterFlex = () => {

// Generate numpy array string
const getNumpyArrayString = () => {
const unitComment = unit === 'metric' ? '# positions in meters' : '# positions in feet'; // Pda43
return `np.array([
${microphones.map(mic => `[${mic.x.toFixed(4)}, ${mic.y.toFixed(4)}]`).join(',\n ')}
])`;
]) ${unitComment}`;
};

// Copy array to clipboard
Expand Down Expand Up @@ -250,6 +252,19 @@ const MicMasterFlex = () => {
</button>
</div>

<div className="absolute top-4 left-4 z-10"> {/* P44ca */}
<label htmlFor="unit-select" className="mr-2">Units:</label>
<select
id="unit-select"
value={unit}
onChange={(e) => setUnit(e.target.value)}
className="p-2 bg-white rounded shadow"
>
<option value="metric">Metric (meters)</option>
<option value="imperial">Imperial (feet)</option>
</select>
</div>

<svg
ref={svgRef}
className="w-full h-full"
Expand Down Expand Up @@ -357,4 +372,4 @@ const MicMasterFlex = () => {
);
};

export default MicMasterFlex;
export default MicMasterFlex;

0 comments on commit f2e01e0

Please sign in to comment.