public RelativeEdgePosition Cross(EdgeInterface e, out double t) { double s = 0.0; RelativeEdgePosition crossType = e.Intersect(this, out s); if ((crossType == RelativeEdgePosition.COLLINEAR) || (crossType == RelativeEdgePosition.PARALLEL)) { t = 0.0; return(crossType); } if ((s < 0.0) || (s > 1.0)) { t = 0.0; return(RelativeEdgePosition.SKEW_NO_CROSS); } Intersect(e, out t); if ((0.0 <= t) && (t <= 1.0)) { return(RelativeEdgePosition.SKEW_CROSS); } else { return(RelativeEdgePosition.SKEW_NO_CROSS); } }
/// <summary> /// swaps left and right, leaves the other options as they are /// </summary> /// <param name="?"></param> /// <returns></returns> public static RelativeEdgePosition SwapLeftRight(RelativeEdgePosition startPosition) { if (startPosition == RelativeEdgePosition.Left) { return(RelativeEdgePosition.Right); } if (startPosition == RelativeEdgePosition.Right) { return(RelativeEdgePosition.Left); } return(startPosition); }
/// <summary> /// swaps top and bottom, leaves the other options as they are /// </summary> /// <param name="?"></param> /// <returns></returns> public static RelativeEdgePosition SwapTopBottom(RelativeEdgePosition startPosition) { if (startPosition == RelativeEdgePosition.Top) { return(RelativeEdgePosition.Bottom); } if (startPosition == RelativeEdgePosition.Bottom) { return(RelativeEdgePosition.Top); } return(startPosition); }
/// <summary> /// returns the opposite edge /// </summary> /// <param name="relativeEdge"></param> /// <returns></returns> public static RelativeEdgePosition GetOppositeRelativeEdge(RelativeEdgePosition relativeEdge) { switch (relativeEdge) { case RelativeEdgePosition.Bottom: return(RelativeEdgePosition.Top); case RelativeEdgePosition.Top: return(RelativeEdgePosition.Bottom); case RelativeEdgePosition.Left: return(RelativeEdgePosition.Right); case RelativeEdgePosition.Right: return(RelativeEdgePosition.Left); default: return(RelativeEdgePosition.NotExisting); } }
public override void Test() { this.scene = new List <ViewItemInterface>(); edge0 = new Edge(10, 10, 100, 50); edge1 = new Edge(100, 5, 5, 100); this.scene.Add(new EdgeView(edge0)); this.scene.Add(new EdgeView(edge1)); double t; RelativeEdgePosition pos = edge0.Intersect(edge1, out t); Point crossPoint = null; if (pos != RelativeEdgePosition.PARALLEL && pos != RelativeEdgePosition.COLLINEAR) { crossPoint = new Point(edge0.Point(t)); this.scene.Add(new PointView(crossPoint)); } }
public double Applicable(Cube cube, RelativeSidePosition side) { RelativeSidePosition relativeSidePosition; RelativeEdgePosition relativeEdgePosition; cube.GetRelativeEdgePosition(cube.Top.CubeSide, cube.Top.Color, cube.Top.GetRelativeSide(side).Color, out relativeSidePosition, out relativeEdgePosition); RelativeSidePosition expectedSidePositon = Helper.GetRotationNeutralRelativeSidePosition(cube.Top, RelativeSidePosition.Left, Helper.ConvertRelativeSidePositionToRelativeEdgePosition(side)); RelativeEdgePosition expectedEdgePosition = RelativeEdgePosition.Right; if (relativeSidePosition == expectedSidePositon && relativeEdgePosition == expectedEdgePosition) { return(1); } else { return(0); } }
public double Applicable(Cube cube, RelativeSidePosition side) { RelativeSidePosition relativeSidePosition; RelativeEdgePosition relativeEdgePosition; cube.GetRelativeEdgePosition(cube.Top.CubeSide, cube.Top.Color, cube.Top.GetRelativeSide(side).Color, out relativeSidePosition, out relativeEdgePosition); RelativeSidePosition expectedSidePositon = Helper.GetRotationNeutralRelativeSidePosition(cube.Top, RelativeSidePosition.Opposite, Helper.ConvertRelativeSidePositionToRelativeEdgePosition(side)); RelativeEdgePosition expectedEdgePosition = Helper.GetRelativeEdge(Helper.ConvertRelativeSidePositionToRelativeEdgePosition(side), RelativeEdgePosition.Left); expectedEdgePosition = Helper.SwapTopBottom(expectedEdgePosition); //because of invertion of opposite side if (relativeSidePosition == expectedSidePositon && relativeEdgePosition == expectedEdgePosition) { return(1); } else { return(0); } }
public double Applicable(Cube cube, RelativeSidePosition side) { RelativeSidePosition relativeSidePosition; RelativeEdgePosition relativeEdgePosition; cube.GetRelativeEdgePosition(cube.Top.CubeSide, cube.Top.Color, cube.Top.GetRelativeSide(side).Color, out relativeSidePosition, out relativeEdgePosition); RelativeSidePosition expectedSidePositon = RelativeSidePosition.Opposite; RelativeEdgePosition expectedEdgePosition = Helper.ConvertRelativeSidePositionToRelativeEdgePosition(side); expectedEdgePosition = Helper.SwapTopBottom(expectedEdgePosition); //because on the opposite side bottom and top are inverted if (relativeSidePosition == expectedSidePositon && relativeEdgePosition == expectedEdgePosition) { return(1); } else { return(0); } }
/// <summary> /// treats the cube as if it were rotated so that the relativeEdgePosition is bottom /// and then returns the side that is given by relativeSidePosition /// </summary> /// <param name="startSide"></param> /// <param name="relativeSidePosition"></param> /// <param name="relativeEdgePosition"></param> /// <returns></returns> public static Side GetRotationNeutralRelativeSide(Side startSide, RelativeSidePosition relativeSidePosition, RelativeEdgePosition relativeEdgePosition) { if (relativeEdgePosition == RelativeEdgePosition.Left) { if (relativeSidePosition == RelativeSidePosition.Left) { return(startSide.Top); } if (relativeSidePosition == RelativeSidePosition.Right) { return(startSide.Bottom); } if (relativeSidePosition == RelativeSidePosition.Bottom) { return(startSide.Left); } if (relativeSidePosition == RelativeSidePosition.Top) { return(startSide.Right); } if (relativeSidePosition == RelativeSidePosition.Opposite) { return(startSide.Opposite); } if (relativeSidePosition == RelativeSidePosition.Self) { return(startSide); } } if (relativeEdgePosition == RelativeEdgePosition.Right) { if (relativeSidePosition == RelativeSidePosition.Left) { return(startSide.Bottom); } if (relativeSidePosition == RelativeSidePosition.Right) { return(startSide.Top); } if (relativeSidePosition == RelativeSidePosition.Bottom) { return(startSide.Right); } if (relativeSidePosition == RelativeSidePosition.Top) { return(startSide.Left); } if (relativeSidePosition == RelativeSidePosition.Opposite) { return(startSide.Opposite); } if (relativeSidePosition == RelativeSidePosition.Self) { return(startSide); } } if (relativeEdgePosition == RelativeEdgePosition.Top) { if (relativeSidePosition == RelativeSidePosition.Left) { return(startSide.Right); } if (relativeSidePosition == RelativeSidePosition.Right) { return(startSide.Left); } if (relativeSidePosition == RelativeSidePosition.Bottom) { return(startSide.Top); } if (relativeSidePosition == RelativeSidePosition.Top) { return(startSide.Bottom); } if (relativeSidePosition == RelativeSidePosition.Opposite) { return(startSide.Opposite); } if (relativeSidePosition == RelativeSidePosition.Self) { return(startSide); } } if (relativeEdgePosition == RelativeEdgePosition.Bottom) { if (relativeSidePosition == RelativeSidePosition.Left) { return(startSide.Left); } if (relativeSidePosition == RelativeSidePosition.Right) { return(startSide.Right); } if (relativeSidePosition == RelativeSidePosition.Bottom) { return(startSide.Bottom); } if (relativeSidePosition == RelativeSidePosition.Top) { return(startSide.Top); } if (relativeSidePosition == RelativeSidePosition.Opposite) { return(startSide.Opposite); } if (relativeSidePosition == RelativeSidePosition.Self) { return(startSide); } } return(null); }
/// <summary> /// gets the edge relative to startEdge according to relativeEdge /// e.g. startEdge = Left and relativeEdge = Top, result = Right /// </summary> /// <param name="startEdge"></param> /// <param name="relativeEdge"></param> /// <returns></returns> public static RelativeEdgePosition GetRelativeEdge(RelativeEdgePosition startEdge, RelativeEdgePosition relativeEdge) { if (relativeEdge == RelativeEdgePosition.Bottom) { return(startEdge); } if (relativeEdge == RelativeEdgePosition.Left) { if (startEdge == RelativeEdgePosition.Bottom) { return(RelativeEdgePosition.Left); } if (startEdge == RelativeEdgePosition.Left) { return(RelativeEdgePosition.Top); } if (startEdge == RelativeEdgePosition.Top) { return(RelativeEdgePosition.Right); } if (startEdge == RelativeEdgePosition.Right) { return(RelativeEdgePosition.Bottom); } } if (relativeEdge == RelativeEdgePosition.Top) { if (startEdge == RelativeEdgePosition.Bottom) { return(RelativeEdgePosition.Top); } if (startEdge == RelativeEdgePosition.Left) { return(RelativeEdgePosition.Right); } if (startEdge == RelativeEdgePosition.Top) { return(RelativeEdgePosition.Bottom); } if (startEdge == RelativeEdgePosition.Right) { return(RelativeEdgePosition.Left); } } if (relativeEdge == RelativeEdgePosition.Right) { if (startEdge == RelativeEdgePosition.Bottom) { return(RelativeEdgePosition.Right); } if (startEdge == RelativeEdgePosition.Left) { return(RelativeEdgePosition.Bottom); } if (startEdge == RelativeEdgePosition.Top) { return(RelativeEdgePosition.Left); } if (startEdge == RelativeEdgePosition.Right) { return(RelativeEdgePosition.Top); } } return(RelativeEdgePosition.NotExisting); }
/// <summary> /// treats the cube as if it were rotated so that the relativeEdgePosition is bottom /// and then returns the side relation of the start side and the relative side /// </summary> /// <param name="startSide"></param> /// <param name="relativeSidePosition"></param> /// <param name="relativeEdgePosition"></param> /// <returns></returns> public static RelativeSidePosition GetRotationNeutralRelativeSidePosition(Side startSide, RelativeSidePosition relativeSidePosition, RelativeEdgePosition relativeEdgePosition) { return(GetSideRelation(startSide.CubeSide, GetRotationNeutralRelativeSide(startSide, relativeSidePosition, relativeEdgePosition).CubeSide)); }
/// <summary> /// finds the position of that edge /// </summary> /// <param name="startSide"></param> /// <param name="primaryColor">determines to which of the 2 adjacent sides the resulting position is relative to</param> /// <param name="secondaryColor"></param> /// <param name="relativeSidePosition">contains the relative side to the startSide</param> /// <param name="relativeEdgePosition">contains the edge relative to the relative side</param> public void GetRelativeEdgePosition(Sides startSide, Brush primaryColor, Brush secondaryColor, out RelativeSidePosition relativeSidePosition, out RelativeEdgePosition relativeEdgePosition) { //default to satisfy the compiler, should never occur relativeSidePosition = RelativeSidePosition.NotExisting; relativeEdgePosition = RelativeEdgePosition.NotExisting; foreach (var side in CubeSides) { var relativePosition = side.GetRelativeEdgePosition(primaryColor, secondaryColor); if (relativePosition != RelativeEdgePosition.NotExisting) { relativeEdgePosition = relativePosition; relativeSidePosition = Helper.GetSideRelation(startSide, side.CubeSide); //normally, to create a real relative position of the edge, here would be a need for special handling of sides and relative sides combinations //but this would introduce a lot of special handling in other places too, which is unnecessary //therefore, the relativeEdgePosition is relative to the side //e.g. in a solved cube: when back (green) is the startside, the edge (primary white, secondary blue) is the top side relative to back //because the edge is relative to the top side, the resulting relative edge position is bottom //the view of the relative edge position is as if the cube is not turned break; //after the position is found, there cannot be another one } } }
public Brush GetSecondaryEdgeColor(RelativeEdgePosition edgePosition) { //these 2 (top, bottom) sides are special cases, because they change the column/row alignment with other sides if (CubeSide == Sides.Top) { switch (edgePosition) { case RelativeEdgePosition.Left: return(left.GetRow(0)[1]); case RelativeEdgePosition.Right: return(right.GetRow(0)[1]); case RelativeEdgePosition.Top: return(top.GetRow(0)[1]); case RelativeEdgePosition.Bottom: return(bottom.GetRow(0)[1]); } } if (CubeSide == Sides.Bottom) { switch (edgePosition) { case RelativeEdgePosition.Left: return(left.GetRow(2)[1]); case RelativeEdgePosition.Right: return(right.GetRow(2)[1]); case RelativeEdgePosition.Top: return(top.GetRow(2)[1]); case RelativeEdgePosition.Bottom: return(bottom.GetRow(2)[1]); } } else { if (edgePosition == RelativeEdgePosition.Left) { return(left.GetColumn(2)[1]); } if (edgePosition == RelativeEdgePosition.Right) { return(right.GetColumn(0)[1]); } if (edgePosition == RelativeEdgePosition.Top) { //only has to handle the remaining 4 cases (top and bottom are handled before) switch (CubeSide) { case Sides.Front: return(top.GetRow(2)[1]); case Sides.Left: return(top.GetColumn(0)[1]); case Sides.Back: return(top.GetRow(0)[1]); case Sides.Right: return(top.GetColumn(2)[1]); } } if (edgePosition == RelativeEdgePosition.Bottom) { //only has to handle the remaining 4 cases (top and bottom are handled before) switch (CubeSide) { case Sides.Front: return(bottom.GetRow(0)[1]); case Sides.Left: return(bottom.GetColumn(0)[1]); case Sides.Back: return(bottom.GetRow(2)[1]); case Sides.Right: return(bottom.GetColumn(2)[1]); } } } return(null); //default case to satisfy the compiler, should never occur }