Skip to content

Allow Box to be defined using center of box as origin #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -803,8 +803,8 @@ public override MemoryReader.Converter<double> GetMemoryConverter(MemoryReader m

class UserBoxCoords : BoxLoader
{
public enum CoordsX { LR, LW, WR };
public enum CoordsY { BT, BH, HT };
public enum CoordsX { LR, LW, WR, CW };
public enum CoordsY { BT, BH, HT, CH };

public class LoaderCreator : ExpressionLoader.LoaderCreator
{
Expand Down Expand Up @@ -893,10 +893,20 @@ public override ExpressionDrawer.IDrawable Load(MemoryReader mreader, Debugger d
maxP[0] = x1 + x2; // r = l + w
else if (coordsX == CoordsX.WR)
minP[0] = x2 - x1; // l = r - w
else if (coordsX == CoordsX.CW)
{
minP[0] = x1 - x2 / 2.0; // l = c - w/2
maxP[0] = x1 + x2 / 2.0; // r = c + w/2
}
if (coordsY == CoordsY.BH)
maxP[1] = y1 + y2; // t = b + h
else if (coordsY == CoordsY.HT)
minP[1] = y2 - y1; // b = t - h
else if (coordsY == CoordsY.CH)
{
minP[1] = y1 - y2 / 2.0; // b = c - h/2
maxP[1] = y1 + y2 / 2.0; // t = c + h/2
}

return new ExpressionDrawer.Box(minP, maxP);
}
Expand All @@ -920,12 +930,27 @@ public override MemoryReader.Converter<double> GetMemoryConverter(MemoryReader m
else if (coordsX == CoordsX.WR) // WXRX
values[offset + 0] = values[offset + 2]
- values[offset + 0]; // l = r - w
else if (coordsX == CoordsX.CW) // CXWX
{
values[offset + 2] = values[offset + 0]
+ values[offset + 2]/2.0; // r = c + w/2.0
values[offset + 0] = values[offset + 0]
- values[offset + 2]/2.0; // l = c - w/2.0
}

if (coordsY == CoordsY.BH) // XBXH
values[offset + 3] = values[offset + 1]
+ values[offset + 3]; // t = b + h
else if (coordsY == CoordsY.HT) // XHXT
values[offset + 1] = values[offset + 3]
- values[offset + 1]; // b = t - h
else if (coordsX == CoordsX.CW) // XCXW
{
values[offset + 3] = values[offset + 1]
+ values[offset + 3]/2.0; // t = c + h/2.0
values[offset + 1] = values[offset + 1]
- values[offset + 3]/2.0; // t = c - h/2.0
}
});
}

Expand Down Expand Up @@ -1967,6 +1992,8 @@ private static bool ReloadUserTypes(Loaders loaders,
elRight = Util.GetXmlElementByTagName(elParent, "Right");
if (elTop == null)
elTop = Util.GetXmlElementByTagName(elParent, "Top");
var elCenterX = Util.GetXmlElementByTagName(elParent, "CenterX");
var elCenterY = Util.GetXmlElementByTagName(elParent, "CenterY");
var elWidth = Util.GetXmlElementByTagName(elParent, "Width");
var elHeight = Util.GetXmlElementByTagName(elParent, "Height");

Expand All @@ -1976,23 +2003,22 @@ private static bool ReloadUserTypes(Loaders loaders,
string exprY2 = null;
UserBoxCoords.CoordsX coordsX = UserBoxCoords.CoordsX.LR;
UserBoxCoords.CoordsY coordsY = UserBoxCoords.CoordsY.BT;
if (elCoordinates != null)

if (elLeft != null && elRight != null)
{
if (elLeft != null && elRight != null)
{
exprX1 = elLeft.InnerText;
exprX2 = elRight.InnerText;
coordsX = UserBoxCoords.CoordsX.LR;
}
exprX1 = elLeft.InnerText;
exprX2 = elRight.InnerText;
coordsX = UserBoxCoords.CoordsX.LR;
}

if (elBottom != null && elTop != null)
{
exprY1 = elBottom.InnerText;
exprY2 = elTop.InnerText;
coordsY = UserBoxCoords.CoordsY.BT;
}
if (elBottom != null && elTop != null)
{
exprY1 = elBottom.InnerText;
exprY2 = elTop.InnerText;
coordsY = UserBoxCoords.CoordsY.BT;
}
else // elCoordinatesDimensions != null

if (elCoordinatesDimensions != null)
{
if (elLeft != null && elWidth != null)
{
Expand All @@ -2006,6 +2032,12 @@ private static bool ReloadUserTypes(Loaders loaders,
exprX2 = elRight.InnerText;
coordsX = UserBoxCoords.CoordsX.WR;
}
else if (elCenterX != null && elWidth != null)
{
exprX1 = elCenterX.InnerText;
exprX2 = elWidth.InnerText;
coordsX = UserBoxCoords.CoordsX.CW;
}

if (elBottom != null && elHeight != null)
{
Expand All @@ -2019,6 +2051,12 @@ private static bool ReloadUserTypes(Loaders loaders,
exprY2 = elTop.InnerText;
coordsY = UserBoxCoords.CoordsY.HT;
}
else if (elCenterY != null && elHeight != null)
{
exprY1 = elCenterY.InnerText;
exprY2 = elHeight.InnerText;
coordsY = UserBoxCoords.CoordsY.CH;
}
}

if (exprX1 != null && exprX2 != null && exprY1 != null && exprY2 != null)
Expand Down
4 changes: 2 additions & 2 deletions examples/cpp.xml
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@
-->
<Box Type="MyBox2" Id="MyBox2" CoordinateSystem="Cartesian" Unit="None">
<CoordinatesDimensions>
<MinX>left</MinX> <!-- or <Left> or <MaxX> or <Right> -->
<MinY>bottom</MinY> <!-- or <Bottom> or <MaxY> or <Top> -->
<MinX>left</MinX> <!-- or <Left> or <MaxX> or <Right> or <CenterX>-->
<MinY>bottom</MinY> <!-- or <Bottom> or <MaxY> or <Top> or <CenterY> -->
<Width>width</Width>
<Height>height</Height>
</CoordinatesDimensions>
Expand Down