Skip to content

Commit

Permalink
handle negative z coordinates in 3D
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielburnworth committed Feb 11, 2025
1 parent 5e01872 commit 2591c71
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
14 changes: 14 additions & 0 deletions frontend/farm_designer/__tests__/three_d_garden_map_test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ describe("<ThreeDGardenMap />", () => {
mapPoints: [],
weeds: [],
botPosition: { x: 1, y: 2, z: 3 },
negativeZ: false,
});

it("converts props", () => {
Expand Down Expand Up @@ -77,4 +78,17 @@ describe("<ThreeDGardenMap />", () => {
weeds: [],
}, {});
});

it("converts props: negative z", () => {
const p = fakeProps();
p.botPosition = { x: undefined, y: undefined, z: -100 };
p.negativeZ = true;
render(<ThreeDGardenMap {...p} />);
expect(ThreeDGarden).toHaveBeenCalledWith({
config: expect.objectContaining({ x: 0, y: 0, z: 100 }),
addPlantProps: expect.any(Object),
mapPoints: [],
weeds: [],
}, {});
});
});
1 change: 1 addition & 0 deletions frontend/farm_designer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ export class RawFarmDesigner
plants={this.props.plants}
get3DConfigValue={get3DConfigValueFunction(this.props.farmwareEnvs)}
sourceFbosConfig={this.props.sourceFbosConfig}
negativeZ={!!this.props.botMcuParams.movement_home_up_z}
gridOffset={gridOffset}
mapTransformProps={this.mapTransformProps}
botSize={this.props.botSize}
Expand Down
5 changes: 4 additions & 1 deletion frontend/farm_designer/three_d_garden_map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface ThreeDGardenMapProps {
gridOffset: AxisNumberProperty;
get3DConfigValue(key: string): number;
sourceFbosConfig: SourceFbosConfig;
negativeZ: boolean;
designer: DesignerState;
plants: TaggedPlant[];
dispatch: Function;
Expand All @@ -39,9 +40,11 @@ export const ThreeDGardenMap = (props: ThreeDGardenMapProps) => {
config.zoomBeacons = false;
config.trail = !!props.getWebAppConfigValue(BooleanSetting.display_trail);

const zDir = props.negativeZ ? -1 : 1;

config.x = props.botPosition.x || 0;
config.y = props.botPosition.y || 0;
config.z = props.botPosition.z || 0;
config.z = zDir * (props.botPosition.z || 0);

const { designer } = props;
config.distanceIndicator = designer.distanceIndicator;
Expand Down

0 comments on commit 2591c71

Please sign in to comment.