Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions kcl-ezpz/src/textual/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,32 @@ impl Problem {
});
}
}
Instruction::FixObjectPointComponent(FixObjectPointComponent {
object,
value,
point,
point_component,
}) => {
// Is this center talking about an arc object?
if let Some(arc_id) = self.inner_arcs.iter().position(|label| label == object) {
let the_point = if point.0 == "a" {
initial_guesses.arc_ids(arc_id).a
} else if point.0 == "b" {
initial_guesses.arc_ids(arc_id).b
} else {
panic!("Unrecognized label {}", point.0)
};
let id = match point_component {
Component::X => the_point.x,
Component::Y => the_point.y,
};
constraints.push(Constraint::Fixed(id, *value));
} else {
return Err(Error::UndefinedPoint {
label: object.0.clone(),
});
}
}
Instruction::Vertical(Vertical { label }) => {
let p0 = datum_point_for_label(&label.0)?;
let p1 = datum_point_for_label(&label.1)?;
Expand Down
9 changes: 9 additions & 0 deletions kcl-ezpz/src/textual/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub enum Instruction {
Tangent(Tangent),
ArcRadius(ArcRadius),
FixCenterPointComponent(FixCenterPointComponent),
FixObjectPointComponent(FixObjectPointComponent),
LinesEqualLength(LinesEqualLength),
IsArc(IsArc),
PointLineDistance(PointLineDistance),
Expand Down Expand Up @@ -155,3 +156,11 @@ pub struct FixCenterPointComponent {
pub center_component: Component,
pub value: f64,
}

#[derive(Debug)]
pub struct FixObjectPointComponent {
pub object: Label,
pub point: Label,
pub point_component: Component,
pub value: f64,
}
31 changes: 29 additions & 2 deletions kcl-ezpz/src/textual/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ use crate::{
ScalarGuess,
instruction::{
AngleLine, ArcRadius, CircleRadius, DeclareArc, DeclareCircle, Distance,
FixCenterPointComponent, IsArc, Line, LinesEqualLength, Midpoint, Parallel,
Perpendicular, PointLineDistance, PointsCoincident, Symmetric, Tangent,
FixCenterPointComponent, FixObjectPointComponent, IsArc, Line, LinesEqualLength,
Midpoint, Parallel, Perpendicular, PointLineDistance, PointsCoincident, Symmetric,
Tangent,
},
},
};
Expand Down Expand Up @@ -381,6 +382,9 @@ fn parse_instruction(i: &mut &str) -> WResult<Vec<Instruction>> {
parse_fix_center_point_component
.map(Instruction::FixCenterPointComponent)
.map(sv),
parse_fix_some_point_component
.map(Instruction::FixObjectPointComponent)
.map(sv),
assign_point,
parse_horizontal.map(Instruction::Horizontal).map(sv),
parse_coincident.map(Instruction::PointsCoincident).map(sv),
Expand Down Expand Up @@ -505,6 +509,29 @@ fn parse_fix_center_point_component(i: &mut &str) -> WResult<FixCenterPointCompo
.parse_next(i)
}

fn parse_fix_some_point_component(i: &mut &str) -> WResult<FixObjectPointComponent> {
(
parse_label,
'.',
parse_label,
'.',
parse_component,
delimited(space0, '=', space0),
parse_number,
)
.map(
|(label, _dot, point_label, _dot2, component, _equals, value)| {
FixObjectPointComponent {
object: label,
value,
point: point_label,
point_component: component,
}
},
)
.parse_next(i)
}

fn parse_number(i: &mut &str) -> WResult<f64> {
fn myint(input: &mut &str) -> WResult<f64> {
digit1
Expand Down
1 change: 1 addition & 0 deletions test_cases/arc_radius/problem.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ point p
arc a
a.center.x = 0
a.center.y = 0
a.a.x = 0
arc_radius(a, 5)

# guesses
Expand Down
Loading