Skip to content

Commit b132776

Browse files
committed
Milestone 3 submission
1 parent 521f17d commit b132776

File tree

6 files changed

+536
-85
lines changed

6 files changed

+536
-85
lines changed

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ set(unittest_src
3535
# EDIT
3636
# add source for any TUI modules here
3737
set(tui_src
38-
)
38+
layout_parameters.h
39+
)
3940

4041
# EDIT
4142
# add source for any GUI modules here

environment.cpp

Lines changed: 40 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,39 @@ Expression make_range(const std::vector<Expression> & args)
599599
return Expression(results);
600600
};
601601

602+
/*
603+
* (apply <procedure> <list>)
604+
* The built-in binary procedure apply has two arguments. The first argument
605+
* is a procedure, the second a list. It treats the elements of the list
606+
* as the arguments to the procedure, returning the result after evaluation.
607+
*/
608+
Expression apply(const std::vector<Expression> & args)
609+
{
610+
//stub
611+
std::vector<Expression> results;
612+
613+
614+
615+
616+
return Expression(results);
617+
};
618+
619+
/*
620+
* (map <procedure> <list>)
621+
* The built-in binary procedure map is similar to apply, but treats each
622+
* entry of the list as a separate argument to the procedure, returning a
623+
* list of the same size of results.
624+
*/
625+
Expression map(const std::vector<Expression> & args)
626+
{
627+
//stub
628+
std::vector<Expression> results;
629+
630+
631+
632+
633+
return Expression(results);
634+
};
602635

603636

604637
/*
@@ -632,89 +665,14 @@ Expression discrete_plot(const std::vector<Expression> & args)
632665
Expression::List data = args[0].asList();
633666
Expression::List options = args[1].asList();
634667

635-
/*--- Declare Default Layout Parameters ---*/
636-
double N = 20; // Scale for the N x N bounding rect
637-
double A = 3; // Vertical offset distance for title and axes labels
638-
double B = 3; // Horizontal offset distance for title and axes labels
639-
double C = 2; // Vertical offset distance for tick labels
640-
double D = 2; // Horizontal offset distance for tick labels
641-
double P = 0.5; // Size of points
642-
double txtScale = 1; // Scaling factor for all Text
643-
644-
/*--- Read and process each Data List entry ---*/
645-
for(auto & point : data){
646-
// Each Data entry must a List of 2 Numbers or error
647-
if(point.isHeadList() && (point.asList().size() == 2)){
648-
if(point.asList()[0].isHeadNumber() && point.asList()[1].isHeadNumber()){
649-
650-
/*--- Keep track of the max and min x and y values ---*/
651-
652-
// Create and add a Point graphic item to result
653-
Expression item = make_list(point.asList());
654-
item.setProperty("\"object-name\"", Expression(Atom("\"point\"")));
655-
item.setProperty("\"size\"", Expression(Atom(P)));
656-
result.push_back(item);
657-
}
658-
else{
659-
throw SemanticError("Error: found invalid Data point");
660-
}
661-
}
662-
else{
663-
throw SemanticError("Error: found invalid Data point");
664-
}
668+
try {
669+
Expression::List temp = Expression::makeDiscretePlot(data, options);
670+
result = temp;
671+
}
672+
catch (const SemanticError & ex) {
673+
throw ex; // Re-throw error? Idk if this helps or not
674+
return EXIT_FAILURE;
665675
}
666-
667-
/*--- Setup graphical layout data ---*/
668-
// Make some sort of function for this
669-
670-
/*--- Read and process each Options List entry ---*/
671-
for(auto & option : options){
672-
// Each Options entry must a List of 2 Expressions
673-
if(option.isHeadList() && (option.asList().size() == 2)){
674-
if(option.asList()[0].isHeadString()){
675-
676-
std::string name = option.asList()[0].asString();
677-
Expression value = option.asList()[1];
678-
679-
// Check which(if any) plotting option to assign
680-
if(name == "title"){
681-
// Title value must be a String
682-
if(value.isHeadString()){
683-
// Create and add a Text graphic item to result
684-
Expression item(value);
685-
item.setProperty("\"object-name\"", Expression(Atom("\"text\"")));
686-
item.setProperty("\"text-scale\"", Expression(Atom(txtScale)));
687-
// Set location properties
688-
689-
result.push_back(item);
690-
}
691-
}
692-
else if(name == "abscissa-label"){
693-
// stub
694-
}
695-
else if(name == "ordinate-label"){
696-
// stub
697-
}
698-
else if(name == "text-scale"){
699-
// Must be a positive Number, defaults to 1
700-
if(value.isHeadNumber() && (value.head().asNumber() > 0)){
701-
txtScale = value.head().asNumber();
702-
}
703-
}
704-
else{
705-
throw SemanticError("Error: found invalid Option");
706-
}
707-
// end selection
708-
}
709-
else{
710-
throw SemanticError("Error: found invalid Option");
711-
}
712-
}
713-
else{
714-
throw SemanticError("Error: found invalid Option");
715-
}
716-
} // end for
717-
718676
}
719677
else{
720678
throw SemanticError("Error: an argument to discrete-plot is not a list");

0 commit comments

Comments
 (0)